示例#1
0
文件: Animal.cs 项目: kmichel/passeur
 public void EatGrass(Island island, float eatGrassProbability)
 {
     if (island.RandFloat(0f, 1f) < eatGrassProbability) {
         foreach (var grass in island.grasses) {
             if (grass.row == row && grass.column == column) {
                 island.grasses.Remove(grass);
                 break;
             }
         }
     }
 }
示例#2
0
文件: Animal.cs 项目: kmichel/passeur
 public void Move(Island island, float movementProbability)
 {
     if (island.RandFloat(0f, 1f) < movementProbability) {
         var direction = island.RandInt(0, 4);
         switch (direction) {
         case 0:
             if (island.IsWalkableAndAvailable(row, column - 1))
                 column -= 1;
             break;
         case 1:
             if (island.IsWalkableAndAvailable(row, column + 1))
                 column += 1;
             break;
         case 2:
             if (island.IsWalkableAndAvailable(row + 1, column))
                 row += 1;
             break;
         case 3:
             if (island.IsWalkableAndAvailable(row - 1, column))
                 row -= 1;
             break;
         }
     }
 }