From 61e2ed3248227058d17d1ec23c2608356189622b Mon Sep 17 00:00:00 2001 From: Evan Dorn Date: Mon, 9 Aug 2021 12:23:19 -0700 Subject: [PATCH 1/5] Add MIT LICENSE file --- LICENSE | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 LICENSE 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. From fb43b07f39cc706b662a79db1e2d6490c433fd30 Mon Sep 17 00:00:00 2001 From: Evan Dorn Date: Mon, 9 Aug 2021 13:36:25 -0700 Subject: [PATCH 2/5] Initial geometric structs, update readme with test instructions --- README.md | 4 ++++ internal/state/geometry.go | 5 +++++ internal/state/geometry_test.go | 12 ++++++++++++ internal/state/location.go | 6 ++++++ internal/state/location_test.go | 16 ++++++++++++++++ internal/state/player | 5 +++++ internal/state/velocity.go | 6 ++++++ internal/state/velocity_test.go | 16 ++++++++++++++++ 8 files changed, 70 insertions(+) create mode 100644 internal/state/geometry.go create mode 100644 internal/state/geometry_test.go create mode 100644 internal/state/location.go create mode 100644 internal/state/location_test.go create mode 100644 internal/state/player create mode 100644 internal/state/velocity.go create mode 100644 internal/state/velocity_test.go 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/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..693ea97 --- /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 = 1.0 + + if (geo.radius != 1.0) { + t.Errorf("Radius not retrieved correctly got %v, wanted %v ", geo.radius, 1.0) + } +} diff --git a/internal/state/location.go b/internal/state/location.go new file mode 100644 index 0000000..f846db1 --- /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 b/internal/state/player new file mode 100644 index 0000000..ad26ec7 --- /dev/null +++ b/internal/state/player @@ -0,0 +1,5 @@ +package state + +type Player struct { + + } 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) + } +} From 4f9cff9f24f368f8419d7a92c9d5e9516af3902e Mon Sep 17 00:00:00 2001 From: Evan Dorn Date: Mon, 9 Aug 2021 14:22:12 -0700 Subject: [PATCH 3/5] added structs for game, goal, and enemy --- internal/state/enemy.go | 7 +++++++ internal/state/game.go | 9 +++++++++ internal/state/game_test.go | 7 +++++++ internal/state/geometry_test.go | 6 +++--- internal/state/goal.go | 6 ++++++ internal/state/goal_test.go | 17 +++++++++++++++++ internal/state/location.go | 2 +- internal/state/player | 5 ----- internal/state/player.go | 14 ++++++++++++++ internal/state/player_test.go | 31 +++++++++++++++++++++++++++++++ 10 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 internal/state/enemy.go create mode 100644 internal/state/game.go create mode 100644 internal/state/game_test.go create mode 100644 internal/state/goal.go create mode 100644 internal/state/goal_test.go delete mode 100644 internal/state/player create mode 100644 internal/state/player.go create mode 100644 internal/state/player_test.go 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/game.go b/internal/state/game.go new file mode 100644 index 0000000..b0c6764 --- /dev/null +++ b/internal/state/game.go @@ -0,0 +1,9 @@ +package state + +type Game struct { + // player list + // enemy list + // goal(crystal) list + // 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..e2ed0f5 --- /dev/null +++ b/internal/state/game_test.go @@ -0,0 +1,7 @@ +package state + +import "testing" + +func TestSetAndRetrieveGame(t *testing.T){ + // game := new(Game) +} diff --git a/internal/state/geometry_test.go b/internal/state/geometry_test.go index 693ea97..cef5e74 100644 --- a/internal/state/geometry_test.go +++ b/internal/state/geometry_test.go @@ -4,9 +4,9 @@ import "testing" func TestSetAndRetrieveGeometry(t *testing.T){ geo := new(Geometry) - geo.radius = 1.0 + geo.radius = 3.0 - if (geo.radius != 1.0) { - t.Errorf("Radius not retrieved correctly got %v, wanted %v ", geo.radius, 1.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 index f846db1..e5854ab 100644 --- a/internal/state/location.go +++ b/internal/state/location.go @@ -3,4 +3,4 @@ package state type Location struct { x float32 y float32 - } +} diff --git a/internal/state/player b/internal/state/player deleted file mode 100644 index ad26ec7..0000000 --- a/internal/state/player +++ /dev/null @@ -1,5 +0,0 @@ -package state - -type Player struct { - - } 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") + } +} From 797a73919369a79bf54fdf980ee5ede2935fa2f0 Mon Sep 17 00:00:00 2001 From: Evan Dorn Date: Mon, 9 Aug 2021 14:23:17 -0700 Subject: [PATCH 4/5] added missing test file for enemy --- internal/state/enemy_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 internal/state/enemy_test.go 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") + } +} From 5ac0d6fee22619d3d2d04aad44b97198dc44c345 Mon Sep 17 00:00:00 2001 From: Evan Dorn Date: Mon, 9 Aug 2021 14:28:09 -0700 Subject: [PATCH 5/5] Start filling out game struct --- internal/state/game.go | 7 ++++--- internal/state/game_test.go | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/internal/state/game.go b/internal/state/game.go index b0c6764..e6a0580 100644 --- a/internal/state/game.go +++ b/internal/state/game.go @@ -1,9 +1,10 @@ package state type Game struct { - // player list - // enemy list - // goal(crystal) list + 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 index e2ed0f5..fbf5274 100644 --- a/internal/state/game_test.go +++ b/internal/state/game_test.go @@ -2,6 +2,23 @@ package state import "testing" -func TestSetAndRetrieveGame(t *testing.T){ - // game := new(Game) +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") + } }