Thread: I Could Use Some Advice

  1. #1
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19

    Question I Could Use Some Advice

    I'm still learning C++ but I have the basics down for now.

    I want to write a MUD in C++ and I want to know what a sample code of a MUD would look like?

    If someone could post one here that would be amazing.

    Thank you.

    -Nos
    Last edited by nosfearatu; 03-22-2010 at 03:12 PM. Reason: Sum it up.

  2. #2
    Master n00b Matty_Alan's Avatar
    Join Date
    Jun 2007
    Location
    Bloody Australia Mate!
    Posts
    96
    I'm not 100% sure what you mean by MUD but I wouldn't jump in to deep most peoples first games are like tic tac toe or hangman. Build experiance on small stuff before jumping into large projects. Read source codes that other people have made to find tricks and techniques.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    MUD = Multi-User-Dungeon.

    It's a TEXT based game. No graphics.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    The first complication that springs to mind about a MUD is that it involves networking. Have you done any client/server socket code? You will need to.

    Unless you mean a single user game akin to a MUD, ie, a text adventure. Then you don't need to do any networking, but also, you do not need to bother looking at MUD code, because that is not quite what you are looking for.

    A text adventure is probably a pretty good C++ beginner project.
    Last edited by MK27; 03-22-2010 at 03:21 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    Yeah I know all about the networking but for now I'm going to make it just for me to use.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I dunno any sources of code for this, but I haven't googled.

    IMO, you're better off just doing a bit of planning and figuring yerself. Think about it in OOP terms, like probably you need a "player" class and a "location" class.

    The locations could be organized like a graph tree, using member pointers like this:
    Code:
    class location {
        location *north;
        location *south;
        location *east;
        location *west;
    Maybe you want an up and down as well; alternately, you could just do this:
    Code:
    class location {
         map<string,location*> neighbourList;
    Since locations may not always be connected in a simple compass like way. So here the string key might be "red door" and the value a pointer to the location thru the red door.

    Try whipping up a few locations and connecting them together. Do not create them with the pointers*, just use the pointers to connect them. Your player can be pretty simple to start:
    Code:
    class player {
          location *current;
    So current would be a pointer to the player's current location.

    Then you want to use an event loop:
    Code:
    while (1) {
    
    
    }
    The game takes place inside the loop.

    * these could all be references& too, probably that is better.
    Last edited by MK27; 03-22-2010 at 03:42 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Mar 2010
    Location
    Salem's Lot
    Posts
    19
    Alright, alright.

    simple character, yes. Right now I just want to move around the world.

    Thanks for the code. I'll tweak it and post the new code on here if you want.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nosfearatu View Post
    Thanks for the code. I'll tweak it and post the new code on here if you want.
    You are always welcome to post code, altho IMO it's best saved for cases where you are having a problem

    You may also want to google "event loop", which is the basis of how virtually all realtime interactive (and many other kinds of) applications work. There is a wikipedia article:

    http://en.wikipedia.org/wiki/Event_loop

    altho it seems overly focussed on "messaging" to me. "Waiting for and dispatching events" can include, eg, frame generation in 3D games, or in the case of a text adventure, input from the user.
    Last edited by MK27; 03-23-2010 at 10:01 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Before doing a MUD you need to do a single-player version of the dungeon. Get that working and design it with the idea in mind that you later want this to be a MUD. After all the multi aspect of it comes down to sending this or that over sockets and could easily be added later provided your design accounts for this. A message based approach is usually the most appropriate way to do this but certainly not the only way or necessarily the best way.

    As to a single player dungeon you only need a map, some baddies, some treasures, some spells, some weapons, npc's if you want, etc. A single player dungeon crawl is an appropriate first game for newcomers and is a bit more exciting than tic tac toe and will offer more challenges. Don't worry about the graphics right now - just use text and get the system working. Then you can add the MUD portion and then you can add the graphics our output portion. If you program all this according to interfaces then it should be easier later to 'plug-in' new functionality or swap in/out various impls of your interfaces.
    Last edited by VirtualAce; 03-23-2010 at 11:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice Programmer Humbly Requests Job Seeking Advice
    By steals10304 in forum General Discussions
    Replies: 7
    Last Post: 10-20-2009, 12:12 PM
  2. Advice on C Programming with MSVC++ 2008
    By IT_Guy in forum Windows Programming
    Replies: 1
    Last Post: 03-06-2009, 04:23 AM
  3. Semaphores, need advice on implementation.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2009, 01:54 AM
  4. Advice for breaking into the industry
    By Trennto in forum Game Programming
    Replies: 9
    Last Post: 07-03-2008, 07:47 PM
  5. girl friend advice (prob. the wrong place)
    By B0bDole in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 10-22-2004, 06:38 PM