Exemple #1
0
        public static double TypeMultiplier(Mon defendingMon, Move attackingMove)
        {
            Dictionary <int, double> multiplier = new Dictionary <int, double>()
            {
                { 0, 1 },
                { 1, 2 },
                { 2, 0.5 },
                { 3, 0 }
            };
            MonType attackType = attackingMove.GetMonType();

            List <MonType> types    = defendingMon.GetMonTypes();
            double         multiply = 1;

            foreach (MonType type in types)
            {
                Dictionary <string, int> typeCompare = new Dictionary <string, int>()
                {
                    { "fairy", type.GetFairy() },
                    { "steel", type.GetSteel() },
                    { "dark", type.GetDark() },
                    { "dragon", type.GetDragon() },
                    { "ghost", type.GetGhost() },
                    { "rock", type.GetRock() },
                    { "bug", type.GetBug() },
                    { "psychic", type.GetPsychic() },
                    { "flying", type.GetFlying() },
                    { "ground", type.GetGround() },
                    { "poison", type.GetPoison() },
                    { "fighting", type.GetFighting() },
                    { "ice", type.GetIce() },
                    { "grass", type.GetGrass() },
                    { "electric", type.GetElectric() },
                    { "water", type.GetWater() },
                    { "fire", type.GetFire() },
                    { "normal", type.GetNormal() },
                };
                double newMultiplier = multiplier[typeCompare[attackType.GetMonTypeName()]];
                multiply = multiply * newMultiplier;
            }
            if (multiply > 1)
            {
                Message newMessage = new Message("<span class='animated jackInTheBox'>It's Super Effective!</span>");
                newMessage.Save();
            }
            else if (multiply < 1)
            {
                Message newMessage = new Message("<span class='animated slideInDown'>It's Not Very Effective...</span>");
                newMessage.Save();
            }
            return(multiply);
        }
Exemple #2
0
        public static double STABMultiplier(Mon attackingMon, Move attackingMove)
        {
            List <MonType> monType    = attackingMon.GetMonTypes();
            MonType        attackType = attackingMove.GetMonType();
            double         multiply   = 1;

            foreach (MonType type in monType)
            {
                if (type.GetMonTypeName().Equals(attackType.GetMonTypeName()))
                {
                    multiply = multiply * 1.5;
                }
            }
            return(multiply);
        }
Exemple #3
0
        public static Mon Find(int id)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT * FROM mons WHERE id = (@searchId);";

            cmd.Parameters.Add(new MySqlParameter("@searchId", id));

            var    rdr            = cmd.ExecuteReader() as MySqlDataReader;
            int    MonId          = 0;
            string MonName        = "";
            int    Level          = 0;
            int    Hitpoints      = 0;
            int    Attack         = 0;
            int    Defense        = 0;
            int    Specialattack  = 0;
            int    Specialdefense = 0;
            int    Speed          = 0;

            while (rdr.Read())
            {
                MonId          = rdr.GetInt32(0);
                MonName        = rdr.GetString(1);
                Level          = rdr.GetInt32(2);
                Hitpoints      = rdr.GetInt32(3);
                Attack         = rdr.GetInt32(4);
                Defense        = rdr.GetInt32(5);
                Specialattack  = rdr.GetInt32(6);
                Specialdefense = rdr.GetInt32(7);
                Speed          = rdr.GetInt32(8);
            }
            Mon newMon = new Mon(MonName, Level, Hitpoints, Attack, Defense, Specialattack, Specialdefense, Speed, MonId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            // return new Mon("", "", 0);
            return(newMon);
        }
Exemple #4
0
        public void AddMon(Mon newMon)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO mons_battle (mons_id, battle_id) VALUES (@MonsId, @BattleId);";

            cmd.Parameters.Add(new MySqlParameter("@MonsId", newMon.GetMonId()));
            cmd.Parameters.Add(new MySqlParameter("@BattleId", _battleId));

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Exemple #5
0
 public override bool Equals(System.Object otherMon)
 {
     if (!(otherMon is Mon))
     {
         return(false);
     }
     else
     {
         Mon  newMon            = (Mon)otherMon;
         bool idEquality        = this.GetMonId().Equals(newMon.GetMonId());
         bool nameEquality      = this.GetMonName().Equals(newMon.GetMonName());
         bool hitpointsEquality = this.GetHitpoints().Equals(newMon.GetHitpoints());
         bool attackEquality    = this.GetAttack().Equals(newMon.GetAttack());
         bool defenseEquality   = this.GetDefense().Equals(newMon.GetMonName());
         bool spattackEquality  = this.GetSpecialattack().Equals(newMon.GetSpecialattack());
         bool spdefenseEquality = this.GetSpecialdefense().Equals(newMon.GetSpecialdefense());
         bool speedEquality     = this.GetSpeed().Equals(newMon.GetSpeed());
         return(idEquality && nameEquality && hitpointsEquality && attackEquality && defenseEquality && spattackEquality && spdefenseEquality && speedEquality);
     }
 }
Exemple #6
0
        public List <Mon> GetMons()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"SELECT mons.* FROM battle
      JOIN mons_battle ON (battle.id = mons_battle.battle_id)
      JOIN mons ON (mons_battle.mons_id = mons.id)
      WHERE battle.id = @BattleId;";

            cmd.Parameters.Add(new MySqlParameter("@BattleId", _battleId));

            MySqlDataReader rdr  = cmd.ExecuteReader() as MySqlDataReader;
            List <Mon>      mons = new List <Mon> {
            };

            while (rdr.Read())
            {
                int    monId          = rdr.GetInt32(0);
                string monName        = rdr.GetString(1);
                int    level          = rdr.GetInt32(2);
                int    hitpoints      = rdr.GetInt32(3);
                int    attack         = rdr.GetInt32(4);
                int    defense        = rdr.GetInt32(5);
                int    specialattack  = rdr.GetInt32(6);
                int    specialdefense = rdr.GetInt32(7);
                int    speed          = rdr.GetInt32(8);

                Mon newMon = new Mon(monName, level, hitpoints, attack, defense, specialattack, specialdefense, speed, monId);
                mons.Add(newMon);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(mons);
        }
Exemple #7
0
        public static void ComputerSequence2(int id, Move computerMove)
        {
            Battle  player      = Battle.FindPlayer();
            Battle  computer    = Battle.FindComputer();
            Mon     playerMon   = Mon.Find(player.GetMon_Id());
            Mon     computerMon = Mon.Find(computer.GetMon_Id());
            Move    playerMove  = Move.Find(id);
            Message newMessage  = new Message(computerMove.GetDescription());

            newMessage.Save();
            double otherHP      = (double)player.GetHitpoints() - (double)Battle.Damage(computerMove, computer, computerMon, playerMon);
            int    roundOtherHP = (int)otherHP;

            if (roundOtherHP > 0)
            {
                player.SetNewHP(roundOtherHP);
            }
            else
            {
                player.SetNewHP(0);
            }
        }
Exemple #8
0
 public static void ComputerChoice(int MonId)
 {
     if (MonId == 1)
     {
         Mon    mon2     = Mon.Find(2);
         Battle computer = mon2.GetAllTrueStats();
         computer.Save();
         computer.SetComputerMon();
         computer.SetActiveMon();
     }
     else if (MonId == 2)
     {
         Mon    mon3     = Mon.Find(3);
         Battle computer = mon3.GetAllTrueStats();
         computer.Save();
         computer.SetComputerMon();
         computer.SetActiveMon();
     }
     else if (MonId == 3)
     {
         Mon    mon1     = Mon.Find(1);
         Battle computer = mon1.GetAllTrueStats();
         computer.Save();
         computer.SetComputerMon();
         computer.SetActiveMon();
     }
     else if (MonId > 3)
     {
         List <Mon> allMons   = Mon.GetAllMons();
         Random     rand      = new Random();
         Mon        chosenMon = Mon.Find(rand.Next(allMons.Count));
         Console.WriteLine(chosenMon.GetMonName());
         Battle computer = chosenMon.GetAllTrueStats();
         computer.Save();
         computer.SetComputerMon();
         computer.SetActiveMon();
     }
 }
Exemple #9
0
        public static void Sequence(int id)
        {
            Battle      player        = Battle.FindPlayer();
            Battle      computer      = Battle.FindComputer();
            Mon         playerMon     = Mon.Find(player.GetMon_Id());
            Mon         computerMon   = Mon.Find(computer.GetMon_Id());
            Move        playerMove    = Move.Find(id);
            List <Move> computerMoves = Mon.Find(computer.GetMon_Id()).GetMoves();
            Random      move          = new Random();
            Move        computerMove  = computerMoves[move.Next(computerMoves.Count)];

            //Speed Check
            int tie = 0;

            if (computer.GetSpeed() == player.GetSpeed())
            {
                Random speedTie = new Random();
                tie = speedTie.Next(1, 3);
            }
            if (player.GetSpeed() > computer.GetSpeed() || tie == 1)
            {
                double newHP   = (double)computer.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), playerMove) * (double)MonType.TypeMultiplier(computerMon, playerMove) * (double)MonType.STABMultiplier(playerMon, playerMove) * (double)playerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                int    roundHP = (int)newHP;
                if (roundHP > 0)
                {
                    computer.SetNewHP(roundHP);
                    double otherHP      = (double)player.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), computerMove) * (double)MonType.TypeMultiplier(playerMon, computerMove) * (double)MonType.STABMultiplier(computerMon, computerMove) * (double)computerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                    int    roundOtherHP = (int)otherHP;

                    if (roundOtherHP > 0)
                    {
                        player.SetNewHP(roundOtherHP);
                    }
                    else
                    {
                        player.SetNewHP(0);
                    }
                }
                else
                {
                    computer.SetNewHP(0);
                }
            }
            else if (player.GetSpeed() < computer.GetSpeed() || tie == 2)
            {
                double otherHP      = (double)player.GetHitpoints() - (double)Battle.BaseDamage(computer.GetBattleId(), computerMove) * (double)MonType.TypeMultiplier(playerMon, computerMove) * (double)MonType.STABMultiplier(playerMon, playerMove) * (double)playerMove.AccuracyMultiplier() * (double)Battle.CritMultiplier();
                int    roundOtherHP = (int)otherHP;

                if (roundOtherHP > 0)
                {
                    player.SetNewHP(roundOtherHP);
                    double newHP   = (double)computer.GetHitpoints() - (double)Battle.BaseDamage(player.GetBattleId(), playerMove) * (double)MonType.TypeMultiplier(computerMon, playerMove) * (double)MonType.STABMultiplier(computerMon, computerMove) * (double)computerMove.AccuracyMultiplier();
                    int    roundHP = (int)newHP;
                    if (roundHP > 0)
                    {
                        computer.SetNewHP(roundHP);
                    }
                    else
                    {
                        computer.SetNewHP(0);
                    }
                }
                else
                {
                    player.SetNewHP(0);
                }
            }
        }