import java.awt.Image; import java.awt.Toolkit; import javax.swing.ImageIcon; import javax.swing.JOptionPane; /** * This is the Driver Class containing * the main method that runs the game * * @author Monique Shotande * @version November 2, 2017 * Lab 11 */ public class Driver { /** * main method * * @param args - command line arguments (not used) * @throws InterruptedException Thrown when a thread is * waiting, sleeping, or otherwise occupied, and the thread is * interrupted, either before or during the activity. */ public static void main(String[] args) throws InterruptedException { // Load the Marvel-DC image Image mdc = Toolkit.getDefaultToolkit().getImage("resources/mdc.png"); // Create the array of button choices String[] buttons = { "Batman", "Superman", "Spiderman", "Captain America" }; // Set-up for the switch statement Superhero superhero = null; // Switch on the button the user selects switch (JOptionPane.showOptionDialog(null, new ImageIcon(mdc), "Which hero would you like to play as?", JOptionPane.DEFAULT_OPTION, JOptionPane.DEFAULT_OPTION, null, buttons, buttons[0])) { case 0: // First button superhero = new Superhero("Batman", "dc", 15, 0); break; case 1: // Second button superhero = new Superhero("Superman", "dc", 30, 1); break; case 2: // Third button superhero = new Superhero("Spiderman", "marvel", 40, 2); break; case 3: // Fourth choice superhero = new Superhero("CaptainAmerica", "marvel", 50, 3); break; case JOptionPane.CLOSED_OPTION: System.exit(0); default: System.exit(0); } // Base Game frame speed which the game will run at. int gameSpeed = 1000; // Width of screen in pixels int width = 800; // Height of screen in pixels int height = 600; // Initialize the game frame GameFrame gameFrame = new GameFrame(superhero, width, height); // Initialize the length and difficulty of the game int gameLength = superhero.getFightLength(); int frameReduction = superhero.getDifficultyLevel() * 20; // game moves for gameLength frames or until game over for (int frameNum = 0; frameNum < gameLength; frameNum++) { // move the villain randomly gameFrame.getPanel().getGame().moveVillainRandom(frameNum, 1); // Repaint gameFrame gameFrame.repaint(); // Check if the player has caught the villain yet if (gameFrame.getPanel().getGame().playerHasWon()) { JOptionPane.showMessageDialog(null, "Congratulations, you caught the bad guy!"); break; } // is the player dead? if (gameFrame.getPanel().getGame().playerIsDead(frameNum)) { // Notify the player that the villain has fled JOptionPane.showMessageDialog(null, "Oh no! The bad guy got away!", "GAME OVER!", 0, new ImageIcon(mdc)); // Quit break; } // set the game speed. Thread.sleep(gameSpeed - frameReduction); } // Quit System.exit(0); } }