Class: ChessVwong::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/chess_vwong/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(players, board = Board.new) ⇒ Game

Returns a new instance of Game.



5
6
7
8
9
# File 'lib/chess_vwong/game.rb', line 5

def initialize(players, board = Board.new)
  @current_player = players[0]
  @other_player = players[1]
  @board = board
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



4
5
6
# File 'lib/chess_vwong/game.rb', line 4

def board
  @board
end

#current_playerObject (readonly)

Returns the value of attribute current_player.



3
4
5
# File 'lib/chess_vwong/game.rb', line 3

def current_player
  @current_player
end

#other_playerObject (readonly)

Returns the value of attribute other_player.



3
4
5
# File 'lib/chess_vwong/game.rb', line 3

def other_player
  @other_player
end

Instance Method Details

#game_overObject



17
18
19
20
# File 'lib/chess_vwong/game.rb', line 17

def game_over
  return current_player if current_player.kill_list.last.instance_of?(King)
  false
end

#playObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chess_vwong/game.rb', line 23

def play
  board.preload_pieces
  while true
    board.formatted_grid
    puts ""
    solicit_get_piece
    puts ""
    solicit_set_piece
    if game_over
      puts game_over_message
      board.formatted_grid
      return
    else
      switch_players
    end
  end
end

#switch_playersObject



11
12
13
# File 'lib/chess_vwong/game.rb', line 11

def switch_players
  @current_player, @other_player = @other_player, @current_player
end