Introduction: HackBerry RPG

This project is a text based role playing game that is set in Hackberry Lab. This project was made in four hours, as it was my project for my senior exit hackathon. The reason I made a text based game is that throughout college, I found that coding is something that I am passionate about. I am also passionate about games. This was a way to combine the two into a project.

Required Tools and Materials



Java experience

Pictures of characters

Step 1: Story

In order to make this game, the first thing that had to be made was a story. A game with no story is not a game worth playing at all. Since it is my senior year of college, I decided to make the objective of the game finishing the final project. Since this was the case, I decided that instead of a health bar, there will be a grade bar. After this, I got permission from people who are constantly in the lab to use their images and then decided where to place everyone.

Step 2: Initial Code

To start out the code, I had to place a bunch of booleans as those would correspond to items that the player collected as well as track the progress. Then I made an initial method that I called run in order to start the game. This method explains the rules and lets a user decide on their name. In order to keep track of their grade, i made a setup function that updates every time they enter a place. After that, I started the game. I made separate methods for each person and place and started connecting them to each other while printing out the story.

Step 3: Image Code

The code to show the images was a little tricky since java does not like to show pictures in the console. Instead, I had to print them off to the side. To do this, I had to import the pictures and then run them through a method called display Image. The pictures that I used were all in black and white in order to emulate the old text based feel.

Step 4: Finishing Touches

For the finishing touches, I went through the program to make sure that everything connected the way it was supposed to. When I got to this step, time was starting to run out but overall, I was happy with the way it turned out. This was a fun project and I would make something like this again.

Step 5: Code

import java.util.*;

import java.awt.FlowLayout; import java.awt.image.BufferedImage; import; import; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class HackberryRPG { Scanner sysin = new Scanner(; String name; int grade; boolean arduino; boolean permissionLA; boolean exactoK; boolean exacto; boolean foamCore; boolean threeDFile; boolean LED; boolean resistor; boolean wood; boolean print; boolean A1; boolean A2; boolean A3; boolean A4; boolean h1; boolean h2; boolean h3; boolean p; String location; Random rand; boolean m; public void run() { m = false; rand = new Random(); p = false; grade = 100; A1 = false; A2 = false; A3 = false; A4 = false; arduino = false; permissionLA = false; exacto = false; foamCore = false; threeDFile = false; LED = false; resistor = false; wood = false; print = false; h1 = true; h2 = false; h3 = false; System.out.println("Welcome to Finishing Your Project, a text based RPG set in Hackberry Lab."); System.out.println("Instructions: Words in all Capital letters represent items or places that can be interacted with."); System.out.println("Please type all items exactly as they appear."); System.out.println("Some words may not be used in the same place they are shown but remember them for later."); System.out.println("The goal is to finish your Final project before time runs out or your grade drops too low"); System.out.println("Please enter your name to start"); String n = sysin.nextLine(); if(n.equals("zane")|| n.equals("Zane")|| n.equals("ZANE")) { System.out.println("That name is too powerful to be chosen"); System.out.println(""); run(); } else name = n; parkingLot(); } private void parkingLot() { Setup("Parking Lot"); System.out.println("You park at the Hackberry Parking Lot and get out of your vehicle."); System.out.println("Once you get out of your car, you notice that something is off."); System.out.println("Instead of the normal lot full of cars, yours is the only one there."); System.out.println("Their appears to be a strange man standing before the doors to the lab"); System.out.println("Upon closer inspection, you reconize this person as ALEX Brice."); String l = sysin.nextLine(); if(l.equals("ALEX")) { Alex(); } else {parkingLot();} // TODO Auto-generated method stub } private void RPS() { Setup("Alex"); System.out.println("3 ... 2 ... 1 ..."); String l = sysin.nextLine(); if(l.equals("PAPER")) { System.out.println("ROCK"); System.out.println("You got me. The exacto knife is yours. No turning back now."); exacto = true; inside(); } else { grade = grade-8; System.out.println("Better Luck next time. Want to Try again? YES or NO"); String m = sysin.nextLine(); if(m.equals("YES")) { RPS(); } else if (m.equals("NO")) { Alex(); } else {inside();} } }

private void Alex() { Setup("Alex"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture1.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(!exactoK) { System.out.println("As you walk up, Alex turns to look at you. You can see that he is holding what looks to be a giant sword"); System.out.println("When you get closer, he says Turn back now. It is dangerous in their tonight."); System.out.println("If you wish to continue INSIDE, you may but I would reccomend turning BACK"); } else if(exactoK && !exacto){System.out.println("Have you decided to turn back?");} else { System.out.println("No turning back now"); inside(); } String l = sysin.nextLine(); // TODO Auto-generated method stub if(l.equals("INSIDE")) { inside(); } else if (l.equals("BACK")) { parkingLot(); } else if (l.equals("EXACTO") && !exacto && exactoK) { System.out.println("You want my sword? Then you will have to battle me for it."); System.out.println(".."); System.out.println(".."); System.out.println(".."); System.out.println(".."); System.out.println("in a game of ROCK, PAPER, SCISSORS"); RPS(); }else if(l.equals("EXACTO") && exacto) { System.out.println("'You already have it. Now there is no turning back' he says as he pushes you inside "); inside(); } else {Alex();} }

private void inside() { Setup("Interior"); System.out.println("As you step into the lab, something seems off. The lab is strangly quiet."); System.out.println("The first thing that you notice is ANDREW standing near the enterance."); String l = sysin.nextLine(); if(l.equals("ANDREW")) { Andrew(); } else if (l.equals("OUTSIDE")) { Alex(); } else if (l.equals("HINT")) { hint(); } else if(l.equals("MACHINES") && !threeDFile) { System.out.println("The way is blocked"); inside(); } else if (l.equals("MACHINES")) { machines(); } else if(l.equals("WOODSHOP") && !wood) { grade = grade - 4; inside(); } else if (l.equals("WOODSHOP")) { woodshop(); } else if (l.equals("SHOP")) { shop(); } else {inside();} }

private void woodshop() { Setup("Woodshop"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture8.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("When you enter the woodshop a figure is waiting for you"); System.out.println("So you finally arrived. I have been waiting for you for hours and hours and ..."); System.out.println("*passes out from exhaustion*"); System.out.println("since he is no longer an obstacle, you continue on with your task to CUT the wood"); String l = sysin.nextLine(); if(l.equals("CUT")) { System.out.println("You cut the wood. You now have evertthing Andrew told you to get."); A2 = false; A3 = true; inside(); } else {woodshop();} }

private void machines() { Setup("Machines"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture7.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("As you approach the machines, you see a strange figure"); System.out.println("He appears to be guarding the machines"); System.out.println("What do you want he asks"); String l = sysin.nextLine(); if(l.equals("PRINT") && !permissionLA) { System.out.println("You need PERMISSION to do anything here"); System.out.println("Go get some then return"); inside(); } else if (l.equals("PRINT") ) { System.out.println("I see you have a permission slip"); System.out.println("Very well. I will allow you to print what you need"); System.out.println("Aftert several hours of waiting, the print is finally done and you leave the machines"); print = true; inside(); } else {machines();} }

private void Andrew() { Setup("Interior"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture3.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(!A1 && !A2 && !A3) { System.out.println("You're finally here. Zane has moved up the deadline for the Final projects."); System.out.println("You need to finish fast. I can help but you have to do exactly as I say."); System.out.println("The first thing you need is some FOAM CORE. I think the SHOP might have some"); System.out.println("Get it quick and hurry back"); } else if(A1) { System.out.println("Good you have the foam core. The next thing I need is some ELECTRONICS."); System.out.println("Specifically an aruino. some leds and a resistor. "); System.out.println("Check the SHOP to see if they have any"); h1 = false; h2 = true; } else if(A2) { System.out.println("Good you got the electronics. Now I need some wood CUT in order to make the case."); System.out.println("Then we can complete the project"); System.out.println("Go to the WOODSHOP and get it done."); h2 = false; h3 = true; wood = true; inside(); } else if (A3) { System.out.println("Good. We have everything. Give me a few minutes and we will have a project"); System.out.println("*A few minutes later*"); System.out.println("It is finished. Go get Mariah to check it over."); System.out.println("She is in the BACK past Slackberry."); p = true; } String l = sysin.nextLine(); if(l.equals("SHOP")) { shop(); } else if (l.equals("HINT")) { hint(); } else if (l.equals("PERMISSION")) { System.out.println("So the shopkeeper wanted something printed. Thats a pain"); System.out.println("Here. Take this slip. It will allow you to PRINT. Now go get me that stuff"); permissionLA = true; inside(); } else if(l.equals("BACK")) { back(); } else {Andrew();} }

private void back() { int r = rand.nextInt(100); Setup("Back Room"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture9.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("To get to MARIAH, you have to pass through Slackberry where Nick is sleeping. "); System.out.println("Be careful not to wake him up"); String l = sysin.nextLine(); if(l.equals("MARIAH")) { if(r > 30) { System.out.println("You make it to Mariah safely"); mariah(); } else { try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture10.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Nick wakes up and talks to you for so long you miss the deadline"); Death(); } } else {back();} }

private void mariah() { int r = rand.nextInt(100); Setup("Mariah"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture11.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("You make it to Mariah. You can Have her CHECK your work, go to ZANE or you can go BACK"); String l = sysin.nextLine(); if(l.equals("CHECK") && p) { System.out.println("That looks good. You may show ZANE"); m = true; mariah(); } else if (l.equals("ZANE") && !m) { try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture12.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("You see a blinding lightand stumble back"); } else if (l.equals("ZANE")) { zane(); } else if (l.equals("BACK")) { if(r > 30) { System.out.println("You make it to back safely"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture9.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } mariah(); } else { try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture10.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Nick wakes up and talks to you for so long you miss the deadline"); Death(); } } else {mariah();} // TODO Auto-generated method stub }

private void zane() { Setup("Zane"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture13.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("You finally make it to Zane and hand him your final prject"); System.out.println("He looks it over with an unreadable look on his face. "); System.out.println("Not a bad job. Could have put a bit more effort into it but not bad"); System.out.println("Final grade:" + grade); }

private void hint() { Setup("interior"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture5.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Welcome to the shrine of knowledge. But be warned, every HINT has a price."); System.out.println("If you wish to LEAVE you may. Many cannot handle the truth"); String l = sysin.nextLine(); // TODO Auto-generated method stub if(l.equals("HINT") && h1) { System.out.println("If you are looking for something to cut with, I saw a someone with a sword OUTSIDE"); System.out.println("Now off you go"); grade = grade - 8; inside(); } else if(l.equals("HINT") && h2) { System.out.print("If you are seeking PERMISSION, ask the one who started the quest."); System.out.println("Now off you go"); grade = grade - 8; inside(); } else if (l.equals("HINT") && h3) { System.out.println("You're in the endgame now. It is all up to chance"); grade = grade - 2; inside(); } else {hint();}


private void shop() { Setup("Shop"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture4.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Welcome to my shop. Is there anything that I can help you find?"); System.out.println("If you want to leave, simply go BACK"); String l = sysin.nextLine(); if(l.equals("FOAM CORE") && !exacto) { System.out.println("Ah. I have exactly what you need. However, it is much to big and bulky for one person to carry."); System.out.println("If you can find something to cut it with, such as an EXACTO knife I will gladly let you have it."); System.out.println("I am sure you can find someting out in the lab"); System.out.println("If you are stuck, you can get a HINT from someone in the main area but be warned, the hints are not free");

exactoK = true; inside(); } else if (l.equals("FOAM CORE") && exacto) { System.out.println("Good. You got the knife. Now lets get you that foam core."); foamCore = true; A1 = true; inside(); } else if (l.equals("BACK")) { inside(); } else if (l.equals("ELECTRONICS")) { System.out.println("I do not carry the items that you desire. I would check in the INNER SHOP"); System.out.println("He might have what you want"); shop(); } else if (l.equals("INNER SHOP")) { iShop(); } else {shop();} }

private void iShop() { Setup("Inner Shop"); try { DisplayImage("C:\\Users\\bboga\\eclipse-workspace\\Hackathon\\src\\Picture6.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Welcome to my shop. I supply specialty items that the OUTER SHOP does not."); System.out.println("What do you need?"); String l = sysin.nextLine(); if(l.equals("ELECTRONICS") && !print) { System.out.println("I have the items you need but they are not free. Tell you what, you do me a favor and they are yours"); System.out.println("I need something 3-D printed but I cannot leave the shop. here is the PRINT file"); System.out.println("Now go. You can get to the MACHINES from the main area"); threeDFile = true; inside(); } else if (l.equals("ELECTRONICS") && print) { System.out.println("You actually got the print. I am suprised. I guess I should honor my end of the bargin."); arduino = true; A1 = false; A2 = true; inside(); } else {iShop();} // TODO Auto-generated method stub }

public void Setup(String locations) { if (grade < 70) { Death(); } location = locations; System.out.println(""); System.out.println(name); System.out.println("Grade: " + grade); System.out.println(location); return; }

private void Death() { System.out.println("YOU FAIL"); new HackberryRPG().run(); }

public void DisplayImage(String im) throws IOException { BufferedImage File(im)); ImageIcon icon=new ImageIcon(img); JFrame frame=new JFrame(); frame.setLayout(new FlowLayout()); frame.setSize(260, 350); JLabel lbl=new JLabel(); lbl.setIcon(icon); frame.add(lbl); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }

public static void main(String[] args) { new HackberryRPG().run(); } }