Sythe     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe  
  Cheap RS Gold Store
I can't get my game to work
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 03-11-2012, 04:59 AM
ClubEric's Avatar
Newcomer
 
Join Date: Oct 2009
Location: East Coast (not going into specifics)
Posts: 10
Send a message via MSN to ClubEric
 
Question 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:


Quote:
You will implement the classes shown in in the figure, along with a Game class which holds the board description. The specific methods that each class will implement are explained in detail in the Javadoc documents for Camelot (which you must read and follow). Notice that the documentation tells you exactly which methods and which properties you need to implement for every class. The Animated class has a protected enum Direction {N,S,E,W}; which shows up as Animated.Direction in the javadocs.

The program will have a main in the Game class which looks like this:
Code:
Public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    Game g = new Game();
    g.add(new Sword(3,3));
    User user = new User(1,4);
    g.add(user);
    g.add(new Knight(5,5));
    g.add(new Peasant(9,5));
    g.add(new Peasant(6,7));
    g.add(new Peasant(4,8));
    g.add(new Peasant(7,2));
    g.add(new Peasant(3,5));
    String command = "";
    do {
      System.out.println(g); //print out the game board
      System.out.print("Your move:");
      command = keyboard.next();
      user.move(command); //move the user
      g.moveAll(); //move everyone
      g.resolveConflicts(); //resolve any conflicts between those in the same row,col
    } while (user.isAlive());
 }
A sample run of the program looks like:

__________
____Y_____
__________
___S_P____
________P_
_____K____
_______P__
__P_______
__________
_____P____

Your move:south
Knight moves S
Peasant moves E
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
__________
__________
____Y_____
___S_P____
________P_
__________
_____K_P__
__P_______
__________
______P___

Your move:west
Knight moves W
Peasant moves S
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves N
Peasant too weak to move.
Peasant too weak to move.
Peasant too weak to move.
______P___
__________
___Y______
___S_P__P_
__________
__________
____K___P_
__P_______
__________
__________

Your move:south
Knight moves W
Peasant moves N
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
User picks up Sword
__________
__________
__________
___Y__P_P_
__________
__________
___K______
___P____P_
__________
______P___

Your move:east
Knight moves W
Peasant too weak to move.
Peasant too weak to move.
Peasant moves E
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant too weak to move.
__________
__________
__________
____Y_P__P
__________
__________
__K_______
__P_____P_
__________
______P___

Your move:east
Knight moves S
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Bloodthristy Knight kills a P
__________
__________
__________
_____Y__P_
______P___
__________
__________
__K_______
________P_
______P___

Your move:south
Knight moves W
Peasant moves W
Peasant too weak to move.
Peasant moves W
Peasant too weak to move.
Peasant moves N
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
__________
__________
________P_
__________
_____Y____
______P___
__________
_K________
_______P__
_____P____

Your move:quit
Knight moves W
Peasant moves E
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant moves S
Peasant too weak to move.
Peasant too weak to move.


Basically, the user tells the User how to move (N,S,E,W). The knights move randomly (one of N,S,E,W) on each turn. The peasants flip a coin, if heads they stay put otherwise they move randomly (one ofN,S,E,W). The world is 10 by 10 and wraps around.

The resolveconflicts method is described in the javadocs. It goes over every Thing. If there is another Thing in the same row,col position then, if the Thing is a Knight it kills (removes) any Thing else there. If it is the user then if it finds the sword there it picks it up (thus killing it) and it is it a peasant it kills it.

I recommend you implement this program in the following order:
  1. The Thing hierarchy, start at the top and work your way down. Start with the properties, then the toString() methods, then the move() methods.
  2. The Game class, its properties and constructor.
  3. Game.toString(), test it.
  4. Game.add()
  5. Game.remove()
  6. Game.thingsAt()
  7. Game.moveAll(): this should just call move() on every thing.
  8. Finally, Game.removeConflicts()
__________________
Quickly snap and crop screen shots like a pro in just one simple motion!

Download SwiftScreen BETA today!


Last edited by ClubEric : 03-11-2012 at 05:24 AM.
Copy this message to clipboard Reply With Quote
  #2  
Old 03-12-2012, 12:28 AM
The Fat Controller's Avatar
Guru
 
Join Date: Aug 2007
Posts: 1,003
 
Default Re: 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.
Copy this message to clipboard Reply With Quote
  #3  
Old 03-12-2012, 07:47 AM
ClubEric's Avatar
Newcomer
 
Join Date: Oct 2009
Location: East Coast (not going into specifics)
Posts: 10
Send a message via MSN to ClubEric
 
Default Re: I can't get my game to work

Quote:
Originally Posted by The Fat Controller View Post
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.

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?
__________________
Quickly snap and crop screen shots like a pro in just one simple motion!

Download SwiftScreen BETA today!


Last edited by ClubEric : 03-12-2012 at 07:57 AM.
Copy this message to clipboard Reply With Quote
  #4  
Old 03-12-2012, 08:31 AM
The Fat Controller's Avatar
Guru
 
Join Date: Aug 2007
Posts: 1,003
 
Default Re: 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.

Last edited by The Fat Controller : 03-12-2012 at 08:48 AM. Reason: changed code
Copy this message to clipboard Reply With Quote
  #5  
Old 03-15-2012, 04:24 AM
Newcomer
 
Join Date: Mar 2012
Posts: 6
 
Default Re: 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
__________________
ThugLife
Copy this message to clipboard Reply With Quote
Reply



RS Gold Flash Sale Cheap RS Gold Store

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 09:45 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1