示例#1
0
 public Cell Move()
 {
     Cell newLocation = currentLocation.CellColour == Color.White ?
     Turn90DegreesRight(currentLocation) :
     Turn90DegreesLeft(currentLocation);
       currentLocation = newLocation;
       CellGraphic = new Rectangle(currentLocation.X * Width, currentLocation.Y * Height, Width, Height);
       return newLocation;
 }
示例#2
0
 public World(int aSize, int cellWidth, int cellHeight)
 {
     size = aSize;
       cells = new Cell[size, size];
       for (int i = 0; i < size; i++) {
     for (int j = 0; j < size; j++) {
       cells[i, j] = new Cell(i, j, cellWidth, cellHeight);
     }
       }
       for (int i = 0; i < size; i++) {
     for (int j = 0; j < size; j++) {
       cells[i, j].NorthCell = i == 0 ? cells[size - 1, j] : cells[i - 1, j];
       cells[i, j].SouthCell = i == size - 1 ? cells[0, j] : cells[i + 1, j];
       cells[i, j].EastCell = j == 0 ? cells[i, size - 1] : cells[i, j - 1];
       cells[i, j].WestCell = j == size - 1 ? cells[i, 0] : cells[i, j + 1];
     }
       }
       ant = new Ant(size / 2, size / 2, cellWidth, cellHeight, cells[size / 2, size / 2]);
 }
示例#3
0
 private Cell Turn90DegreesRight(Cell currentLocation)
 {
     Cell newLocation = null;
       currentLocation.CellColour = Color.Black;
       if (forwardDirection == currentLocation.NorthCell) {
     newLocation = currentLocation.WestCell;
     forwardDirection = newLocation.WestCell;
       }
       else if (forwardDirection == currentLocation.SouthCell) {
     newLocation = currentLocation.EastCell;
     forwardDirection = newLocation.EastCell;
       }
       else if (forwardDirection == currentLocation.EastCell) {
     newLocation = currentLocation.NorthCell;
     forwardDirection = newLocation.NorthCell;
       }
       else if (forwardDirection == currentLocation.WestCell) {
     newLocation = currentLocation.SouthCell;
     forwardDirection = newLocation.SouthCell;
       }
       return newLocation;
 }
示例#4
0
 public Ant(int xPos, int yPos, int aWidth, int aHeight, Cell startLocation)
     : base(xPos, yPos, aWidth, aHeight)
 {
     currentLocation = startLocation;
       forwardDirection = currentLocation.NorthCell;
 }