Documentation of the code - manjil21/Battleships GitHub Wiki
DeploymentController.vb
The DeploymentController controls the players actions during the deployment phase. Handles user input for the deployment phase of the game. This involves in selecting the ships, deloying ships, changing the direction of the ships to add, randomizing deployment, and then end the deployment.
DiscoveryController.vb
The battle phase is handled by the DiscoveryController. This file handles the input during the discovery phase of the game. And by clicking the mouse, it will attack a location.
EndingGameController.vb
The EndingGameController is responsible for managing the interactions at the end of the game by drawing the game screen and the win or lose state of the player. Handle the input during the end of the game. Any interactions will result in it reading in the highsSwinGame .
GameController.vb
The GameController.vb is responsible for controlling the game, managing user input, and displaying the current state of the game. This returns the current state of the game, indicating which screen is currently being used. Create an AI player based upon the _aiSetting. This will stop listening to the old game once a new game is started and listen to the game grids for any changes and redraws the screen when the grids change after the attacks are completed this displays a message plays and redraws the screen. Completes the deployment phase of the game and switches to the battle mode. This adds the players to the game before switching state. Then checks the attack result once the attack is completed.Move the game to a new state. The current state is maintained son that it can be returned to. End the current state and add in the new state then returning to the prior state. At the end it sets the difficulty for the next level of the game.
GameLogic.vb
This loads the resources and opens a new graphics window.
GameResources.vb
Gets an image loaded in the resources and the sound loaded in the resources. Resources class stores all of the Games Media Resources
GameState.vb
This represent the state of the Battleships game play.This is used to control the actions and view displayed to the player. The steps go as follow
- The player is viewing the main menu
- The player is viewing the game menu
- The player is looking at the high scores
- The player is altering the game settings
- Players are deploying their ships
- Players are attempting to locate each other’s ships
- One player has won, showing the victory screen
- At the end credits and terminate the game and the player will quit
HighScoreController.vb
Controls displaying and collecting high score data. Data is saved to a file. The score structure is used to keep the name and scorer of the top players together and allows scores to be compared facilitate sorting. And then loads the scores from the highscores text file. After that the new scores saves back to the highscores text file and draws the high scores to the screen. Handles the user input during the top score screen. Read the user’s name for their highSwinGame. This verifies if the score is a highSwinGame.
MenuController.vb
The MenuController handles the drawing and user interactions from the menus in the game. These include the main menu, game menu and the setting menu. In the setting menu there are text captions like PLAY, SETUP, SCORES, QUIT,RETURN,SURRENDER,QUIT,EASY,MEDIUM,HARD. Handles the processing of user input when the main menu is showing. Handle input in the game menu.players can return to the game, surrender or quit entirely.
UtilityFunctions.vb
This includes a number of utility methods for drawing and interacting with the Mouse. Determines if the mouse. Then you have to determine whether the mouse is in a given rectangle. Draws a large field using the grid and the indicated player’s ship. Draw a small field, showing the attacks which has made and the locations of the player’s ships. Then draws the player’s grid and ships.
AIHardPlayer.vb
AIHardPlayer is a type of player. This AI will know directions of ships when it has found 2 ship tiles and will try to destroy that ship. If that ship is not destroyed it will shoot the other way. Ship still not destroyed, then the AI knows it has hit multiple ships. Then will try to destroy all around tiles. that have been hit. And then target allows the AI to know more things, for example the source of a shot target.
AIMediumPlayer.vb
The AIMediumPlayer is a type of AIplayer where it will try and destroy a ship if t has found a ship. There’s this private enumerator for AI states. Currently there are two states, the AI can be searching for a ship,or if it has found a ship it will target the same ship. GenerateCoordinates should generate random shooting coordinates only when it has not found a ship or has destroyed a ship and needs new shooting coordinates.
AIOption.vb
This file includes the different AI levels from Easy which calculate the total random shootings,Medium which marks the squares around hits. As medium, removes shots once it misses.
AIPlayer.vb
The AIPlayer is a type of player. It can randomly deploy ships, it also has the functionality to generate coordinates and shoot at tiles. Location can store the location of the last hit made by an AI player. The use of which determines the difficulty.
AttackResult.vb
AttackResult gives the result after a shot has been made. And then returns the result of the attack.
BattleShipsGame.vb
The BattleShipGame controls a big part of the game. It will add the two players to the game and make sure that the both players ships are all deployed before starting the game. It also allows players to shoot and swap turns between player. It will also check if players are destroyed. The attack delegate type is used to send notifications of the end of an attack by a player on the AI. The AttackCompleted event is raised when an attack has completed.
Direction.vb
The direction of the ship can be oriented either left or right or up and down