Method: Alpha::Alpha#target_result
- Defined in:
- lib/alpha/alpha.rb
#target_result(coordinates, was_hit, ship_sunk) ⇒ Object
target_result will be called by the system after a call to next_target. The paramters supplied inform the player of the results of the target.
coordinates : string. The coordinates targeted. It will be the same value returned by the previous call to next_target
was_hit : boolean. true if the target was occupied by a ship. false otherwise.
ship_sunk : symbol. nil if the target did not result in the sinking of a ship. If the target did result in
in the sinking of a ship, the ship type is supplied (:carrier, :battleship, :destroyer, :submarine, :patrolship).
An intelligent player will use the information to better play the game. For example, if the result indicates a hit, a player my choose to target neighboring squares to hit and sink the remainder of the ship.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/alpha/alpha.rb', line 132 def target_result(coordinates, was_hit, ship_sunk) result = nil if was_hit result = :hit @red_zone = true unless ship_sunk else result = :miss end @red_zone = false if ship_sunk @opponents_grid.place(coordinates, result) end |