Want improve the flow of my game

Started by
3 comments, last by L. Spiro 11 years, 2 months ago
I have written a rather large text combat game(>600 lines) with no oo or anything, just functions.

It works fine however i would like to streamline the code a lot. Some of my functions have 12 parameters, and it is annoying and unelegant to add new features.

I do realise i could just use globals but i have a nasty feeling they are like #define in c. What can i do(without just importing some form of data structure or dict) to streamline this code?
Advertisement

It's hard to say without seeing any code or knowing what exactly you have going into the functions. As a guess though, you could make an Actor class, so each object of that class could be a monster or party member. Then you'd just send in the object by reference to the functions and you have all of those stats / items / etc in just one argument.

I'm not sure what else you'd be sending in?..

Obviously, going object-oriented is generally a good decision, but without knowing anything else about your game there is nothing more to say on that topic.

Some of my functions have 12 parameters, and it is annoying and unelegant to add new features.

For this specifically, don’t add a bunch of parameters to the functions.
Add a structure as a parameter and pass it as a reference. It is quite easy to add new data to the structure when you want to send more to the function.


There are a ton of other things to consider listed here: http://lspiroengine.com/?p=126
Especially the “Structure” section.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

The problem with using an actor class is that i would have to completely re design the game and i would not like to do that. Plus it works fine already. I would like to avoid oop if that is possible.

Although i think i will try the data structure idea, thanks L spiro

Since I edited my posted just after your reply and you probably missed it, be sure to look back on it for the link and the tips within.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement