Files
space_game_server/core/planet.rb
T

64 lines
1.3 KiB
Ruby

# Nathan Hinton 19 Dec 2025
# Holds a planet and planet information
require './space_object'
# Class for planets.
class Planet < SpaceObject
attr_reader :owner, :resources
# Create a planet in the game
def initialize()
super()
@buildings = []
@owner = nil
@resources = {
'food' => 0,
'energy' => 0,
'people' => 10
}
end
# Any clean up that the planet will need
def delete()
end
# Build a building on the planet
#
# @param building [Building] The building to be built
def building_build(building)
@buildings.append(building)
end
# Remove building from the planet
#
# @param building [Building] The building to be destroyed
def building_destroy(building)
index = @buildings.index(building)
if index == nil
raise PlanetError, 'Building not found to delete'
end
@buildings.delete_at(index)
end
# Capture a planet for a player
#
# @param player [Player] The player who is capturing the planet
def capture(player)
@buildings = [] # Destroy all the buildings on the planet
@owner = player
end
# Tick for the planet
def tick()
@buildings.each do |building|
building.tick
end
end
end
# Generic error for plannets
class PlanetError < StandardError
end