예제 #1
0
        public static void StartBattle(GameSprite player, GameSprite enemy, ICollection <GameSprite> enemies)
        {
            StringBuilder battleLog    = new StringBuilder();
            int           roundCounter = 1;
            bool          playerTurn   = true;

            battleLog.AppendLine(string.Format("Started battle with: {0}", enemy.GetType().Name));
            battleLog.AppendLine(new string('-', 20));

            while (player.IsAlive() && enemy.IsAlive())
            {
                battleLog.AppendLine(string.Format("Round {0}: Player health {1}{2} | Enemy health {1}{3}", roundCounter, (char)3, player.HealthPoints, enemy.HealthPoints));

                int playerAttack  = player.Attack();
                int playerDefence = player.Defend();

                int enemyAttack  = enemy.Attack();
                int enemyDefence = enemy.Defend();

                if (playerTurn)
                {
                    if (playerAttack > enemyDefence)
                    {
                        enemy.HealthPoints -= playerAttack;
                    }
                }
                else
                {
                    if (enemyAttack > playerDefence)
                    {
                        player.HealthPoints -= enemyAttack;
                    }
                }

                playerTurn = !playerTurn;
                roundCounter++;
            }

            battleLog.AppendLine(string.Format("Round {0}: Player health {1}{2} | Enemy health {1}{3}", roundCounter, (char)3, player.HealthPoints, enemy.HealthPoints));

            string confirmMessage = "";

            if (!enemy.IsAlive())
            {
                RemoveEnemy(enemy, enemies);
                battleLog.AppendLine("Player wins.");
                confirmMessage = "Press any key to continue playing...";
            }
            else
            {
                battleLog.AppendLine("Player is dead.");
                confirmMessage = "Game Over...";
            }

            ConsoleDrawEngine.DisplayStickyMsg(battleLog.ToString(), confirmMessage);
            GameEngine.RedrawLabyrinth = true;
        }
예제 #2
0
        public void Run()
        {
            Coords prevoiusPosition = new Coords(0, 0);

            keyhandler.ImplementMove(this.Player, this.Labyrinth);

            this.DrawEngine.DisplayLabyrinth(this.Labyrinth, prevoiusPosition.X, prevoiusPosition.Y);

            try
            {
                while (true)
                {
                    if (!this.Player.IsAlive())
                    {
                        throw new PlayerIsDeadException();
                    }

                    if (!this.IsMinotourAlive())
                    {
                        throw new MinotourIsDeadException();
                    }

                    if (RedrawLabyrinth)
                    {
                        this.DrawEngine.DisplayLabyrinth(this.Labyrinth, prevoiusPosition.X, prevoiusPosition.Y);
                        RedrawLabyrinth = false;
                    }

                    CollisionChecker.CheckPotionCollision(this.Player, this.Potions);
                    CollisionChecker.CheckMobCollision(this.Player, this.Mobs);
                    CollisionChecker.CheckItemCollision(this.Player, this.Items);
                    this.DrawEngine.DisplayPlayer(this.Player);

                    prevoiusPosition.X = this.player.Position.X;
                    prevoiusPosition.Y = this.player.Position.Y;
                    this.DrawEngine.DisplayPotion(this.Potions, prevoiusPosition.X, prevoiusPosition.Y);
                    this.DrawEngine.DisplayMobs(this.Mobs, prevoiusPosition.X, prevoiusPosition.Y);
                    this.DrawEngine.DisplayItems(this.Items, prevoiusPosition.X, prevoiusPosition.Y);

                    Thread.Sleep(200);

                    this.DrawEngine.ClearPosition(prevoiusPosition.X, prevoiusPosition.Y);
                    this.keyhandler.CheckKey();

                    Console.SetCursorPosition(0, 30);
                    Console.WriteLine(player.ToString());
                }
            }
            catch (GameOverException ex)
            {
                this.DrawEngine.ClearAll();
                ConsoleDrawEngine.DisplayStickyMsg(ex.Message, "The game will be restarted...");
                LabyrinthMain.Main();
            }
        }
예제 #3
0
        public ConsoleDrawEngineTests()
        {
            _senderMock = new Mock <IConsoleWriter>();
            _inputMock  = new Mock <IReceiver <ConsoleInputContext> >();

            var serviceProvider = new ServiceCollection()
                                  .RegisterServices();

            // register mocks and stubs
            serviceProvider.AddSingleton(_senderMock.Object);
            serviceProvider.AddSingleton(_inputMock.Object);
            serviceProvider.AddSingleton <ICanvasConfiguration <ConsolePixelData> >(new CanvasConfigurationStub());

            _subject = serviceProvider
                       .BuildServiceProvider()
                       .GetService <ConsoleDrawEngine>();
        }
예제 #4
0
        public GameEngine()
        {
            IDrawEngine drawEngine = new ConsoleDrawEngine();
            Labyrinth   maze       = new Labyrinth(30, 80);

            maze.Generate();

            KeyHandler keyhanlder = new KeyHandler();
            ValidPositionsGenerator positionGenerator  = ValidPositionsGenerator.GetInstance;
            IList <Coords>          availablePositions = positionGenerator.Generate(maze, 30);

            Player             player  = new Player(position: new Coords(1, 1), healthPoints: 50, attackPoints: 10, defensePoints: 12, inventory: new List <Item>());
            IList <Potion>     potions = this.GeneratePotions(10, availablePositions);
            IList <GameSprite> mobs    = this.GenerateMobs(9, availablePositions);
            IList <Item>       items   = this.GenerateItems(6, availablePositions);

            this.DrawEngine = drawEngine;
            this.Labyrinth  = maze;
            this.KeyHandler = keyhanlder;
            this.Player     = player;
            this.Potions    = potions;
            this.Mobs       = mobs;
            this.Items      = items;
        }
        static void Main()
        {
            try
            {
                int playersCount = new int();

                #region Console and font resizing and intro screen
                //resize the console
                ConsoleHelper.SetConsoleFont(2); //Set the font size to  the smallest possible
                Console.WindowHeight = Console.LargestWindowHeight - 1;
                Console.WindowWidth  = Console.LargestWindowWidth - 4;
                ConsoleUtils.CenterConsole();
                SplashScreen.splashScreen();
                SplashScreen.WellcomeScreen();
                #endregion Console and font resizing and intro screen

                #region PlayersCount
                while (true)
                {
                    Console.Write("Type number of players as number on a single line : [2 , 3 or 4] : ");
                    string playerCountAsString = Console.ReadLine();

                    if (int.TryParse(playerCountAsString, out playersCount))
                    {
                        playersCount = int.Parse(playerCountAsString);



                        if (playersCount > 1 && playersCount <= 4)
                        {
                            // here will be player initializing and all this will goes to method or class playerInitializing
                            // for now it will be here so you can understand it easly
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Invalid Input!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Invalid Input!");
                    }
                }

                #endregion PlayersCount

                #region playersInitializing
                Player[] players = new Player[playersCount];

                if (playersCount == 2)
                {
                    Console.Write("Enter 1st player's name : ");
                    players[0] = new Player(1, Console.ReadLine(), Symbols.A);
                    Console.Write("Enter 2nd player's name : ");
                    players[1] = new Player(2, Console.ReadLine(), Symbols.B);

                    //TODO Trqbva da e v masiv za da moje da se izvikvat pored
                }
                if (playersCount == 3)
                {
                    Console.Write("Enter 1st player's name : ");
                    players[0] = new Player(1, Console.ReadLine(), Symbols.A);
                    Console.Write("Enter 2nd player's name : ");
                    players[1] = new Player(2, Console.ReadLine(), Symbols.B);
                    Console.Write("Enter 3rd player's name : ");
                    players[2] = new Player(3, Console.ReadLine(), Symbols.C);
                }
                if (playersCount == 4)
                {
                    Console.Write("Enter 1st player's name : ");
                    players[0] = new Player(1, Console.ReadLine(), Symbols.A);
                    Console.Write("Enter 2nd player's name : ");
                    players[1] = new Player(2, Console.ReadLine(), Symbols.B);
                    Console.Write("Enter 3rd player's name : ");
                    players[2] = new Player(3, Console.ReadLine(), Symbols.C);
                    Console.Write("Enter 4th player's name : ");
                    players[3] = new Player(4, Console.ReadLine(), Symbols.D);
                }
                #endregion playersInitializingplayer

                IDrawingEngine drawEngine = new ConsoleDrawEngine();
                GameManager    manager    = GameManager.GetInstance(drawEngine);
                manager.Game(players);
                var ChanceListCards    = CardInitializer.InitializeChanceList();
                var CommunityListCards = CardInitializer.InitializeCommunityList();
            }
            catch (System.Exception)
            {
                Console.WriteLine("FATAL ERROR !!! :D:D:D");
            }
        }