Home arrow static arrow Java Programming [Archive] - Cat Game
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Cat Game
This topic has 2 replies on 1 page.

Posts:2
Registered: 7/5/04
Cat Game  
Jul 5, 2004 11:30 AM



 
howdy ho!

i am trying to write a programme and have some problems.i have made a class of cats,a class of food and a class of toys. in the main probramme i have defined a specific cat, 4 toys and 4 food types.everzthing is made in a textual mode couse i do not know how to work with graphics yet.
the cats health ,playfullness snd cuddle level are randomlz generated each time the programme is started.my problems began with the cat s feeding method. only when i feed it a cookie it s health rises by the corect amount of health points.if i feed it anz other food type i get the incorrect amount of health points. i tried rearranging some of the variables and the ranndom generator but to no avail.

what did I do wrong? I am enclosing the cats class and the main programme.I use TextIO.class for input processing.

here is the cats class>>>
public class Cats{
int health;
int play;
int cuddle;

String name;
String sex;
String color;

//constructor
public Cats(String ime, String spol, String boja)

{name=ime;
sex=spol;
color=boja;

}


//ABOUT THE CAT

//What's your name?
public String sayName(){return name;}

//What's your sex?
public String saySex(){return sex;}

//What's your color?
public String sayColor(){return color;}

//WHAT CAN YOU DO TO IT

//Feed the *****
public void feedPussy(int feedit){health+=feedit;}

//Play with your *****
public void playPussy(int playit){play=play+playit;}

//Stroke your *****
public void cuddlePussy(int cuddleit){cuddle=cuddle+cuddleit;}

//REPORT IT'S STATE

//How much energy?
public int sayHealth(){return health;}

//How much playfulness?
public int sayPlay(){return play;}

//How much cuddling?
public int sayCuddle(){return cuddle;}

//end class
}


and the main programme>>>>>

public class catGame{

//variables
static char input, input2;

public static void main(String args[]){

//Define what food you can feed the cat
Foods mouse = new Foods("mouse",25);
Foods whiskas = new Foods("Whiskas",15);
Foods milk = new Foods("milk",10);
Foods cookie = new Foods("cookie",5);

//Define what toys it can play with
Toys rubberMouse = new Toys("rubber mouse",25);
Toys twineBall = new Toys("ball of twine",15);
Toys pieceOfCrap = new Toys("piece of ****",10);
Toys booger = new Toys("booger",5);

//create kitty
Cats bucek = new Cats("Bucek","male","orange");
bucek.health=(int)(Math.random()*99+1);
bucek.play=(int)(Math.random()*99+1);
bucek.cuddle=(int)(Math.random()*99+1);

//Display kitty stats
System.out.println("Hi! My name is "bucek.sayName()"."+"I am "bucek.saySex()".");
System.out.println("My fur is "bucek.sayColor()".");
System.out.println("###########################################################");
System.out.println(" Health Playfulness Cudleness ");
System.out.print(" "bucek.sayHealth()" "+bucek.sayPlay());
System.out.println(" "+bucek.sayCuddle());

//Create and display User Interface

System.out.println("[f] Feed your kitty");
System.out.println("[p] Play with kitty");
System.out.println("[c] Cuddle with kitty");
System.out.println("[q] Quit");

//Get Input
input=TextIO.getlnChar();

//Process Input
switch (input) {

case 'f':

//Display Food menu
System.out.println("[m] mouse");
System.out.println("[w] Whiskas");
System.out.println(" milk");
System.out.println("[c] cookie");

//Get Input
input2=TextIO.getlnChar();

//Process Input
switch (input2) {

case 'm' : bucek.feedPussy(mouse.sayFoodPoints());
case 'w' : bucek.feedPussy(whiskas.sayFoodPoints());
case 'i' : bucek.feedPussy(milk.sayFoodPoints());
case 'c' : bucek.feedPussy(cookie.sayFoodPoints());
default : break;
};

case 'm': ;
case 'p': ;
case 'c': ;

default: System.out.println();
System.out.println("Bye!");

//end Interface Input
}

System.out.print("I ate and have " + bucek.sayHealth());

//end main
}

//end catGame
}

 

Posts:27,518
Registered: 11/3/97
Re: Cat Game  
Jul 5, 2004 11:46 AM (reply 1 of 2)



 
When you post code using the code tokens...

http://forum.java.sun.com/features.jsp#Formatting

You have a switch statement. Each case falls through to the next one unless you use a 'break' for each case. So that means that you call feedPussy() more than once.

 

Posts:2
Registered: 7/5/04
Re: Cat Game  
Jul 5, 2004 3:39 PM (reply 2 of 2)



 
thanx! I corrected it. I even added some ascii cat graphics to be a little more interesting.

|\__/,| (`\
|_ _ |.--.) )
( T ) /
(((^_(((/(((_>

I was wondering what should the object of the game be. if the goal was to reach 100 points in all
characteristics, that would be over verz soon. any suggestions?
 
This topic has 2 replies on 1 page.