SHARE
TWEET

block/castle/mapManager/values v2

mmmflac Jan 22nd, 2020 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class block {
  2.     public boolean isAvailable;
  3.     public boolean isWalkable;
  4.     public int x,y;
  5.     public block(int x, int y, boolean isAvailable, boolean isWalkable){
  6.         mapManager.mapNames[x][y]="farm";
  7.         this.isAvailable = isAvailable;
  8.         this.isWalkable = isWalkable;
  9.         this.x = x;
  10.         this.y = y;
  11.     }
  12. }
  13. -----------------------------------------
  14. public class castle extends block{
  15.     public boolean isArmored;
  16.     public int basedFoodProd;
  17.     public int basedGoldProd;
  18.     public int basedSienceProd;
  19.     public int level;
  20.     public int health;
  21.     public int maxHealth;
  22.     public float armor;
  23.     public castle(int x, int y) {
  24.         super(x, y, false, true);
  25.         this.basedFoodProd = 1;
  26.         this.basedGoldProd = 1;
  27.         this.basedSienceProd = 0;
  28.         this.isArmored = false;
  29.         this.level = 1;
  30.         this.health = 10;
  31.         this.maxHealth = health;
  32.         this.armor = (float) 1.0;
  33.     }
  34.     public void fix(){
  35.         if(values.gold>=(maxHealth-health)*2){
  36.             health = maxHealth;
  37.             values.gold-=(maxHealth-health)*2;
  38.         }
  39.     }
  40.     public void buildArmor(){
  41.         if(!isArmored && values.gold > 20){
  42.             isArmored = true;
  43.             values.gold-=20;
  44.         }
  45.     }
  46.     public void attacked(int damage){
  47.         if(!isArmored){
  48.             health -= damage*armor;
  49.         }
  50.         isArmored = false;
  51.     }
  52.     public void levelUp(){
  53.         basedGoldProd += 1;
  54.         basedFoodProd += 1;
  55.         basedSienceProd += 2;
  56.         level++;
  57.         armor *= 0.9;
  58.         maxHealth += maxHealth*0.2;
  59.         health = maxHealth;
  60.     }
  61.     public boolean checkCastle(int x,int y){
  62.         for (int i = -3; i <= 3; i++) {
  63.             for (int j = -3; j <= 3; j++) {
  64.                 if (mapManager.mapNames[x+i][y+j] == "castle"){
  65.                     if(mapManager.mapNames[x][y]!="castle" && mapManager.mapNames[x][y]!="mine" && mapManager.mapNames[x][y]!="farm"){
  66.                         return true;
  67.                     }else{
  68.                         return false;
  69.                     }
  70.                 }
  71.             }
  72.         }
  73.         return false;
  74.     }
  75.     public void buildFarm(int x, int y){
  76.         if(values.gold>=20 && checkCastle(x,y)){
  77.             mapManager.mapNames[x][y]="farm";
  78.             values.gold-=20;
  79.             values.foodProd+=2;
  80.         }
  81.     }
  82.     public void buildMine(int x, int y){
  83.         if(values.gold>=25 && checkCastle(x,y)){
  84.             mapManager.mapNames[x][y]="mine";
  85.             values.gold-=25;
  86.             values.goldProd+=3;
  87.         }
  88.     }
  89.     public void destroyFarm(int x, int y){
  90.         if(mapManager.mapNames[x][y]=="farm"){
  91.             mapManager.mapNames[x][y]="block";
  92.             values.gold+=10;
  93.             values.foodProd-=2;
  94.         }
  95.     }
  96.     public void destroyMine(int x,int y){
  97.         if(mapManager.mapNames[x][y]=="mine") {
  98.             mapManager.mapNames[x][y] = "block";
  99.             values.gold += 10;
  100.             values.goldProd -= 3;
  101.         }
  102.     }
  103.        
  104. }
  105. -----------------------------------------
  106. public class mapManager {
  107.     public static String mapNames[][]= new String[10][10];
  108.  
  109.     public void fillNull(){
  110.         for (int i = 0; i < mapNames.length; i++) {
  111.             for (int j = 0; j < mapNames[0].length; j++) {
  112.                 mapNames[i][j]="block";
  113.             }
  114.         }
  115.     }
  116.  
  117. }
  118.  
  119. -----------------------------------------
  120. public class values {
  121.     public static int gold = 50;
  122.     public static int food = 50;
  123.     public static int science = 0;
  124.     public static int goldProd = 0;
  125.     public static int foodProd = 0;
  126. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top