资源简介
C++编写,DOS界面,分单人和人机模式,可查阅游戏历史,VC6.0测试无bug
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#include
const double PI = 3.1415926535;
//gnum是猜题的次数要求
const int gnum = 10;
class Cperson
{
public:
Cperson(); //出题并初始化
void Pcompare(int gamenum); //比较得出几A几B,并输出
void Pcompare(char PCnum); //用于人机对战
int PGETA(int num);
//这个可以去掉(4) 调试使用(提前看答案)
void gvresult();
private:
char Pquestion[5];
int PA[10] PB[10];
char Panswer[5];
};
Cperson::Cperson()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)FOREGROUND_INTENSITY | FOREGROUND_RED);
int i j k;
for (i = 0; i < 10; i += 1)
{
PA[i] = 0;
PB[i] = 0;
}
Panswer[4] = ‘\0‘;
Pquestion[4] = ‘\0‘;
srand((unsigned)time(NULL));
cout << “电脑出题中....“ << endl;
for (i = 0; i < 4; i += 1)
{
Sleep(1000);
Pquestion[i] = (rand() % 10) + 48; //出题
Panswer[i] = ‘0‘;
}
for (i = 0; i < 4; i += 1)
{
for (j = 0; j < 4; j += 1)
{
if (i != j)
{
for (;;)
{
if (Pquestion[i] == Pquestion[j])
{
for (;;)
{
//Sleep(1000);
k = (rand() % 10) + 48;
if (k != Pquestion[j])
{
Pquestion[j] = k;
break;
}
}
}
else
break;
}
}
}
}
}
void Cperson::Pcompare( int gamenum)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)FOREGROUND_INTENSITY | FOREGROUND_GREEN);
int i = 0 j = 0 k = 0;
int num = 1;
char c;
ofstream file; //创建文件
if (gamenum == 1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE)FOREGROUND_INTENSITY | FOREGROUND_GREEN);
file.open(“d:\\1A2Bhistory.txt“ ios::out);
file.close();
}
file.open(“d:\\1A2Bhistory.txt“ ios::out | ios::app); //已写与追加的方式打开文件
file <<‘\n‘<<‘\n‘<< “第“ << gamenum << “次游戏:“ << ‘\n‘ << ‘\n‘ << endl;
for (;;)
{
cout << “第“ << num << “次猜题“ << endl;
file << “第“ << num << “次猜题“ << endl;
//获取玩家的答案
for (j = 0; j < 4; j += 1)
{
fflush(stdin);
c = _getch();
if (c <= ‘9‘ && c >= ‘0‘)
{
if (j == 0)
{
Panswer[j] = c;
cout << Panswer[j];
file << Panswer[j];
}
else if (j == 1)
{
if (c != Panswer[0])
{
Panswer[j] = c;
cout << Panswer[j];
file << Panswer[j];
}
else
{
j -= 1;
}
}
else if (j == 2)
{
if (c != Panswer[0] && c != Panswer[1])
{
Panswer[j] = c;
cout << Panswer[j];
file << Panswer[j];
}
else
{
j -= 1;
}
}
else
{
if (c != Panswer[0] && c != Panswer[1] && c != Panswer[2])
{
Panswer[j] = c;
cout << Panswer[j];
file << Panswer[j];
}
else
{
j -= 1;
}
}
}
else
{
j -= 1;
}
}
cout相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 猜数字游戏 c语言代码
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 无人机视频代码
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
川公网安备 51152502000135号
评论
共有 条评论