Beispiel #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void update(GameTime gameTime)
        {
            // TODO: Add your update logic here

            //Souris = Mouse.GetState(); implemented on the classe GameScreen
            xSourisMatrice = (int)(Souris.X) / 18;
            ySourisMatrice = (int)(Souris.Y) / 18;

            if (Souris.LeftButton == ButtonState.Pressed)
            {
                if ((Souris.X >= 0) && (Souris.Y >= 0) && (Souris.X < 18 * terrain.tailleMatrice) && (Souris.Y < 18 * terrain.tailleMatrice) && numeroJoueurGagne == 0)
                {
                    if (terrain.matrice[xSourisMatrice, ySourisMatrice] == 0) //si case vide
                    {
                        Pion pion = new Pion(xSourisMatrice, ySourisMatrice);
                        dernierPion = pion;
                        terrain.AjouterPionMatrice(numeroJoueur, pion);        //on ajoute le pion dans la matrice
                        VerifCarre(pion);
                        listeJoueur[numeroJoueur].AjouterPion(pion);           //on ajoute le pion dans la liste des pions selon le joueur
                        numeroJoueur = (numeroJoueur + 1) % listeJoueur.Count; //on change de joueur
                        if (listeJoueur[numeroJoueur].Score > 100)
                        {
                            numeroJoueurGagne = numeroJoueur + 1;
                        }
                    }
                }
                else if (Souris.X >= TAILLECARRE * (NOMBRECASEX - 2) && Souris.X < TAILLECARRE * NOMBRECASEX && Souris.Y > TAILLECARRE * (NOMBRECASEY - 2) && Souris.Y <= TAILLECARRE * NOMBRECASEY)
                {
                    NouvellePartie();
                }
            }
            base.update(gameTime);
        }
Beispiel #2
0
        private void VerifCarre(Pion pion)
        {
            int    x1, y1, x2, y2;
            Joueur joueur = listeJoueur[numeroJoueur];

            foreach (Pion p in joueur.listePion)
            {
                x1 = p.X - (p.Y - pion.Y);
                y1 = p.Y + (p.X - pion.X);
                if ((x1 < terrain.tailleMatrice) && (x1 >= 0) && (y1 < terrain.tailleMatrice) && (y1 >= 0))
                {
                    if (terrain.matrice[x1, y1] == numeroJoueur + 1)
                    {
                        x2 = pion.X - (p.Y - pion.Y);
                        y2 = pion.Y + (p.X - pion.X);

                        if ((x2 < terrain.tailleMatrice) && (x2 >= 0) && (y2 < terrain.tailleMatrice) && (y2 >= 0))
                        {
                            if (terrain.matrice[x2, y2] == numeroJoueur + 1)
                            {
                                joueur.AjouterScore((int)(Math.Pow((p.Y - pion.Y), 2) + Math.Pow((p.X - pion.X), 2)));
                                Pion px = new Pion(1, 1);
                                square = new Square(p, pion, new Pion(x2, y2), new Pion(x1, y1), listeColor[numeroJoueur]);
                                joueur.listeSquare.Add(square);
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public Square(Pion p1, Pion p2, Pion p3, Pion p4, Color couleur)
        {
            listetrait = new List <Trait>();
            this.p1    = p1;
            this.p2    = p2;
            this.p3    = p3;
            this.p4    = p4;

            listetrait.Add(new Trait(p1.X * 18 + 9, p2.X * 18 + 9, p1.Y * 18 + 9, p2.Y * 18 + 9, couleur));
            listetrait.Add(new Trait(p2.X * 18 + 9, p3.X * 18 + 9, p2.Y * 18 + 9, p3.Y * 18 + 9, couleur));
            listetrait.Add(new Trait(p3.X * 18 + 9, p4.X * 18 + 9, p3.Y * 18 + 9, p4.Y * 18 + 9, couleur));
            listetrait.Add(new Trait(p4.X * 18 + 9, p1.X * 18 + 9, p4.Y * 18 + 9, p1.Y * 18 + 9, couleur));
        }
Beispiel #4
0
 private void NouvellePartie()
 {
     terrain.NewMatrice();
     listeJoueur = new List <Joueur>();
     for (int i = 0; i < nombreJoueur; i++)
     {
         Joueur joueur = new Joueur();
         listeJoueur.Add(joueur);
     }
     numeroJoueur      = 0;
     numeroJoueurGagne = 0;
     dernierPion       = null;
 }
Beispiel #5
0
        private Pion IAForte(int[,] matrice, Pion dernierPion, List <Pion> listePion)
        {
            //Defence, searching if the player has a "near" square
            int    x1, x2, y1, y2;
            int    tailleMatrice = matrice.Length;
            double alea;
            Pion   pionAPlacer = null;
            bool   found       = false; // for only one pion

            foreach (Pion p in listePion)
            {
                if (!found)
                {
                    x1 = p.X - (p.Y - dernierPion.Y);
                    y1 = p.Y + (p.X - dernierPion.X);
                    if ((x1 < matrice.Length) && (x1 >= 0) && (y1 < tailleMatrice) && (y1 >= 0))
                    {
                        if (matrice[x1, y1] != 0) //TODO
                        {
                            x2 = dernierPion.X - (p.Y - dernierPion.Y);
                            y2 = dernierPion.Y + (p.X - dernierPion.X);

                            if ((x2 < tailleMatrice) && (x2 >= 0) && (y2 < tailleMatrice) && (y2 >= 0))
                            {
                                if (matrice[x2, y2] == 0) //Si il ne l'a pas encore posé...
                                {
                                    alea = rnd.Next();
                                    if (alea <= 0.1 * type) //Puissance de l'IA
                                    {
                                        pionAPlacer = new Pion(x2, y2);
                                        found       = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(pionAPlacer);
        }
Beispiel #6
0
 public void AjouterPionMatrice(int numJoueur, Pion pion)
 {
     matrice[pion.X, pion.Y] = numJoueur + 1;
 }
Beispiel #7
0
 public void AjouterPion(Pion pion)
 {
     listePion.Add(pion);
 }