第十周-囚徒困境

此游戏由著名的心理测试“囚徒困境”启发制作。

游戏规则极其简单。
初始分数为0分,由玩家与文(电脑)对战。

得分规则:
双方都合作 各得3分
双方都背叛 各得1分

一方合作一方背叛 背叛的5分 合作的0分


<span style="font-size:14px;">/*
 *Copyright (c) 2014,烟台大学计算机学院
 *All gight reserved.
 *文件名称:temp.cpp
 *作者:邵帅
 *完成时间:2014年10月16日
 *版本号:v1.0
*/
#include<iostream>
#include<ctime>
#include<stdlib.h>
#include<conio.h>
using namespace std;
int main()
{
    int scoreA = 0, scoreB = 0, in, out, i = 1, n, j;
    string uA, uB;
    cout << "欢迎来到囚途困境。" << endl << endl;
    cout << "此游戏由著名的“囚徒困境”启发制作。" << endl;
    cout << "游戏规则十分简单。" << endl;
    cout << "玩家初始分数为0分,由玩家与文(电脑)对战。" <<endl << endl;
    cout << "游戏规则:" << endl;
    cout << "双方都合作,各得3分。" << endl;
    cout << "双方都背叛,各得1分。" << endl;
    cout << "一方合作一方背叛,背叛的得5分,合作的得0分。"
         << endl;
    cout << "Creat by Mayuko。" << endl;
    cout << "祝你好运!" << endl;
    system("pause");
    cout << "请输入游戏的局数:";
    cin >> n;
    srand((unsigned)time(0));
    while (i <= n)
    {
        uA = "合作";
        cout << "=========================" << endl;
        cout << "第" << i << "/" << n << "局:" << endl;
        cout << "请选择:1.合作 2.背叛  ";
        cin >> in;
        out = rand() % 11;
        if (in == 1)
        {

            if (out >= 0 && out <= 5)
            {
                j = 1;
                scoreA += 3;
                scoreB += 3;
            }
            else if (out >= 6 && out <= 10)
            {
                j = 2;
                scoreB += 5;
            }
        }
        else if (in == 2)
        {
            uA = "背叛";
            if (out >= 0 && out <= 5)
            {
                j = 1;
                scoreA += 5;
            }
            else if (out >= 6 && out <= 10)
            {
                j = 2;
                scoreA += 1;
                scoreB += 1;
            }
        }
        else if (in > 2)
        {
            cout << "输入格式错误,请重新输入!" << endl;
            continue;
        }
        if (j == 1)
            uB = "合作";
        else if (j == 2)
            uB = "背叛";
        cout << "我" << uA << " 文" << uB << endl;
        cout << "我:" << scoreA << endl;
        cout << "文:" << scoreB << endl;
        i++;
    }
    cout << endl;
    if (scoreA < scoreB)
        cout << "额...你输了." << endl;
    else if (scoreA > scoreB)
        cout << "恭喜,你赢了!" << endl;
    else
        cout << "平局!" << endl;
}
</span>





@ Mayuko




转载于:https://www.cnblogs.com/mayuko/p/4567641.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值