Skip to content

Instantly share code, notes, and snippets.

@sevab
Forked from ecomba/decorating_boards.rb
Created July 28, 2013 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sevab/6098289 to your computer and use it in GitHub Desktop.
Save sevab/6098289 to your computer and use it in GitHub Desktop.
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