private static void SuperPlay() { Console.Clear(); fieldNoFull = true; //do //{ if (_gameProg.PlayerActive != null) { playerActive = _gameProg.PlayerActive; } else { Player playerOne = new Player(PlayerTypes.X, Program.GetPlayerName("Input your name Player1")); Player playerTwo = new Player(PlayerTypes.O, Program.GetPlayerName("Input your name Player2", playerOne.Name)); playerActive = playerOne; _gameProg = new Game(playerOne, playerTwo); } Console.WriteLine(GameFild.ToStringStatic()); _gameProg.OnFieldFull += Game_OnFieldFull; _gameProg.OnStepExecuted += Game_OnStepExecuted; _gameProg.OnGameOver += Game_OnGameOver; Program.PlayGame(_gameProg); //} while (PlayAgain()); }
private static void PlayGame(Game game) { while (fieldNoFull) { do { Console.Clear(); Console.WriteLine(GameFild.ToStringStatic()); Console.WriteLine("_____________"); Console.WriteLine(game.State.ToString()); Console.WriteLine($"Your step Player {playerActive.Name}"); Console.WriteLine("If do you want save game? Press [S] "); consoleKey = Console.ReadKey(); Console.WriteLine(); if (consoleKey.KeyChar.Equals('S')) { Program.SaveGameToDb(game); return; } } while (!IsNumberKeyPressed(consoleKey)); Cell cell = GameFild.State[consoleKey.Key](playerActive.PlayerType); try { game.AddCell(cell); } catch (CellFilledExcention ex) { Console.WriteLine(ex.Message); continue; } playerActive = (playerActive.Equals(game.PlayerOne)) ? game.PlayerTwo : game.PlayerOne; game.PlayerActive = playerActive; } }