public string CreateGame(string player_name) { mut.WaitOne(); if (arrPlayers.Count == 0) { arrPlayers.Add(player_name); curTurnTic = 0; curTurnToe = 0; for (int i = 0; i < 9; i++) { arrVerdicts.Add(TicTacToeLogic.VERDICT.NONE); } mut.ReleaseMutex(); TicTacToeLogic.InitGame(); return("CS"); // Creating success } else { mut.ReleaseMutex(); return("CE"); // Creating error } }
public string SendCommandGame(int row, int col, string player_name) { TicTacToeLogic.VERDICT verdict; if (player_name.Equals("Tic")) { String command = row.ToString() + ":" + col.ToString(); verdict = TicTacToeLogic.TickMoved(row, col); if (verdict == TicTacToeLogic.VERDICT.CONTINUE) { mut.WaitOne(); arrVerdicts[curTurnTic] = verdict; arrCommands.Add(command); curTurnTic++; mut.ReleaseMutex(); return("W"); // Continue game. Wait the opponent } else if (verdict == TicTacToeLogic.VERDICT.TIC_WINS) { TicTacToeLogic.InitGame(); mut.WaitOne(); arrVerdicts[curTurnTic] = verdict; arrCommands.Add(command); curTurnTic++; mut.ReleaseMutex(); return("TiW"); // Tic wins } else if (verdict == TicTacToeLogic.VERDICT.DRAW) { TicTacToeLogic.InitGame(); mut.WaitOne(); arrVerdicts[curTurnTic] = verdict; arrCommands.Add(command); curTurnTic++; mut.ReleaseMutex(); return("D"); // Draw } else { return("E"); // Error, try to do another action } } else { String command = row.ToString() + ":" + col.ToString(); verdict = TicTacToeLogic.ToeMoved(row, col); if (verdict == TicTacToeLogic.VERDICT.CONTINUE) { mut.WaitOne(); arrVerdicts[curTurnToe] = verdict; arrCommands.Add(command); curTurnToe++; mut.ReleaseMutex(); return("W"); // Continue game. Wait the opponent } else if (verdict == TicTacToeLogic.VERDICT.TOE_WINS) { TicTacToeLogic.InitGame(); mut.WaitOne(); arrVerdicts[curTurnToe] = verdict; arrCommands.Add(command); curTurnToe++; mut.ReleaseMutex(); return("ToW"); // Toe wins } else if (verdict == TicTacToeLogic.VERDICT.DRAW) { TicTacToeLogic.InitGame(); mut.WaitOne(); arrVerdicts[curTurnToe] = verdict; arrCommands.Add(command); curTurnToe++; mut.ReleaseMutex(); return("D"); // Draw } else { return("E"); // Error, try to do another action } } }