Computer Science Canada Making a Game |
Author: | dymd3z [ 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 |
Author: | Drakain Zeil [ 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 |
Author: | ericfourfour [ 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. |
Author: | CodeMonkey2000 [ 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. |