Advertisement
makispaiktis

Players with Weapons (Class Player)

Oct 30th, 2019 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Player {
  4.  
  5.     // Variables
  6.     String name;
  7.     String skin;
  8.     String backpack;
  9.     int level;
  10.     boolean hasBattlePass;
  11.     ArrayList <Weapon> weapons;
  12.    
  13.     // Constructors
  14.     Player(){
  15.         name = "Bot Clarence";
  16.         skin = "Default";
  17.         backpack = "Red Cape - Default Backpack";
  18.         level = 1;
  19.         hasBattlePass = false;
  20.         weapons = new ArrayList <Weapon> ();
  21.     }
  22.    
  23.     Player(String name, String skin, String backpack, int level, boolean hasBattlePass, ArrayList <Weapon> weapons){
  24.         this.name = name;
  25.         this.skin = skin;
  26.         this.backpack = backpack;
  27.         this.level = level;
  28.         this.hasBattlePass = hasBattlePass;
  29.         this.weapons = weapons;
  30.     }
  31.    
  32.     // Methods
  33.     void showStatus() {
  34.         System.out.println("Name: " + name);
  35.         System.out.println("Skin: " + skin);
  36.         System.out.println("Backpack: " + backpack);
  37.         System.out.println("Level: " + level);
  38.         System.out.println("HasBattlePass: " + hasBattlePass);
  39.         System.out.println("Weapons' List: ");
  40.         if(weapons.size() > 0) {
  41.             for(int i=0; i<weapons.size(); i++) {
  42.                 System.out.println("Slot " + (i+1) + ": " + weapons.get(i).color + " " + weapons.get(i).name);
  43.             }
  44.         }
  45.         else {
  46.             System.out.println("No weapons yet.");
  47.         }
  48.     }
  49.    
  50.    
  51.    
  52.     public static void main(String[] args) {
  53.         // TODO Auto-generated method stub
  54.         Weapon a = new Weapon("Tactical Shotgun", "blue");
  55.         Weapon b = new Weapon();
  56.         Weapon c = new Weapon("Sniper", "mple");
  57.         ArrayList <Weapon> weapons = new ArrayList <Weapon> ();
  58.         weapons.add(a);
  59.         weapons.add(b);
  60.         weapons.add(c);
  61.         System.out.println();
  62.         Player player1 = new Player();
  63.         player1.showStatus();
  64.         System.out.println();
  65.         Player player2 = new Player("Thomas", "Flamingo King", "Red Cape", 40, true, weapons);
  66.         player2.showStatus();
  67.         System.out.println();
  68.     }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement