Implementation Overview - mmcnicol/StratConClone GitHub Wiki

implemented using processing.js

the code files are in the root directory.

the "images" sub directory contains sub directories for images of size 16x16, 32x32, and 48x48. The current size of a square or cell in the game map is 48x48 (including the grid lines).

the "docs" sub directory contains some documentation and images which I found via google when doing research for this project.

file main.pde contains the setup logic, the processing.js draw loop, and some classes which I've yet to decide where to put other than in here.

the other .pde file names should be intuitive. they were created to avoid the code being in one big file.

GAME ENGINE

file game-engine.pde contains class cGameEngine. This takes care of the following (at a high-level):

  • game day number

  • current player and player turns

  • human player 1 keyboard commands

  • currently selected unit/city

  • enables each player to move all units that have moves left each game day

  • when player 1 is human, the next unit with moves left that game day is highlighted/animated

  • at the end of a game day, player units moved left are reset and player city production advances

  • checks for game over

KEYBOARD

file keyboard.pde uses processing.js standard function keyPressed() to react to certain keyboard events, as follows:

"N": Skip (unit)

"S": Sleep (unit)

"R": Random (useful for instructing a unit to move at random. the ComputerAI logic kicks in, so for example a unit will try to clear any fog-of-war cells nearby, and a fighter will return to a city before running out of fuel.)

"M": Stack Move (one or more units)

"W": Wake (one or more units)

To use any of these, first press the key, then click on the unit.

MOUSE

file mouse.pde implements the following processing.js standard functions: mouseMoved(), mousePressed(), mouseReleased(), mouseDragged(), which processing.js calls automatically when the associated events occur.

the logic in this file handles the following (at a high-level):

  • if a dialogue is showing, the mouse coordinates are passed to the appropriate dialogue handleEvent() function.

  • (prevent human player 1 moving units when computer player 2 is moving)

  • check if user has clicked on the panel for "selected city" (which contains a button)

  • check if user clicked on scroll bar

  • check if user clicked on a unit

  • check if user clicked & dragged a unit

PANEL

a "panel" is used to display information. it can optionally contain clickable buttons.

file panel.pde handles display of the panels which appear below the game map and on the right had side. events are also passed on where a panel contains a clickable item.

  • cPanel is the abstract base class. the other classes in this file extend this abstract base class.

  • cPanel1 displays mouse/cursor grid location and screen coordinates.

  • cPanel2 displays current player.

  • cPanelSelectedUnit displays information about the currently selected unit.

  • cPanelSelectedCity displays information about the currently selected city.

  • cPanelMap displays a small map of the generated world.

DIALOGUE

a dialogue is like a modal window. the game pauses until the dialogue is closed.

file dialogue.pde contains the following classes:

  • cDialogue

  • cDialogueCityProduction

  • cDialogueStartup

  • cDialogueSurrender