此游戏由著名的心理测试“囚徒困境”启发制作。
游戏规则极其简单。
初始分数为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