Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************/
- /** 20150507 Exam 08 (Question) **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2015/05/07 am.11:25 **/
- /***************************************/
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <windows.h>
- using namespace std;
- #define MAXCAP 100
- #define MAXRABBIT 10
- #define MAXLENGTH 1000
- #define PERLEN 20
- class Animal {
- private:
- char name [10];
- int HP;
- int attack;
- int defense;
- public:
- Animal(char *str, int myhp, int myatt, int mydef){
- strcpy (name, str);
- HP = myhp;
- attack = myatt;
- defense = mydef;
- }
- int getattack (){return attack;}
- int getdefense (){return defense;}
- int getHP (){return HP;}
- char *getname (){return name;}
- void injured (int points){HP -= points;}
- bool isdead (){return (HP <= 0 ? true : false);}
- void fightwith (Animal &pk){
- int result = rand () % attack - rand () % pk.getdefense ();
- if (result > 0) {
- pk.injured (result);
- cout << name << "使出必殺絕技攻向 " << pk.getname () << "造成對方 " << result << "點損失, " << endl;
- cout << pk.getname () << "剩下 " << pk.getHP () << endl;
- }
- }
- };
- int main(){
- srand(time(NULL));
- Animal rab ("小兔兔", 100, 50, 10), tur ("小龜龜", 100, 30, 30);
- while (!rab.isdead () && !tur.isdead()){
- rab.fightwith (tur);
- tur.fightwith (rab);
- }
- system("pause"); return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment