Class: ChessVwong::Game
- Inherits:
-
Object
- Object
- ChessVwong::Game
- Defined in:
- lib/chess_vwong/game.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#current_player ⇒ Object
readonly
Returns the value of attribute current_player.
-
#other_player ⇒ Object
readonly
Returns the value of attribute other_player.
Instance Method Summary collapse
- #game_over ⇒ Object
-
#initialize(players, board = Board.new) ⇒ Game
constructor
A new instance of Game.
- #play ⇒ Object
- #switch_players ⇒ Object
Constructor Details
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
4 5 6 |
# File 'lib/chess_vwong/game.rb', line 4 def board @board end |
#current_player ⇒ Object (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_player ⇒ Object (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_over ⇒ Object
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 |
#play ⇒ Object
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 board.formatted_grid return else switch_players end end end |
#switch_players ⇒ Object
11 12 13 |
# File 'lib/chess_vwong/game.rb', line 11 def switch_players @current_player, @other_player = @other_player, @current_player end |