Player nickname generator の implementation C++

Keywords: C++ REST Windows

When we register the game, some user name games can be generated automatically. Let's take you to realize this function

  

Train of thought:

Use several containers to store many strings, and then use random numbers to call TA S

Here we use the string array, which is the code:

cout<<Where[rand()]<<"Of"<<Describe[rand()]<<Who[rand()];

Where array: where

Describe array: how to (describe)

Who array: who

 

Take a chestnut: the magic lady of the second dimension world

Binary world → Where array

Magic → describe array

Little sister → Who array

 

See here, a lot of apes and Yuan are going to talk. What about rand() repeating?

It's very simple to put this code in main:

srand(time(0));

Now, the idea is almost there. Let's give you a routine and a more perfect idea:

/*Use of functions:
Functions of the system: 
rand() random number
sysytem(Command) call cmd command 
system("cls") Clean screen
system("title Change the name at the top of the window. It's hard to say. Open a program and try it
system("color *1*2") *1 For background * 2 for font color (foreground), * 1 * 2 without spaces 
Sleep(Time) as the name suggests, let the program "rest" for a short time. You can try it on your own. Fill in 1000 for 1 second at the time, and so on
getch() The program does not need to enter a character, which is a bit like system("pause"), but records which key to press
goto Location usage: goto where; will jump to where: (no semicolon) 

Functions made by ourselves (all defined, of course):
Enter(Quantity) fill in the quantity. For example, if I fill in 3 programs, three lines will be replaced
Space(Quantity) fill in 3 in the quantity field and three spaces will be output
Tab(Enter 3 in the quantity field to output three tabs (\ T)
run(Time, prompt (string), number of carriage returns, number of spaces) for example, if I fill in run(3, loading, 3, 3), I will output first
3 Three line breaks, three spaces, and three seconds of "loading" animation. You can copy and paste it yourself
conformity(A tool for typesetting that combines Enter and Space. For example, if I fill in 3 and 3, I will
 Change 3 lines and output 3 spaces    
*/ 
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <windows.h>
#include <cstdlib>
#include <conio.h>
#include <ctime>
using namespace std;
HWND hwnd=GetForegroundWindow();//Give Way hwnd Represents the front window 
void Enter(int x)//Carriage return function 
{
    for(int i=1;i<=x;i++)    cout<<endl;
}
void Space(int x)//Space function 
{
    for(int i=1;i<=x;i++)    cout<<" ";
}
void Tab(int x)//Tab function 
{
    for(int i=1;i<=x;i++)    cout<<"\t";
}
void conformity(int a,int b)//Typesetting function 
{
    Enter(a);
    Space(b);
}
void run(int x,string a,int enter,int space)//Start animation 
{
    for(int i=1;i<=x;i++)
    {
        system("cls");
        conformity(enter,space);
        cout<<a; 
        if(i%3==1) cout<<".";
        if(i%3==2) cout<<"..";
        if(i%3==0)    cout<<"...";
        Sleep(500);
        
    }
}
string Where[]={"Alien","universe","Quadratic element","China","U.S.A","Thailand","Vietnam?","Australia","arctic","Antarctic","India","The Republic of Korea","Japan","Shanghai","Tokyo","Beijing","Nanjing","Tianjin","Hunan","Hubei","Hebei","Shaanxi","Shanxi","Henan","Inner Mongolia","Taiwan, China","Osaka","Nagoya","Nepal","Sichuan","Wuhan","Britain","Pakistan","Iran","Turkey","Hainan","Portugal","Spain","France","Switzerland","Sweden","Netherlands","Nail","Four-dimensional space","The three dimension","The four dimension","Five dimensional space","Main world","Different worlds"};
string describe[]={"Magical","Invincible","super","Fierce","Humor","Funny","Greasy injury","Interesting","","","","","","","","","Forbear","happy","Abuses","Soft adorable","Lovely","Little","Interesting","Fried chicken is lovely."}; 
string Who[]={"Steve","Uncle Steve","cowboy","Slime","Niu Niu","Sheep and goat","Kitty","Doggy","Game player","Game player","Game player","Guest","knight","TNT","Red carp and green carp","Red carp and green carp and donkey","War horse","Cutie","Younger sister"};
string area;//Storage area 
bool flag;
char cheek,t;
int main()
{
    system("cls"); //Good habit of Qingping 
    system("color 07");//Color initialization 
    ShowWindow(hwnd,SW_MAXIMIZE);//Window initialization 
    srand(time(0));//Select random number seed 
    
    system("title Player nickname generator 1.0");//Set title 
    
    conformity(20,85);//Typesetting 
    
    cout<<"Player nickname generator"<<endl;
    Space(65);//Blank space 
    
    cout<<"Would you like to disclose your area? It's about your nickname (it's always in Chinese)"<<endl;
    Space(78);//Blank space 
    cout<<"What, I don't want to reveal my area?"<<endl<<endl;
    Space(78);//Blank space 
    cout<<"input Y With confirmation, N So I don't want to disclose the region";
    cheek=getch();//Deposit Y and N 
    if(cheek=='n')    {flag=true;cout<<cheek;goto there;}//If you don't want to reveal the area, send it to there: 
    
    system("cls");//Clean screen 
    conformity(20,83);//Typesetting 
    cout<<"Please enter your region(City):"<<endl; 
    Space(83);//Blank space 
    cin>>area;//input locale 
    
    there://Portal 
    system("cls");//Clean screen 
    conformity(20,85);//Typesetting 
    cout<<"Player nickname generator"<<endl;
    Space(85);//Blank space 
    cout<<"Press any key to generate:";
    getch();//To press any key 
    
    system("cls");//Clean screen 
    run(3,"in run",20,85);//"Loading"animation 
    
    here://Portal 
    int ttt=rand()%31;//Generate a font scrolling effect similar to a lottery machine,What's the effect exe 
    for(int i=1;i<=ttt;i++)
    {
        system("cls");//Clean screen 
        conformity(20,85);//Typesetting 
        if(flag==true)
        cout<<"Your nickname:"<<Where[rand()%(49-1)]<<"Of"<<describe[rand()%(24-1)]<<Who[rand()%(19-1)];
        else
        cout<<"Your nickname:"<<area<<"Of"<<describe[rand()%(24-1)]<<Who[rand()%(19-1)];
    }
    
    Enter(5);//Enter 
    Space(85);//Blank space 
    cout<<"What, I'm not satisfied? Press Tab Key to change a name"<<endl;
    Space(85);//Blank space 
    cout<<"What,I'm satisfied? Press the space bar to exit";
    //Exclusion method 
    t=getch();
    if(t==' ')    return 0;//Sign out 
    goto here;//Portal 
    return 0;
}

My primary school students, no wonder there is such a low level of content, please correct me

Posted by SP8600 on Thu, 19 Mar 2020 11:23:38 -0700