void PrintGame(IMinerGame game) { Console.Clear(); for (int row = 0; row < game.Height; row++) { for (int col = 0; col < game.Width; col++) { switch (game[row, col]) { case CellStatus.NotOpened: Console.Write("X"); break; case CellStatus.Empty: Console.Write(" "); break; case CellStatus.OneAround: Console.Write("1"); break; case CellStatus.TwoAround: Console.Write("2"); break; case CellStatus.ThreeAround: Console.Write("3"); break; case CellStatus.FourAround: Console.Write("4"); break; case CellStatus.FiveAround: Console.Write("5"); break; case CellStatus.SixAround: Console.Write("6"); break; case CellStatus.SevenAround: Console.Write("7"); break; case CellStatus.EightAround: Console.Write("8"); break; case CellStatus.HasMine: Console.Write("@"); break; default: break; } } Console.Write(Environment.NewLine); } Console.ReadKey(); }
internal void Test() { int Width = 0; int Height = 0; int bombs = 0; int currRow = 0; int currCol = 0; Console.WriteLine("Hello, I'm a Miner game, please, choose type of game:\nFor Empty game type 0\nFor Random game type 1"); string typeOfGame = Console.ReadLine(); Console.WriteLine("Please, enter your name"); string playerName = Console.ReadLine(); Console.WriteLine("Please, enter field Width = "); Int32.TryParse(Console.ReadLine(), out Width); Console.WriteLine("Please, enter field Height = "); Int32.TryParse(Console.ReadLine(), out Height); switch (typeOfGame) { case "0": IMinerGame emptyGame = NewEmptyGame(playerName, new Tuple <int, int>(Width, Height)); break; case "1": Console.WriteLine("Please, specify number of bombs on the field"); Int32.TryParse(Console.ReadLine(), out bombs); IMinerGame randomGame = NewRandomGame(playerName, new Tuple <int, int>(Width, Height), bombs); randomGame.Start(); while (!randomGame.Win && !randomGame.Lose) { Console.WriteLine("Choose a cell to open (enter row, that collum)"); Int32.TryParse(Console.ReadLine(), out currRow); Int32.TryParse(Console.ReadLine(), out currCol); randomGame.OpenCell(currRow, currCol); } if (randomGame.Win) { Console.WriteLine("{0} the Victory is yours!", playerName); } else { Console.WriteLine("Game over:("); } break; } }
void PrintPole(IMinerGame game) { for (int poleRow = 0; poleRow < game.Height; poleRow++) { for (int poleCol = 0; poleCol < game.Width; poleCol++) { switch (game[poleRow, poleCol]) { case CellStatus.NotOpened: Console.Write("-"); break; case CellStatus.Empty: Console.Write("0"); // открывать все с нулевым весом! break; case CellStatus.OneAround: Console.Write("1"); break; case CellStatus.TwoAround: Console.Write("2"); break; case CellStatus.ThreeAround: Console.Write("3"); break; case CellStatus.FourAround: Console.Write("4"); break; case CellStatus.FiveAround: Console.Write("5"); break; case CellStatus.SixAround: Console.Write("6"); break; case CellStatus.SevenAround: Console.Write("7"); break; case CellStatus.EightAround: Console.Write("8"); break; case CellStatus.HasMine: Console.Write("M"); break; default: Console.Write("что-то не то"); break; } } Console.WriteLine(); } }
internal void Test() { IMinerGame test = NewRandomGame("Alina", new Tuple <int, int>(10, 20), 50); PrintGame(test); test.Start(); test.OpenCell(0, 0); PrintGame(test); test.OpenCell(7, 6); PrintGame(test); test.OpenCell(1, 2); PrintGame(test); test.OpenCell(8, 8); PrintGame(test); Console.ReadKey(); }
internal void Test() { do { int row = 5; // размеры поля row = 5; int col = 4; // col = 4; int i = 0; // координаты открываемой клетки int j = 0; IMinerGame game = NewRandomGame("Vladimir", new Tuple <int, int>(row, col), 8); game.Start(); Console.Clear(); Console.SetCursorPosition(0, 0); do { Console.Write("Введите, пожалуйста, координату I (целое число от 1 до {0}): ", row); while (!int.TryParse(Console.ReadLine(), out i) || i > row || i < 1) { Console.Write("Попробуйте еще раз. Число должно быть целым от 1 до (включительно) {0}: ", row); } Console.Write("Введите, пожалуйста, координату J (целое число от 1 до {0}): ", col); while (!int.TryParse(Console.ReadLine(), out j) || j > col || j < 1) { Console.Write("Попробуйте еще раз. Число должно быть целым от 1 до (включительно) {0}: ", col); } game.OpenCell(i - 1, j - 1); PrintPole(game); }while (game.Win != true && game.Lose != true); if (game.Win) { Console.WriteLine("Будьте здоровы! Вы выиграли!"); } else if (game.Lose) { Console.WriteLine("Попробуйте снова. Увы, этот сет Вы проиграли"); } Console.WriteLine("Для выхода нажмите Escape; для продолжения - любую другую клавишу"); }while (Console.ReadKey().Key != ConsoleKey.Escape); }
public IMinerGame NewRandomGame(string playerName, Tuple<int, int> rowsCols, int bombs) { game = new MinerGame(playerName, rowsCols.Item1, rowsCols.Item2); return game; }
public IMinerGame NewEmptyGame(string playerName, Tuple<int, int> rowsCols) { game = new MinerGame(playerName, rowsCols.Item1, rowsCols.Item2); return game; }
static void Main(string[] args) { List <IMinerGameFactory> factories = new List <IMinerGameFactory>(); factories.Add(new Alina.MinerGameFactory()); factories.Add(new Andrey.MinerGameFactory()); factories.Add(new Elena.MinerGameFactory()); factories.Add(new Konstantin.MinerGameFactory()); factories.Add(new Valeriya.MinerGameFactory()); factories.Add(new Vladimir.MinerGameFactory()); if (args.Length > 0) { switch (args[0]) { case "Alina": new Alina.MinerGameFactory().Test(); break; case "Andrey": new Andrey.MinerGameFactory().Test(); break; case "Elena": new Elena.MinerGameFactory().Test(); break; case "Konstantin": new Konstantin.MinerGameFactory().Test(); break; case "Valeriya": new Valeriya.MinerGameFactory().Test(); break; case "Vladimir": new Vladimir.MinerGameFactory().Test(); break; default: Console.WriteLine("Wrong argument. Choose one of: Alina, Andrey, Elena, Konstantin, Valeriya, Vladimir"); break; } } else { foreach (var factory in factories) { Console.WriteLine("Testing factory {0}...", factory.ToString()); try { /* empty game */ { Console.WriteLine("Testing empty game..."); IMinerGame game = factory.NewEmptyGame("Dummy", new Tuple <int, int>(5, 6)); Assert(!game.IsGameStarted, "Game shouldn't be started yet"); Assert(game.Height == 5, "Высота не совпадает"); Assert(game.Width == 6, "Ширина не совпадает"); } /* random game */ { Console.WriteLine("Testing random game..."); IMinerGame game = factory.NewRandomGame("Dummy", new Tuple <int, int>(7, 8), 50); Assert(!game.IsGameStarted, "Game shouldn't be started yet"); Assert(game.Height == 7, "Высота не совпадает"); Assert(game.Width == 8, "Ширина не совпадает"); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Factory {0} done.", factory.ToString()); } } // args Console.ReadKey(); }
public IMinerGame NewRandomGame(string playerName, Tuple <int, int> rowsCols, int bombs) { game = new MinerGame(playerName, rowsCols.Item1, rowsCols.Item2); return(game); }
public IMinerGame NewEmptyGame(string playerName, Tuple <int, int> rowsCols) { game = new MinerGame(playerName, rowsCols.Item1, rowsCols.Item2); return(game); }