Advertisement
cgorrillaha

Untitled

Mar 22nd, 2022
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package Entities;
  2.  
  3. import Map.Location;
  4. import Map.Map;
  5.  
  6. public class FlexBot extends Bot{
  7.     int speed;
  8.     public static final int FAST=5, MEDIUM=3, SLOW=1;
  9.     static int nextID=1;
  10.  
  11.     public FlexBot(){
  12.         super();
  13.         setLoc(new Location(0,0));
  14.         setID(nextID);
  15.         nextID++;
  16.         speed=SLOW;
  17.         setDir(Directions.RIGHT);
  18.     }
  19.  
  20.     public FlexBot(Location l, int id, Directions d, int s) {
  21.         super(l, id, d);
  22.         speed=s;
  23.     }
  24.  
  25.     @Override
  26.     public boolean move(Map m){
  27.         int movesMade=0;
  28.         int turnCount=0;
  29.  
  30.         while (movesMade<speed&&turnCount<4){
  31.             if(super.move(m)){
  32.                 movesMade++;
  33.                 turnCount=0;
  34.             }
  35.             else{
  36.                 turn();
  37.                 turnCount++;
  38.             }
  39.         }
  40.         return movesMade==speed;
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement