예제 #1
0
        internal static int ChoisirPiece(int[] piecesJouables, bool sauvegarde, int[,] plateau)
        {
            bool choix           = false;
            int  colonneCourante = 0;
            int  ligneCourante   = 0;
            int  indice          = -1;
            int  pieceCourante   = 0;

            while (indice == -1)
            {
                indice = piecesJouables[pieceCourante];
                if (piecesJouables[pieceCourante] < 0)
                {
                    pieceCourante++;
                }
            }
            IHM.AfficherEcranJeux(piecesJouables, pieceCourante);
            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 && piecesJouables[pieceCourante] != -1)
                {
                    piecesJouables[pieceCourante] = -1;
                    choix      = true;
                    sauvegarde = false;
                }
                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, -1, pieceCourante);
                }

                if (colonneCourante < 0)
                {
                    colonneCourante = Math.Abs(colonneCourante + 4) % 4;
                }
                if (ligneCourante < 0)
                {
                    ligneCourante = Math.Abs(ligneCourante + 4) % 4;
                }
                pieceCourante = Coor2Pos(ligneCourante, colonneCourante);
                //if(piecesJouables[pieceCourante] >= 0)
                if (pause)
                {
                    IHM.AfficherEcranJeux(plateau, piecesJouables, -1, pieceCourante);
                }
                else
                {
                    IHM.AfficherEcranJeux(piecesJouables, pieceCourante);
                }
            }
            return(pieceCourante);
        }
예제 #2
0
        internal static int ChoisirPiece(int[] piecesJouables, bool sauvegarde, int[,] plateau, int tour, bool type, string[] piecesRep)
        {
            bool choix         = false;
            int  indice        = -1;
            int  pieceCourante = 0;

            while (indice == -1)
            {
                indice = piecesJouables[pieceCourante];
                if (piecesJouables[pieceCourante] < 0)
                {
                    pieceCourante++;
                }
            }
            Pos2Coord(out int ligneCourante, out int colonneCourante, pieceCourante);
            IHM.AfficherEcranJeux(piecesJouables, piecesRep, pieceCourante);
            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.DownArrow:
                case ConsoleKey.S:
                    ligneCourante = (ligneCourante += 1) % 4;
                    break;

                case ConsoleKey.Spacebar:
                case ConsoleKey.Enter:
                    if (piecesJouables[pieceCourante] != -1)
                    {
                        piecesJouables[pieceCourante] = -1;
                        choix      = true;
                        sauvegarde = false;
                    }
                    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, -1, pieceCourante);
                    }
                    break;
                }

                if (colonneCourante < 0)
                {
                    colonneCourante = Math.Abs(colonneCourante + 4);
                }
                if (ligneCourante < 0)
                {
                    ligneCourante = Math.Abs(ligneCourante + 4);
                }
                pieceCourante = Coor2Pos(ligneCourante, colonneCourante);
                //if(piecesJouables[pieceCourante] >= 0)
                if (pause)
                {
                    IHM.AfficherEcranJeux(plateau, piecesJouables, piecesRep, -1, pieceCourante);
                    IHM.AfficherInfoTour(tour);
                }
                else
                {
                    IHM.AfficherEcranJeux(piecesJouables, piecesRep, pieceCourante);
                }
            }
            return(pieceCourante);
        }
예제 #3
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);
        }
예제 #4
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);
        }