Beispiel #1
0
        public void PrintMineBoard()
        {
            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    var mineSpace = MineBoard[y, x];
                    var xPosition = mineSpace.XPosition;
                    var yPosition = mineSpace.YPosition;

                    Console.CursorLeft = xPosition;
                    Console.CursorTop  = yPosition - 1;
                    Console.WriteLine("___");
                    Console.CursorLeft = xPosition - 1;
                    Console.WriteLine("|   |");
                    Console.CursorLeft = xPosition - 1;
                    Console.Write("|");

                    if (CurrentPosition[0, 0] == y && CurrentPosition[0, 1] == x)
                    {
                        Console.BackgroundColor = ConsoleColor.Blue;
                    }

                    if (mineSpace.IsExploded && !mineSpace.HasTreasure)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.OutputEncoding  = Encoding.UTF8;
                        Console.Write(" \u263A ");
                        Console.OutputEncoding = Encoding.ASCII;
                    }
                    else if (mineSpace.IsExploded && mineSpace.HasTreasure)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(" $ ");
                        GameState = GameState.Won;
                    }
                    else
                    {
                        Console.Write(" X ");
                    }

                    Console.ResetColor();
                    Console.WriteLine("|");
                    Console.CursorLeft = xPosition - 1;
                    Console.WriteLine("|___|");
                }
            }

            if (GameState == GameState.Won)
            {
                WinLoseMessageManager.PrintMessage(GameState);
            }
        }
Beispiel #2
0
        public void Explode()
        {
            var occupiedMineSpace = GetOccupiedMineSpace();

            if (occupiedMineSpace.IsExploded)
            {
                return;
            }

            var explosionValue = ExplosionValue;

            occupiedMineSpace.IsExploded = true;
            explosionValue--;
            ExplosionsRemainingManager.ReduceExplosionsRemaining();

            var possibleExplosionDirections = new List <Direction>();

            Enum.GetValues(typeof(Direction)).Cast <Direction>().ToList().ForEach(direction =>
            {
                if (GetAdjacentSpace(occupiedMineSpace, direction) != null)
                {
                    possibleExplosionDirections.Add(direction);
                }
            });

            var apportionedExplosionValue = explosionValue / possibleExplosionDirections.Count;

            possibleExplosionDirections.ForEach(direction =>
            {
                var spaceToExplode = GetAdjacentSpace(occupiedMineSpace, direction);
                ExplodeSpace(spaceToExplode, apportionedExplosionValue);
            });

            PrintMineBoard();

            if (!ExplosionsRemainingManager.ExplosionsRemain() && GameState != GameState.Won)
            {
                GameState = GameState.Lost;
                WinLoseMessageManager.PrintMessage(GameState);
            }

            StoreState();
        }