G. Code Documentation (part 1) - SwinbeeMiles/MyBattleship GitHub Wiki
Documented by: Tan Woon Jie
Code file in src folder (With comments)
DeploymentController.vb
Module DeploymentController
- "The DeploymentController controls the players actions during the deployment phase."
Public Sub HandleDeploymentInput()
- "Handles user input for the Deployment phase of the game. Involves selecting the ships, deploying ships, changing the direction of the ships to add, randomising deployment, end then ending deployment"
Private Sub DoDeployClick()
- "The user has clicked somewhere on the screen, check if its is a deployment and deploy the current ship if that is the case. If the click is in the grid it deploys to the selected location with the indicated direction"
Public Sub DrawDeployment()
- "Draws the deployment screen showing the field and the ships that the player can deploy."
Private Function GetShipMouseIsOver() As ShipName
- "Gets the ship that the mouse is currently over in the selection panel. Return the ship selected or none"
DiscoveryController.vb
Module DiscoveryController
- "The battle phase is handled by the DiscoveryController."
Public Sub HandleDiscoveryInput()
- "Handles input during the discovery phase of the game. Escape opens the game menu. Clicking the mouse will attack a location."
Private Sub DoAttack()
- "Attack the location that the mouse if over."
Public Sub DrawDiscovery()
- "Draws the game during the attack phase."
EndingGameController.vb
Module EndingGameController
- "The EndingGameController is responsible for managing the interactions at the end of a game."
Public Sub DrawEndOfGame()
- "Draw the end of the game screen, shows the win/lose state"
Public Sub HandleEndOfGameInput()
- "Handle the input during the end of the game. Any interaction will result in it reading in the highsSwinGame."
GameController.vb (3 FUNCTION MISSING COMMENTS)
Public Module GameController
- "The GameController is responsible for controlling the game,managing user input, and displaying the current state of the game."
Public ReadOnly Property CurrentState() As GameState
- "Returns the current state of the game, indicating which screen is currently being used"
Public ReadOnly Property HumanPlayer() As Player
- "Returns the human player."
Public ReadOnly Property ComputerPlayer() As Player
- "Returns the computer player."
Public Sub StartGame()
- "Starts a new game. Creates an AI player based upon the _aiSetting."
Private Sub EndGame()
- "Stops listening to the old game once a new game is started."
Private Sub GridChanged(ByVal sender As Object, ByVal args As EventArgs)
- "Listens to the game grids for any changes and redraws the screen when the grids change. The grid that changed (param name="sender"), not used (param name="args")
Private Sub AttackCompleted(ByVal sender As Object, ByVal result As AttackResult)
- "Listens for attacks to be complete then displays a message, plays sound and redraws the screen. The game (param name="sender"), the result of the attack (param name="result")."
Public Sub EndDeployment()
- "Completes the deployment phase of the game and switches to the battle mode (Discovering state). This adds the players to the game before switching state."
Public Sub Attack(ByVal row As Integer, ByVal col As Integer)
- "Gets the player to attack the indicated row and column. Checks the attack result once the attack is complete. The row to attack (param name="row"), the column to attack (param name="col")."
Private Sub AIAttack()
- "Gets the AI to attack. Checks the attack result once the attack is complete."
Private Sub CheckAttackResult(ByVal result As AttackResult)
- "Checks the results of the attack and switches to ending the Game if the result was game over. Gets the AI to attack if the result switched to the AI player. the result of the last attack (param name="result")."
Public Sub HandleUserInput()
- "Handles the user SwinGame. Reads key and mouse input and converts these into actions for the game to perform. The actions performed depend upon the state of the game."
Public Sub DrawScreen()
- "Draws the current state of the game to the screen. What is drawn depends upon the state of the game."
Public Sub AddNewState(ByVal state As GameState)
- "Move the game to a new state. The current state is maintained so that it can be returned to. the new game state (param name="state")."
Public Sub SwitchState(ByVal newState As GameState)
- "End the current state and add in the new state."
Public Sub EndCurrentState()
- "Ends the current state, returning to the prior state."
Public Sub SetDifficulty(ByVal setting As AIOption)
- "Sets the difficulty for the next level of the game. The new difficulty level (param name="setting")."
GameResources.vb (Module MISSING COMMENT, 19 FUNCTION MISSING COMMENT)
Public Function GameFont(ByVal font As String) As Font
- "Gets a Font Loaded in the Resources. Name of Font (param name="font"). Return the Font Loaded with this Name.
Public Function GameImage(ByVal image As String) As Bitmap
- "Gets an Image loaded in the Resources. Name of image (param name="image"). Return the image loaded with this name." Public Function GameSound(ByVal sound As String) As SoundEffect
- "Gets an sound loaded in the Resources. Name of sound (param name="sound"). Return the sound with this name.
Public Function GameMusic(ByVal music As String) As Music
- "Gets the music loaded in the Resources."
Public Sub LoadResources()
- "The Resources Class stores all of the Games Media Resources, such as Images, Fonts, Sounds, Music. Name of music (param name="music"). Return the music with this name."
GameState.vb
Public Enum GameState
- "The GameStates represent the state of the Battleships game play. This is used to control the actions and view displayed to the player."
ViewingMainMenu
- "The player is viewing the main menu."
ViewingGameMenu
- "The player is viewing the game menu."
ViewingHighScores
- "The player is looking at the high scores."
AlteringSettings
- "The player is altering the game settings."
Deploying
- "Players are deploying their ships."
Discovering
- "Players are attempting to locate each others ships."
EndingGame
- "One player has won, showing the victory screen."
Quitting
- "The player has quit. Show ending credits and terminate the game."
HighScoreController.vb
Module HighScoreController
- "Controls displaying and collecting high score data. Data is saved to a file."
Private Structure Score : Implements IComparable
- "The score structure is used to keep the name and score of the top players together."
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
- "Allows scores to be compared to facilitate sorting. The object to compare to (param name="obj"). Return a value that indicates the sort order."
Private Sub LoadScores()
- "Loads the scores from the highscores text file. The format is # of scores NNNSSS Where NNN is the name and SSS is the score."
Private Sub SaveScores()
- "Saves the scores back to the highscores text file. The format is # of scores NNNSSS Where NNN is the name and SSS is the score."
Public Sub DrawHighScores()
- "Draws the high scores to the screen."
Public Sub HandleHighScoreInput()
- "Handles the user input during the top score screen."
Public Sub ReadHighScore(ByVal value As Integer)
- "Read the user's name for their highsSwinGame. The player's sSwinGame (param name="value"). This verifies if the score is a highsSwinGame."
MenuController.vb
Module MenuController
- "The menu controller handles the drawing and user interactions from the menus in the game. These include the main menu,game menu and the settings menu."
Private ReadOnly _menuStructure As String()() = { _New String() {"PLAY", "SETUP", "SCORES", "QUIT"}, _New String( {"RETURN", "SURRENDER", "QUIT"}, _New String() {"EASY", "MEDIUM", "HARD"}}
- " The menu structure for the game. These are the text captions for the menu items."
Public Sub HandleMainMenuInput()
- "Handles the processing of user input when the main menu is showing."
Public Sub HandleSetupMenuInput()
- "Handles the processing of user input when the main menu is showing."
Public Sub HandleGameMenuInput()
- "Handle input in the game menu. Player can return to the game, surrender, or quit entirely"
Private Function HandleMenuInput(ByVal menu As Integer,ByVal level As Integer, ByVal xOffset As Integer) As Boolean
- "Handles input for the specified menu. The parameter identifier of the menu(param) being processed, the vertical level(param) of the menu, the xoffset(param) of the menu and return false if a clicked missed the buttons. This can be used to check prior menus."
Public Sub DrawMainMenu()
- "Draws the main menu to the screen."
Public Sub DrawGameMenu()
- "Draws the Game menu to the screen."
Public Sub DrawSettings()
- "Draws the settings menu to the screen. Also shows the main menu."
Private Sub DrawButtons(ByVal menu As Integer)
- "Draw the buttons associated with a top level menu. The index of the menu to draw (param name="menu")."
Private Sub DrawButtons(ByVal menu As Integer, ByVal level As Integer, ByVal xOffset As Integer)
- "Draws the menu at the indicated level.The menu to draw (param name="menu") the level (height) of the menu (param name = "level") the offset of the menu (param name="xOffset") The menu text comes from the _menuStructure field. The level indicates the height of the menu, to enable sub menus. The xOffset repositions the menu horizontally to allow the submenus to be positioned correctly."
Private Function IsMouseOverButton(ByVal button As Integer) As Boolean
- "Determined if the mouse is over one of the button in the main menu. The index of the button to check (param name="button"). Return true if the mouse is over that button."
Private Function IsMouseOverMenu(ByVal button As Integer, ByVal level As Integer, ByVal xOffset As Integer) As Boolean
- "Checks if the mouse is over one of the buttons in a menu. The index of the button to check (param name="button"), the level of the menu (param name="level"), the xOffset of the menu (param name="xOffset"). Return true if the mouse is over the button"
Private Sub PerformMenuAction(ByVal menu As Integer, ByVal button As Integer)
- " A button has been clicked, perform the associated action. The menu that has been clicked (param name="menu"), the index of the button that was clicked (param name="button")."
Private Sub PerformMainMenuAction(ByVal button As Integer)
- "The main menu was clicked, perform the button's action. The button pressed (param name="button")"
Private Sub PerformSetupMenuAction(ByVal button As Integer)
- "The setup menu was clicked, perform the button's action. The button pressed (param name="button")"
Private Sub PerformGameMenuAction(ByVal button As Integer)
- "The game menu was clicked, perform the button's action. The button pressed (param name="button")"
UtilityFuctions.vb (6 FUNCTION MISSING COMMENT)
Module UtilityFunctions
- "This includes a number of utility methods for drawing and interacting with the Mouse."
Public Function IsMouseInRectangle(ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer) As Boolean
- "Determines if the mouse is in a given rectangle. The x location to check (param name="x"), the y location to check (param name="y"), the width to check (param name="w"), the height to check (param name="h"). Return true if the mouse is in the area checked."
Public Sub DrawField(ByVal grid As ISeaGrid, ByVal thePlayer As Player, ByVal showShips As Boolean)
- "Draws a large field using the grid and the indicated player's ships. The grid to draw (param name="grid"), the players ships to show (param name="thePlayer"), indicates if the ships should be shown."
Public Sub DrawSmallField(ByVal grid As ISeaGrid, ByVal thePlayer As Player)
- "Draws a small field, showing the attacks made and the locations of the player's ships. The grid to show (param name="grid"), the player to show the ships of (param name="thePlayer")."
Private Sub DrawCustomField(ByVal grid As ISeaGrid, ByVal thePlayer As Player, ByVal small As Boolean, ByVal showShips As Boolean, ByVal left As Integer, ByVal top As Integer, ByVal width As Integer, ByVal height As Integer, ByVal cellWidth As Integer, ByVal cellHeight As Integer, ByVal cellGap As Integer)
- "Draws the player's grid and ships.The grid to show (param name="grid"), the player to show the ships of (param name="thePlayer"), true if the small grid is shown (param name="small"), true if ships are to be shown (param name="showShips"), the left side of the grid (param name="left"), the top of the grid (param name="top"), the width of the grid (param name="width"), the height of the grid (param name="height"), the width of each cell (param name="cellWidth"), the height of each cell (param name="cellHeight"), the gap between the cells (param name="cellGap")."
Public Property Message() As String
- "The message to display. Return the message to display."
Public Sub DrawMessage()
- "Draws the message to the screen."
Public Sub DrawBackground()
- "Draws the background for the current state of the game."
Code file in src folder (Without comments)
GameController.vb
Sub New()
- "MISSING COMMENTS."
Private Sub PlayHitSequence(ByVal row As Integer, ByVal column As Integer, ByVal showAnimation As Boolean)
- "MISSING COMMENTS."
Private Sub PlayMissSequence(ByVal row As Integer, ByVal column As Integer, ByVal showAnimation As Boolean)
- "MISSING COMMENTS."
GameLogic.vb (MAIN FUNCTION MISSING COMMENT)
Module GameLogic
Public Sub Main()
- "MISSING COMMENTS."
GameResources.vb (Module MISSING COMMENT, 19 FUNCTION MISSING COMMENT)
Public Module GameResources
- "MISSING COMMENTS."
Private Sub LoadFonts()
- "MISSING COMMENTS."
Private Sub LoadImages()
- "MISSING COMMENTS."
Private Sub LoadSounds()
- "MISSING COMMENTS."
Private Sub LoadMusic()
- "MISSING COMMENTS."
Private Sub ShowLoadingScreen()
- "MISSING COMMENTS."
Private Sub PlaySwinGameIntro()
- "MISSING COMMENTS."
Private Sub ShowMessage(ByVal message As String, ByVal number As Integer)
- "MISSING COMMENTS."
Private Sub EndLoadingScreen(ByVal width As Integer, ByVal height As Integer)
- "MISSING COMMENTS."
Private Sub NewFont(ByVal fontName As String, ByVal filename As String, ByVal size As Integer)
- "MISSING COMMENTS."
Private Sub NewImage(ByVal imageName As String, ByVal filename As String)
- "MISSING COMMENTS."
Private Sub NewTransparentColorImage(ByVal imageName As String, ByVal fileName As String, ByVal transColor As Color)
- "MISSING COMMENTS."
Private Sub NewTransparentColourImage(ByVal imageName As String, ByVal fileName As String, ByVal transColor As Color)
- "MISSING COMMENTS."
Private Sub NewSound(ByVal soundName As String, ByVal filename As String)
- "MISSING COMMENTS."
Private Sub NewMusic(ByVal musicName As String, ByVal filename As String)
- "MISSING COMMENTS."
Private Sub FreeFonts()
- "MISSING COMMENTS."
Private Sub FreeImages()
- "MISSING COMMENTS."
Private Sub FreeSounds()
- "MISSING COMMENTS."
Private Sub FreeMusic()
- "MISSING COMMENTS."
Public Sub FreeResources()
- "MISSING COMMENTS."
UtilityFuctions.vb (6 FUNCTION MISSING COMMENT)
Public Sub AddExplosion(ByVal row As Integer, ByVal col As Integer)
- "MISSING COMMENTS."
Public Sub AddSplash(ByVal row As Integer, ByVal col As Integer)
- "MISSING COMMENTS."
Private Sub AddAnimation(ByVal row As Integer, ByVal col As Integer, ByVal image As String)
- "MISSING COMMENTS."
Public Sub UpdateAnimations()
- "MISSING COMMENTS."
Public Sub DrawAnimations()
- "MISSING COMMENTS."
Public Sub DrawAnimationSequence()
- "MISSING COMMENTS."
Code file in src/Model folder (With comments)
AllPlayer.vb
Public MustInherit Class AIPlayer : Inherits Player
- "The AIPlayer is a type of player. It can readomly deploy ships, it also has the functionality to generate coordinates and shoot at tiles."
Protected Class Location
- "Location can store the location of the last hit made by an AI Player. The use of which determines the difficulty."
Public Property Row() As Integer
- "The row of the shot. Return the row of the shot value."
Public Property Column() As Integer
- "The column of the shot. Return the column of the shot value."
Public Sub New(ByVal row As Integer, ByVal column As Integer)
- "Sets the last hit made to the local variables. The row of the location (param name="row"), the column of the location (param name="column")."
Public Shared Operator =(ByVal this As Location, ByVal other As Location) As Boolean
- "Check if two locations are equal. Location 1 (param name="this"), location 2 (param name="other"). Return true if location 1 and location 2 are at the same spot."
Public Shared Operator <>(ByVal this As Location, ByVal other As Location) As Boolean
- "Check if two locations are not equal. Location 1 (param name="this"), location 2 (param name="other"). Return true if location 1 and location 2 are not at the same spot."
Protected MustOverride Sub GenerateCoords(ByRef row As Integer, ByRef column As Integer)
- "Generate a valid row, column to shoot at. Output the row for the next shot (param name="row"), output the column for the next show (param name="column")."
protected mustoverride sub ProcessShot(row as integer, col as integer, result as AttackResult)
- "The last shot had the following result. Child classes can use this to prepare for the next shot. The result of the shot (param name="result"), the row shot (param name="row"),the column shot (param name="col")."
Public Overrides Function Attack() As AttackResult
- "The AI takes its attacks until its go is over. Return the result of the last attack."
Private Sub Delay()
- "Wait a short period to simulate the think time."
AttackResult.vb
Public Class AttackResult
- "AttackResult gives the result after a shot has been made."
Public ReadOnly Property Value() As ResultOfAttack
- "The result of the attack. Return the result of the attack value."
Public ReadOnly Property Ship() As Ship
- "The ship, if any, involved in this result. Return the ship, if any, involved in this result value."
Public ReadOnly Property Text() As String
- "A textual description of the result. Return a textual description of the result value."
Public ReadOnly Property Row() As Integer
- "The row where the attack occurred."
Public ReadOnly Property Column() As Integer
- "The column where the attack occurred."
Public Sub New(ByVal value As ResultOfAttack, ByVal text As String, ByVal row As Integer, ByVal column As Integer)
- "Set the _Value to the PossibleAttack value. Either hit, miss, destroyed, shotalready(param name="value")."
Public Sub New(ByVal value As ResultOfAttack, ByVal ship As Ship, ByVal text As String, ByVal row As Integer, ByVal column As Integer)
- "Set the _Value to the PossibleAttack value, and the _Ship to the ship. Either hit, miss, destroyed, shot already (param name="value"), the ship information (param name="ship")."
Public Overrides Function ToString() As String
- "Displays the textual information about the attack. Return the textual information about the attack."
BattleShipsGame.vb
Public Class BattleShipsGame
- "The BattleShipsGame controls a big part of the game. It will add the two players to the game and make sure that 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."
Public Delegate Sub AttackCompletedHandler(ByVal sender As Object, ByVal result As AttackResult)
- "The attack delegate type is used to send notifications of the end of an attack by a player or the AI. The game sending the notification (param name="sender"), the result of the attack (param name="result")."
Public Event AttackCompleted As AttackCompletedHandler
- "The AttackCompleted event is raised when an attack has completed. This is used by the UI to play sound effects etc."
Public ReadOnly Property Player() As Player
- "The current player. Return the current player value. This value will switch between the two players as they have their attacks."
Public Sub AddDeployedPlayer(ByVal p As Player)
- "AddDeployedPlayer adds both players and will make sure that the AI player deploys all ships. " " (param name="p)."
Private Sub CompleteDeployment()
- "Assigns each player the other's grid as the enemy grid. This allows each player to examine the details visable on the other's sea grid."
Public Function Shoot(ByVal row As Integer, ByVal col As Integer) As AttackResult
- "Shoot will swap between players and check if a player has been killed. It also allows the current player to hit on the enemygrid. The row fired upon (param name="row"), the column fired upon (param name="col"). Return the result of the attack."
Direction.vb
Public Enum Direction
- "The direction the ship can be oriented."
ISeaGrid.vb
Public Interface ISeaGrid
- "The ISeaGrid defines the read only interface of a Grid. This allows each player to see and attack their opponents grid."
Event Changed As EventHandler
- "Indicates that the grid has changed."
ReadOnly Property Item(ByVal row As Integer, ByVal column As Integer) As TileView
- "Provides access to the given row/column. The row to access (param name="row"), the column to access (param name="column"). Return what the player can see at that location value."
Function HitTile(ByVal row As Integer, ByVal col As Integer) As AttackResult
- "Mark the indicated tile as shot. The row of the tile (param name="row"), the column of the tile (param name="col"). Return the result of the attack."
Player.vb
Public Class Player : Implements IEnumerable(Of Ship)
- "Player has its own _PlayerGrid, and can see an _EnemyGrid, it can also check if all ships are deployed and if all ships are detroyed. A Player can also attach."
Public Property Game() As BattleShipsGame
- "Returns the game that the player is part of. The game that the player is playing value."
Public WriteOnly Property Enemy() As ISeaGrid
- "Sets the grid of the enemy player."
Public Property EnemyGrid() As ISeaGrid
- "The EnemyGrid is a ISeaGrid because you shouldn't be allowed to see the enemies ships."
Public ReadOnly Property PlayerGrid() As SeaGrid
- "The PlayerGrid is just a normal SeaGrid where the players ships can be deployed and seen."
Public ReadOnly Property ReadyToDeploy() As Boolean
- "ReadyToDeploy returns true if all ships are deployed."
Public ReadOnly Property Ship(ByVal name As ShipName) As Ship
- "Returns the Player's ship with the given name. The name of the ship to return (param name="name"). Return the ship with the indicated name value. The none ship returns nothing/null."
Public ReadOnly Property Shots() As Integer
- "The number of shots the player has made. Return the number of shots taken value."
Public ReadOnly Property Missed() As Integer
- "Total number of shots that missed. Return the number of shots that have missed ships value."
Public Function GetShipEnumerator() As IEnumerator(Of Ship) Implements IEnumerable(Of Ship).GetEnumerator
- "Makes it possible to enumerate over the ships the player has. Return a Ship enumerator."
Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
- "Makes it possible to enumerate over the ships the player has. Return a Ship enumerator."
Public Overridable Function Attack() As AttackResult
- "Vitual Attack allows the player to shoot."
Friend Function Shoot(ByVal row As Integer, ByVal col As Integer) As AttackResult
- "Shoot at a given row/column. The row to attack (param name="row"), the column to attack (param name="col"). Return the result of the attack."
ResultOfAttack.vb
Public Enum ResultOfAttack
- "The result of an attack."
Hit
- "The player hit something."
Miss
- "The player missed."
Destroyed
- "The player destroyed a ship."
ShotAlready
- "That location was already shot."
GameOver
- "The player killed all of the opponents ships."
SeaGrid.vb
Public Class SeaGrid
- "The SeaGrid is the grid upon which the ships are deployed. The grid is viewable via the ISeaGrid interface as a read only grid. This can be used in conjuncture with the SeaGridAdapter to mask the position of the ships."
Public Event Changed As EventHandler Implements ISeaGrid.Changed
- "The sea grid has changed and should be redrawn."
Public ReadOnly Property Width() As Integer Implements ISeaGrid.Width
- "The width of the sea grid. Return the width of the sea grid value."
Public ReadOnly Property Height() As Integer Implements ISeaGrid.Height
- "The height of the sea grid. Return the height of the sea grid value."
Public ReadOnly Property ShipsKilled() As Integer
- "ShipsKilled returns the number of ships killed."
Public ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As TileView Implements ISeaGrid.Item
- "Show the tile view. x coordinate of the tile (param name="x"), y coordiante of the tile (param name="y")."
Public ReadOnly Property AllDeployed() As Boolean
- "AllDeployed checks if all the ships are deployed."
Public Sub New(ByVal ships As Dictionary(Of ShipName, Ship))
- "SeaGrid constructor, a seagrid has a number of tiles stored in an array."
Public Sub MoveShip(ByVal row As Integer, ByVal col As Integer, ByVal ship As ShipName, ByVal direction As Direction)
- "MoveShips allows for ships to be placed on the seagrid. The row selected (param name="row"), the column selected (param name="col"), the ship selected (param name="ship"), the direction the ship is going (param name="direction")."
Private Sub AddShip(ByVal row As Integer, ByVal col As Integer, ByVal direction As Direction, ByVal newShip As Ship)
- "AddShip add a ship to the SeaGrid. Row coordinate (param name="row"), col coordinate (param name="col"), direction of ship (param name="direction"), the ship (param name="newShip")."
Public Function HitTile(ByVal row As Integer, ByVal col As Integer) As AttackResult Implements ISeaGrid.HitTile
- "HitTile hits a tile at a row/col, and whatever tile has been hit, a result will be displayed. The row at which is being shot (param name="row"), the cloumn at which is being shot (param name="col"). Return an attackresult (hit, miss, sunk, shotalready)."
SeaGridAdapter.vb
Public Class SeaGridAdapter
- "The SeaGridAdapter allows for the change in a sea grid view. Whenever a ship is presented it changes the view into a sea tile instead of a ship tile."
Public Sub New(ByVal grid As SeaGrid)
- "Create the SeaGridAdapter, with the grid, and it will allow it to be changed. The grid that needs to be adapted (param name="grid")."
Private Sub MyGrid_Changed(ByVal sender As Object, ByVal e As EventArgs)
- "MyGrid_Changed causes the grid to be redrawn by raising a changed event. The object that caused the change (param name="sender"), what needs to be redrawn (param name="e")."
Public ReadOnly Property Item(ByVal x As Integer, ByVal y As Integer) As TileView Implements ISeaGrid.Item
- "Changes the discovery grid. Where there is a ship we will sea water. Tile x coordinate (param name="x"), tile y coordinate (param name="y"). Return a tile, either what it actually is, or if it was a ship then return a sea tile."
Public Event Changed As EventHandler Implements ISeaGrid.Changed
- "Indicates that the grid has been changed."
Public ReadOnly Property Width() As Integer Implements ISeaGrid.Width
- "Get the width of a tile."
Public ReadOnly Property Height() As Integer Implements ISeaGrid.Height
- "Get the height of the tile."
Public Function HitTile(ByVal row As Integer, ByVal col As Integer) As AttackResult Implements ISeaGrid.HitTile
- "HitTile calls upon _MyGrid to hit a tile at the row, col. The row its hitting at (param name="row"), the column its hitting at (param name="col"). Return the result from hitting that tile."
Ship.vb
Public Class Ship
- "A Ship has all the details about itself. For example the shipname, size, number of hits taken and the location. Its able to add tiles, remove, hits taken and if its deployed and destroyed. Deployment information is supplied to allow ships to be drawn."
Public ReadOnly Property Name() As String
- "The type of ship. Return the type of ship value"
Public ReadOnly Property Size() As Integer
- "The number of cells that this ship occupies. Return the number of hits the ship can take value."
Public ReadOnly Property Hits() As Integer
- "The number of hits that the ship has taken. Return the number of hits the ship has taken. When this equals Size the ship is sunk."
Public ReadOnly Property Row() As Integer
- "The row location of the ship. The topmost location of the ship. Return the row of the ship."
Public Sub AddTile(ByVal tile As Tile)
- " Add tile adds the ship tile. One of the tiles the ship is on (param name="tile")."
Public Sub Remove()
- "Remove clears the tile back to a sea tile."
Public ReadOnly Property IsDeployed() As Boolean
- "IsDeployed returns if the ships is deployed, if its deplyed it has more than 0 tiles."
Friend Sub Deployed(ByVal direction As Direction, ByVal row As Integer, ByVal col As Integer)
- "Record that the ship is now deployed. param name="direction", param name="row", param name="col"."
ShipName.vb
Public Enum ShipName
- "The names of all of the ships in the game."
Tile.vb
Public Class Tile
- "Tile knows its location on the grid, if it is a ship and if it has been shot before."
Public Property Shot() As Boolean
- "Has the tile been shot? Indicate if the tile has been shot. Return true if the tile was shot."
Public ReadOnly Property Row() As Integer
- "The row of the tile in the grid. Return the row index of the tile value."
Public ReadOnly Property Column() As Integer
- "The column of the tile in the grid. Return the column of the tile in the grid."
Public Property Ship() As Ship
- "Ship allows for a tile to check if there is ship and add a ship to a tile."
Public Sub New(ByVal row As Integer, ByVal col As Integer, ByVal ship As Ship)
- "The tile constructor will know where it is on the grid, and is its a ship. The row on the grid (param name="row"), the col on the grid (param name="col"), what ship it is (param name="ship")."
Public Sub ClearShip()
- "Clearship will remove the ship from the tile."
Public ReadOnly Property View() As TileView
- "View is able to tell the grid what the tile is."
Friend Sub Shoot()
- "Shoot allows a tile to be shot at, and if the tile has been hit before it will give an error."
TileView.vb
Public Enum TileView
- "The values that are visable for a given tile."
Sea
- "The viewer can see sea. May be masking a ship if viewed via a sea adapter."
Miss
- "The viewer knows that site was attacked but nothing was hit."
Ship
- "The viewer can see a ship at this site."
Hit
- "The viewer knows that the site was attacked and something was hit."
AIHardPlayer.vb
Public Class AIHardPlayer : Inherits AIPlayer
- "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 destoy all around tiles that have been hit."
Protected Class Target
- "Target allows the AI to know more things, for example the source of a shot target."
Public ReadOnly Property ShotAt() As Location
- "The target shot at. Return the target shot at value."
Public ReadOnly Property Source() As Location
- "The source that added this location as a target. Return the source that added this location as a target value."
Public ReadOnly Property SameRow() As Boolean
- "If source shot and shootat shot are on the same row then give a boolean true."
Public ReadOnly Property SameColumn() As Boolean
- "If source shot and shootat shot are on the same column then give a boolean true."
Private Enum AIStates
- "Private enumarator 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."
Searching
- "The AI is searching for its next target."
TargetingShip
- "The AI is trying to target a ship."
HittingShip
- "The AI is locked onto a ship."
Protected Overrides Sub GenerateCoords(ByRef row As Integer, ByRef column As Integer)
- "GenerateCoords will call upon the right methods to generate the appropriate shooting coordinates. The row that will be shot at (param name="row"). The column that will be shot at (param name="column")."
Private Sub TargetCoords(ByRef row As Integer, ByRef column As Integer)
- "TargetCoords is used when a ship has been hit and it will try and destroy this ship. Row generated around the hit tile (param name="row"), column generated around the hit tile (param name="column")."
Private Sub SearchCoords(ByRef row As Integer, ByRef column As Integer)
- "SearchCoords will randomly generate shots within the grid as long as its not hit that tile already. The generated row (param name="row"), the generated column (param name="column")."
Protected Overrides Sub ProcessShot(ByVal row As Integer, ByVal col As Integer, ByVal result As AttackResult)
- "ProcessShot is able to process each shot that is made and call the right methods belonging to that shot. For example, if its a miss = do nothing, if it's a hit = process that hit location. The row that was shot at (param name="row"), the column that was shot at (param name="col"), the result from that hit (param name="result")."
Private Sub ProcessDestroy(ByVal row As Integer, ByVal col As Integer, ByVal ship As Ship)
- "ProcessDetroy is able to process the destroyed ships targets and remove _LastHit targets. It will also call RemoveShotsAround to remove targets that it was going to shoot at. The row that was shot at and destroyed (param name="row"), the row that was shot at and destroyed (param name="col"), the row that was shot at and destroyed (param name="ship").
Private Sub RemoveShotsAround(ByVal toRemove As Location)
- "RemoveShotsAround will remove targets that belong to the destroyed ship by checking if the source of the targets belong to the destroyed ship. If they don't put them on a new stack. Then clear the targets stack and move all the targets that still need to be shot at back onto the targets stack. " " (param name="toRemove".)"
Private Sub ProcessHit(ByVal row As Integer, ByVal col As Integer)
- "ProcessHit gets the last hit location coordinates and will ask AddTarget to create targets around that location by calling the method four times each time with a new location around the last hit location. It will then set the state of the AI and if it's not Searching or targetingShip then start ReOrderTargets. " " (param name="row"/param name="col")."
Private Sub ReOrderTargets()
- "ReOrderTargets will optimise the targeting by re-orderin the stack that the targets are in. By putting the most important targets at the top they are the ones that will be shot at first."
Private Sub MoveToTopOfStack(ByVal row As Integer, ByVal column As Integer)
- "MoveToTopOfStack will re-order the stack by checkin the coordinates of each target. If they have the right column or row values it will be moved to the _Match stack else put it on the _NoMatch stack. Then move all the targets from the _NoMatch stack back on the _Targets stack, these will be at the bottom making them less important. The move all the targets from the _Match stack on the _Targets stack, these will be on the top and will there for be shot at first. The row of the optimisation (param name="row"), the column of the optimisation (param name="column")."
Private Sub AddTarget(ByVal row As Integer, ByVal column As Integer)
- "AddTarget will add the targets it will shoot onto a stack. The row of the targets location (param name="row"), the column of the targets location ("param name="column")."
AiMediumPlayer.vb
Public Class AIMediumPlayer : Inherits AIPlayer
- "The AIMediumPlayer is a type of AIPlayer where it will try and destroy a ship if it has found a ship."
Private Enum AIStates
- "Private enumarator 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."
Protected Overrides Sub GenerateCoords(ByRef row As Integer, ByRef column As Integer)
- "GenerateCoordinates should generate random shooting coordinates only when it has not found a ship, or has destroyed a ship and needs new shooting coordinates. The generated row (param name="row"), the generated column (param name="column")."
Private Sub TargetCoords(ByRef row As Integer, ByRef column As Integer)
- "TargetCoords is used when a ship has been hit and it will try and destroy this ship. Row generated around the hit tile (param name="row"), column generated around the hit tile (param name="column")."
Private Sub SearchCoords(ByRef row As Integer, ByRef column As Integer)
- "SearchCoords will randomly generate shots within the grid as long as its not hit that tile already. The generated row (param name="row"), the generated column (param name="column")."
Protected Overrides Sub ProcessShot(ByVal row As Integer, ByVal col As Integer, ByVal result As AttackResult)
- "ProcessShot will be called uppon when a ship is found. It will create a stack with targets it will try to hit. These targets will be around the tile that has been hit. The row it needs to process (param name="row"), the column it needs to process (param name="col"), the result og the last shot (should be hit) (param name="result")."
Private Sub AddTarget(ByVal row As Integer, ByVal column As Integer)
- "AddTarget will add the targets it will shoot onto a stack. The row of the targets location (param name="row"), the column of the targets location (param name="column")."
AIOption.vb
Public Enum AIOption
- "The different AI levels."
Easy
- "Easy, total random shooting."
Medium
- "Medium, marks squares around hits."
Hard
- "As medium, but removes shots once it misses."
Code file in src/Model folder (Without comments)
AllPlayer.vb
Public Sub New(ByVal game As BattleShipsGame)
- "MISSING COMMENTS."
ISeaGrid.vb
ReadOnly Property Width() As Integer
- "MISSING COMMENTS."
ReadOnly Property Height() As Integer
- "MISSING COMMENTS."
Player.vb
Public Sub New(ByVal controller As BattleShipsGame)
- "MISSING COMMENTS."
Public ReadOnly Property IsDestroyed() As Boolean
- "MISSING COMMENTS."
Public ReadOnly Property Hits() As Integer
- "MISSING COMMENTS."
Public ReadOnly Property Score() As Integer
- "MISSING COMMENTS."
Public Overridable Sub RandomizeDeployment()
- "MISSING COMMENTS."
Ship.vb
Public ReadOnly Property Column() As Integer
- "MISSING COMMENTS."
Public ReadOnly Property Direction() As Direction
- "MISSING COMMENTS."
Public Sub New(ByVal ship As ShipName)
- "MISSING COMMENTS."
Public Sub Hit()
- "MISSING COMMENTS."
Public ReadOnly Property IsDestroyed() As Boolean
- "MISSING COMMENTS."
AIHardPlayer.vb
Friend Sub New(ByVal shootat As Location, ByVal source As Location)
- "MISSING COMMENTS."
Public Sub New(ByVal game As BattleShipsGame)
- "MISSING COMMENTS."
AIMediumPlayer.vb
Public Sub New(ByVal controller As BattleShipsGame)
- "MISSING COMMENTS."