Jump to content

  • Log In with Google      Sign In   
  • Create Account

Varlun

Member Since 16 Nov 2012
Offline Last Active Nov 24 2012 11:01 PM

#5003873 Am I on the right track for creating a text-based adventure game with Visual...

Posted by Varlun on 24 November 2012 - 09:54 PM


Hmm. Thanks again for the tips.. I do realize this is a pretty big undertaking, especially for my current level. But, I do feel like I -can- make what I'm trying to do work... it'd be extremely tedious, but I could make it work. And of course, as time goes on and I learn more code fundamentals, such as arrays, I'll use them. Could you believe that I had originally tried to make this game with nothing more than If statements? Then I learned sub procedures.

But.. as for the way I'm trying to do it now.. do you have any tips for making it easier? Or perhaps a couple tips on how to code this in an easier way? Such as using sub procedures.

You said something about good code not being just a crapload of If statements... so, what can I do instead?

Shadowisadog gave a good suggestion about data-driven design, storing all your data (maps, enemies, inventory items, food, etc...) in files which you load inside your code as arrays, this way all your stuff is abstracted away as single index into an array. You can then also create functions to locate specific items in your inventory without hardcoding checking each slot for each element (use a loop) and all that.

Another big one is using objects and classes. Purely imperative code doesn't lend itself well to game logic where each object may do a different thing. By using objects, you can group items into categories, which all do the same thing, e.g. you have an Enemy class, which holds the name of the enemy, its hit points, special abilities, amount of damage it can inflict on you, etc... this means any enemy can be represented as an instance of this class. Do you see the pattern?


Hmm... honestly, I'm starting to feel like I may have indeed jumped into this project way too early, because I currently have no clue how I'd go about having multiple classes, and using those together. I'm probably just going to put the project on pause at this point, and wait until I'm finished with my Visual Basic class before picking this up again.

However, thank you everyone for your tips. I'll definitely keep this thread saved in my favorites, and will likely update it and reuse it in the future.

Farewell all.


#5003864 Am I on the right track for creating a text-based adventure game with Visual...

Posted by Varlun on 24 November 2012 - 08:31 PM

I think you did not get any advice because the post is just far too big (and the absence of code formatting doesn't help either - don't they work? if not, you can always try pastebin). But honestly, there is just too much code, and from what I can tell there is a lot of redundancy in it. Basically, your code lacks abstraction - everything is hardcoded in, which makes the code very inflexible and reading/adding/deleting stuff from the code is very difficult. Also, the interface code and the logic code are jumbled together, which makes it even more difficult to follow the code.

This is not to say that the code is horrible. It's a good start, but you need to rethink your design, right now it is not viable. It is typical beginner code which makes too heavy use of single conditions (if/then/else), and this is not to belittle you - we've all started there - but, simply but, good code is not a sequence of if/then/else statements. You need to learn how to separate interface from implementation, work out design patterns to simplify code, etc...

There is this nice exercise I like to recommend to people who are at about your level - implement a 9x9 sudoku generator (it doesn't have to solve it - just create a valid one randomly). Then, when you're done, extend the code to generate an sudoku where N is any integer within reason (let the user specify the size at the start of the program!). With your current design, you will get stuck at the second part, which'll force you to think outside the box.


Hmm. Thanks again for the tips.. I do realize this is a pretty big undertaking, especially for my current level. But, I do feel like I -can- make what I'm trying to do work... it'd be extremely tedious, but I could make it work. And of course, as time goes on and I learn more code fundamentals, such as arrays, I'll use them. Could you believe that I had originally tried to make this game with nothing more than If statements? Then I learned sub procedures.

But.. as for the way I'm trying to do it now.. do you have any tips for making it easier? Or perhaps a couple tips on how to code this in an easier way? Such as using sub procedures.

You said something about good code not being just a crapload of If statements... so, what can I do instead?


PARTNERS