Prechádzať zdrojové kódy

Fixed: x,y and set the players position (and return from the endless loop...)

Ronald Peterson 10 rokov pred
rodič
commit
23d4bae877
2 zmenil súbory, kde vykonal 6 pridanie a 4 odobranie
  1. 2 2
      board/coordinate.go
  2. 4 2
      games/game.go

+ 2 - 2
board/coordinate.go

@@ -1,6 +1,6 @@
 package board
 
 type Coordinate struct {
-	X int
-	Y int
+	X int `json:"x"`
+	Y int `json:"y"`
 }

+ 4 - 2
games/game.go

@@ -37,7 +37,7 @@ func (g *Game) Join(p *player.Player) {
 	g.mutex.Unlock()
 }
 
-func (g *Game) placePlayer(p *player.Player) *board.Coordinate {
+func (g *Game) placePlayer(p *player.Player) {
 	xRange := g.Board.Cols / 5
 	yRange := g.Board.Rows
 
@@ -46,7 +46,9 @@ func (g *Game) placePlayer(p *player.Player) *board.Coordinate {
 		y := rand.Intn(yRange)
 		
 		if g.isValidPlayerPos(x, y) {
-			return &board.Coordinate{x, y}
+			p.Pos.X = x
+			p.Pos.Y = y
+			return
 		}
 	}