Design and development help in C++ text game

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nemisis
    New Member
    • May 2007
    • 61

    Design and development help in C++ text game

    Hi Everyone I have am doing an object oriented C++ program and I have no idea as to how start it............. ....


    This program prints a motion verb ( fly, run, swim, crawl, walk, or roll ), waits for a second,
    then prints the name of an entity and repeats the verb (for example: fly ..1s.. pigeon fly!.. ).
    The player has ½ second to type ‘y’ for yes or ‘n’ for no. (case insensitive)
    - If the answer is correct, the player scores, if incorrect, or if there was no answer within the ½ second, the
    player looses a point. When correct, all the motions the entity can perform are printed.

    - When wrong, Ka..BOOM! is printed instead.

    The default number of questions per player is 20, but the number can be changed by passing a different
    number on the command line when starting the program.


    At the end of the run the player’s score (and the score of previous players if there were any) is printed, the
    question: “Another player (Y/N): “ is asked. The game exits if ‘n’ is typed.

    The output should look something like this:-

    Player 1 starting.
    You must answer with the letter ‘y’ for YES, or ‘n’ for NO.
    Press [Enter] when ready to start:

    1 – fly pigeon fly!.. y
    - I walk - I fly
    2 – swim Wheelbarrow swim.. n
    - I roll
    3 – crawl ball crawl!..
    Ka...BOOM!
    4 – fly plane fly!.. y
    - I roll - I fly.
    5 – run boat run!.. n
    - I roll.
    6 – walk engine walk!..
    Ka..BOOM!
    7 – roll stone roll!.. y
    - I roll.
    . . .
    16- crawl time crawl!.. y
    - I crawl - I fly.
    17- swim goose swim!.. n
    Ka..BOOM!
    18- run lizard run!.. y
    - I run - I crawl.
    19- run nose run.. y
    - I run
    20- fly goose fly!.. y
    - fly - I walk – I run – I swim.

    Player 1 *** score: 16 ***

    Well done! Start another player (Y or N)? y

    Player 2 starting
    You must answer with the letter ‘y’ for YES, or ‘n’ for NO.
    Press [Enter] when ready to start:

    1 – crawl giraffe crawl!.. y
    Ka..BOOM!



    I am not that good at coding so i tried and made an overview of what the main driver should look like


    main{
    start_function( a,b)
    {
    check here wherther the player is old or new------>Connector

    where a = value of yes or no, taken by cin>>
    if the vaue is yes....
    }
    you are back in main >>>here

    now start the for...while/Do...while[(condition for 1/2 min)& this shld take care of the initial 30 seconds also]
    {
    call function2(loop for 20 questions)
    else if right answer add a point
    Also call a function to print what the object does (for ball, it will be I ROLL)

    keep adding ( + or -)points in a variable

    End for loop of questions
    }

    display final score
    ask to replay ------------>connector
    }


    But as said above I have no idea on the coding part of the whole program and would like some help here please

    Also apart from this can anyone suggest a good compiler, I use Visual Basic C++ if thats good
  • AdrianH
    Recognized Expert Top Contributor
    • Feb 2007
    • 1251

    #2
    Ok, looks like you have a general flow of your programme done. Now can you identify the objects you require?


    Adrian

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Pay attention to what AdrianH says. Your outline is not object-oriented. It is object-based. For it to be object-oriented, you will a) need to identify your entities, b) identify their abilites, c) construct a class hierarchy, d) use virtual functions.

      Object-based programming is perfectly OK but should not be called object-oriented just becuse it has a class or a struct in it.

      Comment

      • nemisis
        New Member
        • May 2007
        • 61

        #4
        ok so how do i go abt it, its too complicated for me to code it!!!!!

        Comment

        • nemisis
          New Member
          • May 2007
          • 61

          #5
          btw what makes my program object oriented then........... .... i havent written the game code still as i am poor at coding but i am just curious as to what would make the overview Object Oriented , i mean what changes???

          Comment

          • AdrianH
            Recognized Expert Top Contributor
            • Feb 2007
            • 1251

            #6
            Originally posted by nemisis
            ok so how do i go abt it, its too complicated for me to code it!!!!!
            Relax. First you don't code, you design.

            When you design, think about what objects you need, you look at the requirements and start picking out nouns (things). When you have your nouns, see if any are of a common group. I.e.

            dog, cat, wolf, bear -- These are all types of animals
            corola, versa, echo, matrix -- These are all types of cars

            Then once you have your objects, start picking out the related verbs (actions) for a noun.

            dog -- walks, eats, runs
            cat -- walks, eats, runs
            wolf -- walks, eats, runs
            bear -- walks, eats, runs
            thus all animals (at least in this set) walks, eats, runs so can be used as function names.

            You can even have questions too for things that may be different between them:
            Code:
            .
                   can get      has how 
                  newspaper?   many legs?
            dog      yes          4
            cat       no          4
            wolf      no          4
            bear      no          4
            Given your description, can you state some objects, group them and make up some verbs/questions for them?


            Adrian

            Comment

            • nemisis
              New Member
              • May 2007
              • 61

              #7
              Originally posted by AdrianH
              Given your description, can you state some objects, group them and make up some verbs/questions for them?


              Adrian
              ok lets c


              object- verbs

              pigeon- fly, walk
              wheelbarrow- roll
              ball- roll, fall
              stone- fall, roll
              lizard -crawl, eat
              wheels- roll, turn
              cat- jump, walk, eat, swim
              plane- fly, roll
              time- crawl, fly
              river- run
              crocodile- crawl, swim, roll
              fish- swim

              each object has different functions some are common, this should give the output as required if designed for random printing of verbs as described in my very first post, what say???

              Comment

              • AdrianH
                Recognized Expert Top Contributor
                • Feb 2007
                • 1251

                #8
                Originally posted by nemisis
                ok lets c


                object- verbs

                pigeon- fly, walk
                wheelbarrow- roll
                ball- roll, fall
                stone- fall, roll
                lizard -crawl, eat
                wheels- roll, turn
                cat- jump, walk, eat, swim
                plane- fly, roll
                time- crawl, fly
                river- run
                crocodile- crawl, swim, roll
                fish- swim

                each object has different functions some are common, this should give the output as required if designed for random printing of verbs as described in my very first post, what say???
                That's good. You will also need to have it able to display what it can do as well.

                Sorry, but I need to go and will not be back for pretty much the rest of the day. If Weaknessforcat is around, s/he may be able to help you as s/he is a quite competent C++ programmer with OOP experience.

                I’ll look in on your progress later. Good luck.


                Adrian

                Comment

                • nemisis
                  New Member
                  • May 2007
                  • 61

                  #9
                  ok thanks for everything till now, but i still have to finish it in 2 days before 25th May, so will look forward for help and fast

                  Comment

                  • AdrianH
                    Recognized Expert Top Contributor
                    • Feb 2007
                    • 1251

                    #10
                    Originally posted by nemisis
                    ok thanks for everything till now, but i still have to finish it in 2 days before 25th May, so will look forward for help and fast
                    Ok, you know the class syntax right? So generate a class for each object, inheiriting from a single class. Use the verbs you stated (and I suggested) as function calls.

                    Let me know if you have any troubles.


                    Adrian

                    Comment

                    • AdrianH
                      Recognized Expert Top Contributor
                      • Feb 2007
                      • 1251

                      #11
                      Originally posted by AdrianH
                      Ok, you know the class syntax right? So generate a class for each object, inheriting from a single class. Use the verbs you stated (and I suggested) as function calls.

                      Let me know if you have any troubles.


                      Adrian
                      Let me know how things are going. You understand inheritance, corret?


                      Adrian

                      Comment

                      • nemisis
                        New Member
                        • May 2007
                        • 61

                        #12
                        srry i had 2 test today so couldnt do c++............ ...... anyways yes i know classes, Inheritance i dont know much but i can look it up in books i have and probably do it. I will start writing stuff tomorrow and post it so if i have problems u can help. Thanks dude.

                        Comment

                        • AdrianH
                          Recognized Expert Top Contributor
                          • Feb 2007
                          • 1251

                          #13
                          Originally posted by nemisis
                          srry i had 2 test today so couldnt do c++............ ...... anyways yes i know classes, Inheritance i dont know much but i can look it up in books i have and probably do it. I will start writing stuff tomorrow and post it so if i have problems u can help. Thanks dude.
                          No prob. Good luck on your tests.


                          Adrian

                          Comment

                          • weaknessforcats
                            Recognized Expert Expert
                            • Mar 2007
                            • 9214

                            #14
                            Originally posted by AdrianH
                            dog -- walks, eats, runs
                            cat -- walks, eats, runs
                            wolf -- walks, eats, runs
                            bear -- walks, eats, runs
                            To make this object-oriented you do not use dog, cat. wolf, or bear in your code.

                            Instead, you deveop a class Animal and derive the dog, cat, wolf and bear from Animal. This says that a dog IS-A a Animal. You then create dog, cat, wolf or bear objects and pass them to functions that have Animal* or Animal& arguments. That means the walks, eats, runs have to be Animal methods BUT if you are passing a dog object to the function and you ask for the runs method, you expect to execute dog::runs and not Animal::runs. So you make the Animal methods virtual.

                            The entire application would use Animal* or Animal& arguments. Nowhere would you see dog, cat, wolf bear except where the objects are created and even there this is often hidden a by factory class where you ask for a specific kind of animal and get a pointer to it:

                            [code=cpp]
                            Animal * dog = AnimalFactory.C reate(I_WANT_A_ DOG);
                            [/code]


                            Unless you code this way, your program is not object-oriented.

                            Comment

                            • nemisis
                              New Member
                              • May 2007
                              • 61

                              #15
                              but i am not using only animals, hence a class of animals does no good, instead what if i make a class for objects which include fish, wheel, goose, stone, etc and another class which includes verbs like run, swim, roll, etc and then create another class functions which inherits both the classes objects and verbs.( i ll need help again in Inheritance)

                              Comment

                              Working...