class MazeGame
Public Class Methods
new(clients)
click to toggle source
# 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
Public Instance Methods
all_players_reached_exit?()
click to toggle source
# File lib/maze/game/maze_game.rb, line 45 def all_players_reached_exit? @players.reject{|client, _| player_reached_exit? client }.empty? end
maze(client)
click to toggle source
# File lib/maze/game/maze_game.rb, line 32 def maze(client) @maze.to_s_for_player(client.number, @players[client].current_position) end
move(client, orientation)
click to toggle source
# File lib/maze/game/maze_game.rb, line 20 def move(client, orientation) @players[client].move(orientation) end
moves()
click to toggle source
# File lib/maze/game/maze_game.rb, line 24 def moves player_moves = {} @players.each do |client, player| player_moves[client.name] = player.moves end player_moves end
player_reached_exit?(client)
click to toggle source
# File lib/maze/game/maze_game.rb, line 41 def player_reached_exit?(client) @maze.exit?(@players[client].current_position) end
print_current_maze()
click to toggle source
# File lib/maze/game/maze_game.rb, line 36 def print_current_maze puts 'Maze Field' puts @maze.to_s end
reached_player_exit?()
click to toggle source
# File lib/maze/game/maze_game.rb, line 49 def reached_player_exit? !winning_players.empty? end
show_next_moves(client)
click to toggle source
# 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()
click to toggle source
# File lib/maze/game/maze_game.rb, line 53 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
Private Instance Methods
rand_start_position()
click to toggle source
# File lib/maze/game/maze_game.rb, line 62 def rand_start_position @maze.fields.reject{|_, field_type| field_type != :way}.keys.sample end