ExpoExe's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
7 (0.01 per day)
Joined:
10-January 13
Profile Views:
92
Last Active:
User is offline Jan 21 2013 09:52 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   ExpoExe has not set their status

Posts I've Made

  1. In Topic: Variable value is not changing with array

    Posted 12 Jan 2013

    Thank you so much for the help. With your guys; help I am now able to run the main class and it will show the correct room. I can also navigate through the array! Aha I am so happy :) thank you all. But now a problem I have run into is when you try to travel outside of the array and it throws a
    java.lang.ArrayIndexOutOfBoundsException
    

    We have not learned how to deal with this in class yet, so if any of you could help me with that I would be very happy. I have heard the term "Catch" used, but I do not know what it means/does.

    Also, using arrays is a really good idea for the roomTitle and roomDescription, but what to do about the other things, like (multiple) objects in the room?
  2. In Topic: Variable value is not changing with array

    Posted 12 Jan 2013

    Haha if statements are my go-to if I feel overwhelmed. Each one looks like this

    if (place == 0){
    		roomTitle = "[Spawn Room]";
    		roomDescription = "spawn";
    	}
    	if (place == 1){
    		roomTitle = "Derp";
    		roomDescription = "Herp";
    	}
    
    


    For now I am trying to get the moving around part of my program done, but later I will add more variables to each room, varying from room to room(items, keys, objects, etc.).
  3. In Topic: Variable value is not changing with array

    Posted 12 Jan 2013

    View Postjon.kiparsky, on 12 January 2013 - 03:23 PM, said:

    This is your method.

    What comes after it is not part of a method, so it's part of the class.

    There's a piece of Java syntax called an initialization block, which you won't have got to yet - that's what you've got here. Because you got confused about where your method ends, Eclipse tried to suggest what it thought you wanted, but it was wrong.

    You can read up on initializer blocks here, but it's not what you're looking for, I think.

    (This is one of the many reasons why I always say you shouldn't use an IDE until you understand the language, but that's another discussion)
    
    		int room[][]={{0, 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}};
    		
    

    If your array will always have this form, you can just calculate room from x,y by simple arithmetic.
    room = 7*y + x;
    


    No need to construct the array at all. Do you see why that works?


    This was very helpful. Thank you. I see why I don't even need to use an array, but just to try to make things a little more complicated and challenging I would like to implement a multidimensional array in my project. I remember reading about initialization blocks a little bit, but the book did not go into depth because it didn't expect us to be making our own classes yet. so to solve my problems could I just
    public Rooms(){
    		
    		int room[][]={{0, 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}};
    
    		
    		place = room[y][x];
    
    // 34 if statements for each room
    
    }
    
    
  4. In Topic: Variables from different class as array arguments

    Posted 10 Jan 2013

    Ah, thanks for the .equals. I totally forgot about that. When I say null I mean the output is the String null. The console outputs
    null
    null
    


    for
    System.out.println(Location.m_roomTitle);
    		System.out.println(Location.m_roomDescription);
    
  5. In Topic: Variables from different class as array arguments

    Posted 10 Jan 2013

    Thank you, I have made some progress, but now the entire program returns null. I cannot find the reason, so I will paste each class ://>

    public class Main {
    	
    	public static void main(String[] args) {
    		
    		Moving MovingObject = new Moving();
    		Location LocationObject = new Location();
    
    		System.out.println(Location.m_roomTitle);
    		System.out.println(Location.m_roomDescription);
    
    	}
    
    }
    
    
    

    public class Location 
    {
    	Rooms RoomsObject = new Rooms();
    	
    	// Member variables
    	public static String m_roomTitle;
    	public static String m_roomDescription;
    
    
    	// Assigns location title
    	public void setTitle(String roomTitle){
    		
    		m_roomTitle = RoomsObject.roomTitle;
    	}
    	
    	// Assigns room description
    	public void setDescription(String roomDescription){
    		
    		m_roomDescription = RoomsObject.roomDescription;
    	}
    	
    	// Returns location title
    	public String getTitle(){
    
    		return m_roomTitle;
    	}
    	
    	// Returns room description
    	public String getDescription(){
    		
    		return m_roomDescription;
    	}
    
    }
    
    

    import java.util.Scanner;
    
    public class Moving {
    
    	private int myY = 0;
    	private int myX = 0;
    	public static int x = 1;
    	public static int y = 1;
    
        Scanner scan = new Scanner(System.in);
        
        
    	
    	public void direction( String d ){ 
    		
    		// Converts input to coords
    		d = scan.nextLine();
    		
    		if (d == "N" || d == "North" || d == "n" || d == "north"){
    			myY += myY;
                        //etc.
    		}
    	 
        } 
    
        public void coord( int x, int y ){ 
        	myX = x; 
    		myY = y;
        }
        
        public int getX(){
        	return x;
        }
        public int getY(){
        	return y;
        }
    }
    
    

    public class Rooms {
    	
    	Moving MovingObject = new Moving();
    	public String roomTitle = "";
    	public String roomDescription = "";
    	
    	public void roomLocation(){
    
    		int room[][]={{0, 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}};
    	
    		
    		
    	int place = room[Moving.x][Moving.y];
    		
    	if (place == 0){
    		roomTitle = "Derp";
    		roomDescription = "Herp";
    	}
    	else
    		roomTitle = "LOL";
    		roomDescription = "YOULOSE";
    
    	}
    }
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

ExpoExe hasn't added any friends yet.

Comments

ExpoExe has no profile comments yet. Why not say hello?