Notes
Notes - notes.io |
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class javaGoblins {
JFrame javaGoblins;
Container con;
JPanel titlePanel, startButtonPanel, mainTextPanel, choiceButtonPanel, playerPanel;
JLabel titleLabel, hpLabel, hpLabelNumber, weaponLabel, weaponLabelName;
JButton startButton, choice1, choice2, choice3, choice4;
JTextArea mainTextArea;
Font titleFont = new Font("Times New Roman" , Font.PLAIN, 60);
Font normalFont = new Font("Times New Roman" , Font.PLAIN, 18);
int playerHP;
String weapon, position;
titleScreenHandler tsHandler = new titleScreenHandler();
choiceHandler choiceHandler= new choiceHandler();
public static void main(String args[]) {
new javaGoblins();
}
public javaGoblins() {
javaGoblins = new JFrame(); //Window properties
javaGoblins.setSize (800, 600);
javaGoblins.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
javaGoblins.getContentPane().setBackground(Color.black);
javaGoblins.setLayout(null);
javaGoblins.setVisible(true);
con = javaGoblins.getContentPane();
titlePanel = new JPanel();
titlePanel.setBounds(100, 100, 600, 150);
titlePanel.setBackground(Color.black);
titleLabel = new JLabel("JAVA GOBLINS!!!");
titleLabel.setForeground(Color.white);
titleLabel.setFont(titleFont);
startButtonPanel = new JPanel();
startButtonPanel.setBounds(300, 400, 200, 100);
startButtonPanel.setBackground(Color.black);
startButton = new JButton("START");
startButton.setBackground(Color.black);
startButton.setForeground(Color.white);
startButton.setFont(normalFont);
startButton.addActionListener(tsHandler); //Calls tsHandler by acknowledging homescreen
startButton.setFocusPainted(false);
titlePanel.add(titleLabel);
startButtonPanel.add(startButton);
con.add(titlePanel);
con.add(startButtonPanel);
javaGoblins.setVisible(true);
}
public void createGameScreen() {
titlePanel.setVisible(false);
startButtonPanel.setVisible(false);
mainTextPanel = new JPanel();
mainTextPanel.setBounds(100, 100, 600, 250);
mainTextPanel.setBackground(Color.black);
con.add(mainTextPanel);
mainTextArea = new JTextArea("[Insert game]");
mainTextArea.setBounds(100, 100, 600, 250);
mainTextArea.setBackground(Color.black);
mainTextArea.setForeground(Color.white);
mainTextArea.setFont(normalFont);
mainTextArea.setLineWrap(true);
mainTextPanel.add(mainTextArea);
choiceButtonPanel = new JPanel();
choiceButtonPanel.setBounds(250, 350, 300, 150);
choiceButtonPanel.setBackground(Color.black);
choiceButtonPanel.setLayout(new GridLayout(4,1));
con.add(choiceButtonPanel);
choice1 = new JButton(); //Choice 1
choice1.setBackground(Color.black);
choice1.setForeground(Color.white);
choice1.setFont(normalFont);
choiceButtonPanel.add(choice1);
choice1.setFocusPainted(false);
choice1.addActionListener(choiceHandler);
choice1.setActionCommand("c1");
choice2 = new JButton(); //Choice 2
choice2.setBackground(Color.black);
choice2.setForeground(Color.white);
choice2.setFont(normalFont);
choiceButtonPanel.add(choice2);
choice2.setFocusPainted(false);
choice2.addActionListener(choiceHandler);
choice2.setActionCommand("c2");
choice3 = new JButton(); //Choice 3
choice3.setBackground(Color.black);
choice3.setForeground(Color.white);
choice3.setFont(normalFont);
choiceButtonPanel.add(choice3);
choice3.setFocusPainted(false);
choice3.addActionListener(choiceHandler);
choice3.setActionCommand("c3");
choice4 = new JButton(); //Choice 4
choice4.setBackground(Color.black);
choice4.setForeground(Color.white);
choice4.setFont(normalFont);
choiceButtonPanel.add(choice4);
choice4.setFocusPainted(false);
choice4.addActionListener(choiceHandler);
choice4.setActionCommand("c4");
playerPanel = new JPanel();
playerPanel.setBounds(100, 15, 600, 50);
playerPanel.setBackground(Color.black);
playerPanel.setLayout(new GridLayout(1,4));
con.add(playerPanel);
hpLabel= new JLabel("Health:");
hpLabel.setFont(normalFont);
hpLabel.setForeground(Color.white);
playerPanel.add(hpLabel);
hpLabelNumber = new JLabel();
hpLabelNumber.setFont(normalFont);
hpLabelNumber.setForeground(Color.white);
playerPanel.add(hpLabelNumber);
weaponLabel= new JLabel("Weapon:");
weaponLabel.setFont(normalFont);
weaponLabel.setForeground(Color.white);
playerPanel.add(weaponLabel);
weaponLabelName= new JLabel();
weaponLabelName.setFont(normalFont);
weaponLabelName.setForeground(Color.white);
playerPanel.add(weaponLabelName);
playerSetup();
}
public void playerSetup() {
playerHP = 15;
weapon = "None";
weaponLabelName.setText(weapon);
hpLabelNumber.setText("" + playerHP);
dungeonEntrance();
} //Public variables deciding what Level says what
public void dungeonEntrance() {
position = "dungeonEntrance";
mainTextArea.setText("You wake up at your desk in the office, knocking your prized coffee over.n Except. Hang on. You don't actually have any coffee... and this isn't even your office! It's a dungeon! This must be the work of a Java Goblin!nOr Karen from HR. Stupid Karen.nn Now what?");
choice1.setText("Look around");
choice2.setText("Arm yourself");
choice3.setText("Email Karen from HR");
choice4.setText("Proceed into the Dungeon");
}
public void lookAround() {
position = "lookAround";
mainTextArea.setText("You can barely see past the darkness within this dungeon,nbut smell the feint scent of coffee and hear distant cackling.nIt seems to come from deep to the Eastern half of the dungeon...");
choice1.setText(">");
choice2.setText("");
choice3.setText("");
choice4.setText("");
}
public void armYourself() {
position = "armYourself";
mainTextArea.setText("You dig around in your desk, looking for a weapon in the darkness...nand stab yourself with a pencil and lose 3 Health. nnYou arm yourself with that pencil!");
playerHP = playerHP -3;
hpLabelNumber.setText(""+playerHP);
choice1.setText("Freggin' Ow.");
choice2.setText("");
choice3.setText("");
choice4.setText("");
}
public void emailKaren() {
position = "emailKaren";
mainTextArea.setText("You send a strongly worded email to Karen from HR. Stupid Karen.nn You gain 3 health!");
playerHP = playerHP +3;
hpLabelNumber.setText(""+playerHP);
choice1.setText("That'll show her...");
choice2.setText("");
choice3.setText("");
choice4.setText("");
}
public void crossRoads() {
position = "crossRoads";
mainTextArea.setText("You progress further into the Dungeon, and meet a Crossroads.nnGoing South will take you to your desk...");
choice1.setText("Go North");
choice2.setText("Go East");
choice3.setText("Go West");
choice4.setText("Go South");
}
public void north() {
position = "north";
mainTextArea.setText("You come to a large room full of ");
choice1.setText("Go North");
choice2.setText("Go East");
choice3.setText("Go West");
choice4.setText("Go South");
}
public void East() {
position = "East";
}
public void West() {
position = "West";
}
public class titleScreenHandler implements ActionListener{
public void actionPerformed(ActionEvent event) {
createGameScreen();
}
}
public class choiceHandler implements ActionListener{
public void actionPerformed(ActionEvent event) {
String yourChoice= event.getActionCommand();
switch(position) { //Factors deciding what button takes you where using Switch Case
case "dungeonEntrance":
switch(yourChoice) {
case "c1": lookAround(); break;
case "c2": armYourself(); break;
case "c3": emailKaren(); break;
case "c4": crossRoads(); break;
}
break;
case "lookAround":
switch(yourChoice) {
case "c1": dungeonEntrance(); break;
}
break;
case "armYourself":
switch(yourChoice) {
case "c1": dungeonEntrance(); break;
}
case "emailKaren":
switch(yourChoice) {
case "c1": dungeonEntrance(); break;
}
case "crossRoads":
switch(yourChoice) {
case "c1": north(); break;
case "c2": break;
case "c3": break;
case "c4": dungeonEntrance();
}
}
}
}
}
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team