import java.text.*; import java.util.*; /**This class contains the main method used to run the game. */ public class Game { //CONSTANTS public static final int DEFAULT_INVENTORY_SIZE = 5; public static final int MAX_INVENTORY_SIZE = 15; public static final int MAX_CARGO_AMT = 10; // how many of each public static final double MAX_CARGO_PRICE = 100.0; public static final double DEFAULT_INITIAL_FUEL = 1000.0; public static final double DEFAULT_FUEL_BURN_RATE = 5.0; public static final double DEFAULT_INITIAL_MONEY = 1000.0; public static final int UNIVERSE_HEIGHT = 12; public static final int UNIVERSE_WIDTH = 10; public static final double UNIVERSE_DENSITY = 0.1; public static final double MAX_COST_FACTOR = 3.0; // random number generator public static Random rand = new Random(); // the universe for the game private static Universe universe; // a general purpose number format public static NumberFormat style = NumberFormat.getNumberInstance(); /** Gets the universe for the game * @return the universe for the game */ public static Universe getUniverse() { return universe; } public static void advanceTurn() { //rotate(); } // application entry point public static void main (String args[]) { // sets the maximum decimal places for numbers to 2 style.setMaximumFractionDigits(2); style.setMinimumFractionDigits(2); // creates a new universe and populates it universe = new Universe (UNIVERSE_HEIGHT, UNIVERSE_WIDTH, UNIVERSE_DENSITY); universe.populate(); // creates a new vehicle and places it at a random location in the universe Vehicle vehicle = new Vehicle("InterGallactic Thunderbird", null, new Inventory(), DEFAULT_INITIAL_FUEL, "gozorkas", DEFAULT_FUEL_BURN_RATE, DEFAULT_INITIAL_MONEY, 0); vehicle.setLocation (universe.getRandomLocation()); // print introductory banner System.out.println("Welcome to CS101 Space Trader v4!"); System.out.println(); System.out.println("Your " + vehicle.getVehicleType() + " is starting at " + vehicle.getLocation() + "."); System.out.println("You burn fuel at the rate of " + Game.style.format(vehicle.getFuelBurnRate()) + " " + vehicle.getFuelUnits() + " per million kilometers."); // begins playing the game vehicle.takeTurn(); // trip done! Print out summary. System.out.println(); System.out.println("Congratulations, Space Trader! "); System.out.println("Your " + vehicle.getVehicleType() + " traveled " + Game.style.format(vehicle.getTotalDistanceTraveled()) + " million kilometers."); System.out.println("You still have " + Game.style.format(vehicle.getFuel()) + " " + vehicle.getFuelUnits() + " of fuel available."); System.out.println("Take the rest of the day off, Space Trader -- you deserve it!"); System.out.println(); } }