working on reimplimenting server

This commit is contained in:
2025-12-19 19:23:54 -07:00
parent 4737531805
commit 057164122a
20 changed files with 1145 additions and 6 deletions
+63
View File
@@ -0,0 +1,63 @@
# 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