Files
space_game_server/game/planet.rb
T
2025-12-19 09:16:48 -07:00

41 lines
1.0 KiB
Ruby

# Nathan Hinton 1 Oct 2025
PLANET_PRODUCTION_RESOURCES = [:ships]
# This class holds information about a planet.
class Planet
attr_reader :owner
# Create a planet
#
# @param random [Random] The random generator for the game (ensures seeds can be duplicated)
def initialize(random)
@random = random
@prod_rate = @random.rand
@resource = PLANET_PRODUCTION_RESOURCES.sample(random: @random)
@owner = nil
end
# Change the ownership of a planet. Should check for things like the planet
# has no defenders left and other fun stuff (later)
#
# @param owner [Player] The owner of the planet
# @return [Boolean] If the operation was successful or not
def change_owner(owner)
# For now only unclaimed planets can be owned
if @owner.nil?
@owner = owner
return true
end
return false
end
# Incriment the planet. Used to add resources to the Player's global resource
# storage
def tick
if !@owner.nil?
@oener.add_resources({@resource => @prod_rate})
end
end
end