Compare commits
No commits in common. "b4c82d6c8fd6c87d2a9bb1e5ed7e7cea1509b78c" and "0f71743598b9e65678c06720edf1a63a3dc34356" have entirely different histories.
b4c82d6c8f
...
0f71743598
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch Package",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"program": "${workspaceFolder}/main.go"
|
||||
}
|
||||
]
|
||||
}
|
@ -58,8 +58,8 @@ func (game Game) GetPlayer2() *Player {
|
||||
}
|
||||
|
||||
func (game *Game) prepare() {
|
||||
game.players[0].SetColor(types.White)
|
||||
game.players[1].SetColor(types.Black)
|
||||
game.players[0].color = types.White
|
||||
game.players[1].color = types.Black
|
||||
|
||||
game.currentTurnPlayer = game.GetPlayer1()
|
||||
|
||||
@ -99,7 +99,7 @@ func (game *Game) Handle() {
|
||||
game.gameState = PlayerToMove
|
||||
|
||||
case PlayerToMove:
|
||||
log.Println("with ", game.currentTurnPlayer.GetColor(), " to move")
|
||||
log.Println("with ", game.currentTurnPlayer.GetPlayerColor(), " to move")
|
||||
receivedMove, err = game.currentTurnPlayer.ReadMove()
|
||||
if err != nil {
|
||||
log.Println("Error while reading message:", err)
|
||||
@ -182,12 +182,12 @@ func (game Game) notifyPlayersAboutGameStart() error {
|
||||
}
|
||||
|
||||
func (game Game) broadcastMove(move types.Move) error {
|
||||
err := game.GetPlayer1().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.GetColor())
|
||||
err := game.GetPlayer1().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = game.GetPlayer2().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.GetColor())
|
||||
err = game.GetPlayer2().SendBoardState(move, game.board.PGN(), game.currentTurnPlayer.color)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -48,14 +48,6 @@ func (p *Player) SetWebsocketConnectionAndSendBoardState(
|
||||
p.SendBoardState(types.Move{}, boardPosition, turnColor)
|
||||
}
|
||||
|
||||
func (p *Player) SetColor(color types.ChessColor) {
|
||||
p.color = color
|
||||
}
|
||||
|
||||
func (p *Player) GetColor() types.ChessColor {
|
||||
return p.color
|
||||
}
|
||||
|
||||
func (p *Player) SetDisconnectCallback(cb func(*Player)) {
|
||||
// Todo: Fucking complicated
|
||||
p.Conn.SetDisconnectCallback(p.PlayerDisconnectedCallback)
|
||||
@ -71,8 +63,8 @@ func (p *Player) IsInGame() bool {
|
||||
}
|
||||
|
||||
func (p *Player) SendBoardState(move types.Move, boardPosition string, turnColor types.ChessColor) error {
|
||||
var pColor = p.GetColor()
|
||||
if p.GetColor() == "" { // we default to white if we do not know the color yet
|
||||
var pColor = p.color
|
||||
if p.color == "" { // we default to white if we do not know the color yet
|
||||
pColor = types.White
|
||||
}
|
||||
|
||||
@ -162,3 +154,7 @@ func (p *Player) readMessage() ([]byte, error) {
|
||||
|
||||
return msg, err
|
||||
}
|
||||
|
||||
func (p Player) GetPlayerColor() string {
|
||||
return string(p.color)
|
||||
}
|
||||
|
@ -16,10 +16,6 @@ func (c ChessColor) Opposite() ChessColor {
|
||||
}
|
||||
}
|
||||
|
||||
func (c ChessColor) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
type AdditionalState struct {
|
||||
BlackKingMoved bool
|
||||
WhiteKingMoved bool
|
||||
|
Loading…
Reference in New Issue
Block a user