Useful Documentation in VB Code - JMcQueen1000/Battleships GitHub Wiki

DeploymentController.vb:

  • DeploymentController: The DeploymentController controls the players' actions during the deployment phase.
  • 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.
  • DoDeployClick(): The user has clicked somewhere on the screen, check if it 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.
  • DrawDeployment(): Draws the deployment screen showing the field and the ships that the player can deploy.
  • GetShipMouseIsOver(): Gets the ship that the mouse is currently over in the selection panel. It returns the selected ship or none.

DiscoveryController.vb:

  • DiscoveryController: The battle phase is handled by the DiscoveryController.
  • HandleDiscoveryInput(): Handles input during the discovery phase of the game. It escapes opens the game menu. Clicking the mouse will attack a location.
  • DoAttack(): Attack the location that the mouse is over.

EndingGameController.vb:

  • EndingGameController: The EndingGameController is responsible for managing the interactions at the end of a game.
  • DrawEndOfGame(): Draw the end of the game screen, shows the win/lose the state.
  • HandleEndOfGameInput(): Handle the input at the end of the game. Any interaction will result in it reading in the highsSwinGame.

GameController.vb:

  • GameController: The GameController is responsible for controlling the game, managing user input, and displaying the current state of the game.
  • CurrentState(): Returns the current state of the game, indicating which screen is currently being used. Its value is the current state. It returns the current state.
  • HumanPlayer(): Returns the human player. Its value is the human player. It returns the human player.
  • GameController: The GameController is responsible for controlling the game, managing user input, and displaying the current state of the game.
  • CurrentState(): Returns the current state of the game, indicating which screen is currently being used. Its value is the current state. It returns the current state.
  • HumanPlayer(): Returns the human player. Its value is the human player. It returns the human player.

GameLogic.vb:

  • GameFont(ByVal font As String): Gets a Font Loaded in the Resources. Parameter "font" receives Name of Font. It returns the Font Loaded with this Name.
  • GameImage(ByVal image As String): Gets an Image loaded in the Resources. Parameter "image" receives Name of image. It returns the image loaded with this name.
  • GameSound(ByVal sound As String): Gets a sound loaded in the Resources. Parameter "sound" receives Name of sound. It returns the sound with this name.

AIPlayer.vb:

  • Public Property Row() As Integer: Returns the row of the shot.
  • Public Property Column() As Integer: Returns the column of the shot.
  • Public Sub New(): sets the last hit made to the local variables.
  • Public Shared Operator =( As Boolean: Checks if two locations are equal. Parameter this is location 1. Parameter 'other' is location 2. Returns true if both locations are in the same spot.
  • Public Shared Operator <>() As Boolean: Checks if two locations are not equal. Parameter this is location 1. Parameter 'other' is location 2. Returns true if both locations are not at the same spot.
  • GenerateCoords(): Generates a valid row. Parameter 'row' outputs the row for the next shot. Parameter 'column; outputs the column for the next shot.
  • ProcessShot(): The last shot had the following result. Child classes can use this to prepare for then next shot. Parameter 'result' is the result of the next shot. Parameter 'row' is the row shot. Parameter 'col' is the column shot.
  • Attack() As AttackResult: The AI takes its attacks until its go is over. Returns the result of the last attack.
  • Delay(): Wait a short period to simulate the think time.

AIOptions.vb:

  • Easy: Easy, total random shooting
  • Medium: Medium, marks squares around hits
  • Hard: As medium, but removes shots once it misses

AIMediumPlayer.vb:

  • GenerateCoords(): GenerateCoordinates should generate random shootin coordinates. Only when it has not found a ship, or has destroyed a ship and needs new shooting coordinates. Parameter 'row' is the generated row. Parameter 'col' is the generated column.
  • TargetCoords(): TargetCoords is used when a ship has been hit and it will try and destroy this ship. Parameter 'row' is the row generated around the hit tile. Parameter 'column' is the column generated around the hit tile.
  • SearchCoords(): SearchCoords will randomly generate shots within the grid as long as its not hit that tile already. Parameter 'row' is the generated row. Parameter 'col' is the generated column.
  • ProcessShot(): ProcessShot will be called upon 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. Parameter 'row' is the row it needs to process. Parameter 'col' is the column it needs to process. Parameter 'result' is the result of the last shot.
  • AddTarget(): AddTarget will add the targets it will shoot onto a stack. Parameter 'row' is the row of the targets location. Parameter 'column' is the column of the targets location.

AIHardPlayer.vb:

  • Class Target: Target allows the AI to know more things, for example the source of a shot target.
  • ShotAt(): The target shot at. Returns the target shot at.
  • Source(): The source that added this location as a target. Returns the source.
  • SameRow(): If source shot and shootat shot are on the same row then give the boolean true.
  • SameColumn(): If source shot and shootat shot are on the same column then give the boolean true.
  • Enum AIStates: Private enumerator for AI states. Currently there are two states, the AI 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.
  • GenerateCoords(): GenerateCoords will call upon the right methods to generate the appropriate shooting coordinates. Parameter 'row' is the row that will be shot at. Parameter 'col' is the column that will be shot at.
  • TargetCoords(): TargetCoords is used when a ship has been hit and it will try and destroy this ship. Parameter 'row' is the row generated around the hit tile. Parameter 'col' is the column generated around the hit tile.
  • SearchCoords(): SearchCoords will randomly generate shots within the grid as long as its not hit that tile already. Parameter 'row' is the generated row. Parameter 'col' is the generated column.
  • ProcessShot(): 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 its a hit = process that hit location. Parameter 'row' is the row that was shot at. Parameter 'col' is the column that was shot at. Parameter 'result' is the result from the last hit.
  • ProcessDestroy(): 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. Parameter 'row' is the row that was shot at and destroyed. Parameter 'col' is the column that was shot at and destroyed. Parameter 'ship' is the ship that was shot at.
  • RemoveShotsAround(): 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.
  • ProcessHit(): 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.
  • 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.
  • MoveToTopOfStack(): 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. Parameter 'row' is the row of the optimisation. Parameter 'col' is the column of the optimisation.
  • AddTarget(): AddTarget will add the targets it will shoot onto a stack. Parameter 'row' is the row of the targets location. Parameter 'col' is the column of the targets location.

AttackResult.vb:

  • Value(): The result of the attack.
  • Ship(): The ship, if any, involved in this result.
  • Text(): A textual description of the result.
  • Row(): The row where the attack occurred.
  • Column(): The column where the attack occurred.
  • New(): Set the value to the PossibleAttack value.
  • ToString(): Displays the textual information about the attack and returns it.

BattleShipsGame.vb:

  • AttackCompletedHandler: The attack delegate type is used to send notifications of the end of an attack by a player or the AI. Parameter 'sender' is the game sending the notification. Parameter 'result' is the result of the attack.
  • AttackCompleted Event: The AttackCompleted event is raised when an attack has completed. This is used by the UI to play sound effects. -Player(): The current Player. This value will switch between the two players as they have their attacks.
  • AddDeployedPlayer(): AddDeployedPlayer adds both players and will make sure that the AI player deploys all ships.
  • 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.
  • Shoot(): Shoot will swap between players and check if a player has been killed. It also allows the current player to hit on the enemygrid. Parameter 'row' is the row fired upon. Parameter 'col' is the column fired upon. Returns the result of the attack.

Direction.vb:

  • LeftRight: If the ship is oriented left/right
  • UpDown: If the ship is oriented Up/Down

ResultOfAttack.vb:

  • 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

ISeaGrid.vb:

  • Changed: Indicator to tell if the map has changed
  • Item(): Provides access to the given row/column
  • HitTile(): Marks the tile as shot

Player.vb:

  • Game(): Returns whether the player is in a game
  • Enemy(): Sets enemy's grid/position of ships
  • EnemyGrid(): Defining the enemy's grid
  • AllyGrid(): Defining Ally grid
  • ReadyToDeploy(): Boolean of if all ships are placed
  • IsDestroyed(): Runs checks if all ships are destoryed
  • Ship(): returns the ships name
  • Shots(): returns the number of shots that have been fired
  • Hits(): returns the number of shots that have been hit
  • Misses(): returns the number of shots that have been missed
  • Score(): returns the score
  • GetShipEnumerator()/GetEnumerator(): Makes it possible to enumerate over the ships the player has
  • Attck(): Allows player to shoot
  • Shoot(): Chooses location of attack
  • RandomizeDeployment(): Randomizes the ships deployment

SeaGrid.vb:

  • Changed: notifies the grid needs to be redrawn as a change has been made
  • Width(): width of the grid
  • Height(): Height of the grid
  • ShipsKilled() the number of ships killed
  • Item(): Shows the tiles view
  • AllDeployed(): Boolean of if all ships are deployed
  • Sub New: fills game board with empty tiles
  • MoveShip(): allows the ships to be placed on the grid
  • AddShip(): Add ship to sea grid and returns error if cant
  • HitTile(): Returns whether an attack is a hit or miss

SeaGridAdapter.vb:

  • grid: new grid that needs to be adapted
  • MyGrid_Changed: when a change is made, it notifies the grid to redraw
  • Item(): makes the view of the grid all water while keeping info on where the ships are by going through the whole grid using x and y
  • Changed(): returns if the grids been changed or not
  • Width(): width of each tile
  • Height(): height of each tile
  • HitTile(): inputs row and column to check if there is a hit

Ship.vb:

  • Name(): Type of ship (none -> AircraftCarrier) and if it gets AircraftCarrier, it returns Aircraft Carrier otherwise just returns the enum name using .ToString()
  • Size(): returns size corresponding to type of ship
  • Hits(): returns how many hits that ship has taken, sinking said ship once that equals the size of said ship
  • Row(): row location of the ship
  • Column(): column location of the ship
  • Direction(): direction of the ship
  • AddTile(): adds a ship tile
  • Remove(): clears a tile back to sea tile
  • IsDeployed(): if the ship is deployed (more than 0 tiles)
  • IsDestroyed(): if the ship is destroyed (Hits = Size)
  • Deployed(): records where and what direction the ship is deployed

ShipName.vb:

  • None: size of 0
  • Tug: size of 1
  • Submarine: size of 2
  • Destroyer: size of 3
  • BattleShip: size of 4
  • AircraftCarrier: size of 5

Tile.vb:

  • Shot(): read/write parameter for if the tile has been shot
  • Row(): row of tile in grid
  • Column(): column of tile in grid
  • Ship(): either returns if there is a ship on that tile or can place a ship in that tile
  • ClearShip(): removes a ship from the tile
  • View(): tells grid what the tile is (if its been shot, whether there is a ship, etc.)
  • Shoot(): allows a tile to be shot unless it already has been

TileView.vb:

  • Sea: the spot shows sea on the grid, or might hide a ship if seen via sea adaptor
  • Miss: indicates the spot has been hit but didn't hit a ship
  • Ship: displays a ship
  • Hit: indicates the spot has been hit and a ship was there