public void ShowSelectedBoard(Game game) { var inGameMenu = new InGameMenu(); ShowBoardLayout(game.Boards[InGameMenu.SelectedBoard]); text.ShowBoardStats(game.Boards[InGameMenu.SelectedBoard]); text.ShowBoardMenu(); inGameMenu.SelectBoardAction(game); }
public void SaveToFile(Game game, string fileName) { string json = JsonConvert.SerializeObject(game); using (FileStream fs = File.Create(fileName + ".json")) { byte[] info = new UTF8Encoding(true).GetBytes(json); fs.Write(info, 0, info.Length); } }
private int StepToNextGeneration(Game world) { var gameCycle = new GameCycle(); var aliveCellsInGame = 0; foreach (SavedBoard board in world.Boards) { gameCycle.ChangeBoardState(board); aliveCellsInGame += board.AliveCells; } return aliveCellsInGame; }
private void FillGameWithBoards(SavedBoard board, Game game) { for (var i = 0; i < 1000; i++) { game.Boards.Add(new SavedBoard { AliveCells = board.AliveCells, Layout = board.Layout, Generation = board.Generation }); } }
public void SelectBoardAction(Game game) { var theGame = new Gameplay(); ConsoleKey key = Console.ReadKey(true).Key; switch (key) { case ConsoleKey.C: theGame.Play(game, true); break; } }
private void PlayWhileKeyNotPressed(Game game, bool isNeededToShowBoard) { while (!Console.KeyAvailable) { int aliveCellsInGame = StepToNextGeneration(game); Console.Clear(); if (isNeededToShowBoard) { ShowGameWithBoard(game, aliveCellsInGame); continue; } text.ShowGameStats(game, aliveCellsInGame); } }
public Game NewGame() { string path = Path.GetFullPath(MAP_TYPE_FILE_NAME); string jsonString = file.LoadGameFromFile(path); var board = JsonConvert.DeserializeObject<SavedBoard>(jsonString); var game = new Game { Boards = new List<SavedBoard>() }; FillGameWithBoards(board, game); return game; }
private void SelectGameAction(Game game, ConsoleKey key) { var theGame = new Gameplay(); switch (key) { case ConsoleKey.S: theGame.SaveGame(game); break; case ConsoleKey.W: SelectBoard(game); break; case ConsoleKey.Escape: Environment.Exit(0); break; } }
public void ShowGameStats(Game game, int aliveCellsInGame) { Console.WriteLine("Alive cells in game: " + aliveCellsInGame); Console.WriteLine("Generation: " + game.Boards[0].Generation); Console.Write("Press any key to show menu..."); }
public void PlayWithoutShowingBoard() { var newGame = new Game(); var game = new Mock<IGameplay>(); game.Setup(g => g.NewGame()).Returns(newGame); }
private void ShowGameWithBoard(Game game, int aliveCellsInGame) { var board = new Board(); board.ShowBoard(game.Boards[InGameMenu.SelectedBoard]); text.ShowGameStats(game, aliveCellsInGame); }
public void Play(Game game, bool isNeededToShowBoard) { do { PlayWhileKeyNotPressed(game, isNeededToShowBoard); inGameMenu.ShowGameMenu(game); } while (true); }
public void SaveGame(Game game) { text.ShowSaveGameText(); string fileName = Console.ReadLine(); file.SaveToFile(game, fileName); }
public void ShowGameMenu(Game game) { text.ShowGameMenuText(); Console.ReadKey(true); SelectGameAction(game, Console.ReadKey(true).Key); }
private void SelectBoard(Game game) { var board = new Board(); SelectedBoard = InputBoardNumber(); board.ShowSelectedBoard(game); }