예제 #1
0
        internal static int ChoisirPieceIA(int[] piecesJouables, int[,] plateau, int[][] piecesCalcul, string[] piecesRep)
        {
            int pieceChoisie = -1;

            for (int i = 0; i < 16; i++)
            {
                if (piecesJouables[i] != -1)
                {
                    if (TrouverPos(i, plateau, piecesCalcul) == -1)
                    {
                        pieceChoisie = i;
                        break;
                    }
                }
            }
            if (pieceChoisie == -1)
            {
                pieceChoisie = ChoisirPiece(piecesJouables, piecesRep);
            }
            else
            {
                IHM.AfficherChoixOrdi(pieceChoisie, piecesRep);
                piecesJouables[pieceChoisie] = -1;
            }
            return(pieceChoisie);
        }
예제 #2
0
        internal static int ChoisirPiece(int[] piecesJouables, string[] piecesRep)
        {
            int pieceChoisie = rn.Next(0, 16);

            while (piecesJouables[pieceChoisie] == -1)
            {
                pieceChoisie = rn.Next(0, 16);
            }
            IHM.AfficherChoixOrdi(pieceChoisie, piecesRep);
            piecesJouables[pieceChoisie] = -1;
            return(pieceChoisie);
        }
예제 #3
0
        internal static string JeuxJvJ(int[,] plateau, int[] piecesJouables, int tour, int[][] piecesCalcul, string[] piecesRep)
        {
            bool type          = false;
            int  caseCourante  = -1;
            int  pieceCourante = -1;

            IHM.AfficherEcranJeux(plateau, piecesJouables, piecesRep, caseCourante, pieceCourante);
            string etat   = "JEUX_2";
            bool   gagner = false;
            //============================================================================================================
            //                           Départ de la Boucle de jeux pour un Player vs player
            //============================================================================================================
            bool sauvegarde = false;

            int[] piecesVides = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            while (!gagner)
            {
                if (piecesJouables.SequenceEqual(piecesVides))
                {
                    IHM.AfficherEgalite();
                }
                IHM.AfficherInfoTour(tour, true);
                // Tour du joueur 1
                if (tour % 2 == 0)
                {
                    IHM.AfficherConseil(2);
                    int idPiece = ChoisirPiece(piecesJouables, sauvegarde, plateau, tour, type, piecesRep);
                    sauvegarde = false;
                    IHM.AfficherEcranJeux(piecesJouables, piecesRep);
                    IHM.AfficherChoixOrdi(idPiece, piecesRep);
                    IHM.AfficherConseil(4);
                    sauvegarde = PoserPiece(out int position, idPiece, plateau, sauvegarde, piecesJouables, tour, type, piecesRep);
                    IHM.AfficherEcranJeux(plateau, piecesRep);
                    IHM.AfficherConseil(6);
                    gagner = TesterVictoire(idPiece, position, plateau, piecesCalcul);
                    if (gagner)
                    {
                        etat = "GAGNER";
                    }
                }
                // Tour du joueur 2
                else
                {
                    IHM.AfficherConseil(3);
                    int idPiece = ChoisirPiece(piecesJouables, sauvegarde, plateau, tour, type, piecesRep);
                    IHM.AfficherChoixOrdi(idPiece, piecesRep);
                    sauvegarde = false;
                    IHM.AfficherEcranJeux(piecesJouables, piecesRep);
                    IHM.AfficherConseil(5);
                    sauvegarde = PoserPiece(out int position, idPiece, plateau, sauvegarde, piecesJouables, tour, type, piecesRep);
                    IHM.AfficherEcranJeux(plateau, piecesRep);
                    IHM.AfficherConseil(6);
                    gagner = TesterVictoire(idPiece, position, plateau, piecesCalcul);
                    if (gagner)
                    {
                        etat = "GAGNER";
                    }
                }
                tour++;
            }
            return(etat);
        }
예제 #4
0
        internal static bool PoserPiece(out int position, int idPiece, int[,] plateau, bool sauvegarde, int[] piecesJouables)
        {
            bool choix = false;

            int colonneCourante = 0;
            int ligneCourante   = 0;
            int caseCourante    = 0;
            int indice          = 0;

            Utilisables.Pos2Coord(out int x, out int y, indice);


            while (plateau[x, y] != -1)
            {
                indice++;
                Utilisables.Pos2Coord(out x, out y, indice);
                if (plateau[x, y] == -1)
                {
                    caseCourante = indice;
                }
            }
            Utilisables.Pos2Coord(out ligneCourante, out colonneCourante, caseCourante);
            IHM.AfficherEcranJeux(plateau, caseCourante);
            while (!choix)
            {
                bool pause = false;
                System.ConsoleKeyInfo mouvement = Console.ReadKey();
                if (mouvement.Key == ConsoleKey.LeftArrow)
                {
                    colonneCourante = (colonneCourante -= 1) % 4;
                }
                else if (mouvement.Key == ConsoleKey.RightArrow)
                {
                    colonneCourante = (colonneCourante += 1) % 4;
                }
                else if (mouvement.Key == ConsoleKey.UpArrow)
                {
                    ligneCourante = (ligneCourante -= 1) % 4;
                }
                else if (mouvement.Key == ConsoleKey.DownArrow)
                {
                    ligneCourante = (ligneCourante += 1) % 4;
                }
                else if (mouvement.Key == ConsoleKey.Enter && plateau[ligneCourante, colonneCourante] == -1)
                {
                    plateau[ligneCourante, colonneCourante] = idPiece;
                    choix      = true;
                    sauvegarde = false;
                    IHM.EffacerChoixOrdi();
                }
                else if (mouvement.Key == ConsoleKey.P)
                {
                    sauvegarde = IHM.AfficherMenuPause(sauvegarde, plateau, piecesJouables);
                    pause      = true;
                }
                else if (mouvement.Key == ConsoleKey.Escape && sauvegarde == true)
                {
                    Environment.Exit(0);
                }
                else if (mouvement.Key == ConsoleKey.Escape && sauvegarde == false)
                {
                    IHM.AfficherQuitter(plateau, piecesJouables, caseCourante, -1, idPiece);
                }
                if (colonneCourante < 0)
                {
                    colonneCourante = Math.Abs(colonneCourante + 4) % 4;
                }
                if (ligneCourante < 0)
                {
                    ligneCourante = Math.Abs(ligneCourante + 4) % 4;
                }
                caseCourante = Coor2Pos(ligneCourante, colonneCourante);
                if (pause)
                {
                    IHM.AfficherEcranJeux(plateau, piecesJouables, caseCourante);
                    IHM.AfficherChoixOrdi(idPiece);
                }
                else
                {
                    IHM.AfficherEcranJeux(plateau, caseCourante);
                }
            }
            position = caseCourante;
            return(sauvegarde);
        }
예제 #5
0
        internal static bool PoserPiece(out int position, int idPiece, int[,] plateau, bool sauvegarde, int[] piecesJouables, int tour, bool type, string[] piecesRep)
        {
            bool choix        = false;
            int  caseCourante = 0;
            int  indice       = 0;

            Pos2Coord(out int x, out int y, indice);
            while (plateau[x, y] != -1)
            {
                indice++;
                Pos2Coord(out x, out y, indice);
                if (plateau[x, y] == -1)
                {
                    caseCourante = indice;
                }
            }
            Pos2Coord(out int ligneCourante, out int colonneCourante, caseCourante);


            IHM.AfficherEcranJeux(plateau, piecesRep, caseCourante);
            while (!choix)
            {
                bool pause = false;
                System.ConsoleKeyInfo mouvement = Console.ReadKey();
                switch (mouvement.Key)
                {
                case ConsoleKey.Q:
                case ConsoleKey.LeftArrow:
                    colonneCourante = (colonneCourante -= 1) % 4;
                    break;

                case ConsoleKey.D:
                case ConsoleKey.RightArrow:
                    colonneCourante = (colonneCourante += 1) % 4;
                    break;

                case ConsoleKey.Z:
                case ConsoleKey.UpArrow:
                    ligneCourante = (ligneCourante -= 1) % 4;
                    break;

                case ConsoleKey.S:
                case ConsoleKey.DownArrow:
                    ligneCourante = (ligneCourante += 1) % 4;
                    break;

                case ConsoleKey.Spacebar:
                case ConsoleKey.Enter:
                    if (plateau[ligneCourante, colonneCourante] == -1)
                    {
                        plateau[ligneCourante, colonneCourante] = idPiece;
                        choix      = true;
                        sauvegarde = false;
                        IHM.EffacerChoixOrdi();
                    }
                    break;

                case ConsoleKey.P:
                    sauvegarde = IHM.AfficherMenuPause(sauvegarde, plateau, piecesJouables, tour, type);
                    pause      = true;
                    break;

                case ConsoleKey.Escape:
                    if (sauvegarde)
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        IHM.AfficherQuitter(plateau, piecesJouables, piecesRep, caseCourante, -1, idPiece);
                    }
                    break;
                }

                if (colonneCourante < 0)
                {
                    colonneCourante = Math.Abs(colonneCourante + 4);
                }
                if (ligneCourante < 0)
                {
                    ligneCourante = Math.Abs(ligneCourante + 4);
                }
                caseCourante = Coor2Pos(ligneCourante, colonneCourante);

                if (pause)
                {
                    IHM.AfficherEcranJeux(plateau, piecesJouables, piecesRep, caseCourante);
                    IHM.AfficherChoixOrdi(idPiece, piecesRep);
                    IHM.AfficherInfoTour(tour);
                }
                else
                {
                    IHM.AfficherEcranJeux(plateau, piecesRep, caseCourante);
                }
            }
            position = caseCourante;
            return(sauvegarde);
        }