It looks like you're new here. If you want to get involved, click one of these buttons!
import java.util.*;
public class TextGame
{
public String playGame()
{
int morality = 0;
boolean extraGuards;
boolean securityCode;
boolean virusActive;
Scanner input = new Scanner(System.in);
System.out.println("You are an 18 year old hacker, established in your own right. " +
"\nOne day, while exploring the internet, you find something strange and unexpected. " +
"\nA mysterious company seems to have set up a malicious program that will allow them to " +
"\nrob people of their identities! You have located both the program and a secret meeting " +
"\nbetween some evil executives. Do you SPY on them or EXPLORE the program?");
String response1 = input.nextLine();
response1 = response1.trim();
if( response1.equalsIgnoreCase(("spy")) )
{
morality = morality + 1;
securityCode = true;
return "The conversation between the men is extremely interesting. " +
"\nYou learn of many of their plans, and a strange security code for their systems. " +
"\nHowever, while eavesdropping, you are discovered by hackers of the company " +
"\nthemselves! They invade your house before you know it and kidnap you, knocking " +
"\nyou unconscious...";
}
else if( response1.equalsIgnoreCase(("explore")) )
{
morality = morality - 1;
securityCode = false;
return "The program is an intricate one, and you admire the genius behind its power. " +
"\nLearning about the details of the program, you discover a meeting place between " +
"\nsome employees of the company. Curious about their intentions, you decide to go " +
"\nto this location. However, upon reaching there, you are discovered by agents of the company " +
"\nand attacked by chloroform! You fall into a deep sleep...";
}
else
{
return "In your lack of a good decision, your lingering unprotected presence draws " +
"\nthe attention of the company's agents. Before you know what's happened, they've " +
"\ninvaded your home and taken you. You are knocked unconscious in the fray...";
}
System.out.println("You awaken in a dank prison cell, apparently controlled electronically. " +
"\nYou look around outside the cell, seeing a few guards wander about occasionally, " +
"\nwaiting for orders about what to do with you. You know you have to escape this situation. " +
"\nDo you HACK the door's lock, or TRICK a guard into coming over?");
if( securityCode == true)
{
return "Or do you use the CODE that you overheard in the conversation?";
}
else
{
}
String response2 = input.nextLine();
response2 = response2.trim();
if( response2.equalsIgnoreCase("hack") )
{
extraGuards = true;
return "You wait until there are no guards passing, and then you jump forth to hack " +
"\nthe keypad controlling the lock. After some fenagling, you manage to get the door " +
"\nto unlock and you make your escape! However, because this took so long, you are noticed " +
"\nby the guards and they begin to make pursuit of you. You run back home.";
}
else if( response2.equalsIgnoreCase("trick") )
{
morality = morality - 1;
extraGuards = false;
return "You wait until there is a particularly stupid guard passing by, and then " +
"\nyou feign injury to draw him closer. Once he leans in close enough, you slam him " +
"\nagainst the bars of the cell, knocking him out. Reaching into his pockets, you manage " +
"\nto find his keycard and unlock the cell. Without him to report back, the other guards " +
"\ndon't come quickly enough, and you make a clean escape to your house.";
}
else if( response2.equalsIgnoreCase("code") && securityCode == true)
{
morality = morality + 1;
extraGuards = false;
return "You wait until no guards are passing by, and then randomly try punching the code " +
"\nyou saw in the conversation between the executives. To your amazement, the cell actually " +
"\nunlocks! Quickly escaping, you get out of the building before any guards notice you and " +
"\nrun back to your home.";
}
else
{
extraGuards = true;
return "Your efforts to escape fail, and you wait for the guards to come retrieve you. " +
"\nAs they remove you from your cell, you make a last ditch effort to break free of their hold. " +
"\nYou barely manage, and make a run for it, escaping the building. However, as you make it " +
"\nto your house, the guards are hot on your trail and will arrive pretty soon.";
}
System.out.println("You are safely at your house and computer, and you know these people " +
"\nmust be stopped. You know you only have two effective options in front of you: " +
"\n1. Call the POLICE, because you are unable to solve this yourself, or " +
"\n2. Release your dangerous VIRUS, destroying the company's program at great risk." +
"\nWhich option do you take?");
String response3 = input.nextLine();
response3 = response3.trim();
if( response3.equalsIgnoreCase("police") )
{
virusActive = false;
morality = morality + 1;
return "Making the safe choice, you call the police. The evil company is shut down " +
"\nand their program put to an end. No one is affected by their evil intentions.";
}
else if( response3.equalsIgnoreCase("virus") )
{
virusActive = true;
morality = morality - 1;
return "Eschewing safety and morals, you release the dangerous virus to the company's " +
"\nservers, causing a complete shut down of their activities. Their evil program is " +
"\nlost to them, and all the commotion on their servers gets them discovered, and they " +
"\nare severely punished as being the source of a dangerous virus.";
}
else
{
morality = 0;
virusActive = false;
return "Your foolish inaction results in next to nothing happening. The program " +
"\nis nearly put into action, but just barely stopped by the police before massive " +
"\nharm occurs. You remain unknown, and anything you did before is forgotten.";
}
if( extraGuards == true)
{
return "However, after you complete these actions, the guards of the company " +
"\nfinally locate you, and you get involved in a vicious fight. " +
"\nYou manage to win, but only barely, and in the process are greatly injured, " +
"\nbecoming unable to use your legs. You remain in a wheelchair for the rest " +
"of your life.";
}
else
{
}
if( morality == 3)
{
return "You are a great hero, becoming well known for your valiant effort in stopping " +
"\nthis evil plan. As you grow holder, your computer skills are put to great use as a " +
"\ncyber-forensics specialist, solving numerous cases of this magnitude and greater.";
}
else if( morality == 2)
{
return "For your many valiant efforts, the police award you a medal for your excellent " +
"\ncitizenship and overall service to society.";
}
else if( morality == 1)
{
return "You are happy with your good deed, but not overly proud. Realizing the danger " +
"\nof evil in computing, you give up your hacking ways and become a relatively upstanding " +
"citizen.";
}
else if( morality == -1)
{
return "With your multiple actions throughout this event, you become an infamous hacker, " +
"\nand no one ever messes with you again, leaving you to your own devices.";
}
else if( morality == -2)
{
return "The police discover your various improper actions and choices, and try and " +
"\nbring you to justice. However, you are never caught for your these crimes, and remain " +
"\nrelatively hidden from the world, plotting who knows what.";
}
else if( morality == -3)
{
return "Your knowledge of the company's program allows you to begin your own evil empire, " +
"\nmaking plans not too unlike their old ones. With the knowledge of how you stopped them, " +
"\nyou manage to ensure that your plans will someday go off without a hitch.";
}
else
{
return "Your intentions strange and unknown, you vanish into obscurity, never to be found again.";
}
if (virusActive == true)
{
return "Despite everything else, however, the virus you unleashed wreaks havoc across " +
"\nthe internet, causing it to be unusable for many, many, many months. People lose " +
"\ninformation and business because of your actions, and it is a long time before the " +
"\nworld recovers from this outbreak. However, the virus is never traced back to you.";
}
else
{
}
}
}
TextGame.java:51: unreachable statement
System.out.println("You awaken in a dank prison cell, apparently controlled electronically. " +
^
TextGame.java:108: unreachable statement
System.out.println("You are safely at your house and computer, and you know these people " +
^
TextGame.java:144: unreachable statement
if( extraGuards == true)
^
TextGame.java:203: unreachable statement
if (virusActive == true)
^
TextGame.java:215: missing return statement
}
^
5 errors
Comments
No seriously, I have no idea how to help you. That might as well be cobal.
I definitely just realized what night it is, and I now know that everyone who probably could help me is at NYAF/NYCC/Other crazy shit this weekend. Awesome.
So, the start with, change every single return statement into a System.out.println instead. And since all of your return statements will be gone, change the function to a public void.
import java.util.*;
public class TextGame
{
int morality = 0;
boolean extraGuards;
boolean securityCode;
boolean virusActive;
Scanner input = new Scanner(System.in);
public void playGame()
{
actI();
actII();
actIII();
conclusionI();
conclusionII();
conclusionIII();
}
public String actI()
{
System.out.println("You are an 18 year old hacker, established in your own right. " +
"\nOne day, while exploring the internet, you find something strange and unexpected. " +
"\nA mysterious company seems to have set up a malicious program that will allow them to " +
"\nrob people of their identities! You have located both the program and a secret meeting " +
"\nbetween some evil executives. Do you SPY on them or EXPLORE the program?");
String response1 = input.nextLine();
response1 = response1.trim();
if( response1.equalsIgnoreCase(("spy")) )
{
morality = morality + 1;
securityCode = true;
return "The conversation between the men is extremely interesting. " +
"\nYou learn of many of their plans, and a strange security code for their systems. " +
"\nHowever, while eavesdropping, you are discovered by hackers of the company " +
"\nthemselves! They invade your house before you know it and kidnap you, knocking " +
"\nyou unconscious...";
}
else if( response1.equalsIgnoreCase(("explore")) )
{
morality = morality - 1;
securityCode = false;
return "The program is an intricate one, and you admire the genius behind its power. " +
"\nLearning about the details of the program, you discover a meeting place between " +
"\nsome employees of the company. Curious about their intentions, you decide to go " +
"\nto this location. However, upon reaching there, you are discovered by agents of the company " +
"\nand attacked by chloroform! You fall into a deep sleep...";
}
else
{
return "In your lack of a good decision, your lingering unprotected presence draws " +
"\nthe attention of the company's agents. Before you know what's happened, they've " +
"\ninvaded your home and taken you. You are knocked unconscious in the fray...";
}
}
public String actII()
{
System.out.println("You awaken in a dank prison cell, apparently controlled electronically. " +
"\nYou look around outside the cell, seeing a few guards wander about occasionally, " +
"\nwaiting for orders about what to do with you. You know you have to escape this situation. " +
"\nDo you HACK the door's lock, or TRICK a guard into coming over, ");
if( securityCode = true)
{
return "or do you use the CODE you found to try and escape?";
}
String response2 = input.nextLine();
response2 = response2.trim();
if( response2.equalsIgnoreCase("hack") )
{
extraGuards = true;
return "You wait until there are no guards passing, and then you jump forth to hack " +
"\nthe keypad controlling the lock. After some fenagling, you manage to get the door " +
"\nto unlock and you make your escape! However, because this took so long, you are noticed " +
"\nby the guards and they begin to make pursuit of you. You run back home.";
}
else if( response2.equalsIgnoreCase("trick") )
{
morality = morality - 1;
extraGuards = false;
return "You wait until there is a particularly stupid guard passing by, and then " +
"\nyou feign injury to draw him closer. Once he leans in close enough, you slam him " +
"\nagainst the bars of the cell, knocking him out. Reaching into his pockets, you manage " +
"\nto find his keycard and unlock the cell. Without him to report back, the other guards " +
"\ndon't come quickly enough, and you make a clean escape to your house.";
}
else if( response2.equalsIgnoreCase("code") && securityCode == true)
{
morality = morality + 1;
extraGuards = false;
return "You wait until no guards are passing by, and then randomly try punching the code " +
"\nyou saw in the conversation between the executives. To your amazement, the cell actually " +
"\nunlocks! Quickly escaping, you get out of the building before any guards notice you and " +
"\nrun back to your home.";
}
else
{
extraGuards = true;
return "Your efforts to escape fail, and you wait for the guards to come retrieve you. " +
"\nAs they remove you from your cell, you make a last ditch effort to break free of their hold. " +
"\nYou barely manage, and make a run for it, escaping the building. However, as you make it " +
"\nto your house, the guards are hot on your trail and will arrive pretty soon.";
}
}
public String actIII()
{
System.out.println("You are safely at your house and computer, and you know these people " +
"\nmust be stopped. You know you only have two effective options in front of you: " +
"\n1. Call the POLICE, because you are unable to solve this yourself, or " +
"\n2. Release your dangerous VIRUS, destroying the company's program at great risk." +
"\nWhich option do you take?");
String response3 = input.nextLine();
response3 = response3.trim();
if( response3.equalsIgnoreCase("police") )
{
virusActive = false;
morality = morality + 1;
return "Making the safe choice, you call the police. The evil company is shut down " +
"\nand their program put to an end. No one is affected by their evil intentions.";
}
else if( response3.equalsIgnoreCase("virus") )
{
virusActive = true;
morality = morality - 1;
return "Eschewing safety and morals, you release the dangerous virus to the company's " +
"\nservers, causing a complete shut down of their activities. Their evil program is " +
"\nlost to them, and all the commotion on their servers gets them discovered, and they " +
"\nare severely punished as being the source of a dangerous virus.";
}
else
{
morality = 0;
virusActive = false;
return "Your foolish inaction results in next to nothing happening. The program " +
"\nis nearly put into action, but just barely stopped by the police before massive " +
"\nharm occurs. You remain unknown, and anything you did before is forgotten.";
}
}
public String conclusionI()
{
if( extraGuards == true)
{
return "However, after you complete these actions, the guards of the company " +
"\nfinally locate you, and you get involved in a vicious fight. " +
"\nYou manage to win, but only barely, and in the process are greatly injured, " +
"\nbecoming unable to use your legs. You remain in a wheelchair for the rest " +
"of your life.";
}
else
{
return "";
}
}
public String conclusionII()
{
if( morality == 3)
{
return "You are a great hero, becoming well known for your valiant effort in stopping " +
"\nthis evil plan. As you grow holder, your computer skills are put to great use as a " +
"\ncyber-forensics specialist, solving numerous cases of this magnitude and greater.";
}
else if( morality == 2)
{
return "For your many valiant efforts, the police award you a medal for your excellent " +
"\ncitizenship and overall service to society.";
}
else if( morality == 1)
{
return "You are happy with your good deed, but not overly proud. Realizing the danger " +
"\nof evil in computing, you give up your hacking ways and become a relatively upstanding " +
"citizen.";
}
else if( morality == -1)
{
return "With your multiple actions throughout this event, you become an infamous hacker, " +
"\nand no one ever messes with you again, leaving you to your own devices.";
}
else if( morality == -2)
{
return "The police discover your various improper actions and choices, and try and " +
"\nbring you to justice. However, you are never caught for your these crimes, and remain " +
"\nrelatively hidden from the world, plotting who knows what.";
}
else if( morality == -3)
{
return "Your knowledge of the company's program allows you to begin your own evil empire, " +
"\nmaking plans not too unlike their old ones. With the knowledge of how you stopped them, " +
"\nyou manage to ensure that your plans will someday go off without a hitch.";
}
else
{
return "Your intentions strange and unknown, you vanish into obscurity, never to be found again.";
}
}
public String conclusionIII()
{
if (virusActive == true)
{
return "Despite everything else, however, the virus you unleashed wreaks havoc across " +
"\nthe internet, causing it to be unusable for many, many, many months. People lose " +
"\ninformation and business because of your actions, and it is a long time before the " +
"\nworld recovers from this outbreak. However, the virus is never traced back to you.";
}
else
{
return "";
}
}
}
Also, when one of your acts returns, the string of text it returns is passed up to wherever it was called from (in this case playGame). However, since playGame does nothing with this string, you never see it anywhere. Presumably you want to print these strings out in an interactive console, and so as theknoxinator said you should be using System.out.println.
import java.applet.*;
import java.awt.*;
public class Bug {
int x;
int y;
int xPosition = x;
int yPosition = y;
public Bug paint(Graphics g) {
g.drawOval(x, y, 15, 15);
g.drawOval(x-3, y+3, 4, 4);
g.drawOval(x-6, y+6, 4, 4);
}
}
public class BugApplet extends Applet {
private Bug someBug;
public void init() {
someBug = new Bug(34, 88);
}
public void paint(Graphics g) {
someBug.paint(g);
}
}
I get a "cannot find symbol" for Bug on line 8. Fuck if I know.
public Bug(int xPosition, int yPosition)
Constructors are run every time you create an object. The parameters work just like they do in methods.{
x = xPosition;
y = yPosition;
}
http://netbeans.org/
I still use vim when working with smaller amounts of code, but when I'm dealing with something involving hundreds of source files, I fire up something else. For Java, my choice is NetBeans. For C/C++ on Linux, I like QtCreator (although Visual Studio on Windows and Xcode on Mac also are pretty nice).
I have seen and used tools like cscope and ctags successfully with vim, but it's still a pain to get them working just right as opposed an editor/IDE that has said functionality built-in.