Пример #1
0
        private void RemoveDisplayPiece(IDisplayPiece displayPiece)
        {
            int idOfDisplayPiece = displayPiece.Id;

            this.boardElements = this.boardElements.Where(x => x.Id != idOfDisplayPiece).ToList();
            Visualizer.EraseDisplayPieceFromConsole(displayPiece);
        }
Пример #2
0
        public static void DrawDisplayPieceOnConsole(IDisplayPiece pieceToDraw)
        {
            Position positionsToDraw = pieceToDraw.Position;
            string drawSymbol = pieceToDraw.DisplaySymbol;
            ConsoleColor color = pieceToDraw.Color;

            DrawSymbolAtPosition(drawSymbol, positionsToDraw, color);
        }
Пример #3
0
        public static void DrawDisplayPieceOnConsole(IDisplayPiece pieceToDraw)
        {
            Position     positionsToDraw = pieceToDraw.Position;
            string       drawSymbol      = pieceToDraw.DisplaySymbol;
            ConsoleColor color           = pieceToDraw.Color;

            DrawSymbolAtPosition(drawSymbol, positionsToDraw, color);
        }
Пример #4
0
        /// <summary>
        /// Draws all elements in the start of the game
        /// </summary>
        /// <param name="allPieces"></param>
        public static void DrawEverything(List <IDisplayPiece> allPieces)
        {
            Console.Clear();

            for (int i = 0; i < allPieces.Count; i++)
            {
                IDisplayPiece currentPiece = allPieces[i];
                DrawDisplayPieceOnConsole(currentPiece);
            }
        }
Пример #5
0
        /// <summary>
        /// Moves player to position adjacent to him and checks whether new position is interactable
        /// Adds the Result of the Interactable position to the player score
        /// </summary>
        /// <param name="direction">string</param>
        private void TryMovingToDirection(string direction)
        {
            Position      adjacentPosition = this.PositionAdjacentToPlayer(this.player, direction);
            IDisplayPiece adjacentPiece    = GetPieceAtPosition(adjacentPosition, this.boardElements);

            if (adjacentPiece is IInteractable)
            {
                IInteractable adjacentInteractable = (IInteractable)adjacentPiece;

                double interactionResult = adjacentInteractable.GetInteractionResult();

                if (interactionResult >= Constants.WinIndicator)
                {
                    this.gameStatus = 1;
                }
                else if (interactionResult < 0)
                {
                    int    playerHP    = this.player.Hp;
                    double playerNewHp = playerHP + interactionResult;
                    this.player.Hp = (int)playerNewHp;
                }
                else
                {
                    this.playerScore += interactionResult;
                }

                Visualizer.DrawEverything(this.boardElements);

                RemoveDisplayPiece(adjacentPiece);
            }
            else if (adjacentPiece == null)
            {
                //// Moving player
                Visualizer.EraseDisplayPieceFromConsole(this.player);
                this.player.Position = adjacentPosition;
                Visualizer.DrawDisplayPieceOnConsole(player);
            }
        }
Пример #6
0
        /// <summary>
        /// Returns position adjacent to player
        /// </summary>
        /// <param name="player">IDisplayPiece</param>
        /// <param name="direction">string</param>
        /// <returns></returns>
        private Position PositionAdjacentToPlayer(IDisplayPiece player, string direction)
        {
            int debthOfAdjacent = player.Position.GetDebthCoo();
            int widthOfAdjacent = player.Position.GetWidthCoo();

            if (direction.ToLower() == "up")
            {
                debthOfAdjacent--;
            }
            else if (direction.ToLower() == "down")
            {
                debthOfAdjacent++;
            }
            else if (direction.ToLower() == "left")
            {
                widthOfAdjacent--;
            }
            else if (direction.ToLower() == "right")
            {
                widthOfAdjacent++;
            }

            return(new Position(widthOfAdjacent, debthOfAdjacent));
        }
Пример #7
0
        public IGame GetGame(string gameName)
        {
            if (gameName == "MainGame")
            {
                MainGame game = new MainGame();
                Position startingPositionOfOuterBorder = new Position(0, 0);
                addBoxToGame(game, startingPositionOfOuterBorder, Constants.BoxWidth, Constants.BoxHeight);



                //// TODO: implement abstract logic for this
                int outerBoxWidthMiddle       = Constants.BoxWidth / 2;
                int outerBoxHeightMiddle      = Constants.BoxHeight / 2;
                int innerBoxPreferedWidth     = Constants.BoxWidth / 10 + 1;
                int innerBoxPreferedHeight    = Constants.BoxHeight / 10 + 1;
                int innerBoxStartingWidthCoo  = outerBoxWidthMiddle - (innerBoxPreferedWidth / 2) - 1;
                int innerBoxStartingHeightCoo = outerBoxHeightMiddle - (innerBoxPreferedHeight / 2) - 1;

                Position innerBoxStarterPosition = new Position(innerBoxStartingWidthCoo, innerBoxStartingHeightCoo);
                addBoxToGame(game, innerBoxStarterPosition, innerBoxPreferedWidth, innerBoxPreferedHeight);
                game.SetInitPositionOfBorderAroundWinArea(innerBoxStarterPosition);

                Position      winAreaTopLeft = new Position(innerBoxStarterPosition.GetWidthCoo() + 1, innerBoxStarterPosition.GetDebthCoo() + 1);
                IDisplayPiece winArea        = new WinArea(winAreaTopLeft);
                game.AddBoardElement(winArea);

                Position playerStartingPosition = new Position(Constants.PlayerStartingX, Constants.PlayerStartingY);

                AbstractHero player;
                int          randNum = Generator.GetRandomNumber(1, 3);
                if (randNum == 1)
                {
                    player = new Priest(playerStartingPosition);
                }
                else
                {
                    player = new Magician(playerStartingPosition);
                }


                player.Id = this.UseCurrentID();

                game.AddBoardElement(player);

                //// TODO: add more quests
                List <Position> bombPositions = new List <Position>();

                var questNames = new List <string>
                {
                    "QuizQuest",
                    "FallingRocks",
                    "FlappyBird",
                    "GuessTheNumber",
                    "Hangman"
                };

                var questsCount = questNames.Count;

                for (int j = 0; j < 4; j++)
                {
                    var xRand1 = 0;
                    var xRand2 = 0;
                    var yRand1 = 0;
                    var yRand2 = 0;
                    switch (j)
                    {
                    case 0:
                        xRand1 = 1;
                        xRand2 = innerBoxStartingWidthCoo - 1;
                        yRand1 = 1;
                        yRand2 = innerBoxStartingHeightCoo - 1;
                        break;

                    case 1:
                        xRand1 = innerBoxStartingWidthCoo + innerBoxPreferedWidth + 1;
                        xRand2 = Constants.BoxWidth - 1;
                        yRand1 = 1;
                        yRand2 = innerBoxStartingHeightCoo - 1;
                        break;

                    case 2:
                        xRand1 = 1;
                        xRand2 = innerBoxStartingWidthCoo - 1;
                        yRand1 = innerBoxStartingHeightCoo + innerBoxPreferedHeight + 1;
                        yRand2 = Constants.BoxHeight - 1;
                        break;

                    case 3:
                        xRand1 = innerBoxStartingWidthCoo + innerBoxPreferedWidth + 1;
                        xRand2 = Constants.BoxWidth - 1;
                        yRand1 = innerBoxStartingHeightCoo + innerBoxPreferedHeight + 1;
                        yRand2 = Constants.BoxHeight - 1;
                        break;

                    default:
                        break;
                    }

                    for (int i = 0; i < 3; i++)
                    {
                        IDisplayPiece quizQuest = QuestFactory.GetQuest(
                            questNames[Generator.GetRandomNumber(0, questsCount)],
                            this.UseCurrentID(),
                            Generator.GetRandomNumber(xRand1, xRand2),
                            Generator.GetRandomNumber(yRand1, yRand2));

                        game.AddBoardElement(quizQuest);
                    }

                    for (int k = 0; k < 5; k++)
                    {
                        Position bombPosition = new Position(Generator.GetRandomNumber(xRand1, xRand2), Generator.GetRandomNumber(yRand1, yRand2));
                        Bomb     bomb         = new Bomb(bombPosition, Generator.GetRandomNumber(1, 4));
                        bomb.Id = this.UseCurrentID();
                        game.AddBoardElement(bomb);
                    }
                }


                PointsItem scoreShower = new PointsItem(new Position(Constants.PlayerScoreWidth, Constants.PlayerScoreDebth));
                scoreShower.MainGame     = game;
                scoreShower.TypeOfPoints = "points";
                scoreShower.Id           = this.UseCurrentID();
                scoreShower.Color        = System.ConsoleColor.White;
                game.AddBoardElement(scoreShower);


                game.SetMinimumWinScore(1);

                return(game);
            }


            return(null);
        }
Пример #8
0
 public void AddBoardElement(IDisplayPiece boardElement)
 {
     this.boardElements.Add(boardElement);
 }
Пример #9
0
 private void RemoveDisplayPiece(IDisplayPiece displayPiece)
 {
     int idOfDisplayPiece = displayPiece.Id;
     this.boardElements = this.boardElements.Where(x => x.Id != idOfDisplayPiece).ToList();
     Visualizer.EraseDisplayPieceFromConsole(displayPiece);
 }
Пример #10
0
        /// <summary>
        /// Returns position adjacent to player
        /// </summary>
        /// <param name="player">IDisplayPiece</param>
        /// <param name="direction">string</param>
        /// <returns></returns>
        private Position PositionAdjacentToPlayer(IDisplayPiece player, string direction)
        {
            int debthOfAdjacent = player.Position.GetDebthCoo();
            int widthOfAdjacent = player.Position.GetWidthCoo();

            if (direction.ToLower() == "up")
            {
                debthOfAdjacent--;
            }
            else if (direction.ToLower() == "down")
            {
                debthOfAdjacent++;
            }
            else if (direction.ToLower() == "left")
            {
                widthOfAdjacent--;
            }
            else if (direction.ToLower() == "right")
            {
                widthOfAdjacent++;
            }

            return new Position(widthOfAdjacent, debthOfAdjacent);
        }
Пример #11
0
        public override double StartGame()
        {
            Visualizer.DrawEverything(this.boardElements);
            this.gameStatus = 0;
            Position      scorePosition = new Position(Constants.PlayerScoreWidth, Constants.PlayerScoreDebth);
            IDisplayPiece scoreShower   = GetPieceAtPosition(scorePosition, this.boardElements);

            Visualizer.DrawDisplayPieceOnConsole(scoreShower);

            this.winAreaPoints = ((WinArea)this.boardElements
                                  .Find(x => x.DisplaySymbol == "W")).GetPositions();

            Position playerStartingPosition = new Position(Constants.PlayerStartingX, Constants.PlayerStartingY);

            this.player = (AbstractHero)GetPieceAtPosition(playerStartingPosition, this.boardElements);

            while (this.gameStatus == 0)
            {
                if (this.playerScore >= minimumWinScore)
                {
                    int      widthCooOfDoor      = this.positionOfBorderAroundWinArea.GetWidthCoo();
                    int      debtCooOfDoor       = this.positionOfBorderAroundWinArea.GetDebthCoo() + 1;
                    Position positionOfDoorToWin = new Position(widthCooOfDoor, debtCooOfDoor);

                    IDisplayPiece doorToWinArea = GetPieceAtPosition(positionOfDoorToWin, this.boardElements);
                    if (doorToWinArea != null)
                    {
                        RemoveDisplayPiece(doorToWinArea);
                    }
                }

                //// TODO: make every move to remove 0.1 points from the player score and explain it at the begining so that the players think on how they play and there is gamification to the movement as well
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo userInput = Console.ReadKey();

                    if (userInput.Key == ConsoleKey.Q)
                    {
                        this.gameStatus = -1;
                    }
                    else
                    {
                        this.TryMovingToDirection(this.player.Move(userInput));
                    }
                }

                if (this.player.Hp <= 0)
                {
                    this.gameStatus = -1;
                }
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.Clear();
            if (gameStatus == 1)
            {
                Console.WriteLine("Congratulations you won!");
                Console.WriteLine("Your Score: {0}", PlayerScore);

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(this.player.ToString());
            }
            else if (gameStatus == -1)
            {
                Console.WriteLine("You lost the game");
            }

            Console.ReadLine();

            return(playerScore);
        }
Пример #12
0
 public void AddBoardElement(IDisplayPiece boardElement)
 {
     this.boardElements.Add(boardElement);
 }
Пример #13
0
 public static void EraseDisplayPieceFromConsole(IDisplayPiece targetedForErasing)
 {
     Position positionsToErase = targetedForErasing.Position;
     DrawSymbolAtPosition(" ", positionsToErase, ConsoleColor.Black);
 }
Пример #14
0
        public static void EraseDisplayPieceFromConsole(IDisplayPiece targetedForErasing)
        {
            Position positionsToErase = targetedForErasing.Position;

            DrawSymbolAtPosition(" ", positionsToErase, ConsoleColor.Black);
        }