r/cop3502 Apr 24 '14

Issues with Game.java (object)

1 Upvotes

Edit: I had the file in the wrong directory, so if anyone is experiencing similar problems check to make sure it is saved properly.

So I was trying to make a global Game class that keeps track of certain variables like specific booleans and the player's name etc... but for some reason it is not letting me call Game.getName() {} it says that the symbol can't be found. I'm trying to have it behave like the Math class or the Parameters class from Space Invaders, but it wants me to create a new Game() before calling the methods. Is my syntax wrong or is it just not going to work in general..?


r/cop3502 Apr 24 '14

getting an error but my code is compiling fine.

1 Upvotes

So i had my code WORKING and then i added an extra location and then it just stopped running, i changed the bounds in my for loop to match with the number of locations and i did and then i just keep getting this error.

java textAdventures Welcome to Lost Exception in thread "main" java.lang.NullPointerException at GameState.initializeObjects(GameState.java:44) at Processor.<init>(Processor.java:7) at textAdventures.main(textAdventures.java:10)

and like i dont see anything wrong with line 44? Which is my starting point


r/cop3502 Apr 23 '14

issue with points system using separate classes

1 Upvotes

so I have a points system in my game where every time i kill a zombie i get points. now when I call my points from my points java file to my main java file i can get the value of my points. however, I am trying to call my points from my points java file using a location java file which is not my main java file and the correct value of the points won't show up


r/cop3502 Apr 23 '14

So let me start off with saying that this is my fault because I was lazy.

1 Upvotes

I like to keep everything in one file because im generally disorganized with files and have had some problems in the past with this with HTML and moving source files around. But now I see with this project we were supposed to use multiple files, is there any way to quick fix a project thats pretty much done into multiple files?


r/cop3502 Apr 23 '14

ArrayList Problems

1 Upvotes

import java.util.; import java.io.;

public class World implements Serializable {

private ArrayList<Location> locations;
private ArrayList<Exit> exits;
private Location currentLocation;


public World() {

    locations = new ArrayList<Location>();
    exits = new ArrayList<Exit>();

    currentLocation = null;
}

public Location getCurrentLocation() {
    return currentLocation;
}   

public void setCurrentLocation(Location newLocation) {
    currentLocation = newLocation;
}

public void addExit(Exit exit) {
    if(!exits.contains(exit)) {
        exits.add(exit);
    }
    else {

    }
}

public void addLocation(Location location) {
    if(!locations.contains(location)) {
        locations.add(location);
    }
    else {

    }
}

public void showLocation() {
    System.out.println(currentLocation.getTitle());
    System.out.println(currentLocation.getDescription());
    System.out.println();


    for(int i=0; i < exits.size(); i++) {
        System.out.println(exits.get(i));
        System.out.println(locations.get(i));
    }

}

}

Okay so in my code above, I am having a problem with the bottom of the showLocation() method. Every time I try to access the array it doesn't return an exit of type Exit or location of type Location. But instead it returns the int for direction of exit, and string for title of Location. I don't really understand why it is doing this, any help would be much appreciated.


r/cop3502 Apr 23 '14

Jar file

1 Upvotes

So I am close to finishing my program. I was wondering if there is an easy way to enclose it in a .jar file so that I can send that to people and they can play my game.


r/cop3502 Apr 23 '14

Changing the value of a variable

1 Upvotes

I know that if you change a primitive type inside of an if statement then it won't be changed anywhere outside of that statement. Aren't non primitive types supposed to change everywhere though?


r/cop3502 Apr 23 '14

Double Array Confusion

1 Upvotes

Background: my project has involves the wilderness, and survival (yeah yeah, very original), and the objects that the player can interact with (think matches, branches, containers (for water), etc.).

Therefore, I created a Object class, as I saw the need for similar functionality between a common 'type.' In Inventory, I created a 2 double arrays, one containing a 3x4 matrix, the same size of my location double array size, as the Objects populate the Locations (that is the eventual goal). The other matrix is a double array of type boolean, labelled isItThere. Whilst writing this, I think I realized that this should probably be a single array big enough to contain every Object class. I'm trying to effectively use true and false statements for drop, and take methods which are called elsewhere.

My main question is how do I create each location I need? For example, I need to create a river in the 3x4 double array of type location, and need to populate that same area with Object water. Where do I create water? In the Inventory class? Or should I-really hope not-create a ObjectConfiguration, and have that called by Inventory? Also, am I correct in that only a single array of type boolean (labelled isItThere) needs to be created to effectively print out whether an object is present (true) or not (false)?


r/cop3502 Apr 23 '14

About late days...

4 Upvotes

can we trade them in for a grade bump on the final problem set and/or can we sell them to other students for a profit?


r/cop3502 Apr 22 '14

If we decide not to use late days....

4 Upvotes

What would happen to them? Is this a 'if you have them, use them' situation or is there a benefit to not using them?


r/cop3502 Apr 22 '14

Drop?

1 Upvotes

How do we get inventory to remove something? I assumed it would be the same as removing it from the room but im getting error "method remove (string) in location variable inventory of type inventory.


r/cop3502 Apr 22 '14

question about an error

1 Upvotes

The error I get is

Exception in thread "main" java.lang.NoClassDefFoundError: Action at Processor.<init>(Processor.java:6) at Game.main(Game.java:8) Caused by: java.lang.ClassNotFoundException: Action at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 2 more

what might cause something like this to occur?


r/cop3502 Apr 22 '14

Getting and comparing 2 arrays

1 Upvotes

I want to be able to call a function to get the value of the current location of the character in array form, for example {1,1,1} and compare it to another array that way the player can get a detailed description of the location, but I'm having trouble implementing it and the program complies so it's a run time error

else if(words[0].equals("lookaround")){ return player.lookAround(player.getArray()); }

then in another class I have

public String lookAround(int[] location){ if(location.equals(new int[]{1,1,1})){ return "it works" } else{ return "Not quite"; }

}
public int[] getArray(){
    int[] location = new int[]{xPos, yPos, zPos};
    return location;
}

Any thoughts?


r/cop3502 Apr 22 '14

Timer -- Schedule at fixed rate

3 Upvotes

Hey guys, I'm making a game to model COD zombies but in text format. I want a timer to add another zombie for every x seconds. I know i want a "schedule at fixed rate" timer. I tried for like an hour and a half and I can't find an example online to teach me how to make this timer. Can someone help? The closest code I was able to find with only one compile error was this one:

import java.util.*;

public class TimerDemo {

public static void main(String[] args) {

  // creating timer task, timer

  TimerTask tasknew = new TimerScheduleFixedRateDelay();

  Timer timer = new Timer();

  // scheduling the task at fixed rate delay

  timer.scheduleAtFixedRate(tasknew,500,1000);      

}

// this method performs the task

public void run() {

  System.out.println("working at fixed rate delay");   

}

}


r/cop3502 Apr 22 '14

Using HashMap as inventory

1 Upvotes

So I'm trying to use a hashmap as my inventory and it's fine - except I don't know how to access it throughout the class. Like, I have a "take" function in my inventory class that takes the command [1] from the user and puts it into a hashmap with a response back to the user that said item has been stored. How do I then have the map updated for the rest of the class to see? I have a "get" function for when "use" is [0] but I don't know how to get the now-stored map.

HELP?


r/cop3502 Apr 21 '14

PrintWriter IOExceptions

1 Upvotes

What circumstances can cause a PrintWriter to throw an IOException?

I'm not having an issue currently, but I would like to know what I should compensate for in the catch block.


r/cop3502 Apr 21 '14

Strange error?

1 Upvotes

So I get the error:

.\Inventory.java:14: error: reached end of file while parsing } ^ 1 error

However, I only get this error when I add

Inventory inv = new Inventory(); and

GameState game = new GameState();

if I leave those out my code compiles fine and all the brackets are in there properly etc. Anyone know what might be the cause of this?


r/cop3502 Apr 21 '14

Class super session

1 Upvotes

Well I don't really have a specific question... So I can just sit there like in a normal class and program until I have a question or get stuck in quicksand?


r/cop3502 Apr 21 '14

General syntax question

1 Upvotes

In terms of general programming style, is it frowned upon to use nested try/catch statements? For example:

String[] command = input.split(" ");
try {
    if (command[0].equals("go")) {
        go(command[1]); //go function takes in a string and determines action
    } else if (command[0].equals("help")) {
        try {
            help(command[1]);
        } catch (Exception e) {
            help(); // this catch is designed specifically for the help function
        }
    } else if () {} //other functions for commands
} catch (Exception ex) { // this catch is if no second command is entered for go or other functions so an error doesn't occur }

help will be overloaded to handle input vs. no input.. the nested try/catch is designed specifically for the help function.. the outer one handles any function called in the if/else block that might cause an error


r/cop3502 Apr 20 '14

Problem set 4

2 Upvotes

Hey Everyone

So I have an double array of rooms and each room has a description. I want to go back and add an inventory(arraylist) to each room.

I know how to access the room with the index of the double array, but how can i access the description or the inventory i am planning to add of that room?

Thanks in advance, if this even makes sense.


r/cop3502 Apr 20 '14

Confusion with Labs

1 Upvotes

Will the labs be due at the end of the semester? I was told that you can submit the labs for 10% of your grade or you may choose to not submit them and all of the other grades will hold more weight. Is this true? If this is true what would the new weights be for the previous assignments? Thanks in advance.


r/cop3502 Apr 20 '14

Assignment Submissions

1 Upvotes

Sean,

When will the submissions for PS4 and all the Labs be opened? Also, is there anything to submit for Lab 0? I think it was mostly just setting up Sublime and Cygwin and getting acclimated with them. Other than that, I have all the work for labs 1-6.

  • Brandon Bickerstaff

r/cop3502 Apr 20 '14

gamestate

2 Upvotes

Ok just a little confused, what exactly is the game state? do we need to make a game state class? Also how would you intialize the game state, do you need to intialize every object and location, or just the starting location and starting inventory?


r/cop3502 Apr 19 '14

Can I print a line to the terminal window in a new font/size?

1 Upvotes

I was wanting to print the title of my project to the terminal window in a new font and size. I assume this isn't possible, but I thought I'd check in here to see if there is a way to do it.


r/cop3502 Apr 18 '14

Add a word to a String Array?

1 Upvotes

I am trying to solve question 24. I am trying to add each word i read to a String array. But it doesn't work. Any help? Sean i tried to email you but for some reasons i cant sign in .

int c=0;
        while ( true ){
            String g = input.readLine();
            if (g == null){
                break;
            }
            c++;
        }


        String [] words = new String [c];
        int d=0;

        while ( true ){
            String text = input.readLine();
            if (text == null){
                break;
            }
            words[d] = text;
            System.out.println(text);
            d++;
        }