Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Entities;
- import Map.Map;
- import Map.Location;
- import java.util.ArrayList;
- public class KillBot extends Bot{//Yes, I know that I was supposed to extend FlexBot, but this is better
- private int speed;
- public KillBot(Location l, int id, Directions d, int s) {
- super(l, id, d);
- speed=s;
- }
- public boolean move(Map m){
- int movesMade=0;
- int turnCount=0;
- while (movesMade<speed&&turnCount<4){
- if(super.move(m)){//can move
- movesMade++;
- turnCount=0;
- }
- else{//can't move
- Entity e=getEntInPath(m);
- System.out.println(e);
- if(e!=null&&e.getID()<getID()&&e instanceof Bot){//try kill
- m.removeEnt(e);
- super.move(m);
- movesMade++;
- turnCount=0;
- }else{//no ent or ent too strong so turn
- turn();
- turnCount++;
- }
- }
- }
- return movesMade==speed;
- }
- public Entity getEntInPath(Map m){
- Entity out=null;
- switch(getDir()){
- case UP:{
- for(Entity e: m.getEntList()){
- if(e.getLoc().equals(new Location(getLoc().getRow()-1,
- getLoc().getCol()))){
- out=e;
- }
- }
- break;
- }
- case DOWN:{
- for(Entity e: m.getEntList()){
- if(e.getLoc().equals(new Location(getLoc().getRow()+1,
- getLoc().getCol()))){
- out=e;
- }
- }
- break;
- }
- case LEFT:{
- for(Entity e: m.getEntList()){
- if(e.getLoc().equals(new Location(getLoc().getRow(),
- getLoc().getCol()-1))){
- out=e;
- }
- }
- break;
- }
- case RIGHT:{
- for(Entity e: m.getEntList()){
- if(e.getLoc().equals(new Location(getLoc().getRow(),
- getLoc().getCol()+1))){
- out=e;
- }
- }
- break;
- }
- }
- return out;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement