Text Attack!

Instead of


if(input.equals("a") || input.equals("A"))

You could just use the “equalsIgnoreCase(string)” method like so:


if(input.equalsIgnoreCase("a"))

Same thing for every other input where casing doesn’t matter. :slight_smile:

WHY IS EVERYONE LOOKING AT MY SOURCE CODE?!!

To improve your code and possibly learn something they didn’t know?

edit: A general statement on why someone may be decompiling the code for any game.

I haven’t looked at your source code; I simply saw Vladiedoo’s post and suggested a way to improve the code he posted. :slight_smile:

Oh. ;D

From this game?

the “possibly learn something they didn’t know?” was more a general on why people may be decompiling the code.

Ah. ok you are absolutely correct then.

New update!!
UPDATE ALPHA 0.1.1!

Slightly offtopic but to solve your Main Class crisis :slight_smile:

The easiest way to create a runnable JAR in Eclipse:

Right click your project and click Export:

Choose “JAR file” and click Next:

Choose “Export all output folders for checked projects” and choose the output file, then hit Next:

OPTIONAL If you want to automate building your JAR file and save your settings, you can save them in a “jardesc” file. It’s best to create a “jar.jardesc” in your project’s folder, then hit Next:

Click “Browse” next to the “Main Class” field and choose the class that contains your main method:

Hit ok and finish:

Your jardesc file should be created and your JAR file should be wherever you saved it:

To run your “jardesc” file in the future, double click it, click “Finish”, and click “Yes” for all “Overwrite?” prompts.

I already do that (except without the jardesc ;D)

You have a huge workspace :stuck_out_tongue: I usually have different work spaces for different things XD

HAS ANYONE TRIED THE LATEST UPDATE!!!

And if none of the input will be case sensitive, you can just do input = input.tolowerCase() when you read the input and then you can just do input.equals("a") and not have to worry about testing either case or ignoring the case in every comparison.

You can replace lines 120-172, 52 lines of code, with this–>

if (playerHealth <= 0) {
	System.out.println("You were defeated by the goblin! Press enter to end the game!");
	input = scanner.nextLine();
	stop = true;
} else {
	System.out.println("Your HP: " + playerHealth);
}

Do not stop formatting your code!

Played it.
Seems like a good concept. Needs to be expanded more.
You should add graphics instead of just text in a console. It would improve the game massively.

But then its not much of a text adventures is it? ):<

Ascii graphics :slight_smile:

I like text games and I am working on one that primarily uses text input (but may have some graphics). I noticed something about your random number generation that I thought I would point out. Here is your code for generating the random number you use:


	public int randomNumber(){
	 keyen = 1 + (int) (Math.random() * 4.0);
	    return 0;}

Where keyen is a field within class. The problem is that you are setting keyen inside of the function. What if you want a second random number in your game, for instance to determine whether an attack break’s the player’s weapon? A better way is to write it like this:


public int randomNumber() {
   return 1 + (int) (Math.random() *4.0);
}

and then call it like this:


keyen = randomNumber();

Now your randomNumber function generates a value that can be assigned to any variable, not k=just keyen. Now you can also do something like keyen2 = randomNumber() and it won’t affect keyen. So this is better there’s still a problem. What if sometimes you want to get a random number between 1 and 4 and sometimes between 1 and 6? With how you have things right now you would need a new function. Instead, make the maximum value a parameter.


public int randomNumber(int maxValue) {
   return 1 + (int)(Math.random()*(double)maxValue);
}

// later on call it like this
keyen = randomNumber(4);

Now you can have keyen2 = randomNumber(6);

The game title already made me think… but (at least in the eclipse console (didn’t try it out in the konsole yet)) “\r” and “\b” didn’t work :confused:

Thinking of JCurses now, but it is supposed to be a lib similar to what AWT gives you, but in ascii. This means “Frame”, “Window”, “Panel”, “CheckBox” and things like that… and “Button”…

A bit too high level, isn’t it? Or is JCurses also capable of doing something low-level stuff, like colored text and replacing text?