软件工程结对项目之黄金点游戏

Posted CyJack

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件工程结对项目之黄金点游戏相关的知识,希望对你有一定的参考价值。

项目是我和孙虎一起完成

用c++语言写

我主要是画流程图

#include <iostream>
#include <stdlib.h>
#include <string>
#include <math.h>
using namespace std;
struct Gold
{
float data;
string name;
int score = 0;
struct Gold *next;
struct Gold *down;
}; typedef struct Gold NODE;
void displayname(int x);
string establishname(int x);
void EverageGold();
void case1();
void Output(NODE *tail);
void countscore(NODE *tail);
void onetime(NODE *newhead);
void Ntime();
void case2();
NODE *Gtail, *head;
int N;
int main()
{
int x = 0;
while (1)
{
N = 0;
cout << " 开始新游戏 按0 " << endl;
cout << " 查看上局数据 按1 " << endl;
cout << " 历史黄金点数据 按2 " << endl;
cout << " 其它输入退出 " << endl;
cout << " 请输入: ";
cin >> x;
switch (x)
{
case 0://新游戏
while (1)
{
while (1)
{
cout << " 请输入玩家数量: ";
cin >> N;
cout << " " << endl;
if (N < 2)
{
cout << " 至少2个玩家" << endl;
}
else break;
}
while (1)
{
cout << "确定输入按 1 重新输入按 2" << endl;
cin >> x;
if (x != 1 && x != 2)
cout << "无效命令请重新输入:" << endl;
else break;
}
if (x == 1)
break;
system("CLS");
}
Ntime();

break;
case 1:
system("CLS");
case1();
while (1)
{
cout << "按1返回主菜单" << endl;
cin >> x;
if (x == 1)break;
}
break;
case 2:case2(); break;
default:
break;
}
if (x < 0 || x>2)break;
}
return 0;
}
void Ntime()
{
float data, j = 0;
int x;
NODE *newhead, *tail = NULL;
for (j = 0; j<10; j++)
{
newhead = new NODE;
newhead->data = j;
newhead->next = NULL;
newhead->down = NULL;
if (j == 0)
{
head = newhead;
tail = newhead;
}
else
{
tail->down = newhead;
tail = newhead;
}
onetime(newhead);
newhead = NULL;
cout << "返回主界面输入1" << endl;
cout << "其他键继续游戏" << endl;
cin >> x;
if (x == 1)
{
system("CLS");
break;
}
}
}
void onetime(NODE *newhead)
{
NODE *pnew, *tail;
tail = newhead;
float data;
int i;
for (i = 0; i<N; i++)
{
displayname(i);
cin >> data;
pnew = new NODE;
newhead->next = pnew;
newhead = pnew;
pnew->data = data;
pnew->next = NULL;
pnew->down = NULL;
pnew->name = establishname(i);
}
countscore(tail);
}
void countscore(NODE *tail)
{
NODE *losepeople, *winpeople, *p, *q;
q = NULL;
int i = 1;
float sum = 0, Min, Max, G;
p = tail->next;

winpeople = p;
losepeople = p;
while (p)
{
sum = sum + p->data;
p = p->next;
i++;
}
G = 0.618*sum / i;
p = tail->next;
Min = fabs(p->data - G);
Max = fabs(p->data - G);
p = p->next;
while (p)
{
if (Min>fabs(p->data - G))
{
Min = fabs(p->data - G);
winpeople = p;
}
else if (Max<fabs(p->data - G))
{
Max = fabs(p->data - G);
losepeople = p;
}
q = p;
p = p->next;
}
winpeople->score = winpeople->score + i - 1;
losepeople->score = losepeople->score - i + 1;
p = new NODE;
q->next = p;
p->name = "黄金点";
p->data = G;
p->down = Gtail;
Gtail = p;
p = tail;
Output(p);
}
void Output(NODE *tail)
{
NODE *p;
int i = 0;
p = tail;
cout << "第" << (p->data + 1) << "轮游戏结果:" << endl;
cout << "姓名 " << "数字 " << "得分" << endl;
p = p->next;
for (i = 0; i<N + 1; i++)
{
cout << p->name << " " << p->data << " " << p->score << " " << endl;
p = p->next;
}
}
void case1()
{
NODE *newhead;
newhead = head;
while (newhead)
{
Output(newhead);
newhead = newhead->down;
cout << endl << endl;
}
}
void EverageGold()
{
float G = 0, i = 0;
NODE *p;
p = Gtail;
while (p)
{
G += p->data;
i++;
}
G = G / i;
cout << "平均G点:" << G << endl;
}
void case2()
{
NODE *p;
int x;
p = Gtail;
cout << "若干轮的G点数据" << endl;
while (p)
{
cout << p->data << endl;
p = p->down;
}
cout << "按1返回主菜单" << endl;
while (1)
{
cin >> x;
if (x == 1)
{
system("CLS");
break;
}
}
}
void displayname(int x)
{
switch (x)
{
case 0:cout << "玩家1 "; break;
case 1:cout << "玩家2 "; break;
case 2:cout << "玩家3 "; break;
case 3:cout << "玩家4 "; break;
case 4:cout << "玩家5 "; break;
case 5:cout << "玩家6 "; break;
case 6:cout << "玩家7 "; break;
case 7:cout << "玩家8 "; break;
case 8:cout << "玩家9 "; break;
case 9:cout << "玩家10 "; break;
}
}
string establishname(int x)
{
string name;
switch (x)
{
case 0:name = "玩家1"; break;
case 1:name = "玩家2"; break;
case 2:name = "玩家3"; break;
case 3:name = "玩家4"; break;
case 4:name = "玩家5"; break;
case 5:name = "玩家6"; break;
case 6:name = "玩家7"; break;
case 7:name = "玩家8"; break;
case 8:name = "玩家9"; break;
case 9:name = "玩家10"; break;
}
return name;
}

以上是关于软件工程结对项目之黄金点游戏的主要内容,如果未能解决你的问题,请参考以下文章

一次奇妙的体验:结对编程之黄金点小游戏

一次奇妙的体验:结对编程之黄金点小游戏

结对编程之黄金点游戏

ASE高级软件工程 第一次结对编程

结对项目--黄金点游戏

(第五周)结对项目——黄金点游戏