Sign in to follow this  
alx123

help with a loop

Recommended Posts

Im making this game and I have only make this for items and character. I am a beginner with C++.
#include <iostream>
using namespace std;
int main()
{
    cout << "                  My first game"<<endl;
        
   cout<<"              ---------------------"<<endl<<endl;     
    char MyWeaponc[100];

cout << "Do you want to play?"<<endl;
cout <<"1-Play"<<endl;
cout << "2-Quit"<<endl;

int choise;
cout <<"Choise: ";
cin>>choise;

switch (choise)
       {
       case 1:
            char MyChar[100];
            cout << "You decided to play"<<endl;
            cout << "Please enter your name: ";
            cout<<endl;
            cout<<endl;
            cin>>MyChar;
            cin.ignore();

           
            cout << "Hello "<<MyChar<<endl<<endl;            
            cout << "Enter your weapon of choice "<<endl;
            cout<< "1 - Axe"<<endl;
            cout<< "2 - Sword"<<endl;
            cout<< "3 - Bow"<<endl; 
            cout<<"------------------------------------------"
            <<endl;          
           int WeaponCh;
           cin>>WeaponCh;
              if  (WeaponCh== 1)
              {
                   int DamagE;
                   int AxeAtack=18;
                   DamagE=AxeAtack;
                   cout << "The atack of the Axe : " <<AxeAtack<<endl;
               }
                           
            if(WeaponCh==2)
            {
                                        
                 int DamagE;
                 int AxeAtack=13;
                 DamagE=AxeAtack;
                 cout << "The atack of the Sword : " <<AxeAtack<<endl;
                 }
            if(WeaponCh==3)
            {
                                        
                 int DamagE;
                 int AxeAtack=10;
                 DamagE=AxeAtack;
                 cout << "The atack of the Bow : " <<AxeAtack<<endl;
                 }

             break;
 
            case 2:
            return 0;
            break;
             
            
             
             default:
                     cout << "You made a illegal move"<<endl;
             
}

    //Here I want to make a loop that makes dots do like . then .. then ... and so on..., for making like Loading .,Loading ..
 
}

I hope everyone understand what I triying to say.

Share this post


Link to post
Share on other sites
I understand what you want to do, but why would you want to put in a fake loading message? Most people would kill to rid themselves of load pauses.

You could just print "Loading" and then use timeGetTime() to print another "." every half second or so for a certain amount of seconds. You'll have to include <time.h>.

    int elapsed=0;
int lastTime=timeGetTime(),newTime;
cout<<"\nLoading";
while(elapsed<8000) {
newTime=timeGetTime();
if(newTime-lastTime>1000) {
cout << ".";
lastTime=newTime;
}
elapsed+=(newTime-lastTime);
}


Share this post


Link to post
Share on other sites
Because loading bars are good fun :D

It would be simpler to just go.


cout<<"\nLoading";
for(int i = 0; i < 100; i++)
{
cout<<".";
}

Share this post


Link to post
Share on other sites
gmp the problom with your way is that the screen would just print 100 '.' with no pause in between them.

another way to do it is just use the sleep function in side the loop. so it will pause for x amount of ms before starting over at the top of the loop.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this