Skip to content

Technical design

azziliz edited this page May 9, 2016 · 1 revision

General design

  • The game uses a client/server architecture.
    • The client is a single-page application that runs inside a web browser.
      • Targeted browsers are Chrome/Desktop, Edge/Desktop, Firefox/Desktop, Chrome/Android, Safari/iOS.
        • The primary objective is Chrome/Desktop compatibility.
      • It uses AJAX to send HTTP requests to the server.
      • The request payload and the server response are JSON strings.
    • The server is a Node.js application.
      • It is intended to be standalone (no package, no "npm install" required).
      • It doesn't have any dependency with third-party modules.

Code structure

  • Game objects (characters, levels, ...) are modeled by javascript classes. Each class is in a separate file.
  • Classes code is designed to be shared between the client and the server.
    • This implies that the code cannot use "module.exports" or call the "require" function, as it would break the compatibility with clients.
  • Getting the classes on client side is just a matter of downloading the files:
    • <script src="src/class1.js"></script>
    • <script src="src/class2.js"></script>
    • ...
  • On server side, as the classes do not export anything, we cannot require them.
    • To load them without require and to resolve dependencies between classes, we chose to use the Node VM.
      • A single context is created and classes are added one by one inside it with a call to vm.runInContext.
      • The first class to be loaded is "GameEngine". This enables the creation of an instance of it just after.
      • The instance, named "gameEngine" is then added to the context, which creates a closure for subsequent classes.

Clone this wiki locally