-
Notifications
You must be signed in to change notification settings - Fork 0
Issue 07 create game struct #10
base: main
Are you sure you want to change the base?
Changes from all commits
61e2ed3
fb43b07
4f9cff9
797a739
5ac0d6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package state | ||
|
||
type Enemy struct { | ||
location Location | ||
velocity Velocity | ||
geometry Geometry | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package state | ||
|
||
type Game struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the game also have some kind of boundaries for where the entities can be located? I figure that we should just display a static board size, so knowing what that size is will be useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, will plan to add boundaries in the next PR |
||
players []Player | ||
enemies []Enemy | ||
goals []Goal | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Goals? not Crystals? Am I mistaken that the objective is to get all crystals? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, i suppose I was just trying to make the name generic. like, when we skin it, enemies might become "ghosts" or "monsters", in the same way that goals are crystals |
||
|
||
// current game time | ||
// start clock time | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package state | ||
|
||
type Geometry struct { | ||
radius float32 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package state | ||
|
||
type Goal struct { | ||
location Location | ||
geometry Geometry | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package state | ||
|
||
type Location struct { | ||
x float32 | ||
y float32 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. loc here is incorrect, should be -1.5 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package state | ||
|
||
type Player struct { | ||
location Location | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need something here to represent the player's controllable actions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, will add in a another PR |
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package state | ||
|
||
type Velocity struct { | ||
x float32 | ||
y float32 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong loc here too |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default geometry test? Also for your
players
tests.On a related note too, should the default radius be 1 instead of the built in value of 0? It seems weird to have an entity with no size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default geo test is a good idea, i will add
agreed that the default radius should be 1, but Go does not have a way to set a default for a struct member that isn't the same as that native type's default. There's no constructor or anything either.
To get non-0 defaults we will need to establish a pattern of our own "constructor" methods and make a habit of calling them. From what I've read, Init() is a common name for struct initializers. I think that's out of the scope of this PR, but would go well with the next one containing default boundaries