Esempio n. 1
0
        public Character()
        {
            userName         = "******";
            userStrength     = Convert.ToInt32(Dice.getBaseStat());
            userConstitution = Convert.ToInt32(Dice.getBaseStat());
            userDexterity    = Convert.ToInt32(Dice.getBaseStat());

            List <Weapon> tempWeapon = new List <Weapon>();

            tempWeapon.Add(new Dagger());
            tempWeapon.Add(new Mace());
            tempWeapon.Add(new LongSword());
            tempWeapon.Add(new DoubleAxe());
            tempWeapon.Add(new DoubleSword());
            tempWeapon.Add(new ExecutionAxe());
            userWeapon = tempWeapon[Dice.random(1, tempWeapon.Count - 1)];

            List <Armor> tempArmor = new List <Armor>();

            tempArmor.Add(new Cloth());
            tempArmor.Add(new Leather());
            tempArmor.Add(new Chain());
            tempArmor.Add(new Plate());
            userArmor = tempArmor[Dice.random(1, tempArmor.Count - 1)];

            List <Race> tempRace = new List <Race>();

            tempRace.Add(new Human());
            tempRace.Add(new Dwarf());
            tempRace.Add(new Elf());
            tempRace.Add(new Halfling());
            userRace = tempRace[Dice.random(1, tempRace.Count - 1)];

            List <Class> tempClass = new List <Class>();

            tempClass.Add(new Tank());
            tempClass.Add(new Fighter());
            tempClass.Add(new Paladin());
            tempClass.Add(new Ranger());
            tempClass.Add(new Barbarian());
            userClass = tempClass[Dice.random(1, tempClass.Count - 1)];

            currentHealth = health();
        }
Esempio n. 2
0
        private void tail_Click(object sender, EventArgs e)
        {
            int turn;

            pbFlip.Visible = false;
            head.Visible   = false;
            tail.Visible   = false;

            if (Dice.random(0, 1) == 1)
            {
                turn = 0;
            }

            else
            {
                turn = 1;
            }

            toTheDeath(turn);
        }
Esempio n. 3
0
        //main function
        private void toTheDeath(int firstTurn)
        {
            int turn = firstTurn; //overall turn

            //player turn
            if (turn == 0)
            {
                record("Human Player set to begin..");
            }

            else
            {
                record("Computer Player set to begin..");
            }

            /*the total turn is incremented by .25.
             * The decider for attacking is the modulus division of the current
             * total turn % their respective attack speed. A zero result means
             * they get to attack. Allowing for very variable attack speeds.*/
            double turnSpeed = .25;

            double player1 = player.attackSpeed();
            double player2 = computer.attackSpeed();

            //continue until someone is dead
            while (player.currentHealth > 0 && computer.currentHealth > 0)
            {
                if (turn == 0 && ((turnSpeed % player1) == 0))
                {
                    //Decide if you can attack
                    if ((Dice.random(1, 20) + player.attackBonus()) > (computer.defenseBonus()) + computer.constitution)
                    {
                        int damage = 0;
                        //tally up the damage
                        for (int i = 0; i < player.weapon.weaponRoll; i++)
                        {
                            damage += Dice.random(1, player.weapon.weaponDamage);
                        }

                        //get your name in the history book
                        record("Human hits Computer: - " + damage);
                        //update health
                        computer.currentHealth = computer.currentHealth - damage;

                        //adjust the health trackers of the player you hit
                        if (computer.currentHealth < 0)
                        {
                            pbComp.Value = 0;
                            lblCompCurrentHealth.Text = Convert.ToString(0);
                        }

                        else
                        {
                            pbComp.Value = computer.currentHealth;
                            lblCompCurrentHealth.Text = Convert.ToString(computer.currentHealth);
                        }
                    }
                    else
                    {
                        //Your opponent has a silly amount of defense
                        record("Human misses Computer.");
                    }
                    //switch turns
                    turn = 1;
                }
                if (turn == 1 && ((turnSpeed % player2) == 0))
                {
                    if ((Dice.random(1, 20) + computer.attackBonus()) > (player.defenseBonus()) + player.constitution)
                    {
                        int damage = 0;
                        for (int i = 0; i < computer.weapon.weaponRoll; i++)
                        {
                            damage += Dice.random(1, computer.weapon.weaponDamage);
                        }

                        record("Computer hits Human: - " + damage);
                        player.currentHealth = player.currentHealth - damage;
                    }
                    else
                    {
                        record("Computer misses Human.");
                    }
                    if (player.currentHealth < 0)
                    {
                        pbPlayer.Value        = 0;
                        lblCurrentHealth.Text = Convert.ToString(0);
                    }

                    else
                    {
                        pbPlayer.Value        = player.currentHealth;
                        lblCurrentHealth.Text = Convert.ToString(player.currentHealth);
                    }
                    turn = 0;
                }
                turnSpeed += .25;                   //increment total turn
                System.Threading.Thread.Sleep(250); //pause for 1/4 a second
            }
            //Declare if its a win or loss
            if (player.currentHealth > 0)
            {
                record("Human Wins !!");
                lblResult.Text      = "Victory !!";
                lblResult.ForeColor = System.Drawing.Color.Blue;
                lblResult.Visible   = true;
            }

            else
            {
                record("Computer Wins !!");
                lblResult.Text      = "Defeat !!";
                lblResult.ForeColor = System.Drawing.Color.Red;
                lblResult.Visible   = true;
            }

            btnRePlay.Visible = true;
            btnExit.Visible   = true;
        }