Thread: Just wondering.

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128

    Just wondering.

    On my on-going game project for school I have come to a slight halt with the design.

    I am making the game so it generates a randon number 1, 2 or 3 and this selects a story.

    I was wondering if there is a way I can have a kind of 'go to' which goes to a certain place within any other .cpp file (e.g. story 1.cpp, story2.cpp, etc) if the user selects the story or do I have to keep it within 1 file.

    If there is an option which would be more practical?

    Thanks

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You can make functions. Declare the functions in a header, implement them in separate files. Then switch on the number to select the function to call.

    Or implement a simple story interpreter and write the stories in completely separate text files.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    ummm ok then Haha.

    Well I have interaction in it, such as math functions, choices etc, so Im not sure how a story interp will work. although riting the story parts in a text file aint half bad idea!

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Example (if you want to go that far):
    Code:
    mainroom {
        description {You are standing in the middle of a room ...}
        west: hallway
        east: outside
    }
    
    hallway {
        description {This seems to be a deserted hallway...}
        east: mainroom
    }
    
    ...
    It sounds like that might be a little too difficult for you to implement at the moment, but it's something for you to keep in mind for future projects.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Yeah slightly, I am pretty new to this

    So I could make a function for each story in a external page and then call it into the main file when needed? Or write parts of the story into functions and call them..

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Right. Using different files is just something that is convenient for you (the programmer), and allows you to modularize the program (object files). So the main idea here is that your different stories are different functions. You could then define these functions wherever you like... in one file, in several files...
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wondering if this would be a dangerous use of globals.
    By suzakugaiden in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 10:51 PM
  2. switch/case - Just wondering
    By Snip in forum C Programming
    Replies: 3
    Last Post: 05-22-2005, 07:04 AM
  3. wondering about people here
    By moemen ahmed in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-08-2002, 09:33 PM
  4. wondering
    By xlordt in forum A Brief History of Cprogramming.com
    Replies: 35
    Last Post: 03-01-2002, 07:05 AM