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