public void StartGameInBackground(int height, int width, int position)
        {
            GameLogic        game       = new GameLogic();
            FieldModel       field      = new FieldModel(height, width);
            AliveCellCounter countCells = new AliveCellCounter();

            game.PopulateFieldRandomly(height, width, field.gameField);
            while (!(Console.KeyAvailable &&
                     Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                game.RepopulateField(height, width, field.gameField, field.gameFieldBuffer);
                game.OverwriteGameField(height, width, field.gameField, field.gameFieldBuffer);
                //Console.SetCursorPosition(0, position);
                //Console.WriteLine(aliveCells = countCells.CountAliveCells(field.gameField));
            }
        }
Example #2
0
        public void StartConsoleGame()
        {
            int              height     = consoleIn.GetHeight();
            int              width      = consoleIn.GetWidth();
            FieldModel       field      = new FieldModel(height, width);
            AliveCellCounter countCells = new AliveCellCounter();

            game.PopulateFieldRandomly(height, width, field.gameField);

            while (!(Console.KeyAvailable &&
                     Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                int aliveCellsAmount = countCells.CountAliveCells(field.gameField);
                drawer.PrintArray(field.gameField);
                game.RepopulateField(height, width, field.gameField, field.gameFieldBuffer);
                game.OverwriteGameField(height, width, field.gameField, field.gameFieldBuffer);
                iterationCount++;
                consoleOut.StopGameMessage(height);
                consoleOut.PrintAliveCellsAmount(aliveCellsAmount, height);
                consoleOut.PrintCountOfIterations(height, iterationCount);
                System.Threading.Thread.Sleep(Constants.threadDelay);
            }

            drawer.PrintArray(field.gameField);
            consoleOut.PrintAliveCellsAmount(countCells.CountAliveCells(field.gameField), height - 2);
            consoleOut.PrintCountOfIterations(height, iterationCount);
            Console.SetCursorPosition(0, height + 2);
            Console.Write("Input [y] to save automaton last state: ");

            bool saveYes = consoleIn.YesOrNo();

            if (saveYes)
            {
                consoleOut.AskForFileName();
                string fileName = consoleIn.GetFileName();
                fileHandler.SaveToNewFile(fileName, field.gameField);
            }
        }
Example #3
0
        public void startGameFromFile()
        {
            FileHandler handleFile = new FileHandler();

            consoleOut.AskForFileName();
            string gameFieldFileName = consoleIn.GetFileName();

            int[]      heightWidth = handleFile.readExistingFieldDimensions(gameFieldFileName);
            int        height      = heightWidth[0];
            int        width       = heightWidth[1];
            FieldModel loadField   = new FieldModel(height, width);

            loadField.gameField = handleFile.readFromFile(gameFieldFileName);

            //quickfix
            GameLogic   game   = new GameLogic();
            FieldDrawer drawer = new FieldDrawer();

            AliveCellCounter countCells = new AliveCellCounter();

            game.PopulateFieldRandomly(height, width, loadField.gameField);

            while (!(Console.KeyAvailable &&
                     Console.ReadKey(true).Key == ConsoleKey.Escape))
            {
                int aliveCellsAmount = countCells.CountAliveCells(loadField.gameField);
                drawer.PrintArray(loadField.gameField);
                game.RepopulateField(height, width, loadField.gameField, loadField.gameFieldBuffer);
                game.OverwriteGameField(height, width, loadField.gameField, loadField.gameFieldBuffer);
                iterationCount++;
                consoleOut.StopGameMessage(height);
                consoleOut.PrintAliveCellsAmount(aliveCellsAmount, height);
                consoleOut.PrintCountOfIterations(height, iterationCount);
                System.Threading.Thread.Sleep(Constants.threadDelay);
            }
        }