Esempio n. 1
0
 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);
 }
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 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
         });
     }
 }
Esempio n. 5
0
 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;
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
 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;
     }
 }
Esempio n. 9
0
 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...");
 }
Esempio n. 10
0
 public void PlayWithoutShowingBoard() {
     var newGame = new Game();
     var game = new Mock<IGameplay>();
     game.Setup(g => g.NewGame()).Returns(newGame);
 }
Esempio n. 11
0
 private void ShowGameWithBoard(Game game, int aliveCellsInGame) {
     var board = new Board();
     board.ShowBoard(game.Boards[InGameMenu.SelectedBoard]);
     text.ShowGameStats(game, aliveCellsInGame);
 }
Esempio n. 12
0
 public void Play(Game game, bool isNeededToShowBoard) {
     do {
         PlayWhileKeyNotPressed(game, isNeededToShowBoard);
         inGameMenu.ShowGameMenu(game);
     } while (true);
 }
Esempio n. 13
0
 public void SaveGame(Game game) {
     text.ShowSaveGameText();
     string fileName = Console.ReadLine();
     file.SaveToFile(game, fileName);
 }
Esempio n. 14
0
 public void ShowGameMenu(Game game) {
     text.ShowGameMenuText();
     Console.ReadKey(true);
     SelectGameAction(game, Console.ReadKey(true).Key);
 }
Esempio n. 15
0
 private void SelectBoard(Game game) {
     var board = new Board();
     SelectedBoard = InputBoardNumber();
     board.ShowSelectedBoard(game);
 }