public override List<Point> NextMovements(BaseFigure[,] grid, bool inclusiveAttackMoves) { List<Point> result = new List<Point>(); int direction = 1; if (Team == Player.Teams.TeamWhite) direction = -1; try { if (grid[X, Y + direction] == null) result.Add(new Point(X, Y + direction)); //Normal movement } catch (IndexOutOfRangeException) {} try { if(((Y == 6 && Team == Player.Teams.TeamWhite) || (Y == 1 && Team == Player.Teams.TeamBlack)) //Pawn is on start position && grid[X, Y + direction] == null //And can move 1 step && grid[X, Y + 2 * direction] == null) //And can move 2 steps result.Add(new Point(X, Y + 2 * direction)); } catch (IndexOutOfRangeException) {} try { if(inclusiveAttackMoves && grid[X + 1, Y + direction] != null && grid[X + 1, Y + direction].Team != Team) //Move diagonal & attack enemy result.Add(new Point(X + 1, Y + direction)); } catch(IndexOutOfRangeException) { } try { if(inclusiveAttackMoves && grid[X - 1, Y + direction] != null && grid[X - 1, Y + direction].Team != Team) //Move diagonal & attack enemy result.Add(new Point(X - 1, Y + direction)); } catch(IndexOutOfRangeException) { } return result; }
public override List<Point> NextMovements(BaseFigure[,] grid, bool inclusiveAttackMoves) { List<Point> result = new List<Point>(); AddBishopMovement(grid, result, inclusiveAttackMoves); AddRookMovement(grid, result, inclusiveAttackMoves); //return EraseDuplicateEntries(result); return result; }
public override List<Point> NextMovements(BaseFigure[,] grid, bool inclusiveAttackMoves) { List<Point> curList = new List<Point>(); try { for(int x = 1; x < GameLogic.GRID_SIZE; x++) { int newX = X + x; int newY = Y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int x = 1; x < GameLogic.GRID_SIZE; x++) { int newX = X - x; int newY = Y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int y = 1; y < GameLogic.GRID_SIZE; y++) { int newX = X; int newY = Y + y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int y = 1; y < GameLogic.GRID_SIZE; y++) { int newX = X; int newY = Y - y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } return curList; }
private void AddBishopMovement(BaseFigure[,] grid, List<Point> curList, bool inclusiveAttackMoves) { try { for(int i = 1; i < GameLogic.GRID_SIZE; i++) { int newX = X + i; int newY = Y + i; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int i = 1; i < GameLogic.GRID_SIZE; i++) { int newX = X + i; int newY = Y - i; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int i = 1; i < GameLogic.GRID_SIZE; i++) { int newX = X - i; int newY = Y + i; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int i = 1; i < GameLogic.GRID_SIZE; i++) { int newX = X - i; int newY = Y - i; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } }
public override List<Point> NextMovements(BaseFigure[,] grid, bool inclusiveAttackMoves) { List<Point> result = new List<Point>(); try { if(grid[X + 1, Y + 1] == null || (grid[X + 1, Y + 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X + 1, Y + 1)); } catch(IndexOutOfRangeException) { } try { if(grid[X + 1, Y] == null || (grid[X + 1, Y].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X + 1, Y)); } catch(IndexOutOfRangeException) { } try { if(grid[X + 1, Y - 1] == null || (grid[X + 1, Y - 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X + 1, Y - 1)); } catch(IndexOutOfRangeException) { } try { if(grid[X, Y + 1] == null || (grid[X, Y + 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X, Y + 1)); } catch(IndexOutOfRangeException) { } try { if(grid[X, Y - 1] == null || (grid[X, Y - 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X, Y - 1)); } catch(IndexOutOfRangeException) { } try { if(grid[X - 1, Y + 1] == null || (grid[X - 1, Y + 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X - 1, Y + 1)); } catch(IndexOutOfRangeException) { } try { if(grid[X - 1, Y] == null || (grid[X - 1, Y].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X - 1, Y)); } catch(IndexOutOfRangeException) { } try { if(grid[X - 1, Y - 1] == null || (grid[X - 1, Y - 1].Team != Team && inclusiveAttackMoves)) result.Add(new Point(X - 1, Y - 1)); } catch(IndexOutOfRangeException) { } return result; }
public Field(BaseFigure figure) { this.Figure = figure; }
private void AddRookMovement(BaseFigure[,] grid, List<Point> curList, bool inclusiveAttackMoves) { try { for(int x = 1; x < GameLogic.GRID_SIZE; x++) { int newX = X + x; int newY = Y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int x = 1; x < GameLogic.GRID_SIZE; x++) { int newX = X - x; int newY = Y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int y = 1; y < GameLogic.GRID_SIZE; y++) { int newX = X; int newY = Y + y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } try { for(int y = 1; y < GameLogic.GRID_SIZE; y++) { int newX = X; int newY = Y - y; if(grid[newX, newY] != null) { if(grid[newX, newY].Team != Team && inclusiveAttackMoves) curList.Add(new Point(newX, newY)); break; } curList.Add(new Point(newX, newY)); } } catch(IndexOutOfRangeException) { } }
public BaseFigure[,] ConvertGameGridToBaseFigureGrid() { BaseFigure[,] resultGrid = new BaseFigure[GRID_SIZE, GRID_SIZE]; for (int y = 0; y < GRID_SIZE; y++) { for (int x = 0; x < GRID_SIZE; x++) { resultGrid[x, y] = _gameGrid[x, y].Figure; } } return resultGrid; }
public abstract List<Point> NextMovements(BaseFigure[,] grid, bool inclusiveAttackMoves);