yay last min uni work part 2.... I need help

It's easy tbh. Here's a hint,

You can create a method which creates each line of the grid as a string,
somthing like... (this is pseudocode)

While bob.length !== line length
{
String bob = "|"

If (location contains ring or whatever)
{
bob = bob + "[R]|"
}
Else
{
bob = bob + " |"
}
}

etc etc.

I'd make an array of the grid, so each square of the grid is a location in the array.
 
Im currently trying to create a loop that goes like this

System.out.print("If you would like to play again press 1, if not press 0);

Then If the user presses 0 I want the game to say "Thank You For Playing"
and if they press 1 I want the game to loop back to the start

So Far I have


But for some reason Y no matter what you enter it still says Thank You For Playing! and ends, and I am unsure how to loop it back to the beginging of the game...
 
Last edited:
You do realise it's common for comp sci departments to have plagiarism detectors that search the net? And simply renaming variables won't be enough to throw it off.
 
Psyk said:
You do realise it's common for comp sci departments to have plagiarism detectors that search the net? And simply renaming variables won't be enough to throw it off.
Hence why im not copying stuff, im looking at it as an example, searching for more on it, learning what it does and why it does it and then rewriting it in my own format...
 
You don't need it in it's own class, I'd just put it in the game's class in it's own method, and then call the method from the main class after they'd played the game.

public void playagain()
{
Scanner sc = new Scanner(System.in);
System.out.println("Would you like to play again? Please enter Y for yes or N For no");
public String replay = "Y";

While(String replay.equals("Y")
{
replay = sc.nextLine().toUpperCase();
If(replay.!equals("Y") & replay.!equals("N"))
{
System.err.println("You're an Eegit");
System.exit(-1);
}
Else If(replay.equals("Y")
{
game.game();
}
Else
{
System.exit(1);
}
}
 
Last edited:
Psyk said:
You do realise it's common for comp sci departments to have plagiarism detectors that search the net? And simply renaming variables won't be enough to throw it off.

Even if he was plagiarising, which he isn't, you can't spider forums.overclockers.co.uk

Well, not without ignoring robots.txt which is a BAD THING.
 
Phnom_Penh said:
You don't need it in it's own class, I'd just put it in the game's class in it's own method, and then call the method from the main class after they'd played the game.

public void playagain()
{
Scanner sc = new Scanner(System.in);
System.out.println("Would you like to play again? Please enter Y for yes or N For no");
public String replay = "Y";

While(String replay.equals("Y")
{
replay = sc.nextLine().toUpperCase();
If(replay.!equals("Y") & replay.!equals("N"))
{
System.err.println("You're an Eegit");
System.exit(-1);
}
Else If(replay.equals("Y")
{
game.game();
}
Else
{
System.exit(1);
}
}

Would there be any way to do it in the line of thought I was having? Realy want to keep it in the relms of what we have been taught if possible... or at least simple as we were not taught random numbers hence my inability to randomly place the treasure!
 
jcb33 said:
Would there be any way to do it in the line of thought I was having? Realy want to keep it in the relms of what we have been taught if possible... or at least simple as we were not taught random numbers hence my inability to randomly place the treasure!
You'd be expected to look stuff up. Random numbers is easy.

This is pretty basic stuff, I guess it depends how basic you're meant to know.
Essentially you need to create an array of 56 strings, then look them up, by taking the inputted co-ordinates, say like 7, C, using an If statement to read the C, and convert it to 13, and add 7 to it, to go to the 21st square in the array (well 20th position, arrays start at 0), and then read that string in the array to see if there is anything there, and if so add it to the total and tell the user.
 
Last edited:
Phnom_Penh said:
You'd be expected to look stuff up. Random numbers is easy.
Well I have the computer taking 5 random guesses for the user... but I need to get the treasure to place randomly on the grid each game, But I also need to keep the treasure in tack, e.g a sword is 3 cells long, and i need to keep it 3 cells long so placing it randomly becomes confusing...
 
Phnom_Penh said:
This is pretty basic stuff, I guess it depends how basic you're meant to know.
Essentially you need to create an array of 56 strings, then look them up, by taking the inputted co-ordinates, say like 7, C, using an If statement to read the C, and convert it to 13, and add 7 to it, to go to the 21st square in the array (well 20th position, arrays start at 0), and then read that string in the array to see if there is anything there, and if so add it to the total and tell the user.

You're making the array too complicated. There's no need to make one 56 length array. Can you imagine the work in parsing that to generate the output?

Just do it with a 2 dimensional array of 7 by 8. Much easier to create, easier to alter and easier to reference.
 
Back
Top Bottom