#include "stdafx.h"
#include<time.h>
#include<iostream>
#include<windows.h>
#include<ctime>
#include<cstdlib>
using namespace std;
void delay(int sec)
{
time_t strat_time, cur_time;
time(&strat_time);
do
{
time(&cur_time);
} while ((cur_time - strat_time) < sec);
}
int main()
{
char another_game = 'y';
int correct = false;
int sequence_length = 0;
time_t seed;
int number;
int counter = 0;
int time_taken = 0;
int now;
//開頭介紹
cout << "\n歡迎來到simple simon,仔細觀察數字,記住它們!!!" << endl;
delay(2);
cout << "只有一秒!" << endl;
delay(2);
cout << "寫下它們,越快越多越好!" << endl;
delay(2);
cout << "Are you ready,come!" << endl;
delay(2);
cout << "按下回車鍵開始" << endl;
cin >> another_game;
//主程式
do
{
correct = true;
counter = 0;
sequence_length = 2;
time_taken = clock();
while (correct)
{
sequence_length += counter++ % 3 == 0;
seed = time(NULL);
now = clock();
srand((unsigned int)seed);
for (int i = 1; i < sequence_length; i++)
cout << " " << rand() % 10;
delay(1);
cout << "\r";
for (int i = 1; i <= sequence_length; i++)
cout << " ";
if (counter == 1)
cout << "\n現在輸入你記下的數字";
else
cout << "\r";
srand((unsigned int)seed);
for (int i = 1; i <= sequence_length; i++)
{
cin >> number;
if (number != rand() % 10)
{
correct = false;
break;
}
}
if (correct == true)
cout << "\nCorrect!";
else
cout << "\nWrong!";
}
cin.sync();
cout << "\nDo you want to paly again(y/n)?";
cin >> another_game;
} while (another_game == 'y');
return 0;
}
最好能用visual studio 2015除錯一下,找出問題,十分感謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/81028.html
標籤:基礎類
上一篇:求:《c++游戲開發》游戲引擎
