今天一定要说的是一款回合制游戏
双人对战,每人可以在一开始赋予一定技能,经过若干轮对战后决出胜负。
说它是因为这款游戏太惊艳了,代码量不多,只是简单构建了几个类,逻辑也不是很复杂,但是分析起来却十分有趣。
下面是几个.h文件,粘贴过来,理理思路
#ifndef MANAGE_H
#define MANAGE_H
#include "skill.h"
class Manage
{
public:
Manage(uint num=0,Skill *skill =NULL);
void addSkill();
Skill *getSkill();
void show();
private:
uint m_uiNum;
Skill *m_pFirstSkill;
};
#endif
#ifndef PLAYER_H
#define PLAYER_H
#include "manage.h"
class Player
{
public:
Player(string name = "npc", uint blood = 1000,uint skillnum=0);
bool isLost();
void showWin();
void showLost();
const string &getName();
uint getBlood();
void attack(Player &other);
uint beAttacked(uint attack);
private:
string m_strName;
uint m_uiBlood;
Manage m_manage;
};
#endif
#ifndef SKILL_H
#define SKILL_H
#include <iostream>
#include <string>
using namespace std;
typedef unsigned int uint;
class Skill
{
public:
Skill(string name = "unarmed", uint attack = 10);
uint getAttack();
const string &getName();
Skill *m_pNext;
private:
string m_strName;
uint m_uiAttack;
};
#endif
网友评论