internal static int TrouverPos(int idPiece, int[,] plateau, int[][] piecesCalcul) { int x, y; int position = -1; for (int i = 0; i < 16; i++) { Utilisables.Pos2Coord(out x, out y, i); if (plateau[x, y] == -1) { plateau[x, y] = idPiece; if (Utilisables.TesterVictoire(idPiece, i, plateau, piecesCalcul)) { position = i; break; } plateau[x, y] = -1; } } if (position >= 0) { Utilisables.Pos2Coord(out x, out y, position); plateau[x, y] = -1; } return(position); }
internal static bool PoserPiece(out int position, int idPiece, int[,] plateau) { int caseChoisie = rn.Next(0, 16); Utilisables.Pos2Coord(out int x, out int y, caseChoisie); while (plateau[x, y] >= 0) { caseChoisie = rn.Next(0, 16); Utilisables.Pos2Coord(out x, out y, caseChoisie); } plateau[x, y] = idPiece; IHM.AfficherCaseOrdi(x, y); position = caseChoisie; return(false); }
internal static bool PoserPieceIA(out int position, int idPiece, int[,] plateau, int[][] piecesCalcul) { int x, y; position = TrouverPos(idPiece, plateau, piecesCalcul); if (position == -1) { PoserPiece(out position, idPiece, plateau); } else { Utilisables.Pos2Coord(out x, out y, position); plateau[x, y] = idPiece; IHM.AfficherCaseOrdi(x, y); } return(false); }
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); }