-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#267): Added server side fight object
- Loading branch information
1 parent
d7aec13
commit a93374e
Showing
9 changed files
with
82 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fight | ||
|
||
import "github.com/lxgr-linux/pokete/server/pokete/user" | ||
|
||
type Fight struct { | ||
ID FightID | ||
playerA *user.User | ||
playerB *user.User | ||
} | ||
|
||
func New(playerA *user.User, playerB *user.User) Fight { | ||
return Fight{playerA: playerA, playerB: playerB} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fight | ||
|
||
import "errors" | ||
|
||
var FIGHT_DOESNT_EXIST = errors.New("fight with id doesnt exist") | ||
|
||
type FightID uint64 | ||
|
||
type Fights struct { | ||
currFightID FightID | ||
fights map[FightID]*Fight | ||
} | ||
|
||
func (f *Fights) incID() { | ||
f.currFightID += 1 | ||
} | ||
|
||
func (f *Fights) Add(fight *Fight) { | ||
f.incID() | ||
fight.ID = f.currFightID | ||
f.fights[fight.ID] = fight | ||
} | ||
|
||
func (f *Fights) Get(id FightID) (*Fight, error) { | ||
fight, ok := f.fights[id] | ||
if !ok { | ||
return nil, FIGHT_DOESNT_EXIST | ||
} | ||
return fight, nil | ||
} | ||
|
||
func NewFights() Fights { | ||
return Fights{0, make(map[FightID]*Fight)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
pkg/server/pokete/fight/poke.go → pkg/server/pokete/poke/instance.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters