Exemple #1
0
        public void EditFight(FightDTO f)
        {
            if (f.WinningArmy != 0)
            {
                string field2 = (f.DefArmy > 0 ? "ChallengedHouseId" : "ChallengedWWId");
                string field3 = (f.WinningArmy > 0 ? "WinningHouseId" : "WinningWWId");

                string sql = "UPDATE Fights SET ChallengingHouseId = @ChallengingHouseId, " + field2 + " = @ChallengedHouseId, " + field3 + " = @WinningHouseId WHERE FightId = @id";
                using (SqlConnection sqlCon = new SqlConnection(_connectionString))
                {
                    sqlCon.Open();
                    using (SqlCommand sqlCmd = new SqlCommand(sql, sqlCon))
                    {
                        sqlCmd.Parameters.Add("@ChallengingHouseId", SqlDbType.Int).Value = f.AttArmy;
                        sqlCmd.Parameters.Add("@ChallengedHouseId", SqlDbType.Int).Value  = f.DefArmy;
                        sqlCmd.Parameters.Add("@WinningHouseId", SqlDbType.Int).Value     = f.WinningArmy;
                        sqlCmd.Parameters.Add("@id", SqlDbType.Int).Value = f.Id;


                        sqlCmd.ExecuteNonQuery();
                    };
                    sqlCon.Close();
                };
            }
        }
Exemple #2
0
        public void AddFight(FightDTO f)
        {
            string field2 = (f.DefArmy > 0 ? "ChallengedHouseId" : "ChallengedWWId");
            string field3 = (f.WinningArmy > 0 ? "WinningHouseId" : "WinningWWId");

            string sql = "INSERT INTO Fights(ChallengingHouseId, " + field2 + ", " + field3 + ") Values(@ChallengingHouseId, @ChallengedHouseId, @WinningHouseId)";

            using (SqlConnection sqlCon = new SqlConnection(_connectionString))
            {
                sqlCon.Open();
                using (SqlCommand sqlCmd = new SqlCommand(sql, sqlCon))
                {
                    sqlCmd.Parameters.Add("@ChallengingHouseId", SqlDbType.Int).Value = f.AttArmy;
                    sqlCmd.Parameters.Add("@ChallengedHouseId", SqlDbType.Int).Value  = f.DefArmy;
                    if (f.WinningArmy != 0) // Gagnant non determiné
                    {
                        sqlCmd.Parameters.Add("@WinningHouseId", SqlDbType.Int).Value = f.WinningArmy;
                    }
                    else
                    {
                        sqlCmd.Parameters.Add("@WinningHouseId", SqlDbType.Int).Value = SqlInt32.Null;
                    }
                    sqlCmd.ExecuteNonQuery();
                };
                sqlCon.Close();
            };
        }
Exemple #3
0
        public FightDTO GetFightById(int p_id)
        {
            FightDTO fight;

            string sql = "SELECT * FROM Fights WHERE FightId = @id";

            using (SqlConnection sqlCon = new SqlConnection(_connectionString))
            {
                sqlCon.Open();
                using (SqlCommand sqlCmd = new SqlCommand(sql, sqlCon))
                {
                    sqlCmd.Parameters.Add("@id", SqlDbType.Int).Value = p_id;
                    SqlDataReader rdr = sqlCmd.ExecuteReader();

                    if (rdr.Read())
                    {
                        int id          = rdr.GetInt32(0);
                        int challenging = rdr.GetInt32(1);
                        int challenged  = (rdr.IsDBNull(2) ? rdr.GetInt32(4) : rdr.GetInt32(2));                         // Soit un House, soit un WW
                        int winning     = (rdr.IsDBNull(3) ? (rdr.IsDBNull(5) ? 0 : rdr.GetInt32(5)) : rdr.GetInt32(3)); // (HouseId Null ? WWId Null ? 0 SINON return WWId SINON return HouseId
                        fight = new FightDTO(id, challenging, challenged, winning);
                    }
                    else
                    {
                        fight = new FightDTO();
                    }
                };
                sqlCon.Close();
            };
            return(fight);
        }
Exemple #4
0
        public Boolean StartFight(FightDTO f)
        {
            if (f.WinningArmy == 0) // If not already fought
            {
                Random rand = new Random();
                House  hAtt = new House(this.GetHouseById(f.AttArmy));
                Army   hDef = GetArmyByID(f.DefArmy);

                int nbAtt = hAtt.NumberOfUnits;
                int nbDef = hDef.NumberOfUnits;

                Boolean battle = true;

                while (battle) // Go
                {
                    switch (rand.Next(0, 3))
                    {
                    case 0:
                        hAtt.UnitWins(rand);            // 1/3 Win
                        hDef.UnitLoses(rand);
                        break;

                    case 1:
                        hAtt.UnitDraw(rand);            // 1/3 Draw
                        hDef.UnitDraw(rand);
                        break;

                    case 2:
                        hAtt.UnitLoses(rand);           // 1/3 Lose
                        hDef.UnitWins(rand);
                        break;
                    }
                    if (hAtt.NumberOfUnits <= 5) // Attacking House loses
                    {
                        hAtt.LoseBattle(nbAtt - hAtt.NumberOfUnits, nbDef - hDef.NumberOfUnits);
                        hDef.WinBattle(nbDef - hDef.NumberOfUnits, nbAtt - hAtt.NumberOfUnits);
                        f.WinningArmy = f.DefArmy;
                        battle        = false;
                    }
                    else if (hDef.NumberOfUnits <= 5) // Defending House loses
                    {
                        hDef.LoseBattle(nbDef - hDef.NumberOfUnits, nbAtt - hAtt.NumberOfUnits);
                        hAtt.WinBattle(nbAtt - hAtt.NumberOfUnits, nbDef - hDef.NumberOfUnits);
                        f.WinningArmy = f.AttArmy;
                        battle        = false;
                    }
                }

                EditHouse(new HouseDTO(hAtt)); // Save the changes
                EditArmy(hDef);
                EditFight(f);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #5
0
 public FightModel(FightDTO fightDTO)
 {
     ID              = fightDTO.ID;
     FirstCharacter  = new CharacterModel(fightDTO.FirstCharacter);
     SecondCharacter = new CharacterModel(fightDTO.SecondCharacter);
     ID_Winner       = fightDTO.ID_Winner;
     ID_Territory    = fightDTO.ID_Territory;
     ID_War          = fightDTO.ID_War;
 }
        // PUT: api/Fights/{id}
        public IHttpActionResult Put(int id, [FromBody] FightDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data"));
            }

            ThronesTournamentManager m = new ThronesTournamentManager();

            m.UpdateFight(value.Transform());

            return(Ok());
        }
Exemple #7
0
        public IHttpActionResult GetFightById(int id)
        {
            FightDTO Fight = GameManager.Instance.GetFightById(id);

            if (Fight.Id == -1)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(Fight));
            }
        }
Exemple #8
0
        public FightDTO GetFightById(int id)
        {
            var fight = businessManager.GetFight(id);

            FightDTO fightDTO = new FightDTO()
            {
                HouseChalleging = fight.HouseChalleging.Name,
                HouseChalleged  = fight.HouseChalleged.Name,
                WinningHouse    = fight.WinningHouse.Name,
                Territory       = new TerritoryDTO()
                {
                    Owner         = fight.Territory.Owner.FirstName + " " + fight.Territory.Owner.LastName,
                    TerritoryType = fight.Territory.TerritoryType.ToString()
                }
            };

            return(fightDTO);
        }
Exemple #9
0
 public void EditFight(FightDTO Fight)
 {
     DalManager.Instance.EditFight(Fight);
 }
Exemple #10
0
 public void AddFight(FightDTO Fight)
 {
     DalManager.Instance.AddFight(Fight);
 }
Exemple #11
0
 public void EditFight(FightDTO Fight)
 {
     bddInterf.EditFight(Fight);
 }
Exemple #12
0
 public void AddFight(FightDTO Fight)
 {
     bddInterf.AddFight(Fight);
 }
Exemple #13
0
 public IHttpActionResult PutFight([FromBody] FightDTO Fight)
 {
     GameManager.Instance.EditFight(Fight);
     return(Ok());
 }
Exemple #14
0
        public FightDTO GetFightById(int id)
        {
            FightDTO fight = new FightDTO(businessManager.GetFightById(id));

            return(fight);
        }