栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

剪刀石头布(自留底)01

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

剪刀石头布(自留底)01

#include 
#include 
#include 
#include 
#include 

using namespace std;

//布=0,剪刀=1,石头=2;
enum Chioce { paper, sisser, rock };

//判断胜负函数(mod3同余判断胜负)
//结算各自得分
void decide_winner(int x, int y)//x是你的出拳状态,y是电脑的
{
	if (x == y) {
		cout << "平局!" << endl;
	}
	else if ((x - y == 1) || (x - y == -2)) {
		cout << "你赢了!" << endl;
	}
	else {
		cout << "你输了!" << endl;
	}
}



//玩家 类
class Player
{
public:
	int PlayerChoice;
	int score;
public:
	Player()
	{
		PlayerChoice= paper;//构造函数初始化数据随便定义一个
		score = 0;
	}
};

//定义一个电脑 基类   :包含电脑出拳选择状态,当前得分
class ComputerBase
{
public:
	int ComputerChioce;
	int score;
public:
	ComputerBase()
	{
		ComputerChioce = paper;
		score = 0;
	}
};

//随机出拳电脑,继承了电脑基类
class ComputerRandom :public ComputerBase
{
public:
	//随机出拳函数,基于当下时间的随机出拳
	static int getChioce()
	{
		int a;
		a = time(NULL) % 3;
		switch (a)
		{
		case 0:
			cout << "电脑出的布" << endl;
			break;
		case 1:
			cout << "电脑出的剪刀" << endl;
			break;
		case 2:
			cout << "电脑出的石头" << endl;
			break;

		}
		

		return (a);
	}
};




int main()
{
	int mode;
	cout << "欢迎来到猜拳游戏" << endl;
	cout << "请选择对手模式:" << endl;
	cout << "1.随机出拳" << endl;
	cout << "2.暂未开放" << endl;
	cout << "3.暂未开放,直接进入模式1" << endl;

	Player player1;
	cout << "你出:(布=0,剪刀=1,石头=2)" << endl;
	cin >> player1.PlayerChoice;

	ComputerRandom computer1;
	computer1.ComputerChioce = ComputerRandom::getChioce();


	decide_winner(player1.PlayerChoice, computer1.ComputerChioce);

	ComputerRandom Computer1;


	system("pause");

	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/980177.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号