diff --git a/Logic/TicTacTocManager.cs b/Logic/TicTacTocManager.cs index fab1e18..2fea6b0 100644 --- a/Logic/TicTacTocManager.cs +++ b/Logic/TicTacTocManager.cs @@ -1,5 +1,3 @@ -using ProjectGrid; -using ProjectGrid.Data; using ProjectGrid.Models; using System; @@ -13,21 +11,27 @@ namespace ProjectGrid public class TicTacTocManager : ITicTacTocManager { - //private ITicTacToctRepository _repo; + private int _currentPlayer; + private TicTacTocBoard _board; public TicTacTocBoard Board => _board; public TicTacTocManager(/*ITicTacToctRepository repo*/) { //_repo = repo; + _currentPlayer = 1; Restart(); } public bool NextMove(TicTacTocRequest move) { - return _board.SetFieldValue(move.Player, move.Field); //move.PosX, move.PosY); + var result = _board.SetFieldValue(_currentPlayer, move.Field); //move.PosX, move.PosY); + // switch between 1 and 2 + _currentPlayer = 3 - _currentPlayer; + + return result; } public TicTacTocResponse GetResponse(int player = 0) @@ -39,11 +43,11 @@ namespace ProjectGrid response.Board = _board.Field; return response; - } public void Restart() { + _currentPlayer = new Random().Next(1, 2); _board = new TicTacTocBoard(); } } diff --git a/clientapp/src/components/GameUI.vue b/clientapp/src/components/GameUI.vue index 6172f2d..eb4012f 100644 --- a/clientapp/src/components/GameUI.vue +++ b/clientapp/src/components/GameUI.vue @@ -9,7 +9,9 @@
Player One :{{this.game.players[0].score}} +
Player Two :{{this.game.players[1].score}} +
Draw :{{this.game.draw_score}} @@ -35,6 +37,7 @@ import { setPiece, restart } from '../services/TicTacTocService' const game = new Game(); + game.players.push(new Player("", 0)); game.players.push(new Player("X", 1)); game.players.push(new Player("O", 2)); @@ -63,22 +66,6 @@ this.btnText[i.toString()] = game.players[response.board[i]].sign; } } - - /*let btn = $event.target; - //check if filled already - if (this.btnText[btn.id.toString()].length > 0) { - alert("Already filled"); - return; - } - //fill X/O - this.btnText[btn.id] = this.game.currentTurn; - this.game.changeTurn(); - //check if game won - setTimeout(() => { - if (this.game.checkWinner(btn) == true) { - this.resetGame(); - } - }, 100);*/ }, resetGame() { //UI and backend reset