/** * The Heads Up Display. This is used for the user to see their current status in the game. This * HUD will display the number of bullets currently, how many lives the player has, the current * level, and how many turns of invincibility the player has. */ public void setHUD() { HUD.removeAll(); JLabel HUDLives = new JLabel("Lives: " + engine.getLife()); JLabel HUDBullets = new JLabel("Bullets: " + engine.getBullets()); JLabel HUDInv = new JLabel("Turns of invincibility: " + engine.getTurns()); JLabel HUDLevel = new JLabel("Level: " + engine.getLevels()); HUD.add(HUDLives, BorderLayout.PAGE_START); HUD.add(HUDBullets, BorderLayout.SOUTH); HUD.add(HUDInv, BorderLayout.CENTER); HUD.add(HUDLevel, BorderLayout.EAST); HUD.revalidate(); }
/** * If this type contains any children by default, add them. * * @param engine * @param ob */ public void createChildren(Engine engine, OObject ob) { ObjectFactory factory = engine.getObjectFactory(); factory.createChild(ob, UIKeyword.WINDOW_TITLE, Keyword.UNTYPED, "Untitled Window"); factory.createChild(ob, UIKeyword.BOUNDS, UIKeyword.BOUNDS, ""); factory.createChild(ob, UIKeyword.CONTENTS, Keyword.UNTYPED, ""); factory.createChild(ob, Keyword.EVENT_ON_OPEN, Keyword.SCRIPT, ""); factory.createChild(ob, Keyword.EVENT_ON_CLOSE, Keyword.SCRIPT, ""); }
public void actionPerformed(ActionEvent e) { setVisible(false); if (e.getSource() == ok) { engine.setPoolOptions( resolution.getValue(), false /*gouraud.getState() gouraud.isEnabled()*/); setVisible(false); } }
/** * This type is runnable, so run it already! Running a window opens it. * * @param engine * @param ob * @return */ public void run(Engine engine, OObject ob) { // OWindow.openWindow( this.getTitle( ob ) ); String title = this.getTitle(ob); OWindow w = new OWindow(engine, title); w.initFromSpec(ob); WindowManager.getInstance().addWindow(title, w); w.setVisible(true); engine.getEventManager().windowOpened(ob); }
public TwoMedia(String title, String world) { super(title, world, true, false); engine = new Engine(this); engine.start(); }
public void stop() { engine.play(); engine.exit(); }
public void start() { engine = new Engine(this); engine.start(); }
/** * Paints the display of the world, the 9 X 9 grid, which is determined by the locations of each * enemy, room, power up, and player. * * @param number - the input that the user specifies. Used for the look method. */ public void paint(int number) { panel.removeAll(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { int counter = 0; if (i == engine.getPlayerRow() && j == engine.getPlayerCol()) { counter++; } for (int r = 0; r < 9; r++) { if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) { counter++; } } for (int p = 0; p < 3; p++) { if (engine.isPowerupActivated(p)) { if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p)) { counter++; } } } for (int e = 0; e < 6; e++) { if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && engine.isEnemyAlive(e)) { counter++; } } if (counter > 0) { int limit = 0; for (int r = 0; r < 9; r++) { if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) { panel.add(engine.getRoomPic(r)); } } if (i == engine.getPlayerRow() && j == engine.getPlayerCol() && limit < 1) { panel.add(engine.getSpyPicture()); limit++; } for (int e = 0; e < 6; e++) { if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && limit < 1 && engine.isEnemyAlive(e)) { JLabel imgEnemy = engine.getEnemyPic(e); panel.add(imgEnemy); engine.hideEnemy(e); limit++; } } for (int p = 0; p < 3; p++) { if (engine.isPowerupActivated(p)) { if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p) && limit < 1) { panel.add(engine.getPowerUpPic(p)); engine.hidePowerup(p); limit++; } } } } else { if (number == 1) { if (i == engine.getPlayerRow() - 1 && j == engine.getPlayerCol()) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else if (i == engine.getPlayerRow() - 2 && j == engine.getPlayerCol()) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else // fog { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg")); panel.add(imgEmpty); } } else if (number == 2) { if (i == engine.getPlayerRow() + 1 && j == engine.getPlayerCol()) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else if (i == engine.getPlayerRow() + 2 && j == engine.getPlayerCol()) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else // fog { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg")); panel.add(imgEmpty); } } else if (number == 3) { if (i == engine.getPlayerRow() && j == engine.getPlayerCol() - 1) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else if (i == engine.getPlayerRow() && j == engine.getPlayerCol() - 2) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else // fog { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg")); panel.add(imgEmpty); } } else if (number == 4) { if (i == engine.getPlayerRow() && j == engine.getPlayerCol() + 1) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else if (i == engine.getPlayerRow() && j == engine.getPlayerCol() + 2) { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } else // fog { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg")); panel.add(imgEmpty); } } else // fog { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/FogAlpha.jpg")); panel.add(imgEmpty); } } panel.validate(); } } }
/** * Key events used in this method allow for the interaction of the game within it. This is done by * adding in a key listener into the JFrame in order to take input from the user. */ @Override public void keyPressed(KeyEvent e) { boolean looking = false; // TODO Auto-generated method stub if (e.getKeyCode() == KeyEvent.VK_C) { JOptionPane.showMessageDialog(f, "DEBUG MODE ACTIVATED (CHEATER MODE ACTIVE MANG.)"); engine.setReveal(true); looking = true; debugPaint(0); } if (e.getKeyCode() == KeyEvent.VK_H) { JOptionPane.showMessageDialog(f, "DEBUG MODE DEACTIVATED (HIDE SHAME MODE ACTIVE.)"); engine.setReveal(false); looking = true; paint(0); } if (e.getKeyCode() == KeyEvent.VK_RIGHT) { engine.movePlayer(4); if (engine.checkForPlayer()) { JOptionPane.showMessageDialog(f, "YOU WERE STABBED!!"); if (engine.getLife() == 0) { JOptionPane.showMessageDialog(f, "0 LIVES! GAME OVER!!"); JOptionPane.showMessageDialog( f, "LEVELS CLEARED: " + (engine.getLevels() - 1) + "\nBULLETS ON DEATH: " + engine.getBullets() + "\nENEMIES KILLED: " + engine.getEnemiesKilled() + "\nPOWERUPS OBTAINED: " + engine.getPowerupsObtained(), "Score", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } engine.moveEnemy(); if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { engine.movePlayer(3); if (engine.checkForPlayer()) { JOptionPane.showMessageDialog(f, "YOU WERE STABBED!!"); if (engine.getLife() == 0) { JOptionPane.showMessageDialog(f, "0 LIVES! GAME OVER!!"); JOptionPane.showMessageDialog( f, "LEVELS CLEARED: " + (engine.getLevels() - 1) + "\nBULLETS ON DEATH: " + engine.getBullets() + "\nENEMIES KILLED: " + engine.getEnemiesKilled() + "\nPOWERUPS OBTAINED: " + engine.getPowerupsObtained(), "Score", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } engine.moveEnemy(); if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { engine.movePlayer(2); if (engine.checkForPlayer()) { JOptionPane.showMessageDialog(f, "YOU WERE STABBED!!"); if (engine.getLife() == 0) { JOptionPane.showMessageDialog(f, "0 LIVES! GAME OVER!!"); JOptionPane.showMessageDialog( f, "LEVELS CLEARED: " + (engine.getLevels() - 1) + "\nBULLETS ON DEATH: " + engine.getBullets() + "\nENEMIES KILLED: " + engine.getEnemiesKilled() + "\nPOWERUPS OBTAINED: " + engine.getPowerupsObtained(), "Score", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } engine.moveEnemy(); if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } else if (e.getKeyCode() == KeyEvent.VK_UP) { engine.movePlayer(1); if (engine.checkForPlayer()) { JOptionPane.showMessageDialog(f, "YOU WERE STABBED!!"); if (engine.getLife() == 0) { JOptionPane.showMessageDialog(f, "0 LIVES! GAME OVER!!"); JOptionPane.showMessageDialog( f, "LEVELS CLEARED: " + (engine.getLevels() - 1) + "\nBULLETS ON DEATH: " + engine.getBullets() + "\nENEMIES KILLED: " + engine.getEnemiesKilled() + "\nPOWERUPS OBTAINED: " + engine.getPowerupsObtained(), "Score", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } engine.moveEnemy(); if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } if (e.getKeyCode() == KeyEvent.VK_4) { if (engine.look(4)) { JOptionPane.showMessageDialog(f, "NINJA SPOTTED", "WARNING", JOptionPane.ERROR_MESSAGE); } if (engine.isDebugging()) { debugPaint(0); } else { paint(4); } looking = true; } else if (e.getKeyCode() == KeyEvent.VK_3) { if (engine.look(3)) { JOptionPane.showMessageDialog(f, "NINJA SPOTTED", "WARNING", JOptionPane.ERROR_MESSAGE); } if (engine.isDebugging()) { debugPaint(0); } else { paint(3); } looking = true; } else if (e.getKeyCode() == KeyEvent.VK_2) { if (engine.look(2)) { JOptionPane.showMessageDialog(f, "NINJA SPOTTED", "WARNING", JOptionPane.ERROR_MESSAGE); } if (engine.isDebugging()) { debugPaint(0); } else { paint(2); } looking = true; } else if (e.getKeyCode() == KeyEvent.VK_1) { if (engine.look(1)) { JOptionPane.showMessageDialog(f, "NINJA SPOTTED", "WARNING", JOptionPane.ERROR_MESSAGE); } if (engine.isDebugging()) { debugPaint(0); } else { paint(1); } looking = true; } if (e.getKeyCode() == KeyEvent.VK_W) { looking = true; if (engine.getBullets() != 0) { JOptionPane.showMessageDialog(f, "BAM!!"); JOptionPane.showMessageDialog(f, engine.shoot(1) + " NINJAS WERE REKT!!"); } else { JOptionPane.showMessageDialog(f, "NO AMMUNITION!! ", "Warning", JOptionPane.ERROR_MESSAGE); } } else if (e.getKeyCode() == KeyEvent.VK_D) { looking = true; if (engine.getBullets() != 0) { JOptionPane.showMessageDialog(f, "BAM!!"); JOptionPane.showMessageDialog(f, engine.shoot(4) + " NINJAS WERE REKT!!"); } else { JOptionPane.showMessageDialog(f, "NO AMMUNITION!! ", "Warning", JOptionPane.ERROR_MESSAGE); } } else if (e.getKeyCode() == KeyEvent.VK_A) { looking = true; if (engine.getBullets() != 0) { JOptionPane.showMessageDialog(f, "BAM!!"); JOptionPane.showMessageDialog(f, engine.shoot(3) + " NINJAS WERE REKT!!"); } else { JOptionPane.showMessageDialog(f, "NO AMMUNITION!! ", "Warning", JOptionPane.ERROR_MESSAGE); } } else if (e.getKeyCode() == KeyEvent.VK_S) { looking = true; if (engine.getBullets() != 0) { JOptionPane.showMessageDialog(f, "BAM!!"); JOptionPane.showMessageDialog(f, engine.shoot(2) + " NINJAS WERE REKT!!"); } else { JOptionPane.showMessageDialog(f, "NO AMMUNITION!! ", "Warning", JOptionPane.ERROR_MESSAGE); } } if (engine.getCheckRoom()) { if (engine.getDocFound()) { JOptionPane.showMessageDialog(f, "DOCUMENT FOUND."); JOptionPane.showMessageDialog(f, "LEVEL CLEARED!!"); engine.levelUp(); if (engine.isDebugging()) { debugPaint(0); } else { paint(0); } } else { JOptionPane.showMessageDialog(f, "NOTHING FOUND IN THIS ROOM!!"); engine.getCheckRoom(false); } } setHUD(); }
/** * Prints the debug version of the display, which so to speak is the mode used to debug the * system. This will reveal all enemies and power ups. * * @param number - the number that the player inputs in order to look around. */ public void debugPaint(int number) { panel.removeAll(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { int counter = 0; if (i == engine.getPlayerRow() && j == engine.getPlayerCol()) { counter++; } for (int r = 0; r < 9; r++) { if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) { counter++; } } for (int p = 0; p < 3; p++) { if (engine.isPowerupActivated(p)) { if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p)) { counter++; } } } for (int e = 0; e < 6; e++) { if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && engine.isEnemyAlive(e)) { counter++; } } if (counter > 0) { int limit = 0; for (int r = 0; r < 9; r++) { if (i == engine.getRoomRow(r) && j == engine.getRoomCol(r)) { engine.revealRoom(r); panel.add(engine.getRoomPic(r)); } } if (i == engine.getPlayerRow() && j == engine.getPlayerCol() && limit < 1) { panel.add(engine.getSpyPicture()); limit++; } for (int e = 0; e < 6; e++) { if (i == engine.getEnemyRow(e) && j == engine.getEnemyCol(e) && limit < 1 && engine.isEnemyAlive(e)) { engine.revealEnemy(e); JLabel imgEnemy = engine.getEnemyPic(e); panel.add(imgEnemy); limit++; } } for (int p = 0; p < 3; p++) { if (engine.isPowerupActivated(p)) { if (i == engine.getPowerupRow(p) && j == engine.getPowerupCol(p) && limit < 1) { engine.revealPowerup(p); panel.add(engine.getPowerUpPic(p)); limit++; } } } } else { JLabel imgEmpty = new JLabel(new ImageIcon("GameImgs/Image-1.jpg")); panel.add(imgEmpty); } panel.revalidate(); } } }