Exemplo n.º 1
0
        private void EndGame(Minefield field)
        {
            var countNotRevealed = 0;

            for (var i = 0; i < field.Field.GetLength(0); i++)
            {
                for (var j = 0; j < field.Field.GetLength(1); j++)
                {
                    if (field.VisibleField[i, j] == '+')
                    {
                        countNotRevealed++;
                    }
                    if (field.Field[i, j] == '*')
                    {
                        field.VisibleField[i, j] = 'X';
                    }
                }
            }
            if (field.MineCount == countNotRevealed)
            {
                Console.WriteLine("You Win!\n");
            }
            else
            {
                Console.WriteLine("You lose :(\n");
            }
        }
Exemplo n.º 2
0
        private bool TakeTurn(Minefield field)
        {
            var x = Workflow.GetInt("\n\nrow: ", 0, field.Field.GetLength(0) - 1);
            var y = Workflow.GetInt("col: ", 0, field.Field.GetLength(1) - 1);

            field.Reveal(x, y);

            if (field.Field[x, y] == '*')
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        public void Run()
        {
            do
            {
                var playing = true;
                var field   = new Minefield();
                while (playing)
                {
                    Console.Clear();
                    field.DisplayField();

                    playing = TakeTurn(field);
                }
                Console.Clear();
                EndGame(field);
                field.DisplayField();
            } while (Workflow.KeepGoing("\n\nWould you like to play again?"));
        }