Title: Networked Games Summary
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

Networked Games Summary

MVC, gameNet High Level

- Model View Controller (MVC) approach
- gameNet package - provided code that has the classes:
  - MyGame - Your Model class
  - MyGameInput - A class you define which contains the user inputs to be sent to the Game.
  - MyGameOutput - A class you define which contains the information sent from the Game for the User Interface to present to the user.
  - MyUserInterface - This class will contain the MVC "User Inputs Controller" and "Update View" code
  - MyMain - this class contains "main" and is responsible for connecting up all of the pieces.
- gameNet Architecture Chart views - block diagram and a Process and socket diagram view

gameNet interfaces

- In this set of notes, we present some code sketches of the MyGame, MyGameInput, MyGameOutput, MyUserInterface, and MyMain classes. We use a chat program as an example, because it is the simplest example we can do.
- MyGameInput and MyGameOutput can have almost anything, but must implement Serializeable.
- MyGame class must extend GameNet_CoreGame and will need to implement the "process" method. The process method will receive a MyGameInput parameter and must return a MyGameOutput object. It often will need to implement Serializeable (depending on the game design). This class contains the game logic.
- MyMain - contains main and starts the whole networked game up. MyMain must extend GameCreator and provide the method createGame(). Normally you don't need to do anything here, but copy a MyMain.java from some other Networked Game.
- MyUserInterface - This class contains your user interface. This class must implement GameNet_UserInterface which requires your class to have 2 methods:
  - startUserInterface - This method is called at the very beginning and passes in the "GamePlayer" object which is used for communicating with your networked game.
  - receivedMessage - This method is called to hand of a MyGameOutput object to the user interface. Typically this object contains information that needs to be drawn to the screen.

Tic Tac Toe

- This is the first of a series of examples using gameNet. The other examples can be found below. It is recommended that you pick the example that seems to most closely resemble the project that you wish to do and use it as a template.
- In particular, Tic Tac Toe has the following features:
  - It restricts the game to exactly 2 players
  - players alternate taking turns
  - An attempt was made to make the Tic-Tac-Toe specific logic reside in a separate module called TttLogic.java. The MyGame class mainly focussed on the gameNet issues and the generic idea of a game where we restricted to 2 players and the players need to alternate turns.

Rock, Paper, Scissors

- Rock Paper Scissors is the second example using gameNet. In this example we are restricted to 2 users, but the inputs can be received from the 2 users in any order. Once both users have made their input, we complete a "game round".

Chess with no brains

- This networked game gives you the starting point for a chess game. The code provided merely sets the board up and lets multiple players drag the pieces around. To make a better chess game, one could consider adding:
  - Restrict the game to 2 players
  - Have the players take turns
  - Restrict the pieces to legal chess moves ... the current code allows pieces to be moved anywhere
  - Provide capture logic
  - There are many other chess things that could be added to this game. A list of things can be found at the bottom of the lecture notes
- A technique called "Generic coordinates" is used to allow the chess boards to be different sizes on each user's screen

Quick Click - Threaded game

- In this game we start out with 20 disks bouncing around within your window. When a user clicks on a disk, he gets a point and the disk goes away. Once all of the disks have been clicked, we can see who clicked on the most disks. Then a "Restart" button can be clicked to start up a new game. This is the first example where we have objects moving on their own.
- In this game we can have any number of players. Players can join or leave the game whenever they wish.
- This program uses "generic coordinates" to allow users to have different sizes of screens.
- If your networked game will have things moving around on their own, Quick Click will show you how this can be done:
  - You will need to override the startGame method in GameNet_CoreGame in order to obtain your GameControl object and start any threads needed by your game.
  - Your overall MyGame class will likely implement Serializeable, but GameControl needs to be marked as "transient" which means that it shouldn't be sent across the network.
  - Your MyGame probably then needs to implement Runnable to provide a running thread. This thread can be the logic that can for example move "bouncing disks" around.
  - The GameControl method putMsgs can be called to send MyGameOutput objects to the user interface as needed.

Pong

- This networked game uses gameNet to create a 2 person Pong game. Like the Quick Click game above, this game demonstrates how to create games that have threads to support having objects moving around on their own.
- This game uses generic coordinates and restricts the number of users to no more than 2 players.

Networked Drawing Program

- This networked program is based on the Drawing program we developed in the Gui section of this class. However, in this program the drawing can show up on any number of users screens.
- Scribbling is very demanding on the Sockets and at some point too much scribbling will likely put gameNet into an overrload problem. I haven't had the time to track down the nature of the overload and how to avoid it.
- This example uses the "generic coordinate" approach so every user can have a different size screen.

Zip file of Networked Game Collection

- This zip file contains a project that contains all of the code to gameNet and all of the previously described networked games. Each game is in a separate package. The gameNet logic itself is also in a separate package. DO NOT USE gameNet_cloneable unless you discuss the ramifications of this with your instructor. In the "Networked Game/JH7" description you will find more words about when to consider gameNet_cloneable.

javaDoc generated documentation for gameNet

- This link provides you gameNet documentation generated by javaDoc (same tool that generates all of the normal Java API documentation). Note that this only shows you the public items that are part of gameNet.

Last Modified: December 20, 2014 9:00 PM