Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Link: https://github.com/sfsu-csc-413-spring-2018/term-project-team-d.git
Project Introduction:
Create game program with java graphics and GUI. The first game is tank game which involves
two tanks with fire power to break down destructible wall and to wear down the opponent. The
second game is Galactic game which reuses components created from in the first game.
1. Develop game objects with Sprite and Animation classes to support game components.
2. Develop collision property for game objects not to cross each other and outside game
buffer.
3. Develop game buffer to store game objects for updates and repaints.
4. Develop game clock as an observable to run a thread with to notify game objects
observers for constant updates.
5. Develop game views to draw game buffer images per requirements.
6. Develop control listener to control tank action according to the keyboard input.
7. Develop game map with destructible and indestructible walls.
8. Develop network socket connection with main console input.
9. Develop control messages to be sending through network socket.
10. Develop network listener running a thread to take in control messages for tank actions.
11. Develop Galactic Game main program with background image and initial game objects
with upgrade condition.
12. Develop Galactic game view with buffer image.
13. Develop constant flying objects of rocket and its behavior with stations and asteroids.
14. Develop launch listener to control the landing behavior of the rocket.
Terminal shell with Github repository command including javac and java command for
compiling and execution. Locally edited in JDK NetBeans IDE 8.2.
1. Develop game objects with Sprite and Animation, store the pitch frame and related image
to be painted for destructible and indestructible walls, tanks, bullets, and explosions.
2. Develop intersect methods to determine if an object got hit and needs to be disappear
while repaint.
3. Develop collision property for game objects not to cross each other and outside game
buffer.
4. Develop game buffer to store game objects for updates and repaints. It repaints the
background tile before repainting updated objects.
5. Develop game clock as an observable to run a thread with to notify game objects
observers for constant updates.
6. Develop game views to draw game buffer images per requirements: Two focused game
view to center around the tank in focus with health bar and life score, and one scaled
game view to scale down the entire buffer image into minimap at the lower center of the
game view.
7. Develop control listener to control tank action according to the keyboard input, ADWS
Space for tank one and JLIK Return for tank two.
8. Develop game map with destructible and indestructible walls. Indestructible walls
surround the map to prevent the tank from crossing outside game buffer.
9. Develop network socket connection with main console input, where one input argument
initiates the server connection command, two input arguments initiates the client
connection command, and others as well as no arguments initiates simple local tank
game.
10. Develop control messages extending control listener to store and construct control
message to be sent through network socket.
11. Develop network listener running a thread to take in control messages to be stored and
read for tank actions.
12. Develop terminate flag to end the game with a dialog box.
13. Develop Galactic Game main program with background image and initial game objects
with upgrade condition where more asteroids are added for game going in higher level.
14. Develop Galactic game view which takes in game buffer frame for buffer image.
15. Develop constant flying objects of rocket and its behavior with stations and asteroids.
When intersecting with the station it can deliver through space bar and the station would
disappear. When intersecting with the asteroid it will end the game.
javac tank_network/NetworkMain.java
java tank_network/NetworkMain (simple tank game on local computer)
java tank_network/NetworkMain 9191 (network tank game server start)
java tank_network/NetworkMain IP_Address 9191 (network tank game client join)
javac mail/GalacticMailMain.java
java mail/GalacticMainMain
Assumption made
For the network tank game version the control message needs to act consistently to the same tank
on two end terminals so that the end users would see the same result when in the same game.
class Animation:
-animation_length: int
-animation_sprite: Sprite
-current_frame: BufferedImage
-frame_counter: int
-active: boolean
+setSprite(my_sprite: Sprite): void
-nextImage(): void
+update(): void
+getImage(): BufferedImage
+play(): void
+setFrame(frame: int)
+isActive(): boolean
class Sprite
-tile_length: int
-tile_count: int
-SpriteImages: BufferedImage []
+Sprite(image: BufferedImage, tile_count: int)
+getTile(tile: int): BufferedImage
+getTileCount(): int
package mail:
class GalacticMailMain
+drawView: GameView
+rocket: Rocket
+main(args[]: String): void
package tank_network:
class NetworkMain
+PATH: int
+tank1: Tank
+tank2: Tank
+drawView: GameView
+main(args[]: String): void
Implementation decisions
1. Instead of implementing game scene altogether as game objects inside game buffer, game
view is adapted as an observer for images created from game buffer.
2. It uses game clock as an observable constantly updating all the game objects.
3. In network tank game a control message is saved locally in order to clear tank control
message for communication purpose. It loses the benefit of constant movement from the
same keyboard status.
Code Organization
common/
GameBuffer: Holds all the game objects and views while running clock thread
Sprite: Breaks a Sprite into small images and gives access to them
Explosion: Subclass of GameObject. Plays the Explosion Animation and deletes itself
mail/
GalacticMailMain: Instantiates GameObjects and adds them to GameBuffer. Instantiates
LaunchListener for the Rocket GameObject. Starts the thread inside the GameBuffer and
runs the GameClock.
GalacticMailView: Subclass of GameView. Displays the original GameBuffer image
with game points.
LaunchListener: Modifies Rocket GameObject based on keyboard input
Rocket: Subclass of GameObject. Updates location based on controls. Intersects with
Asteroid will end the game. Intersects with Station will station the rocket until launch.
Station: Subclass of GameObject. Disappears after the Rocket launches from the
station.
Asteroid: Constantly moves in a direction and bounces with Stations and other Asteroids
tank_network/
FocusedGameView: Subclass of GameView. Crops the image provided by GameBuffer
around specified Tank location.
ScaledGameView: Subclass of GameView. Scales down the entire image provided by
GameBuffer and show it at specified location.
ControlListener: Modifies Tank GameObject based on keyboard input
Tank: Subclass of GameObject. Updates location based on controls. Shoots bullet, and
decrease health index when shot, respawns upon death, and terminates when no life left.
IndestructableTile: Subclass of GameObject. It can’t be moved or destroyed.
DestructableTile: Subclass of GameObject. It can’t be moved but can be destroyed.
Bullet: Subclass of GameObject. Moves in a direction and creates Explosion when
hitting objects.
NetworkMain: Instantiates GameObjects and adds them to GameBuffer. Instantiates
ControlMesssage and NetworkListener for the Tank GameObject. Starts the thread inside
the GameBuffer and runs the GameClock.
ControlMessage: Subclass of ControlListener. Used to send control message over the
network to be recceived by NetworkListener.
NetworkListener: Modifies Tank GameObject based on the control message received
from ControlMessage through specified network socket.
Explosion: Subclass of GameObject. Plays the Explosion Animation and deletes itself
Results/Conclusion
The main issues encountered is how and when the observers update their status. In network tank
game, a control message might be updated multiple times while the other end updates different
times. The solution is to clear the control status so that only one action is performed based on
one control message. In Galactic mail game, different orders in updates might affect the
appearance of the view, say, the rocket might be painted over by the station. Furthermore, the
status would lose its update track count when it was marked as inactive to be deleted during the
object array updates. A solution to it is to remove the observer of the rocket and to read it back
into observer queue.