Skip to content

Instantly share code, notes, and snippets.

@pumpkincouture
Last active August 29, 2015 14:04
Show Gist options
  • Save pumpkincouture/72e9ba3d563806e25433 to your computer and use it in GitHub Desktop.
Save pumpkincouture/72e9ba3d563806e25433 to your computer and use it in GitHub Desktop.
class Game
attr_reader :board, :computer_player, :human_player, :ui
def initialize
@board = Board.new
@computer_player = ComputerPlayer.new
@human_player = HumanPlayer.new
@ui = UserInterface.new(human_player)
end
@@no_space=9
def decrease_space
puts "The game has ended!" if game_over?
@@no_space -= 1
end
def game_over?
@@no_space <= 0
end
def welcome
puts "Welcome to a Simpler Tic Tac Toe. The computer will go first."
@board.board["5"]="X"
puts "The computer chose space number 5."
@board.display_board
self.decrease_space
end
def play_game
@human_player.user_turn(@ui)
@board.human_move(@human_player.human_move, @board, @ui, self)
# @human_player.user_turn(@ui) until @board.no_error
# @board.human_move(@human_player.human_move, @board, @ui, self)
@computer_player.computer_turn(@board)
@board.computer_move(@computer_player.computer_move, self)
end
end
#######CODE########
new_game= Game.new
new_game.welcome
until new_game.game_over?
new_game.play_game
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment