Space Pirates
//player's credit balance
private int credits;
//player's current ship
private Ship ship;
//player's current location
private Location location;
//player's current crew
private ArrayList<CrewMember> crew;
//player's inventory
private ArrayList<Item> inventory;
//player's enemies
private ArrayList<EnemyShip> enemies;
public SpacePirates() {
this.credits = 0;
this.ship = new Ship(null);
this.location = new Location(null);
this.crew = new ArrayList<>();
this.inventory = new ArrayList<>();
this.enemies = new ArrayList<>();
}
//method responsible for game loop and processing game turns
public void startGame() {
printTitle();
Scanner scanner = new Scanner(System.in);
//game loop
while(true) {
//print available actions and prompt player for input
printActions();
String action = scanner.nextLine();
//handle input
switch(action) {
case "1":
exploreNewLocation();
break;
case "2":
upgradeShip();
break;
case "3":
hireCrewMembers();
break;
case "4":
engageEnemies();
break;
case "5":
tradeWithPlanets();
break;
case "6":
sellInBlackMarket();
break;
case "7":
quitGame();
break;
default:
System.out.println("Invalid action!");
}
}
}
//method responsible for game intro
private void printTitle() {
System.out.println("=============================");
System.out.println("Welcome to Space Pirates!");
System.out.println("Join a spacefaring crew and raid the stars for valuable resources and galactic booty!\n");
}
//method responsible for printing available actions
private void printActions() {
System.out.println("What would you like to do?");
System.out.println("1. Explore new location");
System.out.println("2. Upgrade ship");
System.out.println("3. Hire crew members");
System.out.println("4. Engage enemies");
System.out.println("5. Trade with planets");
System.out.println("6. Sell in black market");
System.out.println("7. Quit game");
}
//method responsible for exploring new locations
private void exploreNewLocation() {
//generate and print new location
this.location = new Location(null);
System.out.println("You have discovered the following location:");
System.out.println(this.location);
//roll for events
this.location.rollForEvents();
}
//method responsible for upgrading ship
private void upgradeShip() {
//TODO
}
//method responsible for hiring crew members
private void hireCrewMembers() {
//TODO
}
//method responsible for engaging enemies
private void engageEnemies() {
//TODO
}
//method responsible for trading with planets
private void tradeWithPlanets() {
//TODO
}
//method responsible for selling in the black market
private void sellInBlackMarket() {
//TODO
}
//method responsible for quitting game
private void quitGame() {
System.out.println("Thanks for playing Space Pirates!");
System.exit(0);
}Last updated