public void MakeMove(int x, int y, string gameName) { try { CrossesModel currGame = GetGameByName(gameName); var id = Context.ConnectionId; var opponentId = id == currGame.zeroId ? currGame.crossId : currGame.zeroId; System.Diagnostics.Debug.WriteLine(opponentId); int[] moveResult = currGame.MakeMove(Context.ConnectionId, x, y); if (moveResult[0] != 0) { System.Diagnostics.Debug.WriteLine(moveResult[1]); string point = x.ToString() + ',' + y.ToString(); if (moveResult[1] < 0) { Clients.Client(opponentId).AddMove(point, currGame.zerosMove); Clients.Caller.AddMove(point, currGame.zerosMove); } else if (moveResult[1] == 0) { Clients.Caller.FinishGame("Draw", point, currGame.zerosMove); Clients.Client(opponentId).FinishGame("Draw", point, currGame.zerosMove); } else { Clients.Caller.FinishGame("You win", point, currGame.zerosMove); Clients.Client(opponentId).FinishGame("You lose", point, currGame.zerosMove); } } } catch (Exception) {} }
public void Connect(string gameName) { var id = Context.ConnectionId; CrossesModel currGame = GetGameByName(gameName); if (currGame?.zeroId == null) { currGame.zeroId = id; System.Diagnostics.Debug.WriteLine(currGame.zeroId); } else if (currGame?.crossId == null) { currGame.crossId = id; System.Diagnostics.Debug.WriteLine(currGame.crossId); } }