예제 #1
0
    /// <summary>
    /// Check the different action change buttons
    /// </summary>
    void CheckActionChange()
    {
        // Attack actions
        if (inputManager.SwitchWeaponButton && gameManager.playerAttributes.unlockedAttackActions > 0)
        {
            //
            attackMode = (AttackMode)(int)attackMode + 1;
            attackMode = (attackMode == AttackMode.Count ||
                          (int)attackMode >= gameManager.playerAttributes.unlockedAttackActions) ?
                         (AttackMode)0 : attackMode;

            // TODO: Habrá que trabajar esto con la carga variable
            EnemyAnalyzer.RecalculatePenetration();
        }
        // Defensive actions
        if (inputManager.SwitchDefenseButton && gameManager.playerAttributes.unlockedDefenseActions > 0)
        {
            //
            defenseMode = (DefenseMode)(int)defenseMode + 1;
            defenseMode = (defenseMode == DefenseMode.Count ||
                           (int)defenseMode >= gameManager.playerAttributes.unlockedDefenseActions) ?
                          (DefenseMode)0 : defenseMode;
        }
        // Jump actions
        if (inputManager.SwitchJumpButton && gameManager.playerAttributes.unlockedJumpActions > 0)
        {
            //
            jumpMode = (JumpMode)(int)jumpMode + 1;
            jumpMode = (jumpMode == JumpMode.Count ||
                        (int)jumpMode >= gameManager.playerAttributes.unlockedJumpActions) ?
                       (JumpMode)0 : jumpMode;
        }
        // Sprint actions
        if (inputManager.SwitchSprintButton && gameManager.playerAttributes.unlockedSprintActions > 0)
        {
            //
            sprintMode = (SprintMode)(int)sprintMode + 1;
            sprintMode = (sprintMode == SprintMode.Count ||
                          (int)sprintMode >= gameManager.playerAttributes.unlockedSprintActions) ?
                         (SprintMode)0 : sprintMode;
        }
    }
예제 #2
0
        public void SimulateBattle()
        {
            CreateEnemy();
            AttackMode  attackMode     = new AttackMode();
            DefenseMode defenseMode    = new DefenseMode();
            Random      random         = new Random();
            bool        enemyAttacking = false;
            bool        wrongButton    = false;
            bool        triedDef       = false;
            int         userDamage     = 0;
            bool        userDefended   = false;
            bool        enemyDefended  = false;

            while (player.IsAlive && enemy.IsAlive)
            {
                if (enemyAttacking)
                {
                    Console.WriteLine("Apparently the enemy will attack... Try to defense it\n");
                }

                ShowInfo(player.Name, player.CurrentHealth, player.Weapon, enemy.Name, enemy.CurrentHealth, enemy.Weapon);
                string[] menu =
                {
                    "[1] Front Attack",
                    "[2] Vertical Attack",
                    "[3] Horizontal Attack",
                    "[4] Defense Front",
                    "[5] Defense Vertically",
                    "[6] Defense Horizontally"
                };
                cw.CWStringArray(menu);

                ConsoleKeyInfo selection = Console.ReadKey();
                Console.Clear();
                switch (selection.Key)
                {
                case ConsoleKey.D1:
                    userDamage = (attackMode.GetData(AttackType.NormalAttack).DataItem as IAttack).Damage((int)player.Weapon.AttackRating);
                    break;

                case ConsoleKey.D2:
                    userDamage = (attackMode.GetData(AttackType.VerticalSlashAttack).DataItem as IAttack).Damage((int)player.Weapon.AttackRating);
                    break;

                case ConsoleKey.D3:
                    userDamage = (attackMode.GetData(AttackType.HorizontalSlashAttack).DataItem as IAttack).Damage((int)player.Weapon.AttackRating);
                    break;

                case ConsoleKey.D4:
                    userDefended = (defenseMode.GetData(DefenseType.NormalDefense).DataItem as IDefense).
                                   GetDefense((DefenseType)random.Next((int)Enum.GetValues(typeof(DefenseType)).Cast <DefenseType>().Max()) + 1);
                    triedDef = true;
                    break;

                case ConsoleKey.D5:
                    userDefended = (defenseMode.GetData(DefenseType.VerticalDefense).DataItem as IDefense).
                                   GetDefense((DefenseType)random.Next((int)Enum.GetValues(typeof(DefenseType)).Cast <DefenseType>().Max()) + 1);
                    triedDef = true;
                    break;

                case ConsoleKey.D6:
                    userDefended = (defenseMode.GetData(DefenseType.HorizontalDefense).DataItem as IDefense).
                                   GetDefense((DefenseType)random.Next((int)Enum.GetValues(typeof(DefenseType)).Cast <DefenseType>().Max()) + 1);
                    triedDef = true;
                    break;

                default:
                    Console.WriteLine("You did nothing...");
                    wrongButton = true;
                    break;
                }

                if (enemyAttacking)
                {
                    if (!userDefended)
                    {
                        int enemyDamage = (attackMode.GetData((AttackType)random.
                                                              Next((int)Enum.GetValues(typeof(AttackType)).
                                                                   Cast <AttackType>().Max()) + 1).DataItem as IAttack).
                                          Damage((int)enemy.Weapon.AttackRating);
                        player.DamagePlayer(enemyDamage);

                        if (triedDef)
                        {
                            Console.WriteLine($"You failed to block { enemy.Name }'s attack");
                        }
                        Console.WriteLine($"{ enemy.Name } landed { enemyDamage } damage to you.");
                    }
                    else
                    {
                        Console.WriteLine($"You successfully defended { enemy.Name }'s attack");
                    }

                    if (userDamage > 0)
                    {
                        enemy.DamageEnemy(userDamage);
                        Console.WriteLine($"You landed { enemy.Name } to { userDamage } damage");
                    }
                }
                else
                {
                    if (userDamage > 0)
                    {
                        // enemy tries to defense
                        if (random.Next(100) < 25)
                        {
                            enemyDefended = (defenseMode.GetData((DefenseType)random.
                                                                 Next((int)Enum.GetValues(typeof(DefenseType)).Cast <DefenseType>().Max()) + 1).
                                             DataItem as IDefense).
                                            GetDefense((DefenseType)random.
                                                       Next((int)Enum.GetValues(typeof(DefenseType)).Cast <DefenseType>().Max()) + 1);
                        }

                        if (!enemyDefended)
                        {
                            enemy.DamageEnemy(userDamage);
                            Console.WriteLine($"You landed { enemy.Name } to { userDamage } damage");
                        }
                        else
                        {
                            Console.WriteLine($"{ enemy.Name } managed to block your attack");
                        }
                    }
                    else
                    {
                        if (!wrongButton)
                        {
                            Console.WriteLine("You made an defense move but it was meaningless...");
                        }
                    }
                }

                Console.WriteLine();

                if (!player.IsAlive)
                {
                    Console.Clear();
                    Console.WriteLine($"{ player.Name } Died");
                    Console.WriteLine("...GAME OVER...");
                    Console.ReadLine();
                    Console.Clear();
                }
                if (!enemy.IsAlive)
                {
                    Console.Clear();
                    Console.WriteLine($"{ player.Name } killed { enemy.Name }");
                    Console.WriteLine($"...CONGRUCULATIONS...");
                    Console.ReadLine();
                    Console.Clear();
                }

                userDamage     = 0;
                userDefended   = false;
                triedDef       = false;
                wrongButton    = false;
                enemyAttacking = !enemyAttacking;
            }
        }