Class: MazeGame
- Inherits:
-
Object
- Object
- MazeGame
- Defined in:
- lib/maze/game/maze_game.rb
Instance Method Summary collapse
-
#initialize(clients) ⇒ MazeGame
constructor
A new instance of MazeGame.
- #maze(client) ⇒ Object
- #move(client, orientation) ⇒ Object
- #print_current_maze ⇒ Object
- #reached_player_exit? ⇒ Boolean
- #show_next_moves(client) ⇒ Object
- #winning_players ⇒ Object
Constructor Details
#initialize(clients) ⇒ MazeGame
Returns a new instance of MazeGame.
6 7 8 9 10 11 12 13 |
# File 'lib/maze/game/maze_game.rb', line 6 def initialize(clients) @players = Hash.new @maze = Maze.new(30, 30) start_position = rand_start_position clients.each do |_, client| @players[client] = MazePlayer.new(start_position, client.name) end end |
Instance Method Details
#maze(client) ⇒ Object
24 25 26 |
# File 'lib/maze/game/maze_game.rb', line 24 def maze(client) @maze.to_s_for_player(client.number, @players[client].current_position) end |
#move(client, orientation) ⇒ Object
20 21 22 |
# File 'lib/maze/game/maze_game.rb', line 20 def move(client, orientation) @players[client].move(orientation) end |
#print_current_maze ⇒ Object
28 29 30 31 |
# File 'lib/maze/game/maze_game.rb', line 28 def print_current_maze puts 'Maze Field' puts @maze.to_s end |
#reached_player_exit? ⇒ Boolean
33 34 35 |
# File 'lib/maze/game/maze_game.rb', line 33 def reached_player_exit? !winning_players.empty? end |
#show_next_moves(client) ⇒ Object
15 16 17 18 |
# File 'lib/maze/game/maze_game.rb', line 15 def show_next_moves(client) player_position = @players[client].current_position @maze.possible_directions player_position end |
#winning_players ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/maze/game/maze_game.rb', line 37 def winning_players winning_players = [] @players.each do |_, player| winning_players << player if @maze.exit?(player.current_position) end winning_players.map { |player| player.name } end |