Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Game, Fight Club
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xX_MayDay_Xx




PostPosted: Tue May 09, 2006 8:50 am   Post subject: Game, Fight Club

im having trouble with a game im making, Its basic fighting game, with no graphics, and i have the bare basic's of it down....and by bear basics i mean, i made it so you can choose what action to take against your opponent.

any way, i need some help in 3 areas. the first being the AI..I don't know how to make the computer select a random number between 1-4 and then use the correct command....the second is when one person blocks, i need that varaiable to be pulled over so they dont take any damage...and thats were the third problem lies, I dont have a damage system yet, What i would like to eventually have is that a Kick gives between 20-30 damage but has a 60% chance to hit, and a Hook gives between 15-20 damage with a 70% chance to hit...and a jab gives between 10-15 damage with a 100% chance to hit.

I know this is very confusing, and i am a huge N()()B when it comes to prog- so any help would be greatly appreciated.......oh and heres my code so far.....

code:
public class Fightclub
{
        public static void main (String[]args)
        {
                //The variables of the game
                String a;
                int b;
               
/* The first few lines are the rules given by the Movie "Fight club"
of which the game is based off of*/

                System.out.println("*Welcome to fight club*");
                System.out.println();
                System.out.println("1st rule- You do not talk about Fight Club");
                System.out.println("2nd rule- YOU DO NOT TALK ABOUT FIGHT CLUB");
                System.out.println("3rd rule- If someone says stop,Goes limp, Taps out, The fight is over");
                System.out.println("4th rule- Two guys to a fight");
                System.out.println("5th rule- One fight at a time");
                System.out.println("6th rule- No shirts, No Shoes");
                System.out.println("7th rule- Fights will go on as long as they have to");
                System.out.println("8th rule- If this is your first time playing fight club....you have to fight");
                System.out.println("");
               
                //Asking for the users name, To add a more personal feel
                System.out.println("Plz Enter your first name");

                a = In.getString();

                System.out.println("Welcome "+a+", To Fight club");
                System.out.println("");
                //The instructions to the game
               
                System.out.println("*instructions*");
                System.out.println("Select either, Hook, Kick, Jab,or Block"
                                                        +" by pressing the number that corrisponds with it");
            System.out.println("You have 100 health, When you take a hit it will go down");
            System.out.println("the same with your opponent");

            System.out.println("");
            System.out.println("");
            System.out.println("You enter the "+a+" ring and face your opponent");
            System.out.println("what do you do?");
            System.out.println("1.Hook");
            System.out.println("2.Kick");
            System.out.println("3.Jab");
            System.out.println("4.Block");

/*The working of the game, and depending on what the user input's
a differnt actons is taken and this results in what will happen in the end*/

            b = In.getInt();
            if (b==1){
                        System.out.println("You give a right hook at your opponet");
                }else{
                        if(b==2){
                                System.out.println("You kick at your opponent");
                        }else{
                                if(b==3){
                                        System.out.println("you give a jab towards your opponent");
                                }else{
                                        if(b==4){
                                                System.out.println("You block, you will take no damage during opponets attack");
                                        }else{
                                                System.out.println("Not valid, Enter a number between 1&4");
                                        }
                                }
                        }
                }



        }
}
Sponsor
Sponsor
Sponsor
sponsor
codemage




PostPosted: Tue May 09, 2006 9:36 am   Post subject: (No subject)

Randomness comes from the function
Rand.Int(low,high)

which returns a value between the range of low & high.

ie
Rand.Int(1,100)
will give you a number between 1 and 100.

Do this from 1-4 to pick a computer attack.

To check hit %, ie for 60% hit, you'd do
if Rand.Int(1,100) < 60 then
...
HellblazerX




PostPosted: Tue May 09, 2006 10:12 am   Post subject: (No subject)

codemage wrote:
Rand.Int(low,high)


lol, wrong language man. That's Turing, and this is for Java help. One way is to use the Math.random () method, but this returns a double value between 0 and 1. So, to make it so you can randomly choose from 1 to 4 is like this:

code:
compChoice = (int) (Math.random () * 3) + 1;


You can also create a Random class, which is a random number generator class, but I'm not too sure how to use that.
codemage




PostPosted: Tue May 09, 2006 1:15 pm   Post subject: (No subject)

Jeez... that's what happens when you read through a bunch of posts on Turing before hitting the real languages.

The sentiment stays the same though.
For percentage functions, scale Math.Random to 100 (here, you don't even have to round it to an int) and check if it's under your threshold.

I might be wrong - but I think that the random classe always generates the same number set? Math.Random at least pretends to be random.
Krabjuice




PostPosted: Tue May 09, 2006 10:32 pm   Post subject: (No subject)

Just so you don't get the wrong impression, you're still running on psuedo-random numbers. Either technique, the Math method or the Random class will give you a somewhat random number.
xX_MayDay_Xx




PostPosted: Wed May 10, 2006 5:44 am   Post subject: (No subject)

ok thanks for the help....but im still having trouble getting a variable to get carried over, like when the computer or someone blocks....how do i do that......(example: Billy, You block,........computer, throws a hook but it was blocked)...........and what would be really good if there was someway to make it so blocking would only work 80% of the time....
xX_MayDay_Xx




PostPosted: Wed May 10, 2006 7:40 am   Post subject: (No subject)

ok, im having a problem with my random selection, The segment of code works...but how would i get it to select a random number between 15 and 20.....or anything with defined peramiters.
codemage




PostPosted: Wed May 10, 2006 7:58 am   Post subject: (No subject)

You might find it useful to create your own random function instead of scaling Math.Random every time in the main body of your code.
Sponsor
Sponsor
Sponsor
sponsor
xX_MayDay_Xx




PostPosted: Wed May 10, 2006 4:34 pm   Post subject: (No subject)

WOW....you can do that, that would help alot.........ummm...how would you do that?
[Gandalf]




PostPosted: Wed May 10, 2006 4:55 pm   Post subject: (No subject)

First you must learn how to create methods in Java. The Introduction to Java by wtd (in the [Java Tutorials] section) is a good place to learn this. Done? Ok...

Create a method which returns an integer and takes two (or one, depends) parameters, one for the minimum random value and one for the maximum. Do the calculations neccessary to find that random number, and return the resulting value.
xX_MayDay_Xx




PostPosted: Mon May 29, 2006 7:05 am   Post subject: (No subject)

ok.....its almost done....im just having trouble with the blocking system, i dont know how to carry over, that value onto the next phase...also im having trouble with the.... 'While statements' for some reason it will pick up one or the other but not both....any help would be greatly apperciated.....ps...i do know that it is a little confusing to read and i am working on that as well.


code:
public class Fightclub
{
        public static void main (String[]args)
        {
                //The variables of the game
                String a;
                int b,c,z,x;
                int Health,cHealth;
                Health=(100);
                cHealth=(100);

/* The first few lines are the rules given by the Movie "Fight club"
of which the game is based off of*/

                System.out.println("*Welcome to fight club*");
                System.out.println("");
                System.out.println("1st rule- You do not talk about Fight Club");
                System.out.println("2nd rule- YOU DO NOT TALK ABOUT FIGHT CLUB!");
                System.out.println("3rd rule- If someone says stop,Goes limp, Taps out, The fight is over");
                System.out.println("4th rule- Two guys to a fight");
                System.out.println("5th rule- One fight at a time");
                System.out.println("6th rule- No shirts, No Shoes");
                System.out.println("7th rule- Fights will go on as long as they have to");
                System.out.println("8th rule- If this is your first time playing fight club....you have to fight");
                System.out.println("");

                //Asking for the users name, To add a more personal feel
                System.out.println("Plz Enter your first name");

                a = In.getString();

                System.out.println("Welcome "+a+", To Fight club");
                System.out.println("");
                //The instructions to the game

                System.out.println("*instructions*");
                System.out.println("Select either, Hook, Kick, Jab,or Block"
                                                        +" by pressing the number that corrisponds with it");
            System.out.println("You have 100 health, When you take a hit it will go down");
            System.out.println("the same with your opponent");
            
            while(cHealth>0){
                        while(Health>0){
                               
            System.out.println("");
            System.out.println("");
            System.out.println(a+", you have "+Health+"% health left....");
            System.out.println("what do you do?");
            System.out.println("1.Hook");
            System.out.println("2.Kick");
            System.out.println("3.Jab");
            System.out.println("4.Block");

/*The working of the game, and depending on what the user input's
a differnt actons is taken and this results in what will happen in the end*/


            b = In.getInt();
            if (b==1){
                        System.out.println(a+" gives a right hook at their opponet");
                        z=(int) (Math.random () * 19) + 1;
                        cHealth=(cHealth-z);
                        System.out.println("And deals "+z+" Damage");
                }else{
                        if(b==2){
                                System.out.println(a+" kick's at their opponent");
                                z=(int) (Math.random () * 29) + 1;
                                cHealth=(cHealth-z);
                            System.out.println("And deals "+z+" Damage");
                        }else{
                                if(b==3){
                                        System.out.println(a+" gives a jab towards their opponent");
                                                                        z=(int) (Math.random () * 9) + 1;
                                                                        cHealth=(cHealth-z);
                                                System.out.println("And deals "+z+" Damage");
                                }else{
                                        if(b==4){
                                                System.out.println(a+" blocks, and has a chance to"
                                                                   + "take no damage during opponets attack");

                                        }else{
                                                System.out.println("Not valid, Enter a number between 1&4");
                                        }
                                }
                        }
                }

                System.out.println("");
                System.out.println("");

/*This is the Computers basic AI (Artificial Intellegence) system
it select's a random number between 1 and 4 slecting one of the actions to take*/
        System.out.println("the computer has "+cHealth+"% health left....");
       c =(int) (Math.random () * 3) + 1;
       if (c==1){
                   System.out.println("The computer gives a hook at thier opponent");
                        x=(int) (Math.random () * 19) + 1;
                                  Health=(Health-x);
                        System.out.println("And deals "+x+" Damage");
           }else{
                   if (c==2){
                           System.out.println("The computer kicks at thier opponent");
                                x=(int) (Math.random () * 29) + 1;
                                          Health=(Health-x);
                        System.out.println("And deals "+x+" Damage");
                   }else{
                           if (c==3){
                                   System.out.println("the computer gives a jab towards their opponent");
                                        x=(int) (Math.random () * 9) + 1;
                                                  Health=(Health-x);
                        System.out.println("And deals "+x+" Damage");
                                   }else{
                                           if (c==4){
                                                   System.out.println("the computer block's, and has a chance"
                                                                      +"to take no damage on opponents turn");
                                                                                  }
                                                                                  }
                                                                                  }
                                                                          }
                                                                  }
                                                          }
        }
}
wtd




PostPosted: Mon May 29, 2006 9:56 am   Post subject: (No subject)

Whoa....

code:
if (b==1){
    System.out.println(a+" gives a right hook at their opponet");
    z=(int) (Math.random () * 19) + 1;
    cHealth=(cHealth-z);
    System.out.println("And deals "+z+" Damage");
}else{
    if(b==2){
        System.out.println(a+" kick's at their opponent");
        z=(int) (Math.random () * 29) + 1;
        cHealth=(cHealth-z);
        System.out.println("And deals "+z+" Damage");
    }else{
        if(b==3){
            System.out.println(a+" gives a jab towards their opponent");
            z=(int) (Math.random () * 9) + 1;
            cHealth=(cHealth-z);
            System.out.println("And deals "+z+" Damage");
        }else{
            if(b==4){
                System.out.println(a+" blocks, and has a chance to"
                    + "take no damage during opponets attack");
            }else{
                System.out.println("Not valid, Enter a number between 1&4");
            }
        }
    }
}


Completely ignoring the use (or lack thereof) of whitespace, and "else" hugging, I'm guessing no one ever taught you about "else if".
xX_MayDay_Xx




PostPosted: Mon May 29, 2006 5:08 pm   Post subject: (No subject)

yeah......im working on that whole making it look pretty thing....for some reaso i dont like pretty and neat...i cant find anything.....and no i was never taught else if statements....and i am still working on getting the blocking system to work
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: