Computer Science Canada Game, Fight Club |
Author: | xX_MayDay_Xx [ 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.....
|
Author: | codemage [ Tue May 09, 2006 9:36 am ] |
Post 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 ... |
Author: | HellblazerX [ Tue May 09, 2006 10:12 am ] | ||
Post 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:
You can also create a Random class, which is a random number generator class, but I'm not too sure how to use that. |
Author: | codemage [ Tue May 09, 2006 1:15 pm ] |
Post 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. |
Author: | Krabjuice [ Tue May 09, 2006 10:32 pm ] |
Post 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. |
Author: | xX_MayDay_Xx [ Wed May 10, 2006 5:44 am ] |
Post 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.... |
Author: | xX_MayDay_Xx [ Wed May 10, 2006 7:40 am ] |
Post 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. |
Author: | codemage [ Wed May 10, 2006 7:58 am ] |
Post 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. |
Author: | xX_MayDay_Xx [ Wed May 10, 2006 4:34 pm ] |
Post subject: | |
WOW....you can do that, that would help alot.........ummm...how would you do that? |
Author: | [Gandalf] [ Wed May 10, 2006 4:55 pm ] |
Post 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. |
Author: | xX_MayDay_Xx [ Mon May 29, 2006 7:05 am ] | ||
Post 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.
|
Author: | wtd [ Mon May 29, 2006 9:56 am ] | ||
Post subject: | |||
Whoa....
Completely ignoring the use (or lack thereof) of whitespace, and "else" hugging, I'm guessing no one ever taught you about "else if". |
Author: | xX_MayDay_Xx [ Mon May 29, 2006 5:08 pm ] |
Post 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 |