延迟文本(需要更有效地延迟)C ++

时间:2017-02-03 04:13:36

标签: function visual-c++ text delay

嘿伙计我还有另外一个问题,所以我正在制作一个RPG,我正在尝试使用Pokemon游戏类型的文字,一次弹出一个字母。这是我的代码:

#include <iostream>
#include <string>
#include <windows.h>
#include <sys/types.h>

using namespace std;

string name;

VOID WINAPI Sleep(
    _In_ DWORD dwMilliseconds
);

void pushX(int num) {
    for (int i = 0;i<num;i++)
        cout << " ";
}

void main() {

    system("cls");
    cout << "H";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "o";
    Sleep(50);
    cout << ",";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "W";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "c";
    Sleep(50);
    cout << "o";
    Sleep(50);
    cout << "m";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "T";
    Sleep(50);
    cout << "o";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "T";
    Sleep(50);
    cout << "h";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "G";
    Sleep(50);
    cout << "a";
    Sleep(50);
    cout << "m";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "!\n";
    system("Pause");
    system("cls");
    Sleep(50);
    cout << "P";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "a";
    Sleep(50);
    cout << "s";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "T";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "M";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "Y";
    Sleep(50);
    cout << "o";
    Sleep(50);
    cout << "u";
    Sleep(50);
    cout << "r";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << "N";
    Sleep(50);
    cout << "a";
    Sleep(50);
    cout << "m";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "!\n>> ";
    cin >> name;
    system("cls");
    Sleep(50);
    cout << "H";
    Sleep(50);
    cout << "e";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "l";
    Sleep(50);
    cout << "o";
    Sleep(50);
    cout << ",";
    Sleep(50);
    cout << " ";
    Sleep(50);
    cout << name;
    Sleep(50);
    cout << "!\n";
    system("pause");
    return;    

}

这显然效率低下。它完成了这项工作,但代码太多了。我也不想要只运行一行代码。我正在寻找一个函数,可以找到每当我放置一个cout并使每个字母出现在.050秒的deley或Sleep(50);感谢您的帮助 U

1 个答案:

答案 0 :(得分:0)

void pokeprint(char* s){
      int N = strlen(s);
      system("cls");
      for(int i=0; i<N;i++)
      {
       Sleep(50);
       cout << s[i];
      }
      cout << "\n";
      system("Pause");
      system("cls");
}