public void Start(MySqlConnection conn, int mode, int[] stats) { Console.Clear(); InsertData insertData = new InsertData(); insertData.InsertStatusLog(conn, "STARTED"); Console.WriteLine("STARTED"); field = new char[Size, Size]; for (int i = 0; i < Size; i++) //заполнение массива пробелами { for (int j = 0; j < Size; j++) { field[i, j] = ' '; } } int first = 1; //при 1 - первым ходит игрок, при 0 - бот if (mode == 1 && WhoFirst() == '0') { first = 0; } bool flag = true; step = 1; Field();//чертим пустое поле do { Console.WriteLine("Step: " + step); if (step % 2 == first) { Move move; do { move = playerX.MakeMove('X', field, Size); } while (move.x > Size || move.x < 1 || move.y > Size || move.y < 1 || field[move.x - 1, move.y - 1] != ' '); field[move.x - 1, move.y - 1] = 'X'; } else { Move move; do { move = player0.MakeMove('0', field, Size); } while (move.x > Size || move.x < 1 || move.y > Size || move.y < 1 || field[move.x - 1, move.y - 1] != ' '); field[move.x - 1, move.y - 1] = '0'; } Field(); //Чертим поле после хода flag = GameOver(conn, stats); //поиск победителя step++; } while (step <= Size * Size && flag); //пока не превышено число ходов или кто-то из игроков не победил Console.Write("FINISHED. "); insertData.InsertStatusLog(conn, "FINISHED"); Console.WriteLine("Tap to continue..."); Console.ReadKey(); }
public void Menu(MySqlConnection conn) { InsertData insertData = new InsertData(); Console.Clear(); int number; Console.Write(" Menu program by rPashyk" + "\n1. With bot (" + Size + "x" + Size + ")\n2. With another player (" + Size + "x" + Size + ")\n3. View stats\n4. Change size\n5. Close game\n Choose number: "); do { number = int.Parse(Console.ReadLine()); if (number < 1 || number > 5) { Console.WriteLine("Wrong number\n\nChoose number: "); } } while (number < 1 || number > 5); if (number == 1 || number == 2) { Game game; if (number == 1) { game = new Game(new ConsolePlayer(), new BotPlayer()); } else { game = new Game(new ConsolePlayer(), new ConsolePlayer()); } insertData.InsertGame(conn, "X", "0"); insertData.InsertStatusLog(conn, "CREATED"); game.Start(conn, number, stats); Menu(conn); } else if (number == 3) { Stats(conn); } else if (number == 4) { Console.Clear(); Console.Write("Enter number: "); Size = int.Parse(Console.ReadLine()); Menu(conn); } else { Console.Clear(); Console.Write("\n Good Game program by rPashyk\n"); } }
bool GameOver(MySqlConnection conn, int[] stats) { InsertData insertData = new InsertData(); char winner = Winner(conn); bool flag = true; if (winner == 'n') { insertData.InsertStats(conn, "drawn", "drawn"); Console.WriteLine("Drawn Game\n"); stats[1]++; } else if (winner == '0' || winner == 'X') { if (winner == '0') { stats[2]++; } else { stats[0]++; } Console.WriteLine("Player" + winner + " winner\n"); flag = false; if (winner == 'X') { insertData.InsertStats(conn, "win", "lose"); } else { insertData.InsertStats(conn, "lose", "win"); } } Console.ResetColor(); return(flag); }