第7週プロジェクト3

2762 ワード

/*
 *Copyright(c)2014,              
 *Allrights reserved.
 *    :test.cpp
 *  :  
 *    :2016 4 19 
 *   :v1.0
 *
 *    :    “  2-        ” “        ”     ,            .h   ,
 *                        ,main()       
 *
 */

1.game.h:   
#ifndef GAME_H_INCLUDED
#define GAME_H_INCLUDED
using namespace std;
class Role
{
public:
    void setRole(string M,int x);
    void weapon1(int);
    void weapon2(int);
    bool show();
    void attack();
    void eat(int);
    void beAttack();
private:
    string name;
    int blood;
    bool life;
    int shanghai=1;
};

#endif // GAME_H_INCLUDED
 

2.role.cpp:          

#include <iostream>
#include "game.h"
using namespace std;

void Role::setRole(string M,int x)
{
    blood=x;
    cout<<"  :"<<M<<"      :"<<blood<<endl;
}
bool Role::show()
{
    if(blood>0)
    cout<<"   :"<<blood<<endl;
    else
    cout<<"   "<<endl;
    return 0;
}
void Role::weapon1(int n)
{
    cout<<"        "<<n<<endl;
    shanghai+=n;
}
void  Role::weapon2(int n)
{
    cout<<"        "<<n<<endl;
    shanghai+=n;
}
void Role::attack()
{

    cout<<"    "<<shanghai<<"   "<<endl;
}
void Role::eat(int n)
{
    blood+=n;
    cout<<"   "<<n<<"   "<<endl;
}
void Role::beAttack()
{
    blood=blood-1;
    cout<<"   "<<1<<"   "<<endl;
}

3.main.cpp:    
#include <iostream>
#include "game.h"
using namespace std;
int main()
{
    int x;
    Role mary;
    mary.setRole("   ",6);
    mary.show();
    cout<<"       :1、     2、   "<<endl;
    cin>>x;
    switch(x)
    {
        case 1:
           mary.weapon1(3);
            break;
        case 2:
           mary.weapon2(2);
            break;
    }

    mary.attack();
    mary.eat(2);
    mary.beAttack();
    mary.attack();
    mary.show();
    return 0;
}