Pushing all changes

This commit is contained in:
2025-12-19 09:16:48 -07:00
parent b8f54b44a3
commit 4737531805
7 changed files with 105 additions and 13 deletions
+34 -10
View File
@@ -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 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. 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: # 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 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 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 I think that each universe should be randomly generated that way the players
have to explore it. have to explore it.
@@ -42,11 +46,16 @@ Here are the resources that I am thinking of for now:
- Food - Food
- Metal - Metal
- Fuel/energy - 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 another type of ship called a transport that can transport resources. This
should be automated though so that needed resources are transported 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 I also want there to be some form of tech tree that the player can choose and
can research. Maybe add some rare resources. 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: 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/ ## User accesible API
- ships/
- create/ This is the API that the players will be able to access:
- update/
- move/ ```
universe/
- players/
- planets/ - 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.
+8
View File
@@ -29,4 +29,12 @@ class Planet
end end
return false return false
end 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 end
+12 -1
View File
@@ -3,12 +3,23 @@
# Class for the player. For now does not do much. # Class for the player. For now does not do much.
class Player class Player
attr_reader :name attr_reader :name, :resources
# initializes with just the player name. # initializes with just the player name.
# #
# @param name [String] The name of the player # @param name [String] The name of the player
def initialize(name) def initialize(name)
@name = 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
end end
+10 -2
View File
@@ -8,8 +8,8 @@ RSpec.describe Planet do
let(:seed) { 12345 } let(:seed) { 12345 }
let(:random) { Random.new(seed) } let(:random) { Random.new(seed) }
let(:planet) { Planet.new(random) } let(:planet) { Planet.new(random) }
let(:player_1) {Player.new('tester 01') } let(:player_1) { Player.new('tester 01') }
let(:player_2) {Player.new('tester 02') } let(:player_2) { Player.new('tester 02') }
describe '#initialize' do describe '#initialize' do
it 'stores the random off' 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 expect(planet.instance_variable_get(:@owner)).to eq player_2
end end
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 end
+16
View File
@@ -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
+13
View File
@@ -147,4 +147,17 @@ RSpec.describe Universe do
expect(universe.planets.length).to eq 18 expect(universe.planets.length).to eq 18
end end
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 end
+12
View File
@@ -221,7 +221,18 @@ class Universe
return result return result
end 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) def create_ship(player, position)
return false unless validate_player(player) return false unless validate_player(player)
end end
alias_method :add_ship, :create_ship
# Move a player's ship to a given position # Move a player's ship to a given position
# #