Files
space_game_server/core/player.rb
T

44 lines
879 B
Ruby

# Nathan Hinton 19 Dec 2025
require 'securerandom'
# This defines the player class
class Player
attr_reader :name, :resources, :id
attr_accessor :home_planet
# initialize a player.
#
# @param name [String] The name of the player
def initialize(name: 'test player')
@name = name
@planets = []
@fleets = []
@tech = []
@resources = {
'metal' => 0,
'crystals' => 0,
'credits' => 0
}
# This id will be used to validate the player in the game
@id = SecureRandom.hex()
@id_retrieved = false
@home_planet = nil
end
# Returns the player ID. This *should* only be called once. When called again
# it should print a warning to the log.
#
# @return [String] The ID of the player
def get_id
if @id_retrieved
# Print a warning message!
end
@id_retrieved = true
return @id
end
end