Fixing tests
This commit is contained in:
+28
-5
@@ -6,17 +6,22 @@ require 'yaml'
|
||||
|
||||
# A player object for the class Game
|
||||
class Player
|
||||
attr_reader :player_resources, :player_id, :player_planets, :player_ships, :faction, :researched_tech, :buildings
|
||||
attr_accessor :player_resources, :player_id, :player_planets, :player_ships, :faction, :researched_tech, :buildings, :ship_build_power, :research_tech_build_power, :military_tech_build_power
|
||||
|
||||
def initialize(player_id, faction)
|
||||
@player_id = player_id
|
||||
@player_planets = []
|
||||
@player_ships = []
|
||||
@home_planet = nil
|
||||
@researched_tech = []
|
||||
@buildings = []
|
||||
@ship_build_power = 0
|
||||
@research_tech_build_power = 0
|
||||
@military_tech_build_power = 0
|
||||
|
||||
# Validate faction:
|
||||
if !(['good', 'evil'].include? faction)
|
||||
raise PlayerError, 'Faction must be `good` or `evil`'
|
||||
raise PlayerError, 'Faction must be \`good\` or \`evil\`'
|
||||
end
|
||||
@faction = faction
|
||||
end
|
||||
@@ -26,9 +31,9 @@ class Player
|
||||
#
|
||||
# @param credits [Integer] The number of starting credits
|
||||
# @param metal [Integer] The amount of starting metal
|
||||
# @param crystals [Integer] The number of starting crystals
|
||||
# @param crystals [Integer] The amount of starting crystals
|
||||
# @param fuel [Integer] The amount of fuel to start with.
|
||||
# @param faction [String] The faction that the player should start as. Should be `good` or `evil`
|
||||
# @param faction [String] The faction that the player should start as. Should be \`good\` or \`evil\`
|
||||
def create_new(credits, metal, crystals, fuel)
|
||||
@player_resources = {
|
||||
'credits' => credits,
|
||||
@@ -133,7 +138,12 @@ class Player
|
||||
player_ships: @player_ships,
|
||||
home_planet: @home_planet,
|
||||
faction: @faction,
|
||||
player_resources: @player_resources
|
||||
player_resources: @player_resources,
|
||||
researched_tech: @researched_tech,
|
||||
buildings: @buildings,
|
||||
ship_build_power: @ship_build_power,
|
||||
research_tech_build_power: @research_tech_build_power,
|
||||
military_tech_build_power: @military_tech_build_power
|
||||
}
|
||||
end
|
||||
|
||||
@@ -147,6 +157,19 @@ class Player
|
||||
@home_planet = data[:home_planet]
|
||||
@faction = data[:faction]
|
||||
@player_resources = data[:player_resources]
|
||||
@researched_tech = data[:researched_tech] || []
|
||||
@buildings = data[:buildings] || []
|
||||
@ship_build_power = data[:ship_build_power] || 0
|
||||
@research_tech_build_power = data[:research_tech_build_power] || 0
|
||||
@military_tech_build_power = data[:military_tech_build_power] || 0
|
||||
end
|
||||
|
||||
def all_buildings
|
||||
@buildings
|
||||
end
|
||||
|
||||
def all_tech
|
||||
@researched_tech
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user