my first GAME!!!

Hello people,
I started C++ 2 months ago and last night I finished my very first project!!
Could you please compile it and leave some comment/feedback for me?
I know it's way off being a proper videogame but I had to start somewhere :D

Also, I know, some of you that chek this out are experienced programmers. Could you please give me some tips on my code? I know my style is awful but this is the best I can do (now) and I'd really like to improve.

#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<stdexcept>

using namespace std;
inline void keep_window_open() {char ch; cin>>ch;}

void get_instructions()
{
     cout<<"\n";
     cout<<"1)";cout<<"\n";
     cout<<"you enter a number to let me play";cout<<"\n";
     cout<<"(either 0, 1 or 2)";cout<<"\n";
     cout<<"\n";
     cout<<"1)";cout<<"\n";
     cout<<"you'll play \"rock\" \"paper\" or \"sicssors\"";cout<<"\n";
     cout<<"if I play same as you we draw";cout<<"\n";
     cout<<"rock beat scissors but paper beat rock";cout<<"\n";
     cout<<"scissors beat paper";
     cout<<"\n";
}    
     
void get_started()
{
     cout<<"\n";
     cout<<"o    o    o  oooo  o     ooo   oo    o    o   oooo";cout<<"\n";
     cout<<" o  o o  o   o     o    o     o  o  o o o  o  o   ";cout<<"\n";
     cout<<"  o o o o    oooo  o    o     o  o  o  o   o  oooo";cout<<"\n";
     cout<<"   oo oo     o     o    o     o  o  o      o  o   ";cout<<"\n";
     cout<<"    o o      oooo  ooo   ooo   oo   o      o  oooo";cout<<"\n";
     cout<<"\n";
     cout<<"\n";
     cout<<"MY version of \"rock paper scissors\"";cout<<"\n";
     cout<<"\n";
     cout<<"know how to play? ";
     
     string start;
     cin>>start;
     
     while (start!="no" and start!="yes")
        {
        cin.clear();
        cin.ignore(80,'\n');
        cout<<"answer \"yes\" or \"no\" ";
        
        cin>>start;
        }
    
    if (start=="yes")
    {
    cout<<"..here you go!";
    cout<<"\n";
    }
    else if (start=="no")
    {
    get_instructions();
    }
}
     

double get_double()
{
      double maybe_double=0;
      while (!(cin>>maybe_double))
      {
           cin.clear();
           cin.ignore(80,'\n');
           cout<<"..double please ";
           cout<<"\n";
           cin>>maybe_double;
      }
      return maybe_double;
}


int get_int()
{
  double num = get_double();
  while (num != static_cast<int>(num))
  {
    cout <<"..integers please ";
    num = get_double();
  }
  return static_cast<int>(num);
}


int get_inrange(int low, int high)
{
  int num = get_int();
  while (num<low or num>high)
  {
    cout<<"integer must be from ";
    cout<<low<< " to " << high;
    cout<<".  Try Again: ";
    num = get_int();
  }
  return num;
}

int me_play()
{
    int value1=0;
    string value;
    cout<<"enter your play ";
    
    cin>>value;
    
    while (value!="rock" and value!="paper" and value!="scissors")
        {
        cin.clear();
        cin.ignore(80,'\n');
        cout<<"..rock, paper or scissors please ";
        cin>>value;
        }
    
    if (value=="rock")
    {
         value1=0;
    }
    else if (value=="paper")
    {
         value1=1;
    }
    else if (value=="scissors")
    {
         value1=2;
    }
    else
    {};
    
    return value1;
}

int computer_play(int i)
{
    int value2=0;
    int cmptr=0;
    vector<int>first_sequence;
    vector<int>second_sequence;
    vector<int>third_sequence;
    cout<<"seed me with a number please: ";
    cin>>cmptr;
    
    while (cmptr!=0 and cmptr!=1 and cmptr!=2)
    {
         cin.clear();
         cin.ignore(80,'\n');
         cout<<"..0, 1 or 2 please ";
         cin>>cmptr;
    }
    
    if (cmptr==0)
    {
                 first_sequence.push_back(1);
                 first_sequence.push_back(0);
                 first_sequence.push_back(1);
                 first_sequence.push_back(0);
                 first_sequence.push_back(2);
                 first_sequence.push_back(0);
                 first_sequence.push_back(1);
                 first_sequence.push_back(2);
                 first_sequence.push_back(2);
                 first_sequence.push_back(2);
                 
                 value2=first_sequence[i];
     }
     
     if (cmptr==1)
     {
                 second_sequence.push_back(1);
                 second_sequence.push_back(2);
                 second_sequence.push_back(2);
                 second_sequence.push_back(0);
                 second_sequence.push_back(1);
                 second_sequence.push_back(0);
                 second_sequence.push_back(1);
                 second_sequence.push_back(0);
                 second_sequence.push_back(0);
                 second_sequence.push_back(2);
                 
                 value2=second_sequence[i];
     }
     
     if (cmptr==2)
     {
                  third_sequence.push_back(2);
                  third_sequence.push_back(0);
                  third_sequence.push_back(0);
                  third_sequence.push_back(0);
                  third_sequence.push_back(0);
                  third_sequence.push_back(0);
                  third_sequence.push_back(1);
                  third_sequence.push_back(0);
                  third_sequence.push_back(2);
                  third_sequence.push_back(2);
                  
                  value2=third_sequence[i];
     }
     
return value2;
}  

int main()
{
    int i=0;
    
    int counter_me=0;
    int counter_cmptr=0;
    string answer;
    string start;
    get_started();
    
    cout<<"\n";
    cout<<"want to play? ";
    cin>>answer;

    while (answer!="yes" and answer!="no")
    {
    cin.clear();
    cin.ignore(80,'\n');
    cout<<"answer \"yes\" or \"no\" ";
    cin>>answer;
    }
    
    while (answer=="yes")
    {
          cout<<"\n";
          int cmptr = computer_play(i);
          int me = me_play();
          
          if (cmptr==0)
                {
                       cout<<"I say rock!";
                       cout<<"\n";
                       if (me==0)
                       cout<<"nobody won";
                       else if (me==1)
                       {cout<<"you won"; counter_me++;}
                       else if (me==2)
                       {cout<<"I won"; counter_cmptr++;}
                       else
                       cout<<"some mess happened";
                }
          else if (cmptr==1)
                {
                       cout<<"I say paper!";
                       cout<<"\n";
                       if (me==0)
                       {cout<<"I won"; counter_cmptr++;}
                       else if (me==1)
                       cout<<"nobody won";
                       else if (me==2)
                       {cout<<"you won"; counter_me++;}
                       else
                       cout<<"some mess happened";;
                }
         else if (cmptr==2)
                {
                       cout<<"I say scissors!";
                       cout<<"\n";
                       if (me==0)
                       {cout<<"you won"; counter_me++;}
                       else if (me==1)
                       {cout<<"I won"; counter_cmptr++;}
                       else if (me==2)
                       cout<<"nobody won";
                       else
                       cout<<"some mess happened";;
                }
        else
        cout<<"ERROR MESSAGE: please close game and restart!";
    
    cout<<"\n";
    cout<<"my points: "<<counter_cmptr;
    cout<<"\n";
    cout<<"your points: "<<counter_me;
    cout<<"\n";
    
      if (counter_cmptr>counter_me)
              {
              cout<<"I am winning now";
              }
      else if (counter_cmptr<counter_me)
              {
              cout<<"you are winning now";
              }
      else 
              {
              cout<<"nobody is currently winning";
              }

    cout<<"\n";
    cout<<"do you want to play again? ";
    cin>>answer;

i++;
    
      while (answer!="yes" and answer!="no")
         {
         cin.clear();
         cin.ignore(80,'\n');
         cout<<"answer \"yes\" or \"no\" ";
         cin>>answer;
         }
}

cout<<"\n";
cout<<"It would have been fun playing more with you..";cout<<"\n";
cout<<"all right then.. I will miss you ";

keep_window_open();
return 0;
}
Nice idea! I never saw a rock paper scissor console game. You could clear the screen sometimes, because its very full after a few games. The choice of the computer could be more random, in my case the computer 5 times in a row chose the same as I did.

1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<stdexcept> 


And do you really need all those includes?

Good luck!
while (start!="no" and /*wrong*/ start!="yes")
The and is ok there is an include file that let's you do that, along with or and xor

Am trying to remember where I saw it.

http://msdn.microsoft.com/en-us/library/3akey979%28v=vs.80%29.aspx


The xor operator is the text equivalent of ^. There are two ways to access the xor operator in your programs: include the header file iso646.h, or compile with the /Za (Disable language extensions) compiler option.


http://en.wikipedia.org/wiki/Iso646.h


These identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file. For consistency, the C++98 standard provides the header <ciso646>. However the latter file has no effect, being empty.[1] Notwithstanding some compilers, such as Microsoft Visual C++, do require the header to be included in order to use these identifiers.
Last edited on
so what does it mean? does it mean that in most of compilers does include it, except MSVC++ ?
These identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file.


Well, I guess try it, see if it works.

Don't worry, I am constantly finding new things in C++, like this:

int a(1);

is the same as :

int a = 1;

Have fun !!
@Fransje

Thank you for the input!
I am so happy you found it nice.
clearing the screen..
I'd love to do that but I have't learnt it yet!

How can you clear the screen?

Also, about the headers, you are perfectly right. It's just because I am learning C++ with a book that comes along with a list of headers to include to do everything included in this book, I just copied an pasted just to make sure :D

Also!
question!!
How can I send it to a frend of mine in a different country?
Does he have to compile it? can I send the application directly? (I tried by email and I failed..)
I'd really love to get some help on this one :(
I just copied an pasted just to make sure :D

ah, i see :)

How can you clear the screen?

A possibility is the controversial system( "cls" );, which simply clears the screen. Have a look at this: http://cplusplus.com/forum/beginner/1988/ to see why it is controversial. Another way is going through all console coordinates and setting them to " " (using SetConsoleCursorPosition() or something, http://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx ).

How can I send it to a frend of mine in a different country?
Does he have to compile it? can I send the application directly?

If he has the same sort of compilers you use, you can just send your code, and he can compile it. Sending the .exe file mostly doesn't work, because of virus protection.
again, thank you very much

I think I will go for the controversial one.
I tell you this.
I am learning the easiest (often "crappy") way to do everything.
After I'll be able o do a lot of nice suff, I will probabily (..almost certainly) have the chance to talk to some "expert programmer" that will tell me:
Hey! your code looks like shit!

Then I'll "refine" my way.
I'll have a look at the "form". For now I am happy with just "substance"
only care about the job done.

:)

Thank you again for your amazing help.
I'll be posting another topic when/if I'll get seriously stuck with something.

All the best
Cla
Topic archived. No new replies allowed.