Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Issue 07 create game struct #10

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions LICENSE
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.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...`
7 changes: 7 additions & 0 deletions internal/state/enemy.go
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
}
31 changes: 31 additions & 0 deletions internal/state/enemy_test.go
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")
}
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

10 changes: 10 additions & 0 deletions internal/state/game.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package state

type Game struct {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@Evan-Honey Evan-Honey Aug 16, 2021

Choose a reason for hiding this comment

The 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
}
24 changes: 24 additions & 0 deletions internal/state/game_test.go
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")
}
}
5 changes: 5 additions & 0 deletions internal/state/geometry.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package state

type Geometry struct {
radius float32
}
12 changes: 12 additions & 0 deletions internal/state/geometry_test.go
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)
}
}
6 changes: 6 additions & 0 deletions internal/state/goal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package state

type Goal struct {
location Location
geometry Geometry
}
17 changes: 17 additions & 0 deletions internal/state/goal_test.go
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")
}
}
6 changes: 6 additions & 0 deletions internal/state/location.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package state

type Location struct {
x float32
y float32
}
16 changes: 16 additions & 0 deletions internal/state/location_test.go
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loc here is incorrect, should be -1.5

}
}
14 changes: 14 additions & 0 deletions internal/state/player.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package state

type Player struct {
location Location
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
}
31 changes: 31 additions & 0 deletions internal/state/player_test.go
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")
}
}
6 changes: 6 additions & 0 deletions internal/state/velocity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package state

type Velocity struct {
x float32
y float32
}
16 changes: 16 additions & 0 deletions internal/state/velocity_test.go
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong loc here too

}
}