Created
July 3, 2013 09:40
-
-
Save ecomba/5916673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Board | |
def initialize ships | |
@ships = ships | |
end | |
def shoot coordinates | |
if coordinates == 1 # this would call the ships really | |
@ships = [0,0,-1,1] | |
return 'HIT' | |
end | |
return 'Miss' | |
end | |
def show | |
@ships | |
end | |
end | |
class OpponentBoard | |
def initialize board | |
@board = board | |
end | |
def shoot coordinates | |
result = @board.shoot coordinates | |
end | |
def show | |
@board.show.map do |n| | |
if n > 0 | |
n-1 | |
else | |
n | |
end | |
end | |
end | |
end | |
class Player | |
def initialize target | |
@target = target | |
end | |
def shoot coordinates | |
@target.shoot coordinates | |
end | |
def board | |
@target.show | |
end | |
end | |
board = Board.new [0,0,1,1] | |
target = OpponentBoard.new board | |
player = Player.new target | |
player.shoot 1 | |
puts player.board.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment