/// <summary> /// Validates if a pion can be changed to that place /// </summary> /// <param name="pionToMove"></param> /// <param name="xTo"></param> /// <param name="yTo"></param> /// <param name="mainField"></param> /// <param name="player"></param> /// <returns></returns> public bool Validate(Pion pionToMove, int xTo, int yTo, Pion[,] mainField, char player) { //TODO: only workd when 0,0 is in the botom left if (pionToMove.X != xTo && pionToMove.Y != yTo) { var longeur = Math.Sqrt(Math.Pow(xTo - pionToMove.X, 2) + Math.Pow(yTo - pionToMove.Y, 2)); if (longeur == 1) { if (mainField[xTo, yTo].PlayerSign == ' ') { return(true); } else { return(false); } } if (longeur > 2) { Pion pToGo = mainField[xTo, yTo]; // } } return(false); }
/// <summary> /// Turm of each player /// </summary> /// <param name="player">Current player</param> /// <param name="playField">Playing fied</param> public void Turn(char player, Pion[,] playField) { ValidationEngine validation = new ValidationEngine(); Utils utilities = new Utils(); if (player == '0')//white { Console.WriteLine("Au tour de Blanc"); } if (player == '1')//black { Console.WriteLine("Au tour de noir"); } Console.WriteLine("Coordonne du pion a bougé [x y]"); int[] coordinatesInitialPion = utilities.StringSpliter(Console.ReadLine()); Pion thePion = playField[coordinatesInitialPion[0] - 1, coordinatesInitialPion[1] - 1]; Console.WriteLine("Coordonne de destination [x y]"); int[] coordinatesToMoveTo = utilities.StringSpliter(Console.ReadLine()); var result = validation.Validate(thePion, coordinatesToMoveTo[0], coordinatesToMoveTo[1], playField, player); Console.WriteLine(result.ToString()); // Console.WriteLine(thePion.x + "," + thePion.y + "," + thePion.signe); //Debug }
/// <summary> /// Generates a playing Field /// </summary> /// <param name="size">Size of the playing field</param> /// <returns>Complete playing field</returns> public Pion[,] GeneratePlayField(int size) { Pion[,] field = new Pion[size, size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { field[x, y] = new Pion(x, y, ' '); } } for (int x = 0; x < size; x++) //colones { if (x == 0 || x == 2) { for (int y = 0; y < 10; y = y + 2) //white= 0 { field[x, y] = new Pion(x, y, '0'); } } if (x == 1 || x == 3) { for (int y = 1; y < 10; y = y + 2) //white = 0 { field[x, y] = new Pion(x, y, '0'); } } if (x == 6 || x == 8) { for (int y = 0; y < 10; y = y + 2) //black = 1 { field[x, y] = new Pion(x, y, '1'); } } if (x == 7 || x == 9) { for (int y = 1; y < 10; y = y + 2) //black = 1 { field[x, y] = new Pion(x, y, '1'); } } } string l = ""; foreach (var p in field) { l = l + p.PlayerSign; } FileManager FM = new FileManager(); FM.WriteToFile(field); return(field); }