This is the alternative version of my point and click adventure game.
I added a battle sequence but it didn't fit well with the point and click game mechanics so I discarded the idea.
I made a video about it:
and received a request for the code so here it is:
Class structure
GameManager
package Main;
import java.net.URL;
import Event.Event01;
import Event.Event02;
import Event.Event03;
public class GameManager{
// MAIN CLASS
ActionHandler aHandler = new ActionHandler(this); // Instantiate before UI class otherwise action won't work
public UI ui = new UI(this);
public Player player = new Player(this);
public SceneChanger sChanger = new SceneChanger(this);
Music music = new Music();
SE se = new SE();
public BattleManager bm = new BattleManager(this);
// EVENT CLASS
public Event01 ev1 = new Event01(this);
public Event02 ev2 = new Event02(this);
public Event03 ev3 = new Event03(this);
// SOUND
public URL fieldMusic = getClass().getClassLoader().getResource("audio//bensound-acousticbreeze voldown2.wav");
public URL fieldMusic2 = getClass().getClassLoader().getResource("audio//bensound-ofeliasdream.wav");
public URL battleMusic = getClass().getClassLoader().getResource("audio//bensound-epic-down.wav");
public URL deathSound = getClass().getClassLoader().getResource("audio//darksoulsdeath.wav");
public URL hitSound = getClass().getClassLoader().getResource("audio//hit.wav");
public URL healSound = getClass().getClassLoader().getResource("audio//healSound.wav");
public URL guard01 = getClass().getClassLoader().getResource("audio//guard01.wav");
public URL guard02 = getClass().getClassLoader().getResource("audio//guard02.wav");
public URL guard03 = getClass().getClassLoader().getResource("audio//guard03.wav");
public URL guard03b = getClass().getClassLoader().getResource("audio//guard03b.wav");
public URL guard04 = getClass().getClassLoader().getResource("audio//guard04.wav");
public URL guard05 = getClass().getClassLoader().getResource("audio//guard05.wav");
public URL guard06 = getClass().getClassLoader().getResource("audio//guard06.wav");
public URL awesome = getClass().getClassLoader().getResource("audio//awesome.wav");
public URL chestopen = getClass().getClassLoader().getResource("audio//dqchestopen.wav");
public URL enter = getClass().getClassLoader().getResource("audio//dqstairs.wav");
URL currentMusic;
public static void main(String[] args) {
new GameManager();
}
public GameManager() {
// SET MUSIC
currentMusic = fieldMusic; // Do this before showScreen1 otherwise you get NullPointer to stop the current audio
playMusic(currentMusic);
// SET SCREEN
player.setPlayerDefaultStatus();
sChanger.showScene1();
ui.window.setVisible(true);
}
public void playSE(URL url){
se.setFile(url);
se.play(url);
}
public void playMusic(URL url) {
music.setFile(url);
music.play(url);
music.loop(url);
}
public void stopMusic(URL url) {
music.stop(url);
}
}
UI
package Main;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class UI {
// MAIN UI
JFrame window;
public JTextArea messageText;
public JPanel bgPanel[] = new JPanel[20];
JLabel bgLabel[] = new JLabel[20];
public JButton choiceB1,choiceB2;
// PLAYER UI
JPanel lifePanel;
JLabel life[] = new JLabel[6];
JPanel inventoryPanel;
public JLabel sword;
public JLabel lantern;
public JLabel shield;
// GAME OVER UI
public JLabel titleLabel;
public JButton restartButton;
// CLASS
GameManager gm;
public UI(GameManager gm) {
this.gm = gm;
createMainField();
createPlayerField();
createGameOverField();
generateScreen();
}
public void createMainField() {
window = new JFrame("Awesome Quest III");
window.setSize(800,600);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setBackground(Color.black);
window.setLayout(null);
messageText = new JTextArea();
messageText.setBounds(50,410,700,150);
messageText.setBackground(Color.black);
messageText.setForeground(Color.white);
messageText.setEditable(false);
messageText.setLineWrap(true);
messageText.setWrapStyleWord(true);
messageText.setFont(new Font("Times New Roman", Font.PLAIN, 26));
window.add(messageText);
choiceB1 = new JButton("Add to your wishlist");
choiceB1.setBounds(190,320,200,50);
choiceB1.setBackground(new Color(39,67,89));
choiceB1.setForeground(new Color(97,195,240));
choiceB1.setFocusPainted(false);
choiceB1.setFont(new Font("Arial", Font.PLAIN, 17));
choiceB1.setVisible(false);
window.add(choiceB1);
choiceB2 = new JButton("No way");
choiceB2.setBounds(400,320,200,50);
choiceB2.setBackground(new Color(39,67,89));
choiceB2.setForeground(new Color(97,195,240));
choiceB2.setFocusPainted(false);
choiceB2.setFont(new Font("Arial", Font.PLAIN, 17));
choiceB2.addActionListener(gm.aHandler);
choiceB2.setActionCommand("noway");
choiceB2.setVisible(false);
window.add(choiceB2);
}
public void createBackgroundImage(int num, String bgFileName) {
bgPanel[num] = new JPanel();
bgPanel[num].setBounds(50,50,700,350);
bgPanel[num].setBackground(Color.black);
bgPanel[num].setLayout(null);
bgPanel[num].setVisible(false); // So panel 2 or later panels doesn't show up at the beginning
window.add(bgPanel[num]);
bgLabel[num] = new JLabel();
bgLabel[num].setBounds(0,0,700,350);
ImageIcon bgIcon = new ImageIcon(getClass().getClassLoader().getResource(bgFileName));
Image image = bgIcon.getImage().getScaledInstance(700, 350, Image.SCALE_DEFAULT); // Adjust the size to the label
bgIcon = new ImageIcon(image);
bgLabel[num].setIcon(bgIcon);
// bgPanel[num].add(bgLabel[num]); DON'T ADD Background image to the panel yet!!!!
}
public void createObject(int bgNum, int objX, int objY, int objWidth, int objHeight, String objFileName,
String choice1Name, String choice2Name, String choice3Name, String choice1Command, String choice2Command, String choice3Command) {
// CREATE POP MENU
JPopupMenu popMenu = new JPopupMenu();
// CREATE POP MENU ITEMS
JMenuItem menuItem[] = new JMenuItem[4]; // Use [1], [2], [3]
menuItem[1] = new JMenuItem(choice1Name);
menuItem[1].addActionListener(gm.aHandler);
menuItem[1].setActionCommand(choice1Command);
popMenu.add(menuItem[1]);
menuItem[2] = new JMenuItem(choice2Name);
menuItem[2].addActionListener(gm.aHandler);
menuItem[2].setActionCommand(choice2Command);
popMenu.add(menuItem[2]);
menuItem[3] = new JMenuItem(choice3Name);
menuItem[3].addActionListener(gm.aHandler);
menuItem[3].setActionCommand(choice3Command);
popMenu.add(menuItem[3]);
// CREATE OBJECTS
JLabel objectLabel = new JLabel();
objectLabel.setBounds(objX,objY,objWidth,objHeight);
// objectLabel.setOpaque(true); // Use this when you want to check where the blank object is
// objectLabel.setBackground(Color.blue); // Use this when you want to check where the blank object is
ImageIcon objectIcon = new ImageIcon(getClass().getClassLoader().getResource(objFileName));
Image image = objectIcon.getImage().getScaledInstance(objWidth, objHeight, Image.SCALE_DEFAULT);
objectIcon = new ImageIcon(image);
objectLabel.setIcon(objectIcon);
objectLabel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
if(SwingUtilities.isRightMouseButton(e)){
popMenu.show(objectLabel, e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
});
bgPanel[bgNum].add(objectLabel);
}
public void createArrowButton(int bgNum, int x, int y, int width, int height, String arrowFileName, String command) {
ImageIcon arrowIcon = new ImageIcon(getClass().getClassLoader().getResource(arrowFileName));
Image image = arrowIcon.getImage().getScaledInstance(50, 50, Image.SCALE_DEFAULT);
arrowIcon = new ImageIcon(image);
JButton arrowButton = new JButton();
arrowButton.setBounds(x,y,width,height);
arrowButton.setBackground(Color.black);
arrowButton.setContentAreaFilled(false);
arrowButton.setIcon(arrowIcon);
arrowButton.setBorderPainted(false);
arrowButton.addActionListener(gm.aHandler);
arrowButton.setActionCommand(command);
arrowButton.setVisible(true);
bgPanel[bgNum].add(arrowButton);
}
public void createPlayerField() {
lifePanel = new JPanel();
lifePanel.setBounds(50,0,250,50);
lifePanel.setBackground(Color.black);
lifePanel.setLayout(new GridLayout(1,5));
window.add(lifePanel);
ImageIcon lifeICon = new ImageIcon(getClass().getClassLoader().getResource("image//pixelheart.png"));
Image image = lifeICon.getImage().getScaledInstance(35, 35, Image.SCALE_DEFAULT);
lifeICon = new ImageIcon(image);
int i =1;
while(i<6) {
life[i] = new JLabel();
life[i].setIcon(lifeICon);
lifePanel.add(life[i]);
i++;
}
inventoryPanel = new JPanel();
inventoryPanel.setBounds(650,0,100,50);
inventoryPanel.setBackground(Color.black);
inventoryPanel.setLayout(new GridLayout(1,3));
window.add(inventoryPanel);
// CREATE SWORD
sword = new JLabel();
ImageIcon swordIcon = new ImageIcon(getClass().getClassLoader().getResource("image//plain-dagger.png"));
image = swordIcon.getImage().getScaledInstance(35, 35, Image.SCALE_DEFAULT);
swordIcon = new ImageIcon(image);
sword.setIcon(swordIcon);
inventoryPanel.add(sword);
shield = new JLabel();
ImageIcon shieldIcon = new ImageIcon(getClass().getClassLoader().getResource("image//dragon-shield.png"));
image = shieldIcon.getImage().getScaledInstance(35, 35, Image.SCALE_DEFAULT);
shieldIcon = new ImageIcon(image);
shield.setIcon(shieldIcon);
inventoryPanel.add(shield);
lantern = new JLabel();
ImageIcon lanternIcon = new ImageIcon(getClass().getClassLoader().getResource("image//lanternflame.png"));
image = lanternIcon.getImage().getScaledInstance(35, 35, Image.SCALE_DEFAULT);
lanternIcon = new ImageIcon(image);
lantern.setIcon(lanternIcon);
inventoryPanel.add(lantern);
}
public void createGameOverField() {
titleLabel = new JLabel("",JLabel.CENTER);
titleLabel.setBounds(200,150,400,200);
titleLabel.setFont(new Font("Times New Roman",Font.PLAIN,70));
titleLabel.setForeground(Color.red);
titleLabel.setVisible(false);
window.add(titleLabel);
restartButton = new JButton("Click here to restart");
restartButton.setBounds(340,320,120,50);
restartButton.setBorder(null);
restartButton.setBackground(null);
restartButton.setForeground(Color.white);
restartButton.setFocusPainted(false);
restartButton.addActionListener(gm.aHandler);
restartButton.setActionCommand("restart");
restartButton.setVisible(false);
window.add(restartButton);
}
// SCREEN GENERATION
public void generateScreen() {
// SCREEN1
createBackgroundImage(1,"image//greenbg700x400.png"); // bgPanelNum, fileName
createObject(1,450,130,250,200,"image//hut01 200x200.png","Look","Talk","Rest","lookCabin","talkCabin","restCabin");
createObject(1,300,285,70,52,"image//chest01 x70.png","Look","Talk","Open","lookChest","talkChest","openChest");
createObject(1,70,180,136,150,"image//guard150.png","Look","Talk","Attack","lookGuard","talkGuard","attackGuard");
createArrowButton(1,0,170,50,50,"image//leftarrow50x50.png","goScreen2");
bgPanel[1].add(bgLabel[1]); // IMPORTANT! ADD background after objects otherwise it hides all the objects. ADD background image IN THE END!
// SCREEN2
createBackgroundImage(2,"image//cave700x400.jpg");
createObject(2,0,100,70,300,"image//blank100x100.png","Look","Talk","Enter","lookCave","talkCave","enterCave");
createObject(2,355,250,50,50,"image//blank100x100.png","Look","Talk","Search","lookRoot","talkRoot","searchRoot");
createArrowButton(2,650,170,50,50,"image//rightarrow50x50.png","goScreen1");
bgPanel[2].add(bgLabel[2]);
// SCREEN3
createBackgroundImage(3,"image//cave.png");
// createObject(3,250,80,270,250,"image//halloween-3973250_1280.png","Look","Talk","Enter","lookCave","talkCave","enterCave");
createObject(3,250,80,200,250,"image//werewolf 200x300.png","Look","Talk","Attack","lookMonster","talkMonster","attackMonster");
createArrowButton(3,650,170,50,50,"image//rightarrow50x50.png","goScreen2");
// createArrowButton(3,325,50,50,50,"uparrow50x50.png","goScreen1");
bgPanel[3].add(bgLabel[3]);
}
}
SceneChanger
package Main;
public class SceneChanger{
GameManager gm;
public SceneChanger(GameManager gm) {
this.gm = gm;
}
public void showScene1() {
gm.ui.bgPanel[1].setVisible(true);
gm.ui.bgPanel[2].setVisible(false);
gm.ui.messageText.setText("Let's defeat the Demon Lord and save the world!");
gm.stopMusic(gm.currentMusic);
gm.currentMusic = gm.fieldMusic;
gm.playMusic(gm.currentMusic);
}
public void showScene2() {
gm.ui.bgPanel[1].setVisible(false);
gm.ui.bgPanel[3].setVisible(false);
gm.ui.bgPanel[2].setVisible(true);
gm.ui.messageText.setText("");
gm.stopMusic(gm.currentMusic);
gm.currentMusic = gm.fieldMusic2;
gm.playMusic(gm.currentMusic);
gm.bm.resetMonsterLife();
}
public void showScene3() {
gm.ui.bgPanel[2].setVisible(false);
gm.ui.bgPanel[3].setVisible(true);
gm.stopMusic(gm.currentMusic);
if(gm.player.defeatWerewolf==false) {
gm.ui.messageText.setText("OMG the cave is inhabited by a werewolf!");
gm.currentMusic = gm.battleMusic;
gm.playMusic(gm.currentMusic);
}
else {
gm.ui.messageText.setText("");
}
// gm.ui.messageText.setText("You enter the cave. What is waiting for you inside...?\n\n"
// + "*** This is the end of the Demo. Thank you for playing! ***");
// gm.ui.choiceB1.setVisible(true);
// gm.ui.choiceB2.setVisible(true);
}
public void showGameOverScreen(int currentBgNum) {
gm.ui.bgPanel[currentBgNum].setVisible(false);
gm.ui.titleLabel.setVisible(true);
gm.ui.titleLabel.setText("YOU DIED");
gm.ui.restartButton.setVisible(true);
// gm.ui.choiceB1.setVisible(false);
// gm.ui.choiceB2.setVisible(false);
gm.stopMusic(gm.fieldMusic);
gm.playSE(gm.deathSound);
}
public void exitGameOverScreen() {
gm.ui.titleLabel.setVisible(false);
gm.ui.restartButton.setVisible(false);
gm.bm.resetMonsterLife();
gm.player.setPlayerDefaultStatus();
}
public void showEndScreen(int currentBgNum) {
gm.ui.bgPanel[currentBgNum].setVisible(false);
gm.ui.titleLabel.setVisible(true);
gm.ui.titleLabel.setText("Congratz!");
gm.ui.messageText.setText("You have completed the Awesome Quest III!\nThanks for playing!");
// gm.ui.restartButton.setVisible(true);
gm.stopMusic(gm.fieldMusic);
gm.playSE(gm.awesome);
}
}
ActionHandler
package Main;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ActionHandler implements ActionListener{
GameManager gm;
public ActionHandler(GameManager gm) {
this.gm = gm;
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("here?");
String yourChoice = e.getActionCommand();
switch(yourChoice) {
// Screen 1
case "lookCabin": gm.ev1.lookCabin();break;
case "restCabin": gm.ev1.restCabin();break;
case "talkCabin": gm.ev1.talkCabin();break;
case "lookChest": gm.ev1.lookChest();break;
case "openChest": gm.ev1.openChest();break;
case "talkChest": gm.ev1.talkChest();break;
case "lookGuard": gm.ev1.lookGuard();break;
case "attackGuard": gm.ev1.attackGuard();break;
case "talkGuard": gm.ev1.talkGuard();break;
// Screen 2
case "lookCave": gm.ev2.lookCave();break;
case "enterCave": gm.ev2.enterCave();break;
case "talkCave": gm.ev2.talkCave();break;
case "lookRoot": gm.ev2.lookRoot();break;
case "searchRoot": gm.ev2.searchRoot();break;
case "talkRoot": gm.ev2.talkRoot();break;
// Scene 3
// case "noway": gm.sChanger.showGameOverScreen(3); gm.ui.messageText.setText("What a fool...");break;
case "lookMonster": gm.ev3.lookMonster();break;
case "talkMonster": gm.ev3.talkMonster();break;
case "attackMonster": gm.ev3.attackMonster();break;
// Change Screen
case "goScreen1": gm.sChanger.showScene1();break;
case "goScreen2": gm.sChanger.showScene2();break;
// Others
case "restart": gm.sChanger.exitGameOverScreen(); gm.player.setPlayerDefaultStatus(); gm.sChanger.showScene1();break;
}
}
}
Player
package Main;
public class Player {
GameManager gm;
// PLAYER STATUS
public int playerMaxLife = 5;
public int playerLife = 3;
public int playerStrength = 3;
public int playerEndurance = 1;
public int playerAttack;
public int playerDefense;
public int hasSword;
public int hasShield;
public int hasLantern;
public int weaponPower;
public int shieldPower;
public boolean defeatWerewolf = false;
public Player(GameManager gm) {
this.gm = gm;
}
public void setPlayerDefaultStatus() {
playerMaxLife = 5;
playerLife=3;
playerStrength = 3;
playerEndurance = 1;
hasSword=0;
hasShield=0;
hasLantern=0;
weaponPower=0;
shieldPower=0;
defeatWerewolf = false;
updatePlayerStatus();
}
public void updatePlayerStatus() {
// REMOVE ALL LIFE FIRST
int i=1;
while(i<6) {
gm.ui.life[i].setVisible(false);
i++;
}
// RESET LIFE
int lifeCount = playerLife;
while(lifeCount!=0) {
gm.ui.life[lifeCount].setVisible(true);
lifeCount--;
}
playerAttack = playerStrength + weaponPower;
playerDefense = playerEndurance + shieldPower;
// CHECK PLAYER ITEMS
if(hasSword==0) {
gm.ui.sword.setVisible(false);
}
if(hasSword==1) {
gm.ui.sword.setVisible(true);
}
if(hasShield==0) {
gm.ui.shield.setVisible(false);
}
if(hasShield==1) {
gm.ui.shield.setVisible(true);
}
if(hasLantern==0) {
gm.ui.lantern.setVisible(false);
}
if(hasLantern==1) {
gm.ui.lantern.setVisible(true);
}
}
}
SE
package Main;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class SE {
Clip clip;
public void setFile(URL name)
{
try{
//File file = new File(name);
AudioInputStream sound = AudioSystem.getAudioInputStream(name);
clip = AudioSystem.getClip();
clip.open(sound);
}
catch(Exception e)
{
}
}
public void play(URL name)
{
clip.setFramePosition(0);
clip.start();
}
public void loop(URL name)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
public void stop(URL name)
{
clip.stop();
}
}
Music
package Main;
import java.net.URL;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class Music {
Clip clip;
public void setFile(URL name)
{
try{
AudioInputStream sound = AudioSystem.getAudioInputStream(name);
clip = AudioSystem.getClip();
clip.open(sound);
}
catch(Exception e)
{
}
}
public void play(URL name)
{
// fc.setValue(volume);
clip.setFramePosition(0);
clip.start();
}
public void loop(URL name)
{
clip.loop(Clip.LOOP_CONTINUOUSLY);
}
public void stop(URL name)
{
clip.stop();
clip.close();
}
}
BattleManager
package Main;
import java.util.Random;
import Monster.Monster;
import Monster.Werewolf;
public class BattleManager {
GameManager gm;
Monster monster;
Werewolf werewolf = new Werewolf();
Random randomDie = new Random();
public BattleManager(GameManager gm) {
this.gm = gm;
}
public void resetMonsterLife() {
// add all the monsters if needed
werewolf.monsterLife = werewolf.monsterMaxLife;
}
public void setMonster() {
monster = werewolf;
attack();
}
public void attack() {
int playerDamage = randomDie.nextInt(gm.player.playerAttack)- monster.monsterDefense;
if(playerDamage<0) {
playerDamage=0;
}
gm.ui.messageText.setText("");
gm.ui.messageText.append("You attack the " + monster.monsterName + " and give " + playerDamage + " damage!");
monster.monsterLife -= playerDamage;
if(monster.monsterLife<1) {
win();
}
else {
int monsterDamage = randomDie.nextInt(monster.monsterAttack)-gm.player.playerDefense;
if(monsterDamage<0) {
monsterDamage=0;
}
gm.player.playerLife -= monsterDamage;
gm.ui.messageText.append("\nThe " + monster.monsterName + " attacks you and give " + monsterDamage + " damage!");
if(gm.player.playerLife<1) {
gm.player.playerLife =0;
gm.player.updatePlayerStatus();
lose();
}
else {
gm.player.updatePlayerStatus();
}
}
gm.playSE(gm.hitSound);
}
public void win() {
gm.ui.messageText.append("\nYou have defeated the monster!");
if(monster==werewolf) {
gm.player.defeatWerewolf = true;
gm.stopMusic(gm.currentMusic);
}
else {
}
}
public void lose() {
gm.ui.messageText.append("\nYou died!!");
gm.sChanger.showGameOverScreen(3);
}
}
Event01
package Event;
import Main.GameManager;
public class Event01{
public GameManager gm;
public Event01(GameManager gm) {
this.gm = gm;
}
public void lookCabin() {
gm.ui.messageText.setText("This is your home.");
}
public void talkCabin() {
gm.ui.messageText.setText("Who are you talking to?");
}
public void restCabin() {
if(gm.player.defeatWerewolf==true) {
gm.sChanger.showEndScreen(1);
}
else {
if(gm.player.playerLife != gm.player.playerMaxLife) {
gm.ui.messageText.setText("You rest at the home.\n(Your LIFE has recovered)");
gm.player.playerLife++;
gm.player.updatePlayerStatus();
gm.playSE(gm.healSound);
}
else {
gm.ui.messageText.setText("Your LIFE is full.");
}
}
}
public void lookChest() {
gm.ui.messageText.setText("A chest is on the ground.");
}
public void talkChest() {
gm.ui.messageText.setText("You talk to the chest but it says nothing.");
}
public void openChest() {
gm.ui.messageText.setText("You open the chest and find a sword!");
gm.ui.sword.setVisible(true);
gm.player.hasSword=1;
gm.player.weaponPower=2;
gm.player.updatePlayerStatus();
gm.playSE(gm.chestopen);
}
public void lookGuard() {
gm.ui.messageText.setText("A guard is standing in front of you.");
}
public void talkGuard() {
if(gm.player.hasSword==0) {
gm.ui.messageText.setText("Guard: Don't go any further without a weapon! \nYou should check the chest over there.");
gm.playSE(gm.guard01);
}
else {
gm.ui.messageText.setText("Guard: Don't go any further without a weapon! \n...Oh never mind. It seems you already have it.");
gm.playSE(gm.guard06);
}
}
public void attackGuard() {
if(gm.player.hasShield==0) {
if(gm.player.hasSword==0) {
if(gm.player.playerLife!=1) {
gm.ui.messageText.setText("Guard: Hey, don't be stupid!\n(The guard hits you back and your life decreases by 1)");
gm.player.playerLife--;
// gm.player.updatePlayerStatus();
gm.playSE(gm.hitSound);
gm.playSE(gm.guard02);
}
else if(gm.player.playerLife==1) {
gm.ui.messageText.setText("Guard: What a fool...");
gm.player.playerLife--;
// gm.player.updatePlayerStatus();
gm.sChanger.showGameOverScreen(1);
// gm.playSE(gm.guard03);
}
}
else {
gm.ui.messageText.setText("Guard: Oh, shit!\n(You defeated the guard and got his shield!)");
gm.ui.shield.setVisible(true);
gm.player.hasShield=1;
gm.player.shieldPower=1;
// gm.player.updatePlayerStatus();
gm.playSE(gm.hitSound);
gm.playSE(gm.guard04);
}
gm.player.updatePlayerStatus();
}
else {
gm.ui.messageText.setText("Guard: Just leave me alone.");
gm.playSE(gm.guard05);
}
}
}
Event02
package Event;
import Main.GameManager;
public class Event02 {
public GameManager gm;
public Event02(GameManager gm) {
this.gm = gm;
}
public void lookCave() {
gm.ui.messageText.setText("It's a cave!");
}
public void talkCave() {
gm.ui.messageText.setText("You hear the echo of your voice.");
}
public void enterCave() {
if(gm.player.hasLantern==0) {
gm.ui.messageText.setText("It's too dark to enter.");
}
else {
gm.sChanger.showScene3();
// gm.playSE(gm.enter);
}
}
public void lookRoot() {
gm.ui.messageText.setText("There is something at the tree.");
}
public void talkRoot() {
gm.ui.messageText.setText("They say plants grow well if you talk to them but this tree doesn't look like it needs encouragement.");
}
public void searchRoot() {
gm.ui.messageText.setText("You find a lantern!");
gm.ui.lantern.setVisible(true);
gm.player.hasLantern=1;
gm.playSE(gm.chestopen);
}
}
Event03
package Event;
import Main.GameManager;
public class Event03 {
GameManager gm;
public Event03(GameManager gm) {
this.gm = gm;
}
public void lookMonster() {
if(gm.player.defeatWerewolf==true) {
gm.ui.messageText.setText("The monster is dead...");
}
else {
gm.ui.messageText.setText("It's a monster!");
}
}
public void talkMonster() {
if(gm.player.defeatWerewolf==true) {
gm.ui.messageText.setText("Monster: .......");
}
else {
gm.ui.messageText.setText("Monster: DIE YOU FOOL!");
}
}
public void attackMonster() {
if(gm.player.defeatWerewolf==true) {
gm.ui.messageText.setText("He is already dead...");
}
else {
gm.bm.setMonster();
}
}
}
Monster
package Monster;
public class Monster {
public String monsterName;
// public String status;
public int monsterMaxLife;
public int monsterLife;
public int monsterAttack;
public int monsterDefense;
}
Werewolf
package Monster;
public class Werewolf extends Monster{
public Werewolf() {
monsterName = "Werewolf";
// status = "alive";
monsterMaxLife = 5;
monsterLife = 5;
monsterAttack = 5; // 0-4
monsterDefense = 1;
}
}
No comments:
Post a Comment