zoukankan      html  css  js  c++  java
  • 黄金点游戏

    项目是我和陈雨一起完成

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

  • 相关阅读:
    c#格林治时间实现
    K3WISE常用表
    读取单元格数据
    水晶报表使用方法
    vs2010下使用sqlite
    C#执行EXE程序
    SQLLITE HELPER
    SQL LITE安装
    C#多线程
    VS2012 快捷键
  • 原文地址:https://www.cnblogs.com/yxsh/p/7672737.html
Copyright © 2011-2022 走看看