diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..944ab8a --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2021 PayPal Inc., Evan Dorn, Patryk Grochowski, Molly Li + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 67faa2d..422e45b 100644 --- a/README.md +++ b/README.md @@ -6,3 +6,7 @@ Crystal Caves multiplayer game server ## Relevant Docs - [Overview & Design](https://paypal-my.sharepoint.com/:p:/r/personal/edorn_paypal_com/_layouts/15/guestaccess.aspx?email=molli%40paypal.com&e=0N35Xv&share=Ec7YPp6ofg1Dv2f1y3NzSw0BXVcnQHrgCYKT8y7aZMCCBA) - [Task Breakdown](https://github.com/honeyscience/crystal-caves-golang/issues) + +## Running tests + +`go test ./...` diff --git a/internal/state/enemy.go b/internal/state/enemy.go new file mode 100644 index 0000000..3f04042 --- /dev/null +++ b/internal/state/enemy.go @@ -0,0 +1,7 @@ +package state + +type Enemy struct { + location Location + velocity Velocity + geometry Geometry + } diff --git a/internal/state/enemy_test.go b/internal/state/enemy_test.go new file mode 100644 index 0000000..1c52b0b --- /dev/null +++ b/internal/state/enemy_test.go @@ -0,0 +1,31 @@ +package state + +import "testing" + +func TestEnemyHasDefaultLocation(t *testing.T) { + enemy := new(Enemy) + + gotx := enemy.location.x + goty := enemy.location.y + + if (gotx != 0.0) { + t.Errorf("Initialized enemy did not have default x coord 0.0") + } + if (goty != 0.0) { + t.Errorf("Initialized enemy did not have default y coord 0.0") + } +} + +func TestEnemyHasDefaultVelocity(t *testing.T) { + enemy := new(Enemy) + + gotx := enemy.velocity.x + goty := enemy.velocity.y + + if (gotx != 0.0) { + t.Errorf("Initialized enemy did not have default x velocity 0.0") + } + if (goty != 0.0) { + t.Errorf("Initialized enemy did not have default y velocity 0.0") + } +} diff --git a/internal/state/game.go b/internal/state/game.go new file mode 100644 index 0000000..e6a0580 --- /dev/null +++ b/internal/state/game.go @@ -0,0 +1,10 @@ +package state + +type Game struct { + players []Player + enemies []Enemy + goals []Goal + + // current game time + // start clock time +} diff --git a/internal/state/game_test.go b/internal/state/game_test.go new file mode 100644 index 0000000..fbf5274 --- /dev/null +++ b/internal/state/game_test.go @@ -0,0 +1,24 @@ +package state + +import "testing" + +func TestANewGameShouldHaveAnEmptyPlayerList(t *testing.T){ + game := new(Game) + if !(len(game.players)==0) { + t.Errorf("New game did not have a zero-length list of players") + } +} + +func TestANewGameShouldHaveAnEmptyEnemyList(t *testing.T){ + game := new(Game) + if !(len(game.enemies)==0) { + t.Errorf("New game did not have a zero-length list of enemies") + } +} + +func TestANewGameShouldHaveAnEmptyGoalsList(t *testing.T){ + game := new(Game) + if !(len(game.goals)==0) { + t.Errorf("New game did not have a zero-length list of goals") + } +} diff --git a/internal/state/geometry.go b/internal/state/geometry.go new file mode 100644 index 0000000..31d5454 --- /dev/null +++ b/internal/state/geometry.go @@ -0,0 +1,5 @@ +package state + +type Geometry struct { + radius float32 + } diff --git a/internal/state/geometry_test.go b/internal/state/geometry_test.go new file mode 100644 index 0000000..cef5e74 --- /dev/null +++ b/internal/state/geometry_test.go @@ -0,0 +1,12 @@ +package state + +import "testing" + +func TestSetAndRetrieveGeometry(t *testing.T){ + geo := new(Geometry) + geo.radius = 3.0 + + if (geo.radius != 3.0) { + t.Errorf("Radius not retrieved correctly got %v, wanted %v ", geo.radius, 3.0) + } +} diff --git a/internal/state/goal.go b/internal/state/goal.go new file mode 100644 index 0000000..42d74e6 --- /dev/null +++ b/internal/state/goal.go @@ -0,0 +1,6 @@ +package state + +type Goal struct { + location Location + geometry Geometry + } diff --git a/internal/state/goal_test.go b/internal/state/goal_test.go new file mode 100644 index 0000000..b445018 --- /dev/null +++ b/internal/state/goal_test.go @@ -0,0 +1,17 @@ +package state + +import "testing" + +func TestGoalHasDefaultLocation(t *testing.T) { + goal := new(Goal) + + gotx := goal.location.x + goty := goal.location.y + + if (gotx != 0.0) { + t.Errorf("Initialized goal did not have default x coord 0.0") + } + if (goty != 0.0) { + t.Errorf("Initialized goal did not have default y coord 0.0") + } +} diff --git a/internal/state/location.go b/internal/state/location.go new file mode 100644 index 0000000..e5854ab --- /dev/null +++ b/internal/state/location.go @@ -0,0 +1,6 @@ +package state + +type Location struct { + x float32 + y float32 +} diff --git a/internal/state/location_test.go b/internal/state/location_test.go new file mode 100644 index 0000000..fcaeb2d --- /dev/null +++ b/internal/state/location_test.go @@ -0,0 +1,16 @@ +package state + +import "testing" + +func TestSetAndRetrieveLocation(t *testing.T){ + loc := new(Location) + loc.x = 1.0 + loc.y = -1.5 + + if (loc.x != 1.0) { + t.Errorf("X not retrieved correctly got %v, wanted %v ", loc.x, 1.0) + } + if (loc.y != -1.5) { + t.Errorf("Y not retrieved correctly got %v, wanted %v ", loc.x, 1.0) + } +} diff --git a/internal/state/player.go b/internal/state/player.go new file mode 100644 index 0000000..9ba13e2 --- /dev/null +++ b/internal/state/player.go @@ -0,0 +1,14 @@ +package state + +type Player struct { + location Location + velocity Velocity + geometry Geometry + score int + alive bool + + // If the player has been killed, this + // variable should contain the time (in game time) + // at which they wil reappear on the field + respawnTime float32 + } diff --git a/internal/state/player_test.go b/internal/state/player_test.go new file mode 100644 index 0000000..be5c704 --- /dev/null +++ b/internal/state/player_test.go @@ -0,0 +1,31 @@ +package state + +import "testing" + +func TestPlayerHasDefaultLocation(t *testing.T) { + player := new(Player) + + gotx := player.location.x + goty := player.location.y + + if (gotx != 0.0) { + t.Errorf("Initialized player did not have default x coord 0.0") + } + if (goty != 0.0) { + t.Errorf("Initialized player did not have default y coord 0.0") + } +} + +func TestPlayerHasDefaultVelocity(t *testing.T) { + player := new(Player) + + gotx := player.velocity.x + goty := player.velocity.y + + if (gotx != 0.0) { + t.Errorf("Initialized player did not have default x velocity 0.0") + } + if (goty != 0.0) { + t.Errorf("Initialized player did not have default y velocity 0.0") + } +} diff --git a/internal/state/velocity.go b/internal/state/velocity.go new file mode 100644 index 0000000..b3f5c7b --- /dev/null +++ b/internal/state/velocity.go @@ -0,0 +1,6 @@ +package state + +type Velocity struct { + x float32 + y float32 + } diff --git a/internal/state/velocity_test.go b/internal/state/velocity_test.go new file mode 100644 index 0000000..b2d8db8 --- /dev/null +++ b/internal/state/velocity_test.go @@ -0,0 +1,16 @@ +package state + +import "testing" + +func TestSetAndRetrieveVelocity(t *testing.T){ + vel := new(Velocity) + vel.x = 1.0 + vel.y = -1.5 + + if (vel.x != 1.0) { + t.Errorf("X not retrieved correctly got %v, wanted %v ", vel.x, 1.0) + } + if (vel.y != -1.5) { + t.Errorf("Y not retrieved correctly got %v, wanted %v ", vel.x, 1.0) + } +}