View Single Post
Old 01-28-2015, 02:59 PM   #2
plamzi
Senior Member
 
Join Date: Nov 2009
Home MUD: bedlam.mudportal.com:9000
Home MUD: www.mudportal.com
Posts: 292
plamzi is on a distinguished road
Re: Help With MUD Design In C

Hi there,

A beginner in C should probably start by looking at existing code, and it should probably be something a lot simpler than a MUD server.

There's probably an ABC of game design in C somewhere, whose very first example will show you the classic main loop. There's a reason it is a classic.

There's a very limited number of use cases in C where "goto" does more good than harm. This is not one of them.

Putting closures on their own line is best practice. It improves readability even more than not using "goto".

If you are designing anything more than a 20-line experiment, you should not be hardcoding stuff like room links. "goto Room4;" is an example of hardcoding. You are already sensing that this is wrong when you say that "Stacking up if else statements for each room is tedious." What you need is an easily extendable structure for all rooms and their properties. Movement across any two rooms would then be handled by the same code.

Using "sleep" to introduce a delay is only OK for brief experiments. In normal games, you would have a way to move on to other things and return later when you want to show the user some output. In a main-loop kind of design, this usually involves creating pulse timers (something that runs each second e. g.).

There will be one place in your main loop where you consider user input. This is the place where you will be checking that input against a "global command" list. Because commands are naturally expected to be "global" and only sometimes expected to be location-specific, you should design with the latter as the exception, and the former as the rule.

Last edited by plamzi : 01-28-2015 at 03:15 PM.
plamzi is offline   Reply With Quote