给学生的简单的模拟题

 环境WIN7 64

 工具VS 2008

////

#include "stdafx.h"


#include<iostream>

using namespace std;

//装备模板
struct FireOlt
{
    //装备名称
    char name[20];
    //装备防御值
    int lrpt;
    

};




//角色模板
struct RoleTemplate
{
    //人物名称
    char name[20];

    //人物攻击力
    int attp;

    //占位符
    char pex;
    struct FireOlt filt;

};


//创建人物最大数量
const unsigned short int  MAX_ROLE_COUNT = 2;

//定义全局人物列表
struct RoleTemplate roleList[2];



//保存当前人物列表个数
static int roleListCount = sizeof(roleList)/sizeof(RoleTemplate);

//保存实际占位个数
static int roleListPexCount = 0;

//显示游戏人物
void pRole();
//创建游戏人物
void CreateRole();



int main()
{

    system("cls");   
    char param;
    
    
    cout<<"----------------------------主菜单-------------------------"<<endl;
    cout<<"--------------功能:C创建人物,P打印人物列表--------------"<<endl;
    while(cin>>param)
    {
        
        if (param=='c')
        {
    
            CreateRole();

        }else if (param=='p')
        {
            pRole();
        }

    }





}


void pRole()
{

    system("cls"); 

    cout<<"----------------------------人物列表-------------------------"<<endl;
    cout<<"--------------------------R返回主菜单 C创建人物------------------------"<<endl;
    char t;
    for(int i=0;i<roleListCount;i++)
    {
        if (roleList[i].pex == 'x')
        {
            cout<<"人物名称:"<<roleList[i].name<<" "<<"攻击力:"<<roleList[i].attp<<endl;
        }
    }


    while(cin>>t)
    {

        if (t=='c')
        {

            CreateRole();

        }else if (t=='r')
        {
            main();
        }

    }



}




void CreateRole()
{


    system("cls");   
    //最大数检查
    if ( roleListPexCount >= MAX_ROLE_COUNT)
    {
        cout<<"人物已达到创建最大数,R键返回主菜单"<<endl;
        char t;
        while(cin>>t)
        {
            if (t=='r')
            {


                main();
            }
        }
    }




    cout<<"开始创建人物"<<endl;
    cout<<"格式:人物名 攻击力"<<endl;


    
    
    //遍历整个结构体数组,找出没有被占位的数组,这是笨方法,以后可以看看二分算法 
    for(int i=0;i<roleListCount;i++)
    {
        if (roleList[i].pex != 'x')
        {
            cin>>roleList[i].name>>roleList[i].attp;
            roleList[i].pex = 'x';

            //更新实际占位数
            roleListPexCount = roleListPexCount + 1;

            //任意找到一个没有被占位的马上退出循环
            //注意这里使用break并非使用continue (break退出整体循环,continue退出当前循环并进入下一个循环)
            break;
        }
    }


    cout<<"继续创建按C,退出创建按R"<<endl;

    char t;
    while(cin>>t)
    {
        if (t=='c')
        {
            CreateRole();
        }else
        {
            main();
        }
    }



}
java新手自学群 626070845
java/springboot/hadoop/JVM 群 4915800
Hadoop/mongodb(搭建/开发/运维)Q群481975850
GOLang Q1群:6848027
GOLang Q2群:450509103
GOLang Q3群:436173132
GOLang Q4群:141984758
GOLang Q5群:215535604
C/C++/QT群 1414577
单片机嵌入式/电子电路入门群群 306312845
MUD/LIB/交流群 391486684
Electron/koa/Nodejs/express 214737701
大前端群vue/js/ts 165150391
操作系统研发群:15375777
汇编/辅助/破解新手群:755783453
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/cfas/p/3098104.html