3 Replies - 2668 Views - Last Post: 15 March 2010 - 01:26 PM Rate Topic: -----

#1 Cooke3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-January 10

Cannot find symbol error?

Posted 15 March 2010 - 09:38 AM

I have this project that was due a long time ago but I've finally got it close to done.... I think. But I keep getting this error and I don't know what it means or how to fix it. Please take a look and let me know what I could try. (I'm a newbie to java so I may not understand a very complex answer).

It's supposed to be a game that reads in from the text file to get the room information.


Wumpus.java
import java.io.*;

public class Wumpus
{
  public static TextReader file; 
  public static int location;  //This is our location within the array because array starts at 0 not 1
  public static int move;      //This is the variable that is read in when you specify what room you would like to move into
  public static int shoot;     //This is the variable that is read in when you specify what room you would like to shoot into
  public static int spiders;   //This is the first room of spiders
  public static int spiders2;  //This is the second room of spiders
  public static int wumpi;     //This is where the wumpus is located
  public static int pits;      //This is our bottomless pit!
  public static int bats;      //This is our giant bat!
  public static int supplies;  //This is the wonderful supply room!
  public static int arrows = 3;//This creates the variable that keeps track of arrows and initializes it to three.
  
/**
  Batty function for the Hunt the Wumpus Program programming assignment.	
  Moves you to a new room if you enter the room with the bat and then checks to see if you land in a room with dangers
*/
  public static void Batty ()
  {
  if(move==bats)
	{
		int newroom;
		System.out.println ("A giant bat swoops down...WE'RE FLYING!!! :-D");
		do {
		newroom = (int)(1+19*Math.random());
		location = newroom -1;	
		} while (newroom == bats);
		System.out.println();
		Gameover ();
	}
  }
/**
Gameover function for the Hunt the Wumpus programming assignment.  
This function determines when the game is over.... as in when you die because you walked into an unsafe room!  
*/
  public static void Gameover ()
  {
	if (move==spiders || move==spiders2)
	{
		System.out.println ("Oh no! The poisonous spiders just devoured you!! GAME OVER");
		System.exit(0);
	}
	else if (move==wumpi)
	{
		System.out.println ("Whoops! The wumpus got you. You stink! GAME OVER");
		System.exit(0);
	}
	else if (move==pits)
	{
		System.out.println ("What's that whistling sound?!? Oh wait."); 
		System.out.println ("It's the air rushing past you...."); 
		System.out.println ("You've fallen in the bottomless pit. GAME OVER");
		System.exit(0);
	}
	else if(move==supplies) //this is extra i think
	{
		System.out.println ("You found some more arrows! Lucky you!");
		arrows += 3;
	}
  }
/**
Death function for the Hunt the Wumpus programming assignment.    
This function determines what you hit when you shoot
*/
  public static void Death ()
  {
	if (shoot==wumpi)
	{
		System.out.println("You have slain the mighty wumpus! YOU WIN!!!");
		System.exit(0);
	}
	else if (shoot==spiders || shoot==spiders2)  System.out.println("YOU MONSTER!!! YOU KILLED A BABY GIANT SPIDER!!!");
	else if (shoot==pits)  System.out.println("That arrow never hit anything.... Strange.");
	else if (shoot==bats)  System.out.println("That arrow flew back and landed at your feet...that wasn't wind, right?!");
	else System.out.println("Great job, brave warrior! You just killed the fearsome WALL OF THE NEXT ROOM!");
  }
/**
MovinAndShootin function for the Hunt the Wumpus programming assignment.    
This function allows you to pick between moving and shooting
*/
  public static void MovinAndShootin (Room [] cave)
  {	
	file = new TextReader(System.in);
	int moveshoot = file.readInt();
	System.out.println();
        if (moveshoot == 1)
	{
		System.out.print("Which room would you like?!?: ");
		move = file.readInt();
		System.out.println();
		int adj1 = cave[location].getAdjRm1();
		int adj2 = cave[location].getAdjRm2();
		int adj3 = cave[location].getAdjRm3();
      
		if (move ==adj1 || move==adj2 || move==adj3)
		{
			location = move-1;
			Gameover();
			Batty();
		}
		else  System.out.println ("No no no!!! You can't do that, brave warrior!");
	}
	else if (moveshoot == 2)
	{
		System.out.print("Which room would you like to shoot into?: ");
		shoot = file.readInt();
		System.out.println();
		arrows--;

		if(cave[location].isNext(shoot))  
		{
			Death ();
			if (arrows == 0)
			{
				System.out.println("You have run out of arrows! GAME OVER");
				System.exit(0);
			}
		}
		else  System.out.println("Silly warrior! You've shot a wall. You don't get to retrieve that one!");
	}
	else  System.out.println("Ummm...I'm pretty sure that wasn't an option...");
  }  
/**
Main function for the Hunt the Wumpus programming assignment.    
This is where we start up the game and create an array of rooms.  We also implement our other functions within this and where we pull our random numbers in from the danger file
*/
  public static void main(String [] args) throws IOException
  {
	System.out.println();
	System.out.println("|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|");
	System.out.println("|-|-|-|-|-|-|-|-|Welcome to Hunt the Wumpus!!!|-|-|-|-|-|-|-|");
	System.out.println("|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|.|");
	String filename="cave2.txt";
	TextReader file = new TextReader(new FileInputStream(filename));
	System.out.println();
	int roomcount = file.readInt();
	Room [] cave = new Room[roomcount]; //This line creates the array of rooms, which we named 'cave'
	danger horror = new danger();
	//This 'for loop' reads in each "room" from the file and puts it into the array
	for(int i=0; i<cave.length; i++)
	     cave[i] = new Room(file);
	      
     
	location = 0;
	spiders = horror.getSpider();
	spiders2 = horror.getSpider2();
	wumpi = horror.getWumpus();
	pits = horror.getPit();
	bats = horror.getBat();
	supplies = horror.getSupply();


    //This for loop keeps the turns coming displaying room information, connecting rooms, number of arrows remaining and lets you know of any sounds or smells in the adjoining rooms
    for (int count=0; count>=0; count++)
    {    
	System.out.println("The current room is: "+cave[location].getCurrent());
        System.out.println(cave[location].getPhrase());
	System.out.println("The connecting rooms are: "+cave[location].getAdjRm1()+" "+cave[location].getAdjRm2()+" "+cave[location].getAdjRm3());
	   if(cave[location].isNext(wumpi)) 
	      System.out.println("You smell some nasty B.O. The wumpus is near!");
	   if(cave[location].isNext(spiders) || cave[location].isNext(spiders2))
	      System.out.println("You hear a mysterious clicking noise...spiders?!?!");
	   if(cave[location].isNext(pits))
	      System.out.println("You smell some some nasty air...I don't think it was me!");
	   if(cave[location].isNext(bats))
	      System.out.println("You hear what sounds like giant wings...creepy!");
	System.out.println("You have "+arrows+" arrows left.");
	System.out.println();
	System.out.print("Would you like to [1]Move or [2]Shoot? "); 
	MovinAndShootin (cave);
    }
  }
}



WumpusMain.java
import java.io.*;

public class WumpusMain
{
  public static void main(String [] args) 
  {
    String filename="practice.txt";
    TextReader file = new TextReader(new FileInputStream(filename));

    int roomcount = file.readInt();

    Room [] cave = new Room[roomcount]; 

    for(int i=0; i<cave.length; i++)
      cave[i] = Room(file);
      
    for(int i=0; i<cave.length; i++)
      System.out.println(cave[i]);

  }


}



TextReader.java
import java.io.*;

/**

   Provides a simple interface for standard text reading operations
   from an input stream.  Converts all IOExceptions to
   RuntimeExceptions, so it should be used only with stable input
   streams like System.in.  Uses lazy evaluation (delaying the reading
   of the beginning of a new line until necessary) so as to function
   properly when used with console input.  Unlike the standard
   java.io.BufferedReader, it returns a correct value for ready() with
   console reading (returning false only if the user enters an
   end-of-file from the console).  Includes a one-character peek ahead
   facility.<p>

   TextReader's behavior is similar to that of Pascal's standard
   input.  It has three utilities for processing the input one token
   at a time (one for words and two for numbers).  As in Pascal, these
   token-processing methods skip leading whitespace, but unlike
   Pascal, they also skip trailing whitespace on the current input
   line.  Skipping the trailing space allows one to write
   token-processing programs without worrying about trailing
   whitespace at the end of a line that might imply that more input is
   present when it really isn't.<p>

   TextReader also provides utilities for reading the input one
   character at a time or one line at a time, in which case whitespace
   is preserved.  As noted above, it also has a utility for peeking
   one character ahead in the stream.  There is also a method for
   skipping whitespace.  A programmer can combine these utilities to
   define specialized behavior.<p>

   To simplify differences between operating systems, TextReader skips
   a "\r" character if it sees it so that the two-character sequence
   "\r\n" becomes a single "\n" character.  It also inserts a virtual
   "\n" before end-of-file if one is not present.<p>

   Below is an example of how to construct and manipulate a reader for
   interactive console input.

   <blockquote><pre>
   * TextReader console = new TextReader(System.in);
   * System.out.print("What is your name? ");
   * String name = console.readLine();
   * System.out.print("Give me two positive numbers, " + name + " --> ");
   * double x = console.readDouble();
   * double y = console.readDouble();
   * System.out.println(x + " to the " + y + " power = " + Math.pow(x, y));
   * System.out.print("Give me a positive integer, " + name + " --> ");
   * int n = console.readInt();
   * System.out.println("2 to the " + n + " = " + (int)Math.pow(2, n));
   </pre></blockquote>

   The code above would execute something like this (user input underlined):

   <blockquote><pre>
   * What is your name? <u>John Boy</u>
   * Give me two positive numbers, John Boy --> <u>3.4 2.9</u>
   * 3.4 to the 2.9 power = 34.77673927667935
   * Give me a positive integer, John Boy --> <u>14</u>
   * 2 to the 14 = 16384
   </pre></blockquote>

   By default the token-processing methods like readInt consume the
   newline character at the end of each line, which assumes that
   newline characters are not significant.  There is a utility that
   allows a programmer to specify that newline characters are
   significant, in which case they are left in the input stream.  For
   example, the code below reads exactly one line of input, adding up
   the integers on the line.<p>

   <blockquote><pre>
   * input.eolIsSignificant(true);
   * input.skipWhite(false);  // in case the line contains just whitespace
   * sum = 0;
   * while (input.peek() != '\n')
   *     sum += input.readInt();
   * input.readChar();  // to skip past the newline
   </pre></blockquote>

   To construct a reader using a file, the potential I/O error must be
   caught because, for example, the specified file might not exist.
   Below is an example of how to construct and manipulate a file
   reader using a specific file name (in this case, project.dat).  If
   an error occurs, the program exits with a runtime exception.

   <blockquote><pre>
   * TextReader input;
   * try {
   *     input = new TextReader(new FileInputStream("project.dat"));
   * } catch (IOException e) {
   *     throw new RuntimeException(e.toString());
   * }
   * // if you made it to here, then the file exists and is readable
   * int sum = 0;
   * while (input.ready())
   *     sum += input.readInt();
   </pre></blockquote>

   Below is a variation where the user is prompted for a file name and
   the program loops until a legal file name is given.

   <blockquote><pre>
   * TextReader console = new TextReader(System.in);
   * TextReader input;
   * boolean done = false;
   * do {
   *     System.out.print("input file name? ");
   *     String name = console.readLine();
   *     try {
   *         input = new TextReader(new FileInputStream(name));
   *         done = true;
   *     } catch (IOException e) {
   *         System.out.println(e + ", try again");
   *     }
   * } while (!done);
   * int sum = 0;
   * while (input.ready())
   *     sum += input.readInt();
   </pre></blockquote>

   The previous two code examples use FileInputStream and IOException,
   which would require you to include the line below at the beginning
   of your class file.

   <blockquote><pre>
   * import java.io.*;
   </pre></blockquote>

   Questions about this class can be sent to <a
   href="http://www.cs.arizona.edu/people/reges">Stuart Reges</a> (<a
   href="mailto:reges@cs.arizona.edu">reges@cs.arizona.edu</a>).

   @version 1.1,  1/7/01
   @author Stuart Reges */

public class TextReader
{
    /**
       Create a text-reading stream.
       @param input the input stream to read from
    */
    public TextReader(InputStream input)
    {
        myInput = input;
        myUndefinedState = true;
    }

    private int read()
    // post: reads a character from the stream, converting \r\n into \n
    {
        try {
            int result = myInput.read();
            if (result == '\r')
                result = myInput.read();
            return result;
        } catch (IOException e) {
            throw new RuntimeException(e.toString());
        }
    }   

    private void checkState()
    // post: used to implement lazy input; defines state if it is
    //       currently undefined (should be called as late as possible)
    {
        if (myUndefinedState) {
            myUndefinedState = false;
            myNextChar = read();
        }
    }

    /**
       Read a single character (including whitespace).
       @return next character in the stream
       @throws RuntimeException if end-of-file
    */
    public char readChar()
    {
        checkState();
        if (myNextChar == -1)
            throw new RuntimeException("Attempt to read past end of file");
        else {
            char result = (char)myNextChar;
            if (myNextChar == '\n')  // lazy input, don't read yet
                myUndefinedState = true;
            else {
                myNextChar = read();
                if (myNextChar == -1)   // unexpected end-of-file 
                    myNextChar = '\n';  // insert virtual \n
            }
            return result;
        }
    }

    /**
       Peek ahead one character.
       @return the character that a subsequent call on readChar() would return
       @throws RuntimeException if end-of-file
    */
    public char peek()
    {
        checkState();
        if (myNextChar == -1)
            throw new RuntimeException("Attempt to peek past end of file");
        return (char)myNextChar;
    }

    /**
       Tell whether this stream is ready to be read.
       @return true if ready, false if not
    */
    public boolean ready()
    {
        checkState();
        return myNextChar != -1;
    }

    /**
       Reads a line of text.
       @return the line of text without the '\n'
       @throws RuntimeException if end-of-file
    */
    public String readLine()
    {
        checkState();
        String result = "";
        for(;;)/> {
            char next = readChar();
            if (next == '\n')
                break;
            result += next;
        }
        return result;
    }

    /**
       Determine whether or not ends of line are treated as tokens.
       This method affects only the token-reading methods (readWord,
       readInt, readDouble).
       @param flag whether end-of-line characters should be left in stream */
    public void eolIsSignificant(boolean flag)

    {
        mySignificantEol = flag;
    }

    /**
       Skip whitespace.
       @param skipEoln whether or not to skip end-of-line characters
    */
    public void skipWhite(boolean skipEoln)
    {
        checkState();
        while (ready() && Character.isWhitespace(peek()) &&
               (skipEoln || peek() != '\n'))
            readChar();
    }

    /**
       Read the next token delineated by whitespace.
       @return the word read (empty string if end-of-file reached)
    */
    public String readWord()
    {
        String result = "";
        skipWhite(true);
        while (ready() && !Character.isWhitespace(peek()))
            result = result+readChar();
        skipWhite(false);
        if (ready() && peek() == '\n' && !mySignificantEol)
            readChar();
        return result;
    }

    /**
     



cave2.txt
20
1 2 6 10
A creepy old dude says, "The Wumpus is hungry today!!!"
2 1 11 15
There is a skeleton chained to the wall.
3 4 19 10
Is it just you, or are these rooms getting darker?
4 3 12 19
You see a dismantled flashlight in the corner.
5 6 7 8
A tiny rat scurries across your feet.
6 1 5 13
You really really want a cheeseburger right now.  Oh wait...scary cave, right!
7 5 8 20
Water drips from a stalactite onto your head, causing you to JUMP!
8 7 5 14
You bang your head on the ceiling. Did leprechauns build this maze?!
9 10 18 12
A SPIDER!!! Oh wait, it's just a creepy cave painting...oops!
10 9 1 3
You hear a wicked laugh. That old dude sure is creepy!
11 2 16 17
Look! You can see the stars!...or cave wall chalk...LAME!
12 4 9 16
An empty treasure chest is against the far wall.
13 6 20 15
You realize you don't get any cell phone reception in this cave...stupid Verizon
14 8 15 19
You have found the mystical unicorn of happiness! It's frowning in the corner...
15 14 13 2
You forgot to update your Facebook status...Now no one will know where you are!
16 12 20 18
You suddenly get "Year 3000" by the Jonas Brothers stuck in your head.
17 11 18 19
Your stomach starts to growl...you really REALLY want Keenan's backpack!
18 17 16 9 
You find a magical wand and wave it around.  Sparks fly, but nothing happens...
19 17 14 3
There's a smoke detector on the wall...that's odd...
20 16 13 7
You decide to sit and rest, only to realize you sat in green goo...EWWWWWW!!!



Is This A Good Question/Topic? 0
  • +

Replies To: Cannot find symbol error?

#2 Nameo0  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 75
  • Joined: 30-November 09

Re: Cannot find symbol error?

Posted 15 March 2010 - 09:53 AM

what line do you get this error in?
Was This Post Helpful? 0
  • +
  • -

#3 Cooke3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 24-January 10

Re: Cannot find symbol error?

Posted 15 March 2010 - 01:24 PM

It's in every line with "Room" in it.
Was This Post Helpful? 0
  • +
  • -

#4 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Cannot find symbol error?

Posted 15 March 2010 - 01:26 PM

Well do you have a Room class? You don't have one listed there
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1