Initial commit: C++ courseware
This commit is contained in:
commit
4a4ee7c287
1789 files changed
+373489
No files matched your search
@@ -0,0 +1,42 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
|
||||
struct Hero{
|
||||
int life = 10000;
|
||||
int attack = 10;
|
||||
};
|
||||
|
||||
struct Monster{
|
||||
int life = 10000;
|
||||
int attack = 100;
|
||||
};
|
||||
|
||||
int main(){
|
||||
Hero h; Monster m;
|
||||
cout << "Hero的血量内存地址为:" << &h.life << endl;
|
||||
cout << "Hero的攻击力内存地址为:" << &h.attack << endl;
|
||||
cout << "Monster的血量内存地址为:" << &m.life << endl;
|
||||
cout << "Monster的攻击力内存地址为:" << &m.attack << endl;
|
||||
system("pause");
|
||||
int count = 0;
|
||||
while(true){
|
||||
if(m.life <= 0){
|
||||
cout << "玩家打败了怪物!" << endl;
|
||||
break;
|
||||
}
|
||||
if(h.life <= 0){
|
||||
cout << "怪物打败了玩家!" << endl;
|
||||
break;
|
||||
}
|
||||
h.life -= m.attack;
|
||||
m.life -= h.attack;
|
||||
cout << "--------第<< count << "次攻击-----------";
|
||||
cout << "玩家对怪物造成了:" << h.attack << "点伤害" << endl;
|
||||
cout << "怪物对玩家造成了:" << m.attack << "点伤害" << endl;
|
||||
cout << "玩家血量:" << h.life << endl;
|
||||
cout << "怪物血量:" << m.life << endl;
|
||||
cout << endl;
|
||||
_sleep(5000);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user