# Thread: JAva 1 Simple Dungeon game need help or will fail...

1. Member
Join Date
Dec 2012
Posts
5
Rep Power
0

## JAva 1 Simple Dungeon game need help or will fail...

I am in Java 1 and with all the work I have I am begging for help writing a program
The player must take 10 steps to escape the dungeon. On each step, the player might encounter a monster. One third of the time, the player will encounter a gnome. One third of the time, the player will encounter a dragon. One third of the time, there will be no monster.
If there is a monster, the player can choose to fight or run away. If the player fights and wins, the player gets the monster's gold.
The player starts with 10 hit points. Each time the player is hit by a monster, the player loses hit points. If the player's hit points reach 0 before escaping the dungeon, the game is over and the player loses.
The player does 1 to 8 hit points of damage with each hit
Each gnome encountered starts with 3 hit points, has 1 to 5 gold gold, and does 1 to 2 hit points of damage each time it attacks..
Each dragon starts with 10 hit points, has 10 to 20 gold, and does 1 to 5 points of damage.

Each encounter with a monster consists of a series of turns. For each turn, the player can fight, or run away. If the player chooses to fight, damage is calculated for the monster. The monster retaliates and damage is calculated for the player. Then, the next turn starts and the player may choose to fight or run away again. If the player chooses to run away, they move one step closer to the dungeon exit without getting hurt, but without getting any gold.

When the player escapes, the program displays the total gold collected.

It's a pain in the butt and I know I'm only in Java 1 but I can't program for crap.

Any help at all will be much much appreciated

2. ## Re: JAva 1 Simple Dungeon game need help or will fail...

What questions do you have? What specifically do you need help with?

3. Member
Join Date
Dec 2012
Posts
5
Rep Power
0

## Re: JAva 1 Simple Dungeon game need help or will fail...

I don't even know how to start it, I made a bunch of variables for steps, health point, gold damage, etc. but I dont know what to start with the code

4. ## Re: JAva 1 Simple Dungeon game need help or will fail...

Have a look at the Java tutorials for info on Java specifics: The Really Big Index

Then break down your big project into little steps and try to solve each one, one at a time. If you get stuck at a step, come on back with your specific question and your code, and let's see how we can help you.

5. Senior Member
Join Date
Nov 2012
Posts
105
Rep Power
0

## Re: JAva 1 Simple Dungeon game need help or will fail...

Originally Posted by shookey16
I know I'm only in Java 1 but I can't program for crap.
I imagine if you paid more attention you could.

I suggest you make a class for player, monster, and gamemap to start off. You probably get the point, make methods that have to do with the map in the GameMap class, the ones that have to do with the player in the Player class, and the ones that have to do with the monster in the Monster class.

6. Moderator
Join Date
Apr 2009
Posts
12,918
Rep Power
22

## Re: JAva 1 Simple Dungeon game need help or will fail...

Not sure a map class is actually needed.
Seems to me to be a simple loop 1-10 (well, 0-9).
Each loop consists of a check whether there is a monster.
If there is then fight.

7. Member
Join Date
Dec 2012
Posts
5
Rep Power
0

## Re: JAva 1 Simple Dungeon game need help or will fail...

Hopefully you guys can still help
Again the directions are at the top

Java Code:
```import java.util.Scanner;
import java.util.Random;
public class Dungeon
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner (System.in);
Random rand = new Random();
Random rando = new Random();

int rand.nextInt(3);
int rando.nextInt(8);

int steps = 0;
int count = 0;
int move = 0;

int fightchoice = 0;
int PHP = 10;
int GHP = 3;
int DHP = 10;
int Gold = 0;
int PDamage = rando;
int DDamage = 0;
int GDamage = 0;
int GReward = 0;
int DReward = 0;

System.out.println("You've entered a dungeon, you must take 10 steps to escape the dungeon. Good luck.");

while(steps != 10)
{

System.out.println("Would you like to move on?");
move = keyboard.nextInt();

if(move == 1)
{
System.out.println("You've encountered a dragon, Press 1 to fight or 2 to run");
fightchoice = keyboard.nextInt();

if (fightchoice == 1)
{

if (move ==	2)
{
System.out.println("");

steps++;
}

// game stuff printlines and so forth
// after each event, increment steps
}

}
}```
Keep in mind that im in low level and it doesnt get more complex than this

My questions are how do i make a bunch of random numbers for PDamage, DDamage, GDamage, the rewards and everything else then how do i impliment them in the code? im too lost..
Last edited by Tolls; 12-07-2012 at 10:43 AM. Reason: Added code tags

8. Member
Join Date
Dec 2012
Posts
5
Rep Power
0

## Jva 1 Simple Dungeon game need help or will fail...

It's a basic course and Im not picking it up

The player must take 10 steps to escape the dungeon. On each step, the player might encounter a monster. One third of the time, the player will encounter a gnome. One third of the time, the player will encounter a dragon. One third of the time, there will be no monster.
If there is a monster, the player can choose to fight or run away. If the player fights and wins, the player gets the monster's gold.
The player starts with 10 hit points. Each time the player is hit by a monster, the player loses hit points. If the player's hit points reach 0 before escaping the dungeon, the game is over and the player loses.
The player does 1 to 8 hit points of damage with each hit
Each gnome encountered starts with 3 hit points, has 1 to 5 gold gold, and does 1 to 2 hit points of damage each time it attacks..
Each dragon starts with 10 hit points, has 10 to 20 gold, and does 1 to 5 points of damage.

Each encounter with a monster consists of a series of turns. For each turn, the player can fight, or run away. If the player chooses to fight, damage is calculated for the monster. The monster retaliates and damage is calculated for the player. Then, the next turn starts and the player may choose to fight or run away again. If the player chooses to run away, they move one step closer to the dungeon exit without getting hurt, but without getting any gold.

When the player escapes, the program displays the total gold collected.

It's a pain in the butt and I know I'm only in Java 1 but I can't program for crap.

Any help at all will be much much appreciated

9. Member
Join Date
Dec 2012
Posts
5
Rep Power
0

## Re: Jva 1 Simple Dungeon game need help or will fail...

import java.util.Scanner;
import java.util.Random;
public class Dungeon
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner (System.in);
Random rand = new Random();
Random rando = new Random();

int rand.nextInt(3);
int rando.nextInt(8);

int steps = 0;
int count = 0;
int move = 0;

int fightchoice = 0;
int PHP = 10;
int GHP = 3;
int DHP = 10;
int Gold = 0;
int PDamage = rando;
int DDamage = 0;
int GDamage = 0;
int GReward = 0;
int DReward = 0;

System.out.println("You've entered a dungeon, you must take 10 steps to escape the dungeon. Good luck.");

while(steps != 10)
{

System.out.println("Would you like to move on?");
move = keyboard.nextInt();

if(move == 1)
{
System.out.println("You've encountered a dragon, Press 1 to fight or 2 to run");
fightchoice = keyboard.nextInt();

if (fightchoice == 1)
{

if (move == 2)
{
System.out.println("");

steps++;
}

// game stuff printlines and so forth
// after each event, increment steps
}

}
}

Keep in mind that im in low level and it doesnt get more complex than this

My questions are how do i make a bunch of random numbers for PDamage, DDamage, GDamage, the rewards and everything else then how do i impliment them in the code? im too lost..

10. ## Re: JAva 1 Simple Dungeon game need help or will fail...

shookey16, please go through the Forum Rules -- particularly the second paragraph.

I've merged the second thread you started here. Don't double post the same question again.

db

11. Moderator
Join Date
Apr 2009
Posts
12,918
Rep Power
22

## Re: JAva 1 Simple Dungeon game need help or will fail...

Originally Posted by shookey16
Keep in mind that im in low level and it doesnt get more complex than this

My questions are how do i make a bunch of random numbers for PDamage, DDamage, GDamage, the rewards and everything else then how do i impliment them in the code? im too lost..
I added code tags to the first one above, so it's easier to read.

A couple of comments, basedd on the requirements.
You want to increment 'steps' each time round the loop.
At the moment you only do it if the player does not encounter a monster.

For the fighting, you only need the one Random object, for starters, and you only need to call nextInt() on it when you need a random number, so these two lines can go:
Java Code:
```int rand.nextInt(3);
int rando.nextInt(8);```
There's nothing in the requirements about asking if they want to move on.
So get rid of the "Do you want to move on" bit.
At that point you want to get a random number, 1-3, where 1 is a gnome, 2 is a dragon, 3 is move on.

Get to that point and get it working.
You can worry about fighting later.