I can't get my game to work

Discussion in 'Programming General' started by ClubEric, Mar 10, 2012.

I can't get my game to work
  1. Unread Mar 10, 2012 at 10:59 PM
  2. Joined:
    Oct 5, 2009
    Posts:
    10
    Location:
    East Coast (not going into specifics)
    ClubEric

    ClubEric Newcomer

    I can't get my game to work

    anyone that helps me gets a free copy KT4W ( a vb.net program me and a friend are about to release)...we plan to sell it for $5
    I've been working on the User class and my setters, getters, and constructor are never happy You can download my progress so far here: Camelot.zip If somebody could do just ONE of the Animated subclasses (user, knight, or peasant) i would greatly appreciate it. I'm using Eclipse (Helios) btw. This is due Monday, March 12th.
    Thank you - ClubEric.

    I suggest you check the java docs for this game here: Javadoc documents for Camelot

    Below are the instructions to my assignment:


     
  3. Unread Mar 11, 2012 at 7:28 PM
  4. Joined:
    Aug 16, 2007
    Posts:
    1,002
    The Fat Controller

    The Fat Controller Guru

    I can't get my game to work

    Put your cursor into the main code editing window in Eclipse, hit alt+shift+s and choose the generate getters and setters button. Check the boxes next to the variables you want to create getters and setters for, and Eclipse should generate them automatically.

    Unless you want to override the getters/setters in child classes, you only need to have them defined in the class that defines the variable. For instance, you only seem to need to have methods like these defined in Thing, not child classes like User or Animated.

    Code:
    public void setCol(int col){
    		//Set my col to col
    	}
    
    Disclaimer: I don't do Java.
     
  5. Unread Mar 12, 2012 at 2:47 AM
  6. Joined:
    Oct 5, 2009
    Posts:
    10
    Location:
    East Coast (not going into specifics)
    ClubEric

    ClubEric Newcomer

    I can't get my game to work


    thanks alot man, you're right i don't need them in the user, knight or peasant classes

    Code:
    public void move(){
    		// Half the time a peasant is too weak to move. He says so. 
    		//The other half he moves randomly into one of the four directions: N,S,E,W.  
    
    
    
    		//      column
    		//
    		//		 0 1  2  3  4  5
    		//		0
    		//		1     N
    		//  row         2   W o E
    		//		3     S
    		//		4
    		//		5
    
    		int randomTry = (1 + (int)(Math.random()*2)); // "coin flip"
    
    		if (randomTry == 1){
    
    			int randomDir = (1 + (int)(Math.random()*4));
    
    			switch (randomDir) {
    			case 1:  
    				r=r-1; //N
    				break;
    			case 2:  
    				r++; //S
    				break;
    			case 3:   
    				c++;//E
    				break;
    			case 4:   
    				c=-1; // W
    				break;
    			}
    		}
    		else{
    		System.out.println("Peasant too weak to move");
    			//do nothing
    		}
    now i just have to figure out how to get this ^^^ to change his row and column. Any suggestions?
     
  7. Unread Mar 12, 2012 at 3:31 AM
  8. Joined:
    Aug 16, 2007
    Posts:
    1,002
    The Fat Controller

    The Fat Controller Guru

    I can't get my game to work

    Code:
    if(Math.random() >= 0.5f) // x is >=0.5 in the range 0-1 half the time
    {
      double randomDir = Math.random() * 4;
      if(randomDir >= 0 && randomDir <= 1)
      {
         r--;
      }
      //else if...
    
      if(r < 0) // wrap around
      {
          r = 10;
      }
      if(r > 10)
      {
          r = 0;
      }
      // etc etc
    }
    
    
    By the way, it looks like your randomTry would be 1 less than half the time. 1 + (Math.random*2) would be 2 on average, since I'm guessing Java rounds values to the nearest integer when typecasting.
     
  9. Unread Mar 14, 2012 at 11:24 PM
  10. Joined:
    Mar 14, 2012
    Posts:
    6
    Alidatpro

    Alidatpro Newcomer

    I can't get my game to work

    Yeah bro same prob here, I have to always download the client to play, idk why though :(
     
< What are your opinions on the new Microsoft Visual Studio 11? | fatal error C1853 >

Users viewing this thread
1 guest