示例#1
0
        public static void Presentation()
        {
            Console.Clear();
            string titre = "Puissance 4";

            Affichage.Text("Puissance 4 par Leny Anthunes et Damien Le Borgne", 1, 0, ConsoleColor.Red);
            Affichage.Text(titre, placerMot(titre, 2) + (titre.Length / 2), 5, ConsoleColor.Red);
        }
示例#2
0
        static void Main(string[] args)
        {
            Affichage.noResize();
            Affichage.Presentation();

            Puissance4.LaunchGame(Puissance4.NbJoueur());


            Console.Read();
        }
示例#3
0
        public static void HelpCommand(Joueur[] j)
        {
            string phrase = "Utiliser les fléches pour diriger le jeton";

            for (int i = 0; i < Console.WindowWidth; i++)
            {
                Affichage.Text("-", i, Console.WindowHeight - 3, ConsoleColor.Blue);
            }
            Affichage.Text(phrase, Console.WindowWidth - phrase.Length, Console.WindowHeight - 2, ConsoleColor.Red);
            Affichage.Text(j[0].Nom, 5, Console.WindowHeight - 2, j[0].Color);
            Affichage.Text(j[1].Nom, j[0].Nom.Length + 6, Console.WindowHeight - 2, j[1].Color);
        }
示例#4
0
        public virtual int ChoixPosition()
        {
            int StartPos  = Console.WindowWidth / 2 - 1;
            int HeightPos = 18;
            int Space     = 4;


            int    minValue = (StartPos - 13);
            string Piont    = Char.ToString((char)9632);
            int    Width    = StartPos;
            bool   notGood  = true;
            int    touch    = -1;

            while (notGood)
            {
                if (Id == 'O')
                {
                    Affichage.Text(Piont, StartPos + 0, HeightPos - 14, ConsoleColor.Yellow);
                    Affichage.Text("^", StartPos + 0, HeightPos, ConsoleColor.Red);
                }
                else
                {
                    Affichage.Text(Piont, StartPos + 0, HeightPos - 14, ConsoleColor.Red);
                    Affichage.Text("^", StartPos + 0, HeightPos, ConsoleColor.Yellow);
                }

                touch = Joueur.Touch();
                Affichage.Text(Piont, StartPos + 0, HeightPos - 14, ConsoleColor.Black);
                Affichage.Text("^", StartPos + 0, HeightPos, ConsoleColor.Black);
                switch (touch)
                {
                case 4:

                    if (StartPos >= Width - 11)
                    {
                        StartPos -= Space;
                    }
                    break;

                case 6:
                    if (StartPos <= Width + 11)
                    {
                        StartPos += Space;
                    }
                    break;

                case 5:
                    return((StartPos / 4 - Width / 4) + 4);
                }
            }
            return(0);
        }
示例#5
0
        public static void LaunchGame(int player)
        {
            int  returnPos = 0;
            int  tours     = 0;
            bool Win       = false;

            Joueur j1;
            Joueur j2;

            if (player == 1)
            {
                j1 = new JoueurHumain("1", Puissance4.Jeton1, ConsoleColor.Red);
                j2 = new JoueurHumain("2", Puissance4.Jeton2, ConsoleColor.Yellow);
            }
            else
            {
                j1 = new JoueurHumain("1", Puissance4.Jeton1, ConsoleColor.Red);
                j2 = new JoueurIA("2", Puissance4.Jeton2, ConsoleColor.Yellow);
            }

            Joueur[] tableauJoueur = { j1, j2 };

            Grille g = new Grille();

            Affichage.HelpCommand(tableauJoueur);

            while (tours < 41 && Win == false)
            {
                for (int i = 0; i < tableauJoueur.Length; i++)
                {
                    while (g.PlacerPiont(returnPos - 1, tableauJoueur[i]))
                    {
                        returnPos = tableauJoueur[i].ChoixPosition();
                    }
                    returnPos = 0;
                    Affichage.AfficheGrille(Grille.Ligne, Grille.Colonne);
                    Win = g.TestWin(tableauJoueur[i]);
                    if (Win)
                    {
                        break;
                    }
                }
            }
            Console.Clear();
            Console.WriteLine(Win);
        }
示例#6
0
        public JoueurHumain(string Order, char id, ConsoleColor color)
            : base(id, color)
        {
            bool notGood = true;

            Console.Clear();
            while (notGood)
            {
                Affichage.Text(String.Format("Joueur {0} Entrer votre prénom: ", Order), 0, 0, ConsoleColor.Blue);
                Nom = Console.ReadLine();
                if (Nom.Length < 1)
                {
                    Affichage.Text("Merci d'écrire un prénom valide", 0, 1, ConsoleColor.Red);
                }
                else
                {
                    notGood = false;
                }
            }
        }
示例#7
0
        public static int NbJoueur()
        {
            bool   notGood = true;
            int    choice  = 2;
            string titre   = "Entrer pour continuer";
            string hum     = "Humain vs Humain";
            string comp    = "Humain vs Computeur";

            Affichage.Text(hum, Affichage.placerMot(hum, 2) - 10, 10, ConsoleColor.Green);
            Affichage.Text(comp, Console.WindowWidth / 2 + 9, 10, ConsoleColor.Green);
            Affichage.Text(titre, Affichage.placerMot(titre, 2) + (titre.Length / 2), 15, ConsoleColor.Blue);

            Affichage.Text(">", Console.WindowWidth / 2 + 4, 10, ConsoleColor.Red);

            while (notGood)
            {
                switch (Joueur.Touch())
                {
                case 4:
                    Affichage.Text(">", Console.WindowWidth / 2 + 4, 10, ConsoleColor.Black);
                    Affichage.Text("<", Console.WindowWidth / 2 - 6, 10, ConsoleColor.Red);
                    choice = 1;
                    break;

                case 6:
                    Affichage.Text(">", Console.WindowWidth / 2 + 4, 10, ConsoleColor.Red);
                    Affichage.Text("<", Console.WindowWidth / 2 - 6, 10, ConsoleColor.Black);
                    choice = 2;
                    break;

                case 5:
                    Affichage.Text(">", Console.WindowWidth / 2 + 4, 10, ConsoleColor.Red);
                    Affichage.Text("<", Console.WindowWidth / 2 - 6, 10, ConsoleColor.Black);
                    notGood = false;
                    return(choice);
                }
            }
            return(0);
        }
示例#8
0
        public static void AfficheGrille(int Ligne, int Colonne)
        {
            string BarSup = Affichage.RepeatString("+---", Colonne);

            BarSup = BarSup + "+";
            string BarSep = "|";
            string Piont  = Char.ToString((char)9632);
            int    cursor = 0;

            for (int l = 0; l < Ligne; l++)
            {
                Affichage.Text(BarSup, placerMot(BarSup, 2) + (BarSup.Length / 2), l * 2 + 5, ConsoleColor.White);
                for (int c = 0; c < Colonne; c++)
                {
                    Affichage.Text(BarSep, placerMot(BarSep, 2) + (BarSep.Length / 2) + (cursor - 14), l * 2 + 6, ConsoleColor.White);

                    if (Grille.grille[l, c] != Puissance4.Jeton1 && Grille.grille[l, c] != Puissance4.Jeton2)
                    {
                        Affichage.Text(Piont, placerMot(Piont, 2) + (Piont.Length / 2) + (cursor - 12), l * 2 + 6, ConsoleColor.Black);
                    }
                    else if (Grille.grille[l, c] == Puissance4.Jeton2)
                    {
                        Affichage.Text(Piont, placerMot(Piont, 2) + (Piont.Length / 2) + (cursor - 12), l * 2 + 6, ConsoleColor.Yellow);
                    }
                    else if (Grille.grille[l, c] == Puissance4.Jeton1)
                    {
                        Affichage.Text(Piont, placerMot(Piont, 2) + (Piont.Length / 2) + (cursor - 12), l * 2 + 6, ConsoleColor.Red);
                    }

                    Console.ForegroundColor = ConsoleColor.White;
                    cursor += 4;
                    Affichage.Text(BarSep, placerMot(BarSep, 2) + (BarSep.Length / 2) + (cursor - 14), l * 2 + 6, ConsoleColor.White);
                }
                cursor = 0;
                Affichage.Text(BarSup, placerMot(BarSup, 2) + (BarSup.Length / 2), Ligne * 2 + 5, ConsoleColor.White);
            }
        }
示例#9
0
 public Grille()
 {
     Console.Clear();
     Console.CursorVisible = false;
     Affichage.AfficheGrille(Ligne, Colonne);
 }