|
| 1 | +VERSION 1.0 CLASS |
| 2 | +BEGIN |
| 3 | + MultiUse = -1 'True |
| 4 | +END |
| 5 | +Attribute VB_Name = "IPlayerGrid" |
| 6 | +Attribute VB_GlobalNameSpace = False |
| 7 | +Attribute VB_Creatable = False |
| 8 | +Attribute VB_PredeclaredId = False |
| 9 | +Attribute VB_Exposed = True |
| 10 | +Attribute VB_Description = "Describes an object representing a player's game grid." |
| 11 | +'@Exposed |
| 12 | +'@Folder("Battleship.Model.Abstract") |
| 13 | +'@ModuleDescription("Describes an object representing a player's game grid.") |
| 14 | +'@Interface |
| 15 | +Option Explicit |
| 16 | + |
| 17 | +Public Enum PlayGridId |
| 18 | + '@Ignore UseMeaningfulName |
| 19 | + PlayerGrid1 = 1 |
| 20 | + '@Ignore UseMeaningfulName |
| 21 | + PlayerGrid2 = 2 |
| 22 | +End Enum |
| 23 | + |
| 24 | +Public Enum PlayerGridErrors |
| 25 | + KnownGridStateError = vbObjectError Or 127 |
| 26 | + CannotAddShipAtPosition |
| 27 | + CannotAddMoreShips |
| 28 | +End Enum |
| 29 | + |
| 30 | +Public Enum AttackResult |
| 31 | + Marked |
| 32 | + Miss |
| 33 | + Hit |
| 34 | + Sunk |
| 35 | +End Enum |
| 36 | + |
| 37 | +Public Enum GridState |
| 38 | + Unknown = -1 |
| 39 | + PreviewShipPosition = 0 |
| 40 | + ShipPosition = 1 |
| 41 | + InvalidPosition = 2 |
| 42 | + PreviousMiss = 3 |
| 43 | + PreviousHit = 4 |
| 44 | +End Enum |
| 45 | + |
| 46 | +'@Description("Gets the ID of this grid (Player1/Player2).") |
| 47 | +'@Ignore UseMeaningfulName |
| 48 | +Public Property Get Id() As PlayGridId |
| 49 | +Attribute Id.VB_Description = "Gets the ID of this grid (Player1/Player2)." |
| 50 | +End Property |
| 51 | + |
| 52 | +'@Description("Gets the number of ships placed on the grid.") |
| 53 | +Public Property Get ShipCount() As Long |
| 54 | +Attribute ShipCount.VB_Description = "Gets the number of ships placed on the grid." |
| 55 | +End Property |
| 56 | + |
| 57 | +'@Description("Gets a collection containing all ships on this grid, sunken or afloat.") |
| 58 | +Public Property Get Fleet() As VBA.Collection |
| 59 | +Attribute Fleet.VB_Description = "Gets a collection containing all ships on this grid, sunken or afloat." |
| 60 | +End Property |
| 61 | + |
| 62 | +'@Description("Gets the size of the smallest ship still afloat on this grid.") |
| 63 | +Public Property Get SmallestShipSize() As Byte |
| 64 | +Attribute SmallestShipSize.VB_Description = "Gets the size of the smallest ship still afloat on this grid." |
| 65 | +End Property |
| 66 | + |
| 67 | +'@Description("Adds the specified ship to the grid. Throws if position is illegal.") |
| 68 | +Public Sub AddShip(ByVal Item As IShip) |
| 69 | +Attribute AddShip.VB_Description = "Adds the specified ship to the grid. Throws if position is illegal." |
| 70 | +End Sub |
| 71 | + |
| 72 | +'@Description("Gets a value indicating whether a ship can be added at the specified position/direction/size.") |
| 73 | +Public Function CanAddShip(ByVal position As IGridCoord, ByVal direction As ShipOrientation, ByVal shipSize As Byte) As Boolean |
| 74 | +Attribute CanAddShip.VB_Description = "Gets a value indicating whether a ship can be added at the specified position/direction/size." |
| 75 | +End Function |
| 76 | + |
| 77 | +'@Description("Gets the IGridCoord of the intersecting coordinate where the specified position/direction/size is intersecting with another ship. Returns 'Nothing' if no other ships intersect.") |
| 78 | +Public Function IntersectsAny(ByVal position As IGridCoord, ByVal direction As ShipOrientation, ByVal shipSize As Byte) As IGridCoord |
| 79 | +Attribute IntersectsAny.VB_Description = "Gets the IGridCoord of the intersecting coordinate where the specified position/direction/size is intersecting with another ship. Returns 'Nothing' if no other ships intersect." |
| 80 | +End Function |
| 81 | + |
| 82 | +'@Description("Gets a value indicating whether the specified position/direction/size has any adjacent existing ship.") |
| 83 | +Public Function HasAdjacentShip(ByVal position As IGridCoord, ByVal direction As ShipOrientation, ByVal shipSize As Byte) As Boolean |
| 84 | +Attribute HasAdjacentShip.VB_Description = "Gets a value indicating whether the specified position/direction/size has any adjacent existing ship." |
| 85 | +End Function |
| 86 | + |
| 87 | +'@Description("Attempts a hit at the specified position; returns the result of the attack, and a reference to the hit ship if successful. Function is side-effecting: alters ship's hit state.") |
| 88 | +Public Function TryHit(ByVal position As IGridCoord, Optional ByRef outShip As IShip) As AttackResult |
| 89 | +Attribute TryHit.VB_Description = "Attempts a hit at the specified position; returns the result of the attack, and a reference to the hit ship if successful. Function is side-effecting: alters ship's hit state." |
| 90 | +End Function |
| 91 | + |
| 92 | +'@Description("True if specified position contains a ship that was previously hit, but not sunken.") |
| 93 | +Public Property Get HasDamagedShip(ByVal position As IGridCoord) As Boolean |
| 94 | +Attribute HasDamagedShip.VB_Description = "True if specified position contains a ship that was previously hit, but not sunken." |
| 95 | +End Property |
| 96 | + |
| 97 | +'@Description("Gets the GridState value at the specified position.") |
| 98 | +Public Property Get State(ByVal position As IGridCoord) As GridState |
| 99 | +Attribute State.VB_Description = "Gets the GridState value at the specified position." |
| 100 | +End Property |
| 101 | + |
| 102 | +'@Description("Gets a 2D array containing the GridState of each coordinate in the grid.") |
| 103 | +Public Property Get StateArray() As Variant |
| 104 | +Attribute StateArray.VB_Description = "Gets a 2D array containing the GridState of each coordinate in the grid." |
| 105 | +End Property |
| 106 | + |
| 107 | +'@Description("Gets a value indicating whether the ship at the specified position is sunken.") |
| 108 | +Public Property Get IsSunken(ByVal position As IGridCoord) As Boolean |
| 109 | +Attribute IsSunken.VB_Description = "Gets a value indicating whether the ship at the specified position is sunken." |
| 110 | +End Property |
| 111 | + |
| 112 | +'@Description("Gets a value indicating whether all ships have been sunken.") |
| 113 | +Public Property Get IsAllSunken() As Boolean |
| 114 | +Attribute IsAllSunken.VB_Description = "Gets a value indicating whether all ships have been sunken." |
| 115 | +End Property |
| 116 | + |
| 117 | +'@Description("Finds area around a damaged ship, if one exists.") |
| 118 | +Public Function FindHitArea() As VBA.Collection |
| 119 | +Attribute FindHitArea.VB_Description = "Finds area around a damaged ship, if one exists." |
| 120 | +End Function |
| 121 | + |
| 122 | +'@Description("Removes confirmed ship positions from grid state.") |
| 123 | +Public Sub Scramble() |
| 124 | +Attribute Scramble.VB_Description = "Removes confirmed ship positions from grid state." |
| 125 | +End Sub |
| 126 | + |
0 commit comments