473,946 Members | 17,657 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 3989
nemisis
64 New Member
ok i ll go through the stuff till u get back then i have to sleep. see ya l8r
May 26 '07 #31
nemisis
64 New Member
Get rid of the *. Make it return a 'string' not a 'string*'.

doesnt work i have to change it in all files ie. motion.h, motion.cc and flymotion.h and after doing that too i am getting more errors which is way out of my understanding!! !

EDIT: P.S. If you want, you can take a look at a preliminary document I am writing regarding Parsing in C++ here. It is in review so that is why it is located in the Editors Corner.
Again, i am not that familiar with parsing so i will have a look 2morrow as soon as i am out of bed since nothing is getting inside at this time of the night. Good night


ps- if u want i can post the errors i get when i change to string from string* , i didnt as there are 4-5 of them and i got confused lookin at them hence put back string*.
May 26 '07 #32
AdrianH
1,251 Recognized Expert Top Contributor
Ok, when you state a type (whether it is a return type, parameter type or variable type) there are three ways of declaring it in C++, by value, by reference and by indirection (I'm not sure if indirection is the standard term though).

By value means that you have an object. If you initialise an object by another object a constructor is invoked to initialise the object. If is initialised with another object of the same type the copy constructor is invoked to copy the object. The copy constructor is just a special constructor that takes a const type reference. More on that type later. E.g.
Expand|Select|Wrap|Line Numbers
  1. // Takes a string by value, constructor is invoked in this case (copy 
  2. // constructor if passed a string).
  3. // 
  4. // Returns a string by value, copy constructor is invoked.
  5. string fn1(string param)
  6. {
  7.   return param;
  8. }
  9.  
  10. int main()
  11. {
  12.   string var1("hello");  // Constructor to init var1 to contain "hello".
  13.  
  14.   string var2 = "hello"; // Even though this looks like an assignment, it is 
  15.                          // still an initialisation, so the same constructor
  16.                          // as above is called.
  17.  
  18.   string var2(var1);     // var1 is a string, so the copy constructor is 
  19.                          // invoked.
  20.  
  21.   string returnValue 
  22.     = fn1(var1);  // fn1 is passed var1 which is a string.  param is the same 
  23.                   // type, thus to initialise param, the copy constructor is
  24.                   // invoked.  This is known as passing by value.
  25.                   //
  26.                   // fn1 returns a string, param is also a string, the return
  27.                   // value is initialised using the copy constructor.
  28.   return 0;
  29. }
  30.  
By reference means that you are borrowing the actual object. Thus, if you modify it (and it is not a const type reference), the original object will be modified. Behind the scenes, this may look like a const pointer (see by indirection). It is almost always initialised with an actual object.
Expand|Select|Wrap|Line Numbers
  1. void fn2(string& param1, string const & param2)
  2. {
  3.   param1="bye";  // Not invoking constructor, invoking the assignment operator.
  4.                  // If no assignment operator function defined, it will destroy
  5.                  // var1 and invoke the copy constructor on the memory space of
  6.                  // var1.
  7.  
  8.   param2="lala"; // Invalid operation, param2 is a constant, thus cannot be 
  9.                  // changed.  Comment out to get to compile.
  10. }
  11.  
  12. int main()
  13. {
  14.   string var1("hello");  // Constructor to init var1 to contain "hello".
  15.   string var2("bye-bye");
  16.   string& var3(var1);    // Init to reference var1 (also known as an alias)
  17.   string& var4 = var2;   // Init to reference var2
  18.   fn2(var1, var2);
  19.  
  20.   cout << "var1: " << var1 << endl; // outputs "var1: bye"
  21.   cout << "var2: " << var2 << endl; // outputs "var2: bye-bye"
  22.   cout << "var3: " << var3 << endl; // outputs "var3: bye"
  23.   cout << "var4: " << var4 << endl; // outputs "var4: bye-bye"
  24.  
  25.   return 0;
  26. }
  27.  
By indirection means that you indirectly point at the object you are referring to. To get access to the object, you either use the dereference operator (‘*’), or the member selection operator (‘->’) which is only valid for non-base types. The value of the pointer can be any value between 0 (usually called NULL) and the maximum addressable space value.

Expand|Select|Wrap|Line Numbers
  1. void fn3(string* param1, string const * param2)
  2.   if (param1 == NULL) {
  3.     cout << "param1 is NULL" << endl;
  4.   }
  5.   else {
  6.     cout << "param1 points at string '" << *param1 
  7.          << "'.  Its length is " << param1->length()
  8.          << ".  Adding ' there' to it." << endl;
  9.     *param1 += " there";
  10.   }
  11.  
  12.   if (param2 == NULL) {
  13.     cout << "param2 is NULL" << endl;
  14.   }
  15.   else {
  16.     cout << "param2 points at string '" << *param2 
  17.          << "'.  Its length is " << (*param1).length() // also valid
  18.          << ".  Cannot add ' there' to it." << endl;
  19.     //*param2 += " there";  // INVALID since pointing at a const value.
  20.   }
  21. }
  22.  
  23. int main()
  24. {
  25.   string var1("hello");
  26.   string var2("bye-bye");
  27.   string* var3(&var1);   // Init to point at var1
  28.   string* var4 = &var2;  // Init to point at var2
  29.   fn3(var1, var2);
  30.  
  31.   cout << "var1: " << var1 << endl; // outputs "var1: bye"
  32.   cout << "var2: " << var2 << endl; // outputs "var2: bye-bye"
  33.   cout << "var3: " << var3 << endl; // outputs "var3: bye"
  34.   cout << "var4: " << var4 << endl; // outputs "var4: bye-bye"
  35.  
  36.   return 0;
  37. }
  38.  
NOTE: there are no constructors that will convert a string* to a string (although one could theoretically be made, it makes little sense and could result in inadvertent conversions) or a string to a string* (there is no automated way to make such a conversion).

I hope that what I have written will help point you in understanding what you are doing wrong.


Adrian
May 27 '07 #33
nemisis
64 New Member
ok I changed string* to string......... ........ now i get these errors


flymotion.cc: In static member function 'static FlMotion* FlyMotion::inst ance()':
flymotion.cc:li ne 20:error: cannot allocate an object of type 'flymotion'
flymotion.cc:li ne 20:error: because the following virtual functions are abstract:
Motion.h:line 17:error: virtual bool Motion::contain s(std::string) const
May 27 '07 #34
AdrianH
1,251 Recognized Expert Top Contributor
ok I changed string* to string......... ........ now i get these errors


flymotion.cc: In static member function 'static FlMotion* FlyMotion::inst ance()':
flymotion.cc:li ne 20:error: cannot allocate an object of type 'flymotion'
flymotion.cc:li ne 20:error: because the following virtual functions are abstract:
Motion.h:line 17:error: virtual bool Motion::contain s(std::string) const
You didn't declare and define bool FIMotion::conta ins(string) const function.

Won't be in for the rest of the day.


Adrian
May 27 '07 #35
nemisis
64 New Member
Won't be in for the rest of the day.


Adrian
hhmmmmmm just when i need u............. o well i aint sleeping for 48 hrs so whenever u come back i ll still be here
May 27 '07 #36
Savage
1,764 Recognized Expert Top Contributor
hhmmmmmm just when i need u............. o well i aint sleeping for 48 hrs so whenever u come back i ll still be here
What a irony,eh?

PS:Subscribing

Savage
May 27 '07 #37
nemisis
64 New Member
What a irony,eh?

PS:Subscribing

Savage

better get to work then i was slackin cuz i thought adrian wasnt around, well next post in an hr or so............. ..
May 27 '07 #38
nemisis
64 New Member
You didn't declare and define bool FIMotion::conta ins(string) const function.

the bool FlyMotion::cont ains(string) is declared in Motion.h line 17 but i cant figure out what to define in it?? any suggestions??
May 27 '07 #39
nemisis
64 New Member
Expand|Select|Wrap|Line Numbers
  1. #ifndef MOTION_H
  2. #define MOTION_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. class Motion
  10. {
  11.     friend ostream &operator << (ostream &out, const Motion &m);
  12.  
  13.     public:
  14.         Motion();
  15.         virtual ~Motion(){};
  16.         virtual string toString() const = 0;
  17.         virtual bool contains(const string key) const = 0;
  18. };
  19.  
  20.  
  21. #endif


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. #include "Motion.h"
  6.  
  7. ostream &operator << (ostream &out, const Motion &m)
  8. {
  9.     out << "- I " << m.toString();
  10.     return out;
  11. }

Expand|Select|Wrap|Line Numbers
  1. #ifndef FLYMOTION_H
  2. #define FLYMOTION_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. #include "Motion.h"
  10.  
  11. class FlyMotion : public Motion
  12. {
  13.     public:
  14.         static FlyMotion* instance();
  15.         virtual string toString() const;
  16.         virtual bool contains(const string key) const;
  17.  
  18.     //protected:
  19.         FlyMotion();
  20.         FlyMotion(const FlyMotion&);
  21.         ~FlyMotion(){};
  22.  
  23.     private:
  24.         static FlyMotion *inst;
  25.      // return &inst;
  26. };
  27.  
  28.  
  29. #endif

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4.  
  5. #include "FlyMotion.h"
  6.  
  7. using namespace std;
  8.  
  9. FlyMotion* FlyMotion::inst = 0;
  10.  
  11. FlyMotion::FlyMotion()
  12. {
  13.     inst = 0;
  14. }
  15.  
  16. FlyMotion* FlyMotion::instance()
  17. {
  18.     if(inst == 0)
  19.     {
  20.         inst = new FlyMotion;
  21.     }
  22.     return inst;
  23. }
  24.  
  25.  
  26. string FlyMotion::toString() const 
  27. {
  28.   ostringstream outStr;
  29.  
  30.    outStr << Motion::toString() << "fly " << flush;
  31.  
  32. return outStr.str();
  33. }        



------ Build started: Project: Project1, Configuration: Debug Win32 ------
Linking...

FlyMotion.obj : error LNK2019: unresolved external symbol "public: __thiscall Motion::Motion( void)" (??0Motion@@QAE @XZ) referenced in function "public: __thiscall FlyMotion::FlyM otion(void)" (??0FlyMotion@@ QAE@XZ)


FlyMotion.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall FlyMotion::cont ains(class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> >)const " (?contains@FlyM otion@@UBE_NV?$ basic_string@DU ?$char_traits@D @std@@V?$alloca tor@D@2@@std@@@ Z)


FlyMotion.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> > __thiscall Motion::toStrin g(void)const " (?toString@Moti on@@UBE?AV?$bas ic_string@DU?$c har_traits@D@st d@@V?$allocator @D@2@@std@@XZ) referenced in function "public: virtual class std::basic_stri ng<char,struct std::char_trait s<char>,class std::allocator< char> > __thiscall
FlyMotion::toSt ring(void)const " (?toString@FlyM otion@@UBE?AV?$ basic_string@DU ?$char_traits@D @std@@V?$alloca tor@D@2@@std@@X Z)


LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStar tup


C:\Documents and Settings\Admin\ Desktop\c++\Pro ject1\Debug\Pro ject1.exe : fatal error LNK1120: 4 unresolved externals


Build log was saved at "file://c:\Documents and Settings\Admin\ Desktop\c++\Pro ject1\Project1\ Debug\BuildLog. htm"


Project1 - 5 error(s), 0 warning(s)


========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
May 28 '07 #40

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

Similar topics

1
2898
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
1848
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
2278
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
1299
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
2530
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
1919
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
1486
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
1819
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
2386
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
10162
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9981
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
11566
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...
1
11337
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10687
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7424
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
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4533
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.