Beispiel #1
0
        public void AddTournoi(string nom, MatchContract match1, MatchContract match2, MatchContract match3, MatchContract match4)
        {
            List <MatchContract> listMatchc = new List <MatchContract>();

            listMatchc.Add(match1);
            listMatchc.Add(match2);
            listMatchc.Add(match3);
            listMatchc.Add(match4);

            List <Match> listMatch = new List <Match>();

            List <Jedi> listJedi = jtm.getAllJedis();

            List <Stade> listStade = jtm.getAllStades();

            Jedi  jedi1 = new Jedi();
            Jedi  jedi2 = new Jedi();
            Stade stade = new Stade();

            foreach (MatchContract m in listMatchc)
            {
                jedi1 = listJedi.Find(j => j.Nom == m.Jedi1.Nom);
                jedi2 = listJedi.Find(j => j.Nom == m.Jedi2.Nom);
                stade = listStade.Find(s => s.Planete == m.Stade.Planete);

                listMatch.Add(new Match(m.Id, jedi1, jedi2, EPhaseTournoi.QuartFinale, stade));
            }

            Tournoi tournoi = new Tournoi(0, nom, listMatch);

            jtm.addTournoi(tournoi);
        }
Beispiel #2
0
        /// <summary>
        /// Constructeur pour modifier le tournoi
        /// </summary>
        /// <param name="tournoiEnCours"></param>
        public CreerTournoiWindow(Tournoi tournoiEnCours)
        {
            InitializeComponent();

            // Modifier le titre
            Title = "Modification de tournoi";

            // Initialiser le tournoi
            temp      = new Tournoi(tournoiEnCours);
            LeTournoi = null;

            // Mettre le datacontext au tournoi
            DataContext = temp;

            // Initialiser la liste
            Views = new List <UserControl>()
            {
                new InformationsGeneralesView(),
                new LocauxView(),
                new VolontairesView(),
                new ParticipantsView(),
                new EquipesView(),
                new PrixView()
            };

            // Initialiser l'index
            Index = 0;

            // Afficher la première page
            content.Content = Views.First();

            // Disable le bouton précédent
            btnPrecedent.IsEnabled = false;
        }
Beispiel #3
0
        public async Task <IActionResult> EndRound(int id, int round)
        {
            var temp = await CallAPI.GetTournoi(id);

            if (temp.Item1)
            {
                return(NotFound());
            }

            Tournoi tournoi = temp.Item2;

            if (tournoi.Over)
            {
                return(NotFound());
            }

            RetourAPI retour = await CallAPI.EndRound(id, round);

            if (!retour.Succes)
            {
                //
            }

            return(RedirectToAction("Tournoi", new { id = id }));
        }
Beispiel #4
0
        public async Task <IActionResult> Pairing(int id, int round)
        {
            var temp = await CallAPI.GetTournoi(id);

            if (temp.Item1)
            {
                return(NotFound());
            }

            Tournoi tournoi = temp.Item2;

            if (tournoi.Over)
            {
                return(NotFound());
            }

            RetourAPI retour = await CallAPI.PairingRound(new Round { IdTournament = id, RoundNumber = round });

            if (!retour.Succes)
            {
                //
            }

            return(RedirectToAction("Tournoi", new { id = id }));
        }
Beispiel #5
0
        public async Task <IActionResult> EndTournoi(Tournoi tournoi)
        {
            if (tournoi == null || tournoi.IdTournament < 1 || tournoi.Deleted != null)
            {
                return(NotFound());
            }

            if (tournoi.Deleted != null)
            {
                return(NotFound());
            }

            if (tournoi.Over)
            {
                return(NotFound());
            }

            RetourAPI retour = await CallAPI.EndTournoi(tournoi);

            if (retour.Succes)
            {
                return(RedirectToAction("Details", "Tournois", new { id = tournoi.IdTournament }));
            }

            return(RedirectToAction("EndTournoi", new { id = tournoi.IdTournament }));
        }
        public void testTournoi()
        {
            Jedi jedi1 = new Jedi();
            Jedi jedi2 = new Jedi();
            Jedi jedi3 = new Jedi();
            Jedi jedi4 = new Jedi();

            Stade stade  = new Stade(12, "Test", 2000, "Ouine", null, null);
            Stade stade2 = new Stade(13, "Test2", 4000, "Tata", null, null);

            List <Match> listMatchs = new List <Match>();

            listMatchs.Add(new Match(42, jedi1, jedi2, EPhaseTournoi.QuartFinale, stade));
            listMatchs.Add(new Match(56, jedi3, jedi4, EPhaseTournoi.DemiFinale, stade2));

            List <Match> listMatchs2 = new List <Match>();

            listMatchs2.Add(new Match(2, jedi3, jedi1, EPhaseTournoi.Finale, stade));

            Tournoi tournoi = new Tournoi(27, "Le Premier Tournoi", listMatchs);

            Assert.AreEqual(tournoi.ID, 27);
            Assert.AreEqual(tournoi.Nom, "Le Premier Tournoi");
            Assert.AreEqual(tournoi.Matchs, listMatchs);

            tournoi.Nom    = "Un Nouveau Tournoi";
            tournoi.Matchs = listMatchs2;

            Assert.AreEqual(tournoi.Nom, "Un Nouveau Tournoi");
            Assert.AreEqual(tournoi.Matchs, listMatchs2);
        }
Beispiel #7
0
        public BettingManager(BusinessManager businessManager, int nbJoueur)
        {
            this.businessManager = businessManager;
            rand    = new Random();
            joueurs = new List <Joueur>();

            for (int i = 0; i < nbJoueur; i++)
            {
                joueurs.Add(new Joueur("player" + i, 0));
            }

            List <Jedi> allJedis      = businessManager.getJedis();
            List <Jedi> jedis_to_pool = new List <Jedi>();


            //Creation de la liste a mettre dans la pool
            for (int i = 0; i < 16; i++)
            {
                int index = rand.Next() % allJedis.Count;
                jedis_to_pool.Add(allJedis[index]);
                allJedis.Remove(allJedis[index]);
            }

            jedis = jedis_to_pool;
            pool  = new Tournoi(jedis_to_pool, businessManager.getStades());
        }
Beispiel #8
0
        /// <summary>
        /// Ajoute un nouveau tounoi à la liste de tournoi.
        /// </summary>
        private void New()
        {
            Tournoi t = new Tournoi(_newNextId--, "<New>", null);

            this.SelectedTournoi = new TournoiViewModel(t);
            Tournois.Add(this.SelectedTournoi);
        }
Beispiel #9
0
        public async Task <IActionResult> Create([Bind("IdTournament,Name,Date,Description,IdGame,MaxNumberPlayer,DeckListNumber,Ppwin,Ppdraw,Pplose,Over,Deleted,Dotation")]
                                                 Tournoi tournoi)
        {
            if (ModelState.IsValid)
            {
                if ((tournoi.Organisateurs == null || !tournoi.Organisateurs.Any()) && int.TryParse(HttpContext.Session.GetString("UserId"), out int IdUser))
                {
                    tournoi.Organisateurs = new List <ViewOrga> {
                        new ViewOrga {
                            Level = 0, IdUser = IdUser, IdTournament = -1, Name = "", Pseudo = ""
                        }
                    };
                }

                if (tournoi.Organisateurs != null && tournoi.Organisateurs.Count() != 0)
                {
                    var retourApi = await CallAPI.InsertTournoi(tournoi);

                    if (retourApi.Succes)
                    {
                        return(RedirectToAction("Details", new { id = retourApi.CreateID }));
                    }
                }
            }


            IEnumerable <ViewJeu> Jeus = await CallAPI.GetAllJeus();

            ViewData["AllGame"] = new SelectList(Jeus, "IdGame", "Name", tournoi.jeu.IdGame);
            ViewData["Title"]   = "Création d'un tournoi";
            return(View("~/Views/Tournoi/CreateTournoi.cshtml", tournoi));
        }
Beispiel #10
0
        public async Task <IActionResult> Register([Bind("Deck, IdTournament")] Joueur joueur)
        {
            if (joueur.IdTournament < 1 || !int.TryParse(HttpContext.Session.GetString("UserId"), out int IdUser))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                joueur.User.IdUser = IdUser;


                RetourAPI retourApi = await CallAPI.RegisterTournoi(joueur);

                if (retourApi.Succes)
                {
                    return(RedirectToAction("Details", "Tournois", new{ id = joueur.IdTournament }));
                }

                ViewBag.error = retourApi.Message;
            }

            var temp = await CallAPI.GetTournoi(joueur.IdTournament);

            if (temp.Item1)
            {
                return(NotFound());
            }

            Tournoi tournoi = temp.Item2;

            ViewBag.NbDeck    = tournoi.DeckListNumber;
            ViewData["Title"] = "S'inscire pour " + tournoi.Name;
            return(View("~/Views/Tournoi/Register.cshtml", joueur));
        }
        public int EditTournoi(Tournoi _tournoi)
        {
            int val = 0;

            using (SqlConnection sqlConnection = new SqlConnection(m_connectionString))
            { //reste les Matchs à supprimer
                try
                {
                    string     query      = "UPDATE Tournoi SET Nom=@nom WHERE idTournoi=@idTournoi";
                    SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
                    sqlCommand.Parameters.AddWithValue("@nom", _tournoi.Nom);
                    sqlConnection.Open();
                    sqlCommand.ExecuteNonQuery();
                    val = 1;
                }
                catch (SqlException e)
                {
                    string s = e.Message;
                }
                finally
                {
                    sqlConnection.Close();
                }
            }
            return(val);
        }
Beispiel #12
0
 protected void OnRemoveTournoi(Tournoi t)
 {
     if (this.RemoveTournoi != null)
     {
         this.RemoveTournoi(this, new TournoiEventArgs(t));
     }
 }
Beispiel #13
0
        public async Task <IActionResult> CreateNextRound(int id, int round)
        {
            var temp = await CallAPI.GetTournoi(id);

            if (temp.Item1)
            {
                return(NotFound());
            }

            Tournoi tournoi = temp.Item2;

            if (tournoi.Over)
            {
                return(NotFound());
            }

            RetourAPI retour = await CallAPI.CreateRound(new Round { IdTournament = id, RoundNumber = (round + 1), StartRound = DateTime.UtcNow });

            if (!retour.Succes)
            {
                //
            }

            return(RedirectToAction("Tournoi", new { id = id }));
        }
Beispiel #14
0
 public TournoiWS(Tournoi t)
 {
     this.Id      = t.Id;
     this.Nom     = t.Nom;
     this.Matches = new List <MatchWS>();
     t.Matchs.ForEach(x => this.Matches.Add(new MatchWS(x)));
 }
Beispiel #15
0
        public void delTournoi(int id)
        {
            List <Tournoi> listTournoi = jtm.getAllTournois();
            Tournoi        tournoi     = listTournoi.Find(t => t.ID == id);

            jtm.delTournoi(tournoi);
        }
Beispiel #16
0
        public void getUpdateTournoisTest()
        {
            int            taille    = 0;
            int            debTaille = 0;
            List <Tournoi> liste     = bdd.getTournois();

            debTaille = liste.Count;
            Assert.AreNotEqual <int>(liste.Count, 0);
            if (liste.Count > 0)
            {
                Tournoi j = liste[0];
                Assert.AreEqual <int>(liste.Count, bdd.getTournois().Count);
                liste.Remove(liste.First());
                bdd.updateTournois(liste);
                taille = liste.Count;
                liste  = bdd.getTournois();
                Assert.AreEqual <int>(taille, liste.Count);
                liste.Add(j);
                Assert.AreEqual <int>(15, liste.First().Matchs.Count);
                bdd.updateTournois(liste);
                taille = liste.Count;
                liste  = bdd.getTournois();
                Assert.AreEqual <int>(taille, liste.Count);
                j = new Tournoi(0, "Test", bdd.getMatches());
                liste.Add(j);
                bdd.updateTournois(liste);
                taille = liste.Count;
                liste  = bdd.getTournois();
                Assert.AreEqual <int>(taille, liste.Count);
                liste.Remove(liste.Last());
                bdd.updateTournois(liste);
                Assert.AreEqual(debTaille, bdd.getTournois().Count);
            }
        }
Beispiel #17
0
        public async Task <IActionResult> Edit(int id, [Bind("IdTournoi,Nom,Prix,Description,Date,Jeu,Theme")] Tournoi tournoi)
        {
            if (id != tournoi.IdTournoi)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tournoi);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TournoiExists(tournoi.IdTournoi))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tournoi));
        }
        public bool InsertTournoi(Tournoi tournoi)
        {
            bool result = false;

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    sqlConnection.Open();
                    string     sql        = "INSERT INTO Tournoi VALUES(@Nom, @IdPokemonVainqueur); SELECT @@IDENTITY";
                    SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
                    sqlCommand.Parameters.Add("@Nom", SqlDbType.VarChar, 50).Value        = tournoi.Nom;
                    sqlCommand.Parameters.Add("@IdPokemonVainqueur", SqlDbType.Int).Value = tournoi.Vainqueur.ID;
                    sqlCommand.CommandType = CommandType.Text;
                    tournoi.ID             = Convert.ToInt32(sqlCommand.ExecuteScalar().ToString());
                    sqlConnection.Close();
                    result = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            return(result);
        }
        public void addTournoi(Tournoi tournoi)
        {
            int id = 0;

            using (SqlConnection sqlConnection = new SqlConnection(m_connexionString))
            {
                SqlCommand sqlAddTournoi = new SqlCommand("INSERT INTO dbo.tournoi (nom) VALUES ('" + tournoi.Nom + "')", sqlConnection);
                sqlAddTournoi.Connection = sqlConnection;
                sqlConnection.Open();
                sqlAddTournoi.ExecuteNonQuery();
                sqlConnection.Close();
            }

            using (SqlConnection sqlConnection = new SqlConnection(m_connexionString))
            {
                SqlCommand sqlCommandTournoi = new SqlCommand("SELECT IDENT_CURRENT('tournoi')", sqlConnection);
                sqlConnection.Open();

                SqlDataReader sqlDataReaderTournoi = sqlCommandTournoi.ExecuteReader();

                while (sqlDataReaderTournoi.Read())
                {
                    id = (int)sqlDataReaderTournoi.GetDecimal(0);
                }
            }

            if (id != 0)
            {
                changeTournoi(tournoi.Matchs, id);
            }
        }
        public bool UpdateTournoi(Tournoi tournoi)
        {
            bool result = false;

            try
            {
                using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                {
                    sqlConnection.Open();
                    string     sql        = "UPDATE Tournoi SET Nom=@Nom WHERE ID=@Id;";
                    SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
                    sqlCommand.Parameters.Add("@Id", SqlDbType.Int).Value          = tournoi.ID;
                    sqlCommand.Parameters.Add("@Nom", SqlDbType.VarChar, 50).Value = tournoi.Nom;
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.ExecuteReader();
                    sqlConnection.Close();
                    result = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            return(result);
        }
Beispiel #21
0
        public TournoiWS playTournoi(TournoiWS tournoi)
        {
            Tournoi t = businessManager.getTournois().Find(x => x.Id == tournoi.Id);

            businessManager.playTournament(t);
            return(new TournoiWS(t));
        }
        public int RemoveTournoi(Tournoi _tournoi)
        {
            int val = 0;

            using (SqlConnection sqlConnection = new SqlConnection(m_connectionString))
            { //reste les Matchs à supprimer
                try {
                    string     requete    = "DELETE FROM Tournoi WHERE idTournoi=@idtournoi";
                    SqlCommand sqlCommand = new SqlCommand(requete, sqlConnection);
                    sqlCommand.Parameters.AddWithValue("@idtournoi", _tournoi.ID);
                    sqlConnection.Open();
                    sqlCommand.ExecuteNonQuery();
                    sqlConnection.Close();
                    val = 1;
                }catch (SqlException e)
                {
                    string s = e.Message;
                }
                finally
                {
                    sqlConnection.Close();
                }
            }
            return(val);
        }
Beispiel #23
0
        bool IServiceJediTournament.launchTournoi(int tournoiId)
        {
            bool    flag     = false;
            Tournoi toLaunch = null;
            JediTournamentManager manager = new JediTournamentManager();

            List <Tournoi> list = manager.getTournois();

            foreach (Tournoi t in list)
            {
                if (t.Id == tournoiId)
                {
                    toLaunch = t;
                    break;
                }
            }

            if (toLaunch != null)
            {
                try {
                    manager.simulateTournament(toLaunch);
                    flag = true;
                }
                catch {
                    flag = false;
                }
            }

            return(flag);
        }
Beispiel #24
0
        public void lancerPhaseTournoi(List <int> paris, List <Jedi> jedis_paris)
        {
            foreach (Match match in pool.Matches)
            {
                PlayingMatch pMatch = new PlayingMatch(match);
                while (!pMatch.MatchOver)
                {
                    pMatch.playTurn(pMatch.automaticChoose(), pMatch.automaticChoose());
                }
                for (int i = 0; i < joueurs.Count; i++)
                {
                    if (match.JediVainqueur.Id == jedis_paris[i].Id)
                    {
                        joueurs[i].Score += paris[i];
                    }
                }
            }

            //Maj bdd
            List <Match> oldMatches = businessManager.getMatches();

            oldMatches.Concat(pool.Matches);
            businessManager.updateMatch(oldMatches);
            pool  = pool.nextPool();
            jedis = new List <Jedi>();
            foreach (Match match in pool.Matches)
            {
                jedis.Add(match.Jedi1);
                jedis.Add(match.Jedi2);
            }
            end = pool.PoolVide;
        }
 public bool DeleteTournoi(Tournoi tournoi)
 {
     foreach (Match match in tournoi.Matches)
     {
         DeleteMatch(match);
     }
     return(Delete("DELETE FROM Tournoi WHERE ID=@Id;", tournoi.ID));
 }
Beispiel #26
0
        public bool updateTournoi(Tournoi t)
        {
            bool flag = true;

            // TODO : to implement

            return(flag);
        }
Beispiel #27
0
        public bool removeTournoi(TournoiWS tournoi)
        {
            List <Tournoi> liste = businessManager.getTournois();
            Tournoi        paria = liste.First(x => x.Id == tournoi.Id);

            liste.Remove(paria);
            return(0 == businessManager.updateTournois(liste));
        }
 public TournoiViewer(Tournoi t, bool auto, int idJ1, int idJ2)
 {
     this.tournoi = t;
     Auto         = auto;
     IdJ1         = idJ1;
     IdJ2         = idJ2;
     InitializeComponent();
 }
        /// <summary>
        /// Créer un nouveau tournoi avec les valeurs des champs correspondants
        /// </summary>
        private void btnAjouterTournoi_Click(object sender, EventArgs e)
        {
            Tournoi t = new Tournoi(0, dtpDateDebut.Value.Date + dtpHeureDebut.Value.TimeOfDay, DateTime.Now, tbxNomTournoi.Text, (int)nudEquipes.Value, 0, 0);

            Tournoi.Ajouter(t);

            this.Close();
        }
        public GamePage(Tournoi t, bool b)
        {
            InitializeComponent();

            m_tournament    = t;
            m_manual        = b;
            m_current_match = 0;
            m_currentPhase  = EPhaseTournoi.HuitiemeFinale;
        }