Skip to content

annkonna/MMOGamePart3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

MMOGamePart3

Steps to Execute Program (Web-Web):

  1. Bring up the PROJECT directory into an IDE such as IntelliJ or PyCharm as a project.
  2. The Part3 subdirectory contains the final source files.
  3. The src/model/surviv_model.py has the code for the webserver. Open that file in the IDE.
  4. The IDE will install any libraries needed (bottle webserver library, pygame library, etc.). Python 3.7 (or higher most likely) may have to be setup under Project Structure (Module Libraries).
  5. Open src/controller/surviv_controller.py in the IDE and the IDE will install json and requests libraries, if not already installed.
  6. Run src/model/surviv_model.py to start the webserver.
  7. Open src/webapp/welcome.html in a web browser to bring up the Welcome Page. Type in a name and click the Start Game button to play the game.
  8. To see the MMO (Massively Multiplayer Online) feature, open another browser window and bring up a second Welcome Page, type a name, and click the Start Game button to bring up the 2nd player. The first window and second window show both players and the game finishes when one of them survive for 30 seconds.

Steps to Execute Program (Desktop-Desktop & Desktop-Web):

In step 7, instead of opening the welcome.html page above, run the surviv_main.py file in the root folder to bring up the Desktop UI.

Architecture and Concepts:

The Project implements an MMO (Massively-Multiplayer-Online) game.

Part 2 was a Desktop Single-user game that had the following architectural components using the MVC-pattern:

  1. Src\surviv_main.py – this create the View and then calls the main_loop() method. This is the main program. Note: The name is a special variable that evaluates to main, if surviv_main.py is run. If the file is being imported by another file which is being run, the name variable evaluates to the filename and so the if condition is not satisfied and so nothing is run. It is a way to have files in the project to be run as the main module – useful to test a file separately from the whole project.
  2. Src\View\surviv_view.py – a. The constructor init in ‘surviv_view.py’ has the initialization code for PyGame UI. Among other things, it does initialize the display caption, width, height, and position. b. The main_loop() method has two event loops (while not done… - these are setup to operate at speeds up to 20 frames per second – line 80 and 102) - c. the first loop is for the Welcome Screen and the second for the Game Screen. It uses a Controller object (game_controller) to process events (user input – arrow keys, window close, etc.).
    d. The draw_welcome_frame and draw_game_frame methods contain the code to draw those two screens. The draw_game_frame also updates the redzone position by moving it 15 pixels to the left each time the method is called – this is how the redzone animates to the Left. e. The time spent by the player in the redzone and the elapsed time are tracked to show the text output that shows survival time in the game_logic method.
  3. Src\Controller\surviv_controller.py – a. The process_game_events method updates the player position in response to Arrow Keys. b. The process_welcome_events method looks for the MOUSEBUTTONUP event type and checks to see whether it was pressed while on the ‘Play Solo’ button.
  4. Src\Model\surviv_model.py – a. The Model consists of three classes – Game, Player, and Redzone. The Game represents the Model for the whole game and it has a Player object and a Redzone object to keep track of the player and redzone positions. b. Game Class - The Controller interacts with the Model using a Game object which is created during Controller constructor Initialization (Line 10) – it takes the player’s image size and the width of the screen as constructor parameters. The Game Object in turn creates a Player and Redzone objects in its constructor – those two take the player’s image size and the display width respectively as their constructor parameters. c. Player Class – it contains the logic to hold the position of the player on the game screen. d. Redzone – it contains the logic to hold the position of the redzone on the game screen.

Part 3 introduced multi-player along with Desktop and Web-UIs using the following architectural components:

  1. Bottle Web Server between the controller and the model implemented in Model\surviv_model.py.
  2. JavaScript based front-end equivalent to the Pygame UI used for the desktop implemented in welcome.html and game.html under WebApp directory.
  3. Note: The desktop UI using Python pygame library and the web UI using JavaScript were modeled from sample programs (see the sample projects in this directory).
  4. Communicating using JSON and network sockets from Python Controller to the Model for the Desktop UI.
  5. Communicating using JSON and AJAX from JS Controller to the Model for the Web UI.
  6. Note: changing any of the Javascript etc. files that the html accesses can result in the webserver still using the old files due to browser caching. The issue can be avoided by forcing the browser to do a “hard refresh” - Windows: Ctrl+F5, Mac: Cmd+Shift+R, Linux: Ctrl+Shift+R. Also, use “debug=True, reloader=True” as additional bottle.run parameters when developing code.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages