From ea6ef5b34ad7e8273688c14c4f9a7f7237717e52 Mon Sep 17 00:00:00 2001 From: Shuozhe Date: Tue, 29 Jun 2021 15:54:01 +0200 Subject: [PATCH] got basic commands working --- Controllers/TicTacTocController.cs | 8 ++++ Logic/TicTacTocBoard.cs | 12 ++++-- Logic/TicTacTocManager.cs | 11 ++++-- Models/TicTacTocRequest.cs | 7 ++-- ProjectGrid.csproj | 4 ++ clientapp/src/Game.js | 7 ++++ clientapp/src/Player.js | 3 +- clientapp/src/components/GameUI.vue | 46 +++++++++++++++------- clientapp/src/services/TicTacTocService.js | 19 +++++---- clientapp/vue.config.js | 3 +- 10 files changed, 87 insertions(+), 33 deletions(-) diff --git a/Controllers/TicTacTocController.cs b/Controllers/TicTacTocController.cs index 3652d04..8d88e39 100644 --- a/Controllers/TicTacTocController.cs +++ b/Controllers/TicTacTocController.cs @@ -33,6 +33,14 @@ namespace ProjectGrid.Controllers return _manager.GetResponse(); } + [HttpGet] + [Route("api/ttt/Restart")] + public void RestartGame() + { + _logger.LogTrace("RestartGame called."); + _manager.Restart(); + } + [HttpPost] [Route("api/ttt/SetPiece")] [Consumes("application/json")] diff --git a/Logic/TicTacTocBoard.cs b/Logic/TicTacTocBoard.cs index bb04ce4..7285291 100644 --- a/Logic/TicTacTocBoard.cs +++ b/Logic/TicTacTocBoard.cs @@ -29,6 +29,11 @@ namespace ProjectGrid.Models _field[PosToIdx(x, y)] = value; _lastSetValue = value; } + private void SetField(int value, int idx) + { + _field[idx] = value; + _lastSetValue = value; + } // 0 1 2 // 3 4 5 @@ -55,12 +60,13 @@ namespace ProjectGrid.Models _lastSetValue = 0; } - public bool SetFieldValue(int value, int x, int y, bool force = false) + //public bool SetFieldValue(int value, int x, int y, bool force = false) + public bool SetFieldValue(int value, int idx, bool force = false) { - int field = GetField(x, y); + int field = _field[idx]; if (0 == field || force) { - SetField(value, x, y); + SetField(value, idx); return true; } return false; diff --git a/Logic/TicTacTocManager.cs b/Logic/TicTacTocManager.cs index fdffe6e..fab1e18 100644 --- a/Logic/TicTacTocManager.cs +++ b/Logic/TicTacTocManager.cs @@ -14,7 +14,7 @@ namespace ProjectGrid public class TicTacTocManager : ITicTacTocManager { - private ITicTacToctRepository _repo; + //private ITicTacToctRepository _repo; private TicTacTocBoard _board; public TicTacTocBoard Board => _board; @@ -22,12 +22,12 @@ namespace ProjectGrid public TicTacTocManager(/*ITicTacToctRepository repo*/) { //_repo = repo; - _board = new TicTacTocBoard(); + Restart(); } public bool NextMove(TicTacTocRequest move) { - return _board.SetFieldValue(move.Player, move.PosX, move.PosY); + return _board.SetFieldValue(move.Player, move.Field); //move.PosX, move.PosY); } public TicTacTocResponse GetResponse(int player = 0) @@ -41,5 +41,10 @@ namespace ProjectGrid return response; } + + public void Restart() + { + _board = new TicTacTocBoard(); + } } } \ No newline at end of file diff --git a/Models/TicTacTocRequest.cs b/Models/TicTacTocRequest.cs index 8711c96..09be3ce 100644 --- a/Models/TicTacTocRequest.cs +++ b/Models/TicTacTocRequest.cs @@ -2,12 +2,13 @@ namespace ProjectGrid.Models { public class TicTacTocRequest { - public int PosX { get; set; } + //public int PosX { get; set; } - public int PosY { get; set; } + //public int PosY { get; set; } + public int Field { get; set; } public int Player { get; set; } - public string DebugString() => $"Pos: [{PosX}|{PosY}; Player: {Player}"; + public string DebugString() => $"Field: {Field}, Player: {Player}";//$"Pos: [{PosX}|{PosY}; Player: {Player}"; } } \ No newline at end of file diff --git a/ProjectGrid.csproj b/ProjectGrid.csproj index 5dec6c9..004c026 100644 --- a/ProjectGrid.csproj +++ b/ProjectGrid.csproj @@ -28,6 +28,10 @@ + + + + diff --git a/clientapp/src/Game.js b/clientapp/src/Game.js index 9c0fa0b..82fc622 100644 --- a/clientapp/src/Game.js +++ b/clientapp/src/Game.js @@ -17,6 +17,13 @@ class Game { this._winningConditions = this.winningCondition.map(x => x.join(",")); } + + + makeMove() { + + } + + changeTurn() { this.currentTurn = this.currentTurn == this.players[0].sign ? this.players[1].sign : this.players[0].sign; } diff --git a/clientapp/src/Player.js b/clientapp/src/Player.js index d1b2ef5..eebd589 100644 --- a/clientapp/src/Player.js +++ b/clientapp/src/Player.js @@ -1,5 +1,6 @@ class Player { - constructor(sign) { + constructor(sign, id) { + this.id = id; this.sign = sign; this.clicks = []; this.score = 0; diff --git a/clientapp/src/components/GameUI.vue b/clientapp/src/components/GameUI.vue index 53da302..6172f2d 100644 --- a/clientapp/src/components/GameUI.vue +++ b/clientapp/src/components/GameUI.vue @@ -16,15 +16,15 @@
- - - - - - - - - + + + + + + + + +
@@ -32,10 +32,11 @@