Cleaning up and writing tests

This commit is contained in:
2025-10-02 21:45:52 -06:00
parent ed3cd08130
commit 279658f3e5
17 changed files with 584 additions and 56 deletions
+17
View File
@@ -5,11 +5,28 @@ 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[(@random.rand * PLANET_PRODUCTION_RESOURCES.length).floor]
@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
end