📄 sharkfish.h
字号:
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std; //命名空间
const int TIMELOOP=100; //最大迭代次数
const int ROW=20; //海域矩阵行数
const int COLUMN=20; //海域矩阵列数
const int FISH_LIFE_SPAN=10; //小鱼生命周期
const int FISH_BORN_AGE=3; //小鱼生育周期
const int SHARK_LIFE_SPAN=20; //鲨鱼生命周期
const int SHARK_STARVE_SPAN=5; //鲨鱼饥饿极限
const int SHARK_BORN_AGE=5; //鲨鱼生育周期
const int EMPTY=0; //空白区域类型
const int NOTHING_TO_EAT=-1; //鲨鱼没有食物
const int NOWHERE_TO_MOVE=-1; //没有方向移动
const int FISH_TYPE=1; //小鱼占据区域
const int SHARK_TYPE=2; //鲨鱼占据区域
const enum {RIGHT,DOWN,LEFT,UP}; //方向枚举类型
class Cell //细胞类定义
{
public:
Cell() //构造函数
{ //初始化新空间为空白区域
Type=EMPTY;
Age=0;
StarvationTime=0;
}
void PrintCell() //输出细胞状态
{
cout<<"["<<Type<<";"<<Age<<";"<<StarvationTime<<"]";
}
void Grow() //细胞长一个时间单位
{
Age++;
}
void Starve() //鲨鱼饥饿时间增加一个单位
{
StarvationTime++;
}
void SetType(int type) //设置细胞类型
{
Type=type;
}
int GetAge() //获得细胞年龄
{
return Age;
}
int GetStarvationTime() //获得细胞饥饿时间
{
return StarvationTime;
}
int GetType() //获得细胞类型
{
return Type;
}
void Clear() //清空细胞,可能是细胞死亡
{
Type=0;
Age=0;
StarvationTime=0;
}
void ClearStarve() //获得食物后清空饥饿时间
{
StarvationTime=0;
}
private:
int Type; //细胞类型
int Age; //细胞年龄
int StarvationTime; //饥饿时间
};
typedef struct CellNode{ //细胞节点结构类型
Cell* NodeElem; //细胞指针
int x; //细胞位置坐标
int y;
struct CellNode * next; //细胞链表指针
}CellNode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -