Need help with UNI project !

Java Discuss, Need help with UNI project ! at Programmers Lounge forum; hi, i have an assignment for uni where i have to make a text game according to a given scenario, ...


Go Back   Gamerz Needs - For All Your Gaming Needs! > Technology Zone > Programmers Lounge > Java
Forgot Password? | Sign Up!

Notices

Advertisement
   

Reply
 
Bookmark this Thread Tools Display Modes
  #1  
Old 11-23-2007, 01:55 PM
Stone Axe
 
Last Online: 10-25-2008 10:08 AM
Join Date: Oct 2005
Age: 23
Posts: 31
Thanks: 1
Thanked 0 Times in 0 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 0
frodotheone is on a distinguished road
Points: 1,331.33
Bank: 624.80
Total Points: 1,956.13
Need help with UNI project !

hi, i have an assignment for uni where i have to make a text game according to a given scenario, a part of the game has a bomb room and a bomb timer, where if the player doesent get the code right within 10 seconds the bomb explodes and the player has the choice to restart.

here is the code to the bomb, im not sure if the sleep method timer is causing the problems, it runs, but when you choose y to restart it just goes into this error:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at hostage.Main.main(Main.java:134)

here is the code:



--------------------------------------------------------------------------------

boolean go = true;
boolean countfinish = false;
Scanner sc = new Scanner(System.in);
int rn1, rn2, answer, sumofrn1rn2;
boolean restart = true;
System.out.println("you have entered the BOMB ROOM!!! solve the equasion within 10 seconds to defuse the bomb");
System.out.println();

//below is the equasion to defuse the bomb

//------------------------------------------------------


rn1 = (int)(Math.random()*1000);
rn2 = (int)(Math.random()*1000);
System.out.print(rn1);
System.out.print(" + ");
System.out.print(rn2);
System.out.print(" = ");
answer = 0;
sumofrn1rn2 = (rn1+rn2);


try
{
// the sleep method of the thread object is called
Thread.sleep(10000);
}
catch(InterruptedException e)
{
}

countfinish = true;


if (countfinish == true)
{
if (sumofrn1rn2 != answer)
{

System.out.println("You faild, oh and your dead... Restart? (y/n)");
restart2 = sc.next().charAt(0);

if (restart2 == 'y')
{
Current_Room = "ROOM 1";
System.out.println("Welcome to the Lobby!.....again....");
}
}

}

answer = sc.nextInt();
if (answer == rn1+rn2)
{
System.out.println("You have defused the bomb... fewww...");


//go back to lobby
}




--------------------------------------------------------------------------------

any help would be appresiated, thank you
-----------------This post was merged together. In future use the edit button.-----------------

/*
* Main.java
*
* Created on 21 November 2007, 23:21
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package hostage;


import java.io.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;


/**
*
* @author Pain In Arse
*/
public class Main {

public static void main (String[] args) {

System.out.println("Welcome to the Lobby!");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

String Last_Command = null;

String Temp_Split[] = {null};
String Temp_String = null;

boolean Room_1_South_Door_Locked;
boolean Game_Over;
char restart2;

boolean Picked_Up_Note = false;
boolean Picked_Up_Key = false;

String Current_Room = null;

Current_Room = "ROOM 1"; // START OF HERE
Room_1_South_Door_Locked = true;

Game_Over = false;

do{

try {
Last_Command = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error reading 'Command'");
System.exit(1);
}

Last_Command = Last_Command.toUpperCase();

Temp_Split = Last_Command.split(" ");

while (Current_Room.equals("ROOM 1")){
// ROOM 1
if (Temp_Split[0].equals("MOVE")){
if (Temp_Split[1].equals("NORTH")){
// R1 - North - NO ROOM TO NORTH
System.out.println("NO ROOM TO THE NORTH!");
}else{
if (Temp_Split[1].equals("EAST")){
// R1 - EAST - YOUR DEAD == BOMB ROOM








boolean go = true;
boolean countfinish = false;
Scanner sc = new Scanner(System.in);
int rn1, rn2, answer, sumofrn1rn2;
boolean restart = true;
System.out.println("you have entered the BOMB ROOM!!! solve the equasion within 10 seconds to defuse the bomb");
System.out.println();


//below is the equasion to defuse the bomb

//------------------------------------------------------


rn1 = (int)(Math.random()*1000);
rn2 = (int)(Math.random()*1000);
System.out.print(rn1);
System.out.print(" + ");
System.out.print(rn2);
System.out.print(" = ");
answer = 0;
sumofrn1rn2 = (rn1+rn2);


try
{
// the sleep method of the thread object is called
Thread.sleep(10000);
}
catch(InterruptedException e)
{
}

countfinish = true;


if (countfinish == true)
{
if (sumofrn1rn2 != answer)
{

System.out.println("You faild, oh and your dead... Restart? (y/n)");
restart2 = sc.next().charAt(0);

if (restart2 == 'y')
{
Current_Room = "ROOM 1";
System.out.println("Welcome to the Lobby!.....again....");
}
}

}

answer = sc.nextInt();
if (answer == rn1+rn2)
{
System.out.println("You have defused the bomb... fewww...");


//go back to lobby
}









System.exit(0);
}else{
if (Temp_Split[1].equals("SOUTH")){
if (Room_1_South_Door_Locked == true){
// R1 - LOCKED DOOR
System.out.println("DOOR LOCKED");
}else{
// R1 - Next Level
System.out.println("!!! Next Level !!!");
System.out.println("!!! GAME OVER !!!");
System.exit(0);
}
}else{
if (Temp_Split[1].equals("WEST")){
// R1 - GOTO ROOM 2
Current_Room = "ROOM 2";
System.out.println("WELCOME TO ROOM " + Current_Room);

}
}
}
}
}else{
if (Temp_Split[0].equals("LOOK")){
System.out.println("There is a Door to the 'EAST'");
System.out.println("There is a Door to the 'SOUTH'");
System.out.println("There is a Door to the 'WEST'");
if (!Picked_Up_Note){
System.out.println("There is a 'NOTE' on the floor");
}
}else{
if (Temp_Split[0].equals("PICKUP")){
if (Temp_Split[1].equals("NOTE")){
System.out.println("You pickup up a '" + Temp_Split[1] + "'");
Picked_Up_Note = true;
}else{
System.out.println("There is no " + Temp_Split[1] + " to pick up");
}
}else{
if (Temp_Split[0].equals("USE")){
if (Temp_Split[1].equals("NOTE")){
if (Picked_Up_Note){
System.out.println("There are 3 doors in room 1, 1 door is locked, the other 2 are open!");
System.out.println("HOWEVER 1 contains a bomb! (fizz!) the other contains the key to the locked door! choose wiseley!");
}
}else{
if (Room_1_South_Door_Locked == true){
if (Temp_Split[1].equals("KEY")){
if (Picked_Up_Key){
System.out.println("Door UnLocked");
Room_1_South_Door_Locked= false;
}
}
}else{
System.out.println("Door Already UnLocked");
}
}
}
}
}

}
}

if (Temp_Split[0].equals("MOVE")){
if (Temp_Split[1].equals("EAST")){
// R2 - GOTO ROOM 1
Current_Room = "ROOM 1";
System.out.println("WELCOME TO ROOM " + Current_Room);
}else{
System.out.println("NO ROOM TO THE " + Temp_Split[1]);
}
}else{
if (Temp_Split[0].equals("LOOK")){
System.out.println("There is a Door to the 'EAST'");
if (!Picked_Up_Key){
System.out.println("There is a 'KEY' on the floor");
}
}else{
if (Temp_Split[0].equals("PICKUP")){
if (Temp_Split[1].equals("KEY")){
System.out.println("You pickup up a '" + Temp_Split[1] + "'");
Picked_Up_Key = true;
}else{
System.out.println("There is no " + Temp_Split[1] + " to pick up");
}
}else{
if (Temp_Split[0].equals("USE")){
if (Temp_Split[1].equals("NOTE")){
if (Picked_Up_Note){
System.out.println("There are 3 doors in room 1, 1 door is locked, the other 2 are open!");
System.out.println("HOWEVER 1 contains a bomb! (fizz!) the other contains the key to the locked door! choose wiseley!");
}

}else{
if (Temp_Split[1].equals("KEY")){
if (Picked_Up_Key){
System.out.println("No Doors to UnLock");
}
}
}
}
}
}
}


}while(!Game_Over);
}

}

Last edited by frodotheone; 11-23-2007 at 02:19 PM.. Reason: Automerged Doublepost
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Advertisement
   


Main Navigation
Home
GzN Forums
GzN Games
GzN News
Top Games
GzN Cheats
GzN Articles
GzN Reviews
GzN Downloads
User Control Panel
Advertising
RSS Feed
2Moons
Adventure Quest
AirRivals
America's Army
Anarchy Online
Archlord
Audition
Battlefield Series
Cabal Online
Call Of Duty Series
Combat Arms
Conquer Online
Counter Strike
Day of Defeat
Deicide Online
Diablo Series
Doom Series
Drift City
Enemy Territory
Eudemons Online
Final Fantasy
Flyff (Fly For Fun)
General Game Discussion
Ghost Online
Granado Espada
Grand Theft Auto Series
Guild Wars
Gunbound
Gunz Online
Habbo Hotel
Half-Life 2
Hero Online
KartRider
Knights Online
Maple Story
Medal of Honor
MU Online
Neopets
Pangya
Quake Series
Ragnarok Online
Rappelz
Rakion
Red Orchestra
Rose Online
Runescape
Scions of Fate
Silkroad Online
Sims Series
Soldier Front
Starcraft
Tales of Pirates
Tibia
The Ship
Trickster Online
TS Online
Unreal Tournament
War Rock
WolfTeam
World of Warcraft & Series
Affiliates
COD4 Hacks
BF2 Hacks


All times are GMT -8. The time now is 03:25 PM.