Advertisement
cgorrillaha

Map

Mar 26th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. package model;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. public class Map {
  7.     public static int NUM_ROWS=10, NUM_COLS=10;
  8.     private Entity[][] botMap;
  9.     private ArrayList<Entity> bots;
  10.  
  11.     public Map(ArrayList<Entity> bots){
  12.         this.bots=bots;
  13.         botMap=new Entity[NUM_ROWS][NUM_COLS];
  14.         putBotsOnMap();
  15.     }
  16.  
  17.     public void putBotOnMap(Bot b){
  18.         botMap[b.getLoc().getRow()][b.getLoc().getCol()]=b;
  19.     }
  20.  
  21.     public Bot removeBotFromMap(Bot b){
  22.         Bot temp=b;
  23.         botMap[b.getLoc().getRow()][b.getLoc().getCol()]=null;
  24.         return temp;
  25.     }
  26.  
  27.     public Bot removeBotFromList(Bot b){
  28.         int index=bots.indexOf(b);
  29.         System.out.println(index);
  30.         return (Bot)(bots.remove(index));
  31.     }
  32.  
  33.     public void putBotsOnMap(){
  34.         for(int i=0; i<bots.size(); i++){
  35.             Entity b=bots.get(i);
  36.             botMap[b.getLoc().getRow()]
  37.                     [b.getLoc().getCol()]=b;
  38.         }
  39.     }
  40.  
  41.     public void clearMap(){
  42.         for(Entity[] bots: botMap){
  43.             Arrays.fill(bots, null);
  44.         }
  45.     }
  46.  
  47.     public void updateMap(){
  48.         clearMap();
  49.         putBotsOnMap();
  50.     }
  51.  
  52.     public void printMap(){
  53.         for(Entity[] row: botMap){
  54.             for(Entity b: row){
  55.                 if(b!=null){
  56.                     System.out.print(b.getId()+", ");
  57.                 }
  58.                 else{
  59.                     System.out.print("00, ");
  60.                 }
  61.             }
  62.             System.out.println();
  63.         }
  64.     }
  65.  
  66.     public Entity[][] getBotMap() {
  67.         return botMap;
  68.     }
  69.  
  70.     public void setBotMap(Entity[][] botMap) {
  71.         this.botMap = botMap;
  72.     }
  73.  
  74.     public ArrayList<Entity> getBots() {
  75.         return bots;
  76.     }
  77.  
  78.     public void setBots(ArrayList<Entity> bots) {
  79.         this.bots = bots;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement