From 4737531805bead5ddf6b290c5ea5bdac24bcaf27 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 19 Dec 2025 09:16:48 -0700 Subject: [PATCH] Pushing all changes --- README.md | 44 +++++++++++++++++++++++++++++--------- game/planet.rb | 8 +++++++ game/player.rb | 13 ++++++++++- game/spec/planet_spec.rb | 12 +++++++++-- game/spec/player_spec.rb | 16 ++++++++++++++ game/spec/universe_spec.rb | 13 +++++++++++ game/universe.rb | 12 +++++++++++ 7 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 game/spec/player_spec.rb diff --git a/README.md b/README.md index 7d54974..c52a33e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ bonuses. Some can produce ships faster, others will produce more resources and in others you can find bonuses for different kinds of ships. I want to make it so that you can also upgrade the planets to improve the value of them. -The maximum player count in a game will be 20 however I want this to be scalable. +The maximum player count in a game will be 20 however I want this to be +scalable. # Thoughts: @@ -30,7 +31,10 @@ gone. This means that the worlds need to be persistent. As a follow up that means that each world will be always running. This means that if there is a main loop for the game it should be very lightweight so that -it does not consume massive amounts of resources. +it does not consume massive amounts of resources. Another thing that I want to +have is that the game speed will change based on the number of players +online. For example, if there are 4 players in the game and all 4 are active I +want to have the game move faster so that they can play together better. I think that each universe should be randomly generated that way the players have to explore it. @@ -42,11 +46,16 @@ Here are the resources that I am thinking of for now: - Food - Metal - Fuel/energy + - Crystals + - Galaxy Credits (Universal money) -How do we have resources travel be twee planets? I am not sure yet. Maybe have + +How do we have resources travel be tween planets? I am not sure yet. Maybe have another type of ship called a transport that can transport resources. This should be automated though so that needed resources are transported -auto-magically. +auto-magically. Another option is to have some resources like metal, crystals, +and Galaxy Credits to be global while things like food and energy are local to +each planet. This way you can build production buildings on each planet. I also want there to be some form of tech tree that the player can choose and can research. Maybe add some rare resources. @@ -89,10 +98,25 @@ security however the server does need to be secure. The `Universe` class will contain everything in the universe. This means planets, ships, and other stelar objects. This will be the API that I can think of: - - universe/ - - ships/ - - create/ - - update/ - - move/ +## User accesible API + +This is the API that the players will be able to access: + +``` +universe/ + - players/ - planets/ - - update/ + - buildings + - fleets/ + - fleet1/ + - ships/ + - fleet2/ + - ships/ + ships/ + - tech/ +``` + +## Admin/server API + +I want them to be able to do anything in the game incliding normally illiegial +actions. diff --git a/game/planet.rb b/game/planet.rb index 46059ca..9e58d69 100644 --- a/game/planet.rb +++ b/game/planet.rb @@ -29,4 +29,12 @@ class Planet 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 diff --git a/game/player.rb b/game/player.rb index bb3f170..5827eaa 100644 --- a/game/player.rb +++ b/game/player.rb @@ -3,12 +3,23 @@ # Class for the player. For now does not do much. class Player - attr_reader :name + attr_reader :name, :resources # initializes with just the player name. # # @param name [String] The name of the player def initialize(name) @name = name + @resources = {:ships => 10, :metal => 100} + end + + def add_resources(resources) + resources.keys.each do |resource_key| + if @resources[resource_key].nil? + @resources[resource_key] = resources[resource_key] + else + @resources[resource_key] += resources[resource_key] + end + end end end diff --git a/game/spec/planet_spec.rb b/game/spec/planet_spec.rb index 215bf18..2e4bfab 100644 --- a/game/spec/planet_spec.rb +++ b/game/spec/planet_spec.rb @@ -8,8 +8,8 @@ RSpec.describe Planet do let(:seed) { 12345 } let(:random) { Random.new(seed) } let(:planet) { Planet.new(random) } - let(:player_1) {Player.new('tester 01') } - let(:player_2) {Player.new('tester 02') } + let(:player_1) { Player.new('tester 01') } + let(:player_2) { Player.new('tester 02') } describe '#initialize' do it 'stores the random off' do @@ -41,4 +41,12 @@ RSpec.describe Planet do expect(planet.instance_variable_get(:@owner)).to eq player_2 end end + + describe '#tick' do + it 'adds resources to the Players storage' do + planet.change_owner(player_1) + planet.tick + expect(player_1.resources).to eq('') + end + end end diff --git a/game/spec/player_spec.rb b/game/spec/player_spec.rb new file mode 100644 index 0000000..8596fbb --- /dev/null +++ b/game/spec/player_spec.rb @@ -0,0 +1,16 @@ +# Nahtan Hinton 3 Oct 2025 + +require './player' + +RSpec.describe Player do + let(:player_1) { Player.new('tester 01') } + describe '#initialize' do + it 'sets the player name' do + expect(player_1.instance_variable_get(:@name)).to eq 'tester 01' + end + + it 'gives initial resources' do + expect(player_1.instance_variable_get(:@resources)).to eq ({:ships => 10, :metal => 100}) + end + end +end diff --git a/game/spec/universe_spec.rb b/game/spec/universe_spec.rb index 7e5c42d..1bb1105 100644 --- a/game/spec/universe_spec.rb +++ b/game/spec/universe_spec.rb @@ -147,4 +147,17 @@ RSpec.describe Universe do expect(universe.planets.length).to eq 18 end end + + describe '#tick' do + it 'runs a tick of the game' do + universe.create_universe + player_1 = Player.new('test player 01') + universe.add_player(player_1) + universe.add_ship(player_1, Position.new(3, 5)) + ships = universe.get_player_ships(player_1) + universe.move_ship(player_1, ships[0], Position.new(2, 4)) + # Now we tick the universe and the ship should move a little and the player should gain resources. + expect{universe.tick}.to_not raise_error() + end + end end diff --git a/game/universe.rb b/game/universe.rb index fdc5f23..b44074e 100644 --- a/game/universe.rb +++ b/game/universe.rb @@ -221,7 +221,18 @@ class Universe return result end + # Runs a tick of the game. Passes it on to all of the sub objects + def tick + # Incriment planets + @planet_list.each do |planet| + planet.tick + end + # Incriment ships + @ship_list.each do |ship| + ship.tick + end + end @@ -272,6 +283,7 @@ class Universe def create_ship(player, position) return false unless validate_player(player) end + alias_method :add_ship, :create_ship # Move a player's ship to a given position #