90 likes | 539 Vues
Overview of the Server. Server component listens for connections from Client appletsServer also validates all moves and keeps track of game dataServer sends game information to the clientsServer automatically restarts and listens for new connections after a game is complete.At present only one g
                
                E N D
1. Java Battleship Final Project
CSCI 2001-91
Jeff Fisher 
2. Overview of the Server Server component listens for connections from Client applets
Server also validates all moves and keeps track of game data
Server sends game information to the clients
Server automatically restarts and listens for new connections after a game is complete.
At present only one game can be played at one time 
3. Overview of the Client Client applet connects to the Server application
Client provides a graphical interface for the player
Client does some validation of its own to prevent erroneous moves
Client plays sounds and displays graphics during certain game events 
4. Basic Algorithm (Server) Application starts ->
Initializes variables ->
Binds to port 31337 and listens ->
Uses threads interact with clients after they connect ->
Main thread waits until end of game 
Player threads:
Have players place their ships ->
Wait until both have successfully placed ships ->
Take turns accepting input from the client and making validating gameplay moves ->
Update the client with information ->
Determine GameOver and inform client of the victor ->
Show the loser what ships he or she missed ->
Tell the server to listen for more connections 
5. Basic Algorithm (Client) Applet starts ->
Initializes variables and GUI ->
Shows intro splash ->
Solicits user for Server IP ->
Connect to Server ->
Allow player to place ships ->
Allow player to make moves on their turn ->
Plays sound effects ->
Processes messages from server until end of game ->
Shows endgame splash 
6. Packages/Techniques Used Packages java.net and java.io
Private Classes
Many arrays
Sounds and Graphics
A very large number of Swing components Signed Jar files
Multithreading
Mouse and Action Listeners
Timers
Lots and lots of trial and error 
7. Classes (Server) Class BattleShipServer
		Main class, extends JFrame, controls references to the other 	game objects and methods for them to manipulate one 	another.
Class Player
		Extends Thread, controls connection to a Battleship client, 	allows player to place ships and take turns.
Class Fleet
		Extends Object, contains information regarding a players fleet, 	contains references to Ship objects and an array that keeps 	track of grid data (hits, misses, water)
Class Ship
		Also extends Object, holds information about a specific ship 	and the squares that make it up, also keeps track of the overall 	status of the ship itself. 
8. Classes (Client) Class BattleShipClient
		Main class, extends JApplet, controls a 	pretty GUI, and communicates with the 	Battleship Server.
Class HelpFrame
		Provides a nice help window to explain 	the gameplay to a user. 
9. References Used Chapter on Networking in the text
		TicTacToe Sever/Client example
The Java Tutorial and API Docs
A Battleship Board Game
Numerous Internet Tutorials
Google!
Battlefield 1942
		For letting me borrow some sound effects and 	snippets of their intro movie