You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
552 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#define NO_FIGHT 0
#define WIN 1
#define LOSE -1
class Fighter
{
private:
int power;
public:
friend int Fight(Fighter &me, Fighter &enemy)
{
// 任何一方已经死亡,则不发生战斗
if (me.power < 0 || enemy.power < 0)
return NO_FIGHT;
// 战斗并返回胜负且修改失败者power为-1
if (me.power > enemy.power)
{
enemy.power = -1;
return WIN;
}
else
{
me.power = -1;
return LOSE;
}
}
void SetPower(int p) { power = p; }
int GetPower() const { return power; }
// 初始化
void Init()
{
power = 0;
}
};