Making a Game
Author |
Message |
dymd3z
|
Posted: Mon Apr 30, 2007 8:08 am Post subject: Making a Game |
|
|
I have to make a game for an assignment but I'm stuck on changing a characters weapon. I'm trying to get it to work by pressing a number between 1 and 5 using a case structure to switch the characters equipped item whenever a number between 1 and 5 is chosen. I know I need a string variable to store the names of the items but i just cant get it to work xD |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Drakain Zeil
|
Posted: Mon Apr 30, 2007 3:37 pm Post subject: RE:Making a Game |
|
|
Based on what you've said, you should probably think about re-structureing your code.
You could store the strings in an array, for example
itemName(1)="knife"
itemName(2)="sword"
itemName(3)="gun"
etc...
Then have the character use weapon number _whatever_. You can easily do all this using structures, and have:
item(1).name = "gun"
item(1).damage=4000
item(1).blah=blah blah
And the character could have things like:
player.name="Jim the hobo"
player.weapon=1
and so on
here are plenty of tutorials on-site for structures |
|
|
|
|
|
ericfourfour
|
Posted: Mon Apr 30, 2007 6:58 pm Post subject: RE:Making a Game |
|
|
Look up Zylum's bitwise operators tutorial. It contains one approach to this situation. |
|
|
|
|
|
CodeMonkey2000
|
Posted: Mon Apr 30, 2007 7:17 pm Post subject: RE:Making a Game |
|
|
Or just use enumerated types. It's easier. If you aren't sure what that is, it's somewhere in the Turing Walkthrough. |
|
|
|
|
|
|
|