Skip to content
Snippets Groups Projects
Commit 29034b09 authored by ForkBench's avatar ForkBench
Browse files

Updating type : adding pointers.

parent 64fa1ace
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ type Competition struct {
CompetitionPlayers []Player
}
func (c Competition) String() string {
func (c *Competition) String() string {
return "Competition : " + c.CompetitionName + " - " + c.CompetitionCategory.String() + " - " + c.CompetitionWeapon.String() + " - " + c.CompetitionState.String()
}
......@@ -27,12 +27,13 @@ func CreateCompetition(competitionID uint8, competitionName string, competitionC
c.CompetitionWeapon = competitionWeapon
c.CompetitionState = REGISTERING
c.CompetitionMaxStageNumber = competitionMaxStageNumber
c.CompetitionStages = make([]Stage, competitionMaxStageNumber)
c.CompetitionStages = []Stage{}
c.CompetitionPlayers = []Player{}
return c
}
func (c Competition) AddStage(stage Stage) bool {
func (c *Competition) AddStage(stage Stage) bool {
if c.CompetitionState != IDLE {
return false
}
......@@ -46,7 +47,7 @@ func (c Competition) AddStage(stage Stage) bool {
return true
}
func (c Competition) StagePosition(stage Stage) uint16 {
func (c *Competition) StagePosition(stage Stage) uint16 {
for i, competitionStage := range c.CompetitionStages {
if competitionStage == stage {
return uint16(i)
......@@ -56,7 +57,7 @@ func (c Competition) StagePosition(stage Stage) uint16 {
return math.MaxInt16
}
func (c Competition) RemoveStage(stage Stage) bool {
func (c *Competition) RemoveStage(stage Stage) bool {
if c.CompetitionState != IDLE {
return false
}
......@@ -70,7 +71,7 @@ func (c Competition) RemoveStage(stage Stage) bool {
return true
}
func (c Competition) StartCompetition() bool {
func (c *Competition) StartCompetition() bool {
if c.CompetitionState != REGISTERING {
return false
}
......@@ -80,7 +81,7 @@ func (c Competition) StartCompetition() bool {
return true
}
func (c Competition) FinishCompetition() bool {
func (c *Competition) FinishCompetition() bool {
if c.CompetitionState != STARTED {
return false
}
......@@ -92,7 +93,7 @@ func (c Competition) FinishCompetition() bool {
return true
}
func (c Competition) AddPlayer(player Player) bool {
func (c *Competition) AddPlayer(player Player) bool {
if c.CompetitionState != REGISTERING {
return false
}
......@@ -102,7 +103,7 @@ func (c Competition) AddPlayer(player Player) bool {
return true
}
func (c Competition) PlayerPosition(player Player) uint16 {
func (c *Competition) PlayerPosition(player Player) uint16 {
for i, competitionPlayer := range c.CompetitionPlayers {
if competitionPlayer == player {
return uint16(i)
......@@ -112,7 +113,7 @@ func (c Competition) PlayerPosition(player Player) uint16 {
return math.MaxInt16
}
func (c Competition) RemovePlayer(player Player) bool {
func (c *Competition) RemovePlayer(player Player) bool {
if c.CompetitionState != REGISTERING {
return false
}
......@@ -128,18 +129,10 @@ func (c Competition) RemovePlayer(player Player) bool {
return true
}
func (c Competition) AddPlayerToStage(player Player, stage Stage) bool {
if stage.AddPlayer(player) {
return true
}
return false
func (c *Competition) AddPlayerToStage(player Player, stage Stage) bool {
return stage.AddPlayer(player)
}
func (c Competition) RemovePlayerFromStage(player Player, stage Stage) bool {
if stage.RemovePlayer(player) {
return true
}
return false
func (c *Competition) RemovePlayerFromStage(player Player, stage Stage) bool {
return stage.RemovePlayer(player)
}
......@@ -8,12 +8,24 @@ type Player struct {
PlayerNationID uint16
PlayerRegionID uint16
PlayerClubID uint16
PlayerInitialRank uint16
}
func (p Player) String() string {
return "Player : " + p.PlayerFirstname + " " + p.PlayerLastname
}
func CreatePlayer(playerID uint16, playerFirstname string, playerLastname string) Player {
var p Player
p.PlayerID = playerID
p.PlayerFirstname = playerFirstname
p.PlayerLastname = playerLastname
p.PlayerInitialRank = 10000
return p
}
// Referee : Person details
type Referee struct {
RefereeID uint16 // More than 255 referees
......
......@@ -44,7 +44,7 @@ func (p Pool) PlayerPosition(player Player) uint16 {
return math.MaxInt16
}
func (p Pool) AddPlayer(player Player) bool {
func (p *Pool) AddPlayer(player Player) bool {
if p.PoolState != IDLE {
return false
}
......@@ -61,7 +61,7 @@ func (p Pool) AddPlayer(player Player) bool {
return false
}
func (p Pool) RemovePlayer(player Player) bool {
func (p *Pool) RemovePlayer(player Player) bool {
if p.PoolState != IDLE {
return false
}
......@@ -76,6 +76,6 @@ func (p Pool) RemovePlayer(player Player) bool {
return false
}
func (p Pool) SetReferee(referee Referee) {
func (p *Pool) SetReferee(referee Referee) {
p.PoolReferee = referee
}
......@@ -32,3 +32,30 @@ func (s *Session) RemoveCompetition(competitionID uint8) {
func (s *Session) GetCompetitions() []Competition {
return s.Competitions
}
func (s *Session) GetCompetition(competitionID uint8) Competition {
for _, competition := range s.Competitions {
if competition.CompetitionID == competitionID {
return competition
}
}
return Competition{}
}
func (s *Session) AddPlayerToCompetition(competitionID uint8, player Player) bool {
competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" {
return false
}
return competition.AddPlayer(player)
}
func (s *Session) RemovePlayerFromCompetition(competitionID uint8, player Player) bool {
competition := s.GetCompetition(competitionID)
if competition.CompetitionName == "" {
return false
}
return competition.RemovePlayer(player)
}
export function randomColor(brightness: number): string {
function randomChannel(brightness: number): string {
var r = 255-brightness;
var n = 0|((Math.random() * r) + brightness);
var s = n.toString(16);
return (s.length==1) ? '0'+s : s;
}
return '#' + randomChannel(brightness) + randomChannel(brightness) + randomChannel(brightness);
}
export const rightBrighness = 240;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment