Esempio n. 1
0
        public static Character GetCharacter(int id)
        {
            Character character = null;

            using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.DatabaseConnectionString))
            {
                connection.Open();

                string sql = "SELECT Name, Stat, Amount FROM Character INNER JOIN CharacterStats ON ID = Character WHERE ID = @id";

                SqlCommand command = new SqlCommand(sql, connection);
                command.Parameters.AddWithValue("@id", id);
                SqlDataReader reader = command.ExecuteReader();

                string name = null;
                int health = 0;
                int attack = 0;
                int speed = 0;
                int crit = 0;

                while (reader.Read())
                {
                    name = reader.GetString(0);

                    switch (reader.GetString(1))
                    {
                        case "Health":
                            health = reader.GetInt32(2);
                            break;
                        case "AttackPower":
                            attack = reader.GetInt32(2);
                            break;
                        case "Speed":
                            speed = reader.GetInt32(2);
                            break;
                        case "CriticalHitChance":
                            crit = reader.GetInt32(2);
                            break;
                    }
                }

                character = new Character(name, health, attack, speed, crit);

                connection.Close();
            }

            return character;
        }
Esempio n. 2
0
        public void Hit(Character target)
        {
            Dice dice = new Dice(10);

            int power = dice.Roll() * AttackPower;

            double roll = dice.Roll();
            if (roll <= CriticalHitChance)
            {
                if (roll == 1)
                    roll = 1.5;

                power = (int)(power + AttackPower * roll);

            }

            if (dice.Roll() <= Speed)
                target.Hurt(power);
        }
Esempio n. 3
0
 public Player(Character character)
     : this(character.Name, character.Health, character.AttackPower, character.Speed, character.CriticalHitChance)
 {
 }