Beispiel #1
0
 public AbstractHero(Position position)
 {
     this.position = position;
     this.color = Constants.HeroColor;
     this.width = 1;
     this.height = 1;
 }
Beispiel #2
0
 public AbstractItem(Position position)
 {
     this.position = position;
     //this.displaySymbol = Constants.BombDisplaySymbol;
     //this.color = Constants.BombColor;
     //this.width = 1;
     //this.height = 1;
 }
Beispiel #3
0
 public Priest(Position position)
     : base(position)
 {
     this.Hp = Constants.PriestStartingHp;
     this.DisplaySymbol = Constants.PriestDisplaySymbol;
     this.Position = position;
     this.Explanation = string.Format("Priests have {0} hp and ...", this.Hp);
 }
Beispiel #4
0
 public WinArea(Position position)
 {
     this.initialPositions = position;
     this.displaySymbol = Constants.WinAreaDisplaySymbol;
     this.color = Constants.WinAreaColor;
     this.width = Constants.BoxWidth / 10 - 1;
     this.height = Constants.BoxHeight / 10 - 1;
 }
Beispiel #5
0
 public AbstractQuest(Position position)
 {
     this.position = position;
     this.color = Constants.QuestsColor;
     this.displaySymbol = Constants.QuestDisplaySymbol;
     this.width = 1;
     this.height = 1;
 }
Beispiel #6
0
 public Box(Position startingPosition,int length, int height)
 {
     this.startingPosition = startingPosition;
     this.topBorder = new List<Position>();
     this.botBorder = new List<Position>();
     this.leftBorder = new List<Position>();
     this.rightBorder = new List<Position>();
     initBorders(length, height);
 }
Beispiel #7
0
        public static void DrawSymbolAtPosition(string symbol, Position position, ConsoleColor color)
        {
            Console.SetCursorPosition(position.GetWidthCoo(), position.GetDebthCoo());
            Console.ForegroundColor = color;
            Console.Write(symbol);

            //// set to avoid the visual glitches caused by the underscore ("_") ;
            Console.SetCursorPosition(0, 41);
        }
Beispiel #8
0
 public Bomb(Position position, int damage)
 {
     this.position = position;
     this.amountOfDamageItInflicts = damage;
     this.displaySymbol = Constants.BombDisplaySymbol;
     this.color = Constants.BombColor;
     this.width = 1;
     this.height = 1;
 }
Beispiel #9
0
 public Magician(Position position)
     : base(position)
 {
     //// TODO: add something that makes Priest and Magician different.
     //// TODO: add more classes
     this.Hp = Constants.MagicianStartingHp;
     this.DisplaySymbol = Constants.MagicianDisplaySymbol;
     this.Position = position;
     this.Explanation = string.Format("Magicians have {0} hp and ...", this.Hp);
 }
Beispiel #10
0
 public Box(Position startingPosition, int length, int height)
 {
     this.startingPosition = startingPosition;
     this.topBorder = new List<Position>();
     this.botBorder = new List<Position>();
     this.leftBorder = new List<Position>();
     this.rightBorder = new List<Position>();
     this.InitBorders(length, height);
     this.displaySymbol = Constants.BoxDisplaySymbol;
     this.color = Constants.BoxColor;
     this.width = length;
     this.height = height;
 }
Beispiel #11
0
        protected IDisplayPiece GetPieceAtPosition(Position targetPosition, List<IDisplayPiece> boardPieces)
        {
            for (int i = 0; i < boardPieces.Count; i++)
            {
                Position currentBoardPiecePosition = boardPieces[i].Position;

                bool widthCooMatches = targetPosition.GetWidthCoo() == currentBoardPiecePosition.GetWidthCoo();
                bool debthCooMatches = targetPosition.GetDebthCoo() == currentBoardPiecePosition.GetDebthCoo();

                if (widthCooMatches && debthCooMatches)
                {
                    return boardPieces[i];
                }

            }

            return null;
        }
Beispiel #12
0
        private IDisplayPiece getPieceAtPosition(Position targetPosition,List<IDisplayPiece> boardPieces)
        {
            for (int i = 0; i < boardPieces.Count; i++)
            {
                List<Position> currentBoardPiecePositions = boardPieces[i].getPositions();

                for (int j = 0; j < currentBoardPiecePositions.Count; j++)
                {
                    bool widthCooMatches = targetPosition.getWidthCoo() == currentBoardPiecePositions[j].getWidthCoo();
                    bool debthCooMatches = targetPosition.getDebthCoo() == currentBoardPiecePositions[j].getDebthCoo();

                    if(widthCooMatches && debthCooMatches)
                    {
                        return boardPieces[i];
                    }
                }
            }

            return null;
        }
Beispiel #13
0
        private void initBorders(int length, int height)
        {
            //Creating top and bottom borders
            for (int i = 0; i < length; i++)
            {
                Position partOfTopBorder = new Position(this.startingPosition.getWidthCoo() + i,this.startingPosition.getDebthCoo());
                Position partOFBottomBorder = new Position(this.startingPosition.getWidthCoo() + i,this.startingPosition.getDebthCoo() + height -1);
                this.topBorder.Add(partOfTopBorder);
                this.botBorder.Add(partOFBottomBorder);
            }

            //Creating left and right borders
            for (int i = 0; i < height; i++)
            {
                Position partOfLeftBorder = new Position(this.startingPosition.getWidthCoo(),this.startingPosition.getDebthCoo() + i);
                Position partOfRightBorder = new Position(this.startingPosition.getWidthCoo() + length - 1, this.startingPosition.getDebthCoo() + i);
                this.leftBorder.Add(partOfLeftBorder);
                this.rightBorder.Add(partOfRightBorder);
            }
        }
Beispiel #14
0
        public static IDisplayPiece GetQuest(string questName, int id, int widthCoo, int debthCoo)
        {
            //// TODO: make the quests drop items
            //// TODO: make items that show on the side of the board (3 items are more than enough)

            Position initPosition = new Position(widthCoo, debthCoo);

            if (questName == "QuizQuest")
            {
                QuizQuest quest = new QuizQuest(initPosition);
                quest.Id = id;
                return quest;
            }
            else if (questName == "FallingRocks")
            {
                FallingRocks quest = new FallingRocks(initPosition);
                quest.Id = id;
                return quest;
            }
            else if(questName == "FlappyBird")
            {
                FlappyBirdQuest quest = new FlappyBirdQuest(initPosition);
                quest.Id = id;
                return quest;
            }
            else if (questName == "GuessTheNumber")
            {
                GuessTheNumber quest = new GuessTheNumber(initPosition);
                quest.Id = id;
                return quest;
            }
            else if (questName == "Hangman")
            {
                Hangman quest = new Hangman(initPosition);
                quest.Id = id;
                return quest;
            }

            return null;
        }
Beispiel #15
0
 public void SetInitPositionOfBorderAroundWinArea(Position initPositionOfBorderAroundWinArea)
 {
     this.positionOfBorderAroundWinArea = initPositionOfBorderAroundWinArea;
 }
Beispiel #16
0
 public FallingRocks(Position position)
     : base(position)
 {
     this.position = position;
 }
Beispiel #17
0
 public QuizQuest(Position position)
     : base(position)
 {
     this.position = position;
 }
Beispiel #18
0
 public FlappyBirdQuest(Position position)
     : base(position)
 {
     this.DisplaySymbol = "F";
 }
Beispiel #19
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;
        }
Beispiel #20
0
        private void addBoxToGame(MainGame game, Position startingPosition, int width, int height)
        {
            int startingWidth = startingPosition.GetWidthCoo();
            int startingDebt = startingPosition.GetDebthCoo();
            int depricatedUse = 1;
            for (int i = 0; i < width; i++)
            {
                Position currentPositionOfPartOfTopBorder = new Position(startingWidth + i, startingDebt);
                Box partOfTopBorder = new Box(currentPositionOfPartOfTopBorder, depricatedUse, depricatedUse);
                partOfTopBorder.Id = this.UseCurrentID();

                Position currentPositionOFPartOfBotBorder = new Position(startingWidth + i, startingDebt + height);
                Box partOfBotBorder = new Box(currentPositionOFPartOfBotBorder, depricatedUse, depricatedUse);
                partOfBotBorder.Id = this.UseCurrentID();
                game.AddBoardElement(partOfTopBorder);
                game.AddBoardElement(partOfBotBorder);
            }

            for (int i = 0; i < height - 1; i++)
            {
                Position currentPositionOfPartOfLeftBorder = new Position(startingWidth, startingDebt + 1 + i);
                Box partOfLeftBorder = new Box(currentPositionOfPartOfLeftBorder, depricatedUse, depricatedUse);
                partOfLeftBorder.Id = this.UseCurrentID();

                Position currentPositionOfPartOfRightBorder = new Position(startingWidth + width - 1, startingDebt + 1 + i);
                Box partOfRightBorder = new Box(currentPositionOfPartOfRightBorder, depricatedUse, depricatedUse);
                partOfRightBorder.Id = this.UseCurrentID();

                game.AddBoardElement(partOfLeftBorder);
                game.AddBoardElement(partOfRightBorder);
            }
        }
Beispiel #21
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;
        }
Beispiel #22
0
 public void WinAreaAddPosition(Position initialPositions)
 {
     this.winAreas.Add(initialPositions);
 }
Beispiel #23
0
 public GuessTheNumber(Position position)
     : base(position)
 {
     this.position = position;
 }
Beispiel #24
0
 public PointsItem(Position position)
     : base(position)
 {
 }