示例#1
0
 public Vector3 Move(DirectionEnum direction)
 {
     Position2d newPos = new Position2d (playerPosition.x, playerPosition.y);
     Position2d positionChange = new Position2d (0, 0);
     switch (direction) {
     case DirectionEnum.NORTH:
         positionChange.x = -1;
         break;
     case DirectionEnum.EAST:
         positionChange.y = 1;
         break;
     case DirectionEnum.SOUTH:
         positionChange.x = 1;
         break;
     case DirectionEnum.WEST:
         positionChange.y = -1;
         break;
     default:
         throw new System.ArgumentOutOfRangeException ();
     }
     do {
         newPos.AddLocal (positionChange);
     } while (posInBounds (newPos)
              && Landscape [newPos.x, newPos.y].Equals (GT.__I));
     if (!posInBounds (newPos) || Landscape [newPos.x, newPos.y].Equals (GT.WAL)) {
         newPos.AddLocal (positionChange.negateLocal ());
     }
     playerPosition = newPos;
     return IntToFloat (newPos);
 }
 public void PutCheese(Position2d position, GameObject button)
 {
     if (position.x == mousePosition.x && position.y == mousePosition.y) {
         Mouse.showUnreachable ();
     } else if (position.x != mousePosition.x && position.y != mousePosition.y) {
         Mouse.showUnreachable ();
     } else {
         Position2d newPos = new Position2d (mousePosition.x, mousePosition.y);
         Position2d positionChange = new Position2d (0, 0);
         if (mousePosition.x < position.x) {
             positionChange.x = 1;
         } else if (mousePosition.x > position.x) {
             positionChange.x = -1;
         } else if (mousePosition.y < position.y) {
             positionChange.y = 1;
         } else {
             positionChange.y = -1;
         }
         do {
             newPos.AddLocal (positionChange);
         } while(!Landscape [newPos.x, newPos.y].Equals (GT.WAL) && !(newPos.x == position.x && newPos.y == position.y));
         if ((newPos.x == position.x && newPos.y == position.y)) {
             Mouse.targetPosition = IntToFloat (newPos);
             mousePosition = newPos;
             this.ActivateButtons (false);
             PutCheese (button);
             RemainingCheese--;
             cheeseTextField.text = "" + RemainingCheese;
         } else {
             Mouse.showUnreachable ();
         }
     }
 }