• 黄金点游戏


    项目是我和陈雨一起完成

    用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;
    }

  • 相关阅读:
    Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(四)
    中国B2B行业将进入后平台时代
    做产品经理 而不是功能经理(转淘宝鬼脚七)
    全球最值的学习的100个网站
    gridview 内的button 用法
    框架内 FRAME的源src如何根据条件而变化?C#解决方案
    一般中小企网络出口的后备线路(adsl做后备)
    Windows server 2012_远程_没有远程桌面授权服务器可以提供许可证
    访问网站返回常见的状态码200,404等表示什么意思(转)
    站长学习 一 Robots简单认识
  • 原文地址:https://www.cnblogs.com/yxsh/p/7672737.html
Copyright © 2020-2023  润新知