Ejemplo n.º 1
0
        public static void Move()
        {
            Monster enemy = new Monster(40, 20, 0);

            //Monster enemy2 = new Monster(40, 10, 0);
            //Monster enemy3 = new Monster(40, 10, 0);
            //Console.CursorVisible = false;
            Arena.CreateArena();
            StartPosition();
            var input = Console.ReadKey();

            do
            {
                input = Console.ReadKey();
                OldPlayerPositionTop  = CurrentPlayerPositionTop;
                OldPlayerPositionLeft = CurrentPlayerPositionLeft;

                switch (input.Key)       // Move player
                {
                case ConsoleKey.UpArrow: // move.Y -= 1;
                    NewPlayerPositionTop  = CurrentPlayerPositionTop - 1;
                    NewPlayerPositionLeft = CurrentPlayerPositionLeft;
                    break;

                case ConsoleKey.LeftArrow:     // move.X -= 1;
                    NewPlayerPositionTop  = CurrentPlayerPositionTop;
                    NewPlayerPositionLeft = CurrentPlayerPositionLeft - 1;
                    break;

                case ConsoleKey.DownArrow:     // move.Y += 1;
                    NewPlayerPositionTop  = CurrentPlayerPositionTop + 1;
                    NewPlayerPositionLeft = CurrentPlayerPositionLeft;
                    break;

                case ConsoleKey.RightArrow:     // move.X += 1;
                    NewPlayerPositionTop  = CurrentPlayerPositionTop;
                    NewPlayerPositionLeft = CurrentPlayerPositionLeft + 1;
                    break;
                }

                // Prevents walking through walls
                bool wall = Arena.IsWall(NewPlayerPositionLeft, NewPlayerPositionTop);

                if (wall)
                {
                    Console.Write("\b");
                    continue;
                }
                if (!wall)
                {
                    CurrentPlayerPositionTop  = NewPlayerPositionTop;
                    CurrentPlayerPositionLeft = NewPlayerPositionLeft;
                    Console.CursorTop         = OldPlayerPositionTop;
                    Console.CursorLeft        = OldPlayerPositionLeft;
                    Console.Write(" ");
                    Console.CursorTop  = CurrentPlayerPositionTop;
                    Console.CursorLeft = CurrentPlayerPositionLeft;
                    Console.Write("@");
                    Console.Write("\b");
                }

                // Starts battle if player over monster
                if (Arena.IsMonster(NewPlayerPositionLeft, NewPlayerPositionTop))
                {
                    Battle.GetAttackResult(killer, enemy);
                    Arena.monsterElements[NewPlayerPositionLeft, NewPlayerPositionTop] = '\0';
                }

                //if (Arena.IsMonster2(NewPlayerPositionLeft, NewPlayerPositionTop))
                //{
                //    Battle.GetAttackResult(killer, enemy2);
                //    Arena.monsterElements2[NewPlayerPositionLeft, NewPlayerPositionTop] = '\0';
                //}

                //if (Arena.IsMonster3(NewPlayerPositionLeft, NewPlayerPositionTop))
                //{
                //    Battle.GetAttackResult(killer, enemy3);
                //    Arena.monsterElements3[NewPlayerPositionLeft, NewPlayerPositionTop] = '\0';
                //}

                // Player gains buffs if over chest
                if (Arena.IsChest(NewPlayerPositionLeft, NewPlayerPositionTop))
                {
                    Chest.DropLoot();
                    Arena.chestElements[NewPlayerPositionLeft, NewPlayerPositionTop] = '\0';
                }

                // Player exits arena
                if (CurrentPlayerPositionLeft == Arena.ExitPositionLeft && CurrentPlayerPositionTop == Arena.ExitPositionTop)
                {
                    EndGame.Exit();
                }
            } while (input.Key != ConsoleKey.Escape);
        }
Ejemplo n.º 2
0
        public static void GetAttackResult(Player playerA, Monster monsterB)
        {
            bool dead = false;

            //PLayer spesification
            int warAttack  = playerA.Attack();
            int warDefence = monsterB.Defence();
            int warIsHellB = -warDefence + warAttack;

            //Monster spesification
            int warAttack2  = monsterB.Attack();
            int warDefence2 = playerA.Defence();
            int warisHellA  = -warDefence2 + warAttack2;

            do
            {
                // Player hits monster
                if (warIsHellB > 0)
                {
                    monsterB.HealthPoints = monsterB.HealthPoints - warIsHellB;
                    UserInterface.Text    = "Player dmg: " + warIsHellB + ", monster hp: " + monsterB.HealthPoints + "";
                }

                else
                {
                    warIsHellB         = 0;
                    UserInterface.Text = "Player dmg: " + warIsHellB + ", monster hp: " + monsterB.HealthPoints + "";
                }

                // Monster hits player
                if (warisHellA > 0)
                {
                    playerA.HealthPoints = playerA.HealthPoints - warisHellA;
                    UserInterface.Text2  = "|| Monster dmg: " + warisHellA + ", player hp: " + playerA.HealthPoints + "";
                }

                else
                {
                    warisHellA          = 0;
                    UserInterface.Text2 = "|| Monster dmg: " + warisHellA + ", player hp: " + playerA.HealthPoints + "";
                }

                // Monster dies
                if (monsterB.HealthPoints <= 0)
                {
                    UserInterface.Text  = "Monster died" + "\t\t\t\t\t\t\t";
                    UserInterface.Text2 = " ";
                    dead = true;
                }

                // Player dies
                if (playerA.HealthPoints <= 0)
                {
                    UserInterface.Text  = "\t\t\t\t";
                    UserInterface.Text2 = "\t\t\t\t";
                    dead = true;
                    EndGame.GameOver();
                }
                UserInterface.BuildUI();
                Thread.Sleep(1000);
            } while (!dead);
            monsterB.HealthPoints = 40;
            UserInterface.Text    = "\t\t\t\t";
            UserInterface.Text2   = "\t\t\t\t";
            UserInterface.BuildUI();
        }