473,832 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design and development help in C++ text game

nemisis
64 New Member
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
May 21 '07
45 3968
AdrianH
1,251 Recognized Expert Top Contributor
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
May 23 '07 #11
nemisis
64 New Member
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.
May 23 '07 #12
AdrianH
1,251 Recognized Expert Top Contributor
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
May 23 '07 #13
weaknessforcats
9,208 Recognized Expert Moderator Expert
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:

Expand|Select|Wrap|Line Numbers
  1. Animal * dog = AnimalFactory.Create(I_WANT_A_DOG);
  2.  

Unless you code this way, your program is not object-oriented.
May 23 '07 #14
nemisis
64 New Member
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)
May 24 '07 #15
nemisis
64 New Member
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.

no wait Adrian said something else above.......... ...... i ll work on it
May 24 '07 #16
nemisis
64 New Member
Expand|Select|Wrap|Line Numbers
  1. class object
  2. {
  3.  
  4. private:
  5.  
  6.   char *verb1 = fly, *verb2 = walk, *verb3 = fall, *verb4= roll, *verb5 = crawl,  *verb6 = eat, *verb7= turn, *verb8= jump, *verb9= swim, *verb10 = run; 
  7.  
  8. public:
  9.   void printdata();
  10.  
  11. };
  12.  
  13. void verb::printdata()
  14. {
  15.   cout<<       // how to randomly print the verbs??? //
  16.  
  17. }
  18.  
  19.  
  20.  
  21. class pigeon::private object
  22. {
  23. private:
  24.   char *object1= pigeon;
  25.  
  26. public:
  27.   void printdata();
  28.   void functions();
  29. };
  30.  
  31.  
  32. void pigeon::printdata()
  33. {
  34.   cout<< *object1;
  35. }
  36.  
  37. void pigeon::functions()
  38. {
  39.   verb::printdata();
  40.   cout<< "I" << *verb1 << ", I " << *verb2 << endl;
  41. }


So the printdata of pigeon class prints name and the functions of pigeon prints what the pigeon does( I fly, I walk) . This will be for all objects like time, river,cat,etc.

i wasnt sure how to create "words" without using arrary in char so used pointers(and i am pretty sure its somehow wrong)

anyways plz tell me what next
May 24 '07 #17
nemisis
64 New Member
ok srry will keep in mind next time i post a code
May 24 '07 #18
AdrianH
1,251 Recognized Expert Top Contributor
Ok nemis, you got a reasonable start with a few errors such as using the scope ‘verb’. I’m sure you didn’t mean that intentionally. Also, you don’t need to declare all the verbs in the base class, though it could be done depending on the design.

I would suggest using a base type that would check and display the types of things it does. And in addition, have a pure virtual function that would return a list (perhaps a vector) of things it can do.

In each class that inherits from the base class, I would have a vector class that would be initialized with the appropriate things it can do and implement the pure virtual function, returning that vector. Like this:
Expand|Select|Wrap|Line Numbers
  1. vector<char*> canDo;
  2.  
  3. canDo.push_back(“walk”);
  4. canDo.push_back(“fly”);
  5.  
NOTE: I am using a char* but this is because I am only pushing things that are literals (preallocated and will never be deallocated) so I will not have to worry about deleting them afterwards or someone deleting them on me. I would normally use a string object under other circumstances.

In your base class you can then iterate through the things it can do (calling the pure virtual function to get that information) when listing the types it uses or check if it can be done.

Does all of this make sense to you?

If you have any difficulties, let me know.


Adrian
May 24 '07 #19
nemisis
64 New Member
sorry i hardly got what u wrote, i have heard of vectors but dont know how and why is it used, also if i do create a base class then what would that class contain??
May 24 '07 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2891
by: vbian | last post by:
Hi, I'm looking for information about companies using dotnet for the next generation of games. I've been impressed by the managed examples that come with the dx9 sdk, they're a huge step up from those available with the dx8 and below sdk's. There also seem to be a number of books covering this subject, but then I've still got a copy of "C++ real-time graphics" which probably didn't inspire the original wolfenstein ;) If you can...
3
1840
by: noob23434 | last post by:
Hi all I've been told that the best platform to make games on (strategy games) is a c++. I want to start making games using my mac and I was wondering if anyone could tell me what software is the best to get started with? Kind regards  Marc
18
2268
by: jaso | last post by:
Hi, I'm making this video game in C. The game contains a player, enemies and bullets. These objects, which are arrays of structures, are initialized, updated and drawn in a game loop. Now I am unsure on where to declare these things. I could declare them in main() like this #define NUM_ENEMIES 10 #define NUM_BULLETS 20
7
1293
by: JJ | last post by:
Having done most of the background sql coding I'm now ready to start designing my asp.net web pages. A basic question though - is there a way of having 'common' elements on pages (e.g. a header)? This used to be done using frames, but I undertand these are now not advised. Basically what I want is to have some text/code that is common to all pages, but that I only need to update in one place?
0
2517
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that don't work nearly as well as they should, even for analysts and power users. The reason they haven't reached the masses is because most of the tools are so difficult to use and reveal so little
3
1910
by: =?Utf-8?B?cGNnYW1lcg==?= | last post by:
Is VB good for game development? Or is C# or some other language better? I'm a beginner programmer and would like to get into game development. I can't find any decent tutorials, so links would be very helpful. Thanks
0
1480
by: Advertiser for `2D Games Development Central` | last post by:
New to game development? Need a headstart in creating that first game of yours? Want to meet others who share a passion for playing and creating games? Need support, but don't know where go for it? Are you just passionate about games? 2D Game Development Central is a newly founded group on Google Groups that is dedicated to the creation of games, especially with regards to 2D. We offer you the chance to join a community of newcomers just...
6
1812
by: pereges | last post by:
I want to begin by making simple 2D games for Dos. What particular features of C should I look to strengthen ? I am not asking about the graphics bit but in general.
7
2377
by: Benjamin Vigneaux | last post by:
Well, I'm very interested in game development, I'm just starting out though, browsing here and there for tutorials, references, etc.. and learning about the game development industry... What i've realized is that, apparently, most of the games out there are likely to be coded in C++, is this because the language offers features which are better suited for game development? or just because it has been out in market for a longer period of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10781
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10499
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.