Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (576)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Code Won't Compile  (Read 911 times)
0 Members and 2 Guests are viewing this topic.
Offline michael.becerra

Senior Newbie





« Posted 2007-05-16 23:29:20 »

This code gives me the following errors:

unreachable statement Line 99
missing return statement Line 135

JIFT.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
import java.util.*;
import java.applet.*;
import java.awt.*;
// JIFTDemo - Demonstrates some of the features of JIFT
// Last modification date : October 08, 1997

public class JIFT extends Applet {
   
   Room currentLocation;
   String command;
   TextField commandInput;
   TextArea displayOutput;
   Button buttonInput;
   
   // Constructor
  public JIFT() {
      super();
      }
     
   // Initialisation method
  public void init() {
      super.init();
   
   // Define colours setBackground
  setBackground(Color.white);
   setForeground(Color.black);
   Panel appletPanel = new Panel();
   
   // Use a border layout
  BorderLayout b = new BorderLayout();
   appletPanel.setLayout (b); add(appletPanel);
   
   // Define UI items
  commandInput = new TextField(20);
   
   displayOutput = new TextArea( 10, 60);
   
   // 10 rows x 60 chars
  buttonInput = new Button("Go");
   Panel inputPanel = new Panel();
   
   // Add components to our layout / panels
  inputPanel.add(commandInput);
   inputPanel.add(buttonInput);
   
   appletPanel.add("North", displayOutput);
   appletPanel.add("South", inputPanel);
   
   // Create two locations
  Room JailCell = new Room ("Jail Cell", "You stand at the entrance of your Jail Cell. Byond your cell you hear screaming in agony to the East. To The West is a hole large enough for you to fit through. The guards left your Cell door opened the last time your were served your meal");
   Room Hall = new Room ("Hall", "You have reached the end of a long dark hallway. You see demons torturing inicent souls\n You decide its best to go back.");
   Room SecretTunnel = new Room ("Secret Tunnel", "You move a large brick to find a secret tunnel leading out of your cell.\n You crawl through the tunnel to reach a small opening leading to the main Corridor");
   
   // Create an exit for JailCell
  JailCell.addExit (new Exit(Exit.NORTH, Hall));
   JailCell.addExit (new Exit(Exit.EAST, SecretTunnel));
   
   // Create an exit for Hall
  Hall.addExit (new Exit(Exit.SOUTH, JailCell));
     
   // Create an exit for SecretTunnel
  SecretTunnel.addExit (new Exit(Exit.WEST, JailCell));
   
   // Set up room locations
  currentLocation = JailCell;
   
   // Show first location
  showLocation();
   repaint();
   }
   
   private void showLocation() {
   // Show room title
  displayOutput.appendText( "\n" + currentLocation.getTitle() + "\n" );
   displayOutput.appendText( "\n" );
   // Show room description
  displayOutput.appendText( currentLocation.getDescription() + "\n" );
   // Show available exits
  displayOutput.appendText( "\nAvailable exits : \n" );
   for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();) {
      Exit an_exit = (Exit) e.nextElement();
      displayOutput.appendText (an_exit + "\n");
      }
   }
   
   public boolean action (Event evt, Object focus) {
      String command;
      // Was a button pressed ?
     if (evt.target instanceof Button) {
         
         // Obtain string
        command = commandInput.getText();
         
         // Don't parse blank commands
        if (command.length() == 0) {
            return true;
         
         // Convert to uppercase for comparison
        command = command.toUpperCase();
         
         // Search for an exit match
        for (Enumeration e = currentLocation.getExits().elements(); e.hasMoreElements();) {
            Exit an_exit = (Exit) e.nextElement();
           
            if ( (an_exit.getDirectionName().compareTo(command) == 0) || (an_exit.getShortDirectionName().compareTo(command) == 0 ) ) {
         
         // Set location to the location pointed to by exit
        currentLocation = an_exit.getLeadsTo();
         
         // Show new location
        showLocation();
         
         // Clear text area
        commandInput.setText (new String());
         
         // Event handled
        return true;
                  }
               }
         // If code reaches here, direction is invalid
        displayOutput.appendText ("\nHuh? Invalid direction!\n");
         
         // Clear text area
        commandInput.setText (new String());
         
         // Event handled
        return true;
            }
         
         // Event not handled else
       
         return false;
         
         }
      }
}


Room.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
import java.util.Vector; 
import java.util.Enumeration;
// Location - represents a gaming location //
// Last modification date : May 14, 2007

public class Room {

// Member variables
private String m_roomTitle;
private String m_roomDescription;
private Vector m_vecExits;

// Blank constructor
public Room() {
// Blank title + description
m_roomTitle = new String ();
m_roomDescription = new String();
m_vecExits = new Vector();
}
// Partial constructor
public Room( String title ) {
   // Assign title
  m_roomTitle = title;
   
   // Blank description
  m_roomDescription = new String();
   
   // Blank exits
  m_vecExits = new Vector();
   }
   
   // Full constructor
  public Room( String title, String description ) {
   
   // Assign title + description
  m_roomTitle = title;
   m_roomDescription = description;
   
   // Blank exits
  m_vecExits = new Vector();
   }
   
   // toString method
  public String toString() {
      return m_roomTitle;
      }
   
   // Adds an exit to this location
  public void addExit ( Exit exit ) {
      m_vecExits.addElement (exit);
      }
     
   // Removes an exit from this location
  public void removeExit ( Exit exit ) {
      if (m_vecExits.contains (exit)) {
         m_vecExits.removeElement (exit);
         }
      }
     
   // Returns a vector of exits
  public Vector getExits () {
   // Return a clone, as we don't want an external
  // object to modify our original vector return (Vector)
        m_vecExits.clone();
         return (Vector) m_vecExits.clone();
      }
         
   // Returns location title
     public String getTitle() {
         return m_roomTitle;
      }
           
   // Assigns location title
     public void setTitle( String roomTitle ) {
         m_roomTitle = roomTitle;
      }
         
   // Returns location description
     public String getDescription() {
         return m_roomDescription;
      }
           
   // Assigns location description
     public void setDescription( String roomDescription ) {
         m_roomDescription = roomDescription;
      }
}


Exit.java
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
// Exit - represents an exit to a location
// Last modification date : May 14, 2007
public class Exit {

// Numerical codes
public static final int UNDEFINED = 0;
public static final int NORTH = 1;
public static final int SOUTH = 2;
public static final int EAST = 3;
public static final int WEST = 4;
public static final int UP = 5;
public static final int DOWN = 6;
public static final int NORTHEAST = 7;
public static final int NORTHWEST = 8;
public static final int SOUTHEAST = 9;
public static final int SOUTHWEST = 10;
public static final int IN = 11;
public static final int OUT = 12;

// String codes
public static final String[] dirName = { "UNDEFINED", "NORTH", "SOUTH", "EAST", "WEST", "UP", "DOWN", "NORTHEAST", "NORTHWEST", "SOUTHEAST", "SOUTHWEST", "IN", "OUT" };
public static final String[] shortDirName = { "NULL", "N", "S", "E", "W", "U", "D", "NE", "NW", "SE", "SW", "I", "O" };

// Member variables
private Room m_leadsTo = null;
private int m_direction;

// Full name of direction eg SOUTHEAST
private String m_directionName;

// Shortened version of direction eg SE
private String m_shortDirectionName;

// Default constructor
public Exit() {
   m_direction = Exit.UNDEFINED;
   m_leadsTo = null;
   m_directionName = dirName[UNDEFINED];
   m_shortDirectionName = shortDirName[UNDEFINED];
   }
   
// Full constructor
public Exit( int direction, Room leadsTo ) {
   m_direction = direction;
   
   // Assign direction names
  if (direction <= dirName.length ){
      m_directionName = dirName[m_direction];
   }
   if (direction <= shortDirName.length ){
      m_shortDirectionName = shortDirName[m_direction];
   }
   
   // Assign location
     m_leadsTo = leadsTo;
   }
   
   // toString method
  public String toString() {
      return m_directionName;
      }
     
   // Assigns direction name
  public void setDirectionName( String dirname ) {
      m_directionName = dirname;
      }
     
   // Returns direction name
  public String getDirectionName() {
      return m_directionName;
      }
     
   // Assigns short direction name
  public void setShortDirectionName ( String shortName ) {
      m_shortDirectionName = shortName;
      }
   // Returns short direction name
  public String getShortDirectionName () {
      return m_shortDirectionName;
      }
     
   // Assigns location
  public void setLeadsTo ( Room leadsTo ) {
      m_leadsTo = leadsTo;
      }
     
   // Returns location
  public Room getLeadsTo ( ) {
      return m_leadsTo;
      }
}

Space Xscape Development Team
Space Xscape
Progress:----------
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2007-05-16 23:39:26 »

>unreachable statement

Means... the statement isn't reachable at all. Eg if there is a line of code below a return statement.

>missing return statement

Means... the function (which claims to return something in *ANY* case) doesn't return something (always or in some cases).

弾幕 ☆ @mahonnaiseblog
Offline noblemaster

JGO Ninja


Medals: 19
Projects: 9


Age of Conquest makes your day!


« Reply #2 - Posted 2007-05-17 00:43:25 »

I see your problem:
1  
2  
3  
4  
5  
6  
                        // Don't parse blank commands
        if (command.length() == 0) {
            return true;
         
         // Convert to uppercase for comparison
        command = command.toUpperCase();


You have to be careful with the "{" and "}"! You forgot one after the return!!!

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2007-05-17 01:05:55 »

wouldn't a mediocre ide allow you to pick this up without using any brain cycles?

It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Offline michael.becerra

Senior Newbie





« Reply #4 - Posted 2007-05-17 16:24:07 »

Thanks Guys. I'm using JCreator 4 Pro as my IDE.

Space Xscape Development Team
Space Xscape
Progress:----------
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (16 views)
2014-04-15 18:08:23

BurntPizza (14 views)
2014-04-15 03:46:01

UprightPath (27 views)
2014-04-14 17:39:50

UprightPath (12 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (51 views)
2014-04-10 04:04:31

BurntPizza (110 views)
2014-04-08 23:06:04

tom_mai78101 (211 views)
2014-04-05 13:34:39

trollwarrior1 (180 views)
2014-04-04 12:06:45

CJLetsGame (185 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!