第6週種目2ゲーム類(武器)
2062 ワード
/*
02.*Copyright (c)2016,
03.*All rights reserved.
04.* :main.cpp
05.* :
06.* :2016 4 2
07.* :v1.0
08.*
09.* :
10.
11. :
12.* :
13.*/
#include <iostream>
using namespace std;
class Role
{
public:
void setRole(string M,int blood);
void show();
void attack();
void eat(int );
void beAttack();
void weapon1();
void weapon2();
void weapon3();
private:
string name;
int blood;
bool life;
int shanghai=1;
};
void Role::weapon1()
{
shanghai=shanghai+1;
}
void Role::weapon2()
{
shanghai=shanghai+100;
}
void Role::weapon3()
{
shanghai=shanghai+1000;
}
void Role ::setRole(string M,int x)
{
blood=x;
cout<<" "<<M<<" "<<blood<<endl;
}
void Role::show()
{
if(blood>0)
cout<<" "<<"live"<<" "<<blood<<" "<<shanghai<<endl;
else
cout<<" "<<"die"<<" "<<blood<<endl;
}
void Role::attack()
{
cout<<" "<<shanghai<<" "<<endl;
}
void Role::eat(int a)
{
blood=blood+a;
cout<<" "<<a<<" "<<endl;
}
void Role::beAttack()
{
blood=blood-1;
cout<<" "<<1<<" "<<endl;
}
int main()
{
Role mary;
mary.setRole("Mary",4);
mary.show();
mary.attack();
cout<<" 1 ( 1 ) 2 ( 100 ) 3 ( 1000 )"<<endl;
int n;
cin>>n;
switch(n)
{
case 1:mary.weapon1();break;
case 2:mary.weapon2();break;
case 3:mary.weapon3();break;
}
mary.show();
mary.attack();
mary.eat(2);
mary.beAttack();
mary.beAttack();
mary.show();
return 0;
}
実行結果:
学習の心得:
類の簡単な運用
知識ポイントのまとめ:
略