/*
* 程序名称:植物大战僵尸之锤僵尸小游戏
* 作 者:JiHe
* 注 释:ZXF
* 暂未实现功能:僵尸遇到植物停下开始吃及其音效
*/
#include "head.h"
#pragma warning (disable:4996)
#pragma comment( lib, "MSIMG32.LIB")
#pragma comment( lib, "winmm.lib")
// 游戏参数
int mapState[32][32]; // 地图状态。0:空,1:墓碑,2:地雷(没出土),3:地雷(已出土),4:寒冰菇
int currentSunshine;
LinkList<Sun> suns;
LinkList<Plant> plants;
LinkList<Zombie> zombies;
LinkList<Bang> bangs;
Lawnmower* lawnmowers[5];
double normalfrequency;
double coneheadfrequency;
double bucketheadfrequency;
double SunsFrequency;
int isNewGame;
int isHitting;
int hammerRadius;
int drawingHint;
int hintCountDown;
int snowCountDown;
int graveNum;
int Win1Lose2;
// 初始化地图
void init()
{
// 草地
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 9; j++)
{
mapState[i][j] = GRASS;
}
}
// 阳光数、植物、僵尸、阳光、锤击初始化
currentSunshine = 0;
plants.DeleteAllNode();
zombies.DeleteAllNode();
suns.DeleteAllNode();
bangs.DeleteAllNode();
// 初始化割草机
for (int i = 0; i < 5; i++)
{
lawnmowers[i] = new Lawnmower();
}
// 初始化游戏状态
normalfrequency = 0.002;
coneheadfrequency = 0.0025;
bucketheadfrequency = 0.0028;
SunsFrequency = 0.05;
isNewGame = 1;
isHitting = 0;
hammerRadius = 0;
drawingHint = 0;
hintCountDown = 70;
snowCountDown = 0;
graveNum = 0;
Win1Lose2 = 0;
}
// 获取文件名,将其存入files
void getFiles(string path)
{
files.clear();
//文件句柄
intptr_t hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
{
do
{
files.push_back(fileinfo.name);
} while (_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
files.erase(files.begin());
files.erase(files.begin());
}
// 读取存档
void readArchive(char name[])
{
init();
char path[] = "./archives/", tmppath[200] = { 0 };
strcat(strcat(tmppath, path), name);
FILE* fp = fopen(tmppath, "rb");
::fread(&mapState, sizeof(mapState), 1, fp);
// 读取割草机信息
for (int i = 0; i < 5; i++)
{
lawnmowers[i] = new Lawnmower();
::fread(&lawnmowers[i]->location, sizeof(int), 1, fp); //位置,原位置-20
::fread(&lawnmowers[i]->isActivated, sizeof(int), 1, fp); //0表示静止
::fread(&lawnmowers[i]->isOut, sizeof(int), 1, fp); //0表示未使用
}
// 读取存档参数
fread(¤tSunshine, sizeof(int), 1, fp);
fread(&normalfrequency, sizeof(double), 1, fp);
fread(&coneheadfrequency, sizeof(double), 1, fp);
fread(&bucketheadfrequency, sizeof(double), 1, fp);
fread(&SunsFrequency, sizeof(double), 1, fp);
fread(&isNewGame, sizeof(int), 1, fp);
fread(&isHitting, sizeof(int), 1, fp);
fread(&hammerRadius, sizeof(int), 1, fp);
fread(&drawingHint, sizeof(int), 1, fp);
fread(&hintCountDown, sizeof(int), 1, fp);
fread(&snowCountDown, sizeof(int), 1, fp);
fread(&graveNum, sizeof(int), 1, fp);
fread(&Win1Lose2, sizeof(int), 1, fp);
// 添加僵尸状态
int separator;
while (1)
{
fread(&separator, sizeof(int), 1, fp);
// 1234567 分隔信息
if (separator!=1234567)
{
Zombie* tmpZombie = new Zombie();
fseek(fp, -(int)sizeof(int), SEEK_CUR);
fread(&tmpZombie->HP, sizeof(int), 1, fp);
fread(&tmpZombie->row, sizeof(int), 1, fp);
fread(&tmpZombie->location, sizeof(int), 1, fp);
fread(&tmpZombie->emerge1walk2eat3, sizeof(int), 1, fp);
fread(&tmpZombie->frameNo, sizeof(int), 1, fp);
fread(&tmpZombie->height, sizeof(int), 1, fp);
fread(&tmpZombie->No, sizeof(int), 1, fp);
fread(&tmpZombie->changeFrameCountDown, sizeof(int), 1, fp);
fread(&tmpZombie->isFrozen, sizeof(int), 1, fp);
fread(&tmpZombie->isSlowed, sizeof(int), 1, fp);
fread(&tmpZombie->type, sizeof(int), 1, fp);
zombies.InsertNode(tmpZombie);
}
else break;
}
// 添加植物状态
int tmpPlantType;
while (1)
{
fread(&separator, sizeof(int), 1, fp);
// 7654321 分隔信息
if (separator!=7654321)
{
fseek(fp, -(int)sizeof(int), SEEK_CUR);
fread(&tmpPlantType, sizeof(int), 1, fp);
switch (tmpPlantType)
{
case POTATOMINE:
{
PotatoMine* tmpPotatoMine = new PotatoMine();
tmpPotatoMine->type = tmpPlantType;
fread(&tmpPotatoMine->frameNo, sizeof(int), 1, fp);
fread(&tmpPotatoMine->No, sizeof(int), 1, fp);
fread(&tmpPotatoMine->x, sizeof(int), 1, fp);
fread(&tmpPotatoMine->y, sizeof(int), 1, fp);
fread(&tmpPotatoMine->changeFrameCountDown, sizeof(int), 1, fp);
fread(&tmpPotatoMine->underCountDown, sizeof(int), 1, fp);
fread(&tmpPotatoMine->boomCountDown, sizeof(int), 1, fp);
plants.InsertNode(tmpPotatoMine);
break;
}
case GRAVEBUSTER_GRAVE1:
{
GraveBuster* tmpGraveBuster = new GraveBuster();
tmpGraveBuster->type = tmpPlantType;
fread(&tmpGraveBuster->frameNo, sizeof(int), 1, fp);
fread(&tmpGraveBuster->No, sizeof(int), 1, fp);
fread(&tmpGraveBuster->x, sizeof(int), 1, fp);
fread(&tmpGraveBuster->y, sizeof(int), 1, fp);
fread(&tmpGraveBuster->changeFrameCountDown, sizeof(int), 1, fp);
plants.InsertNode(tmpGraveBuster);
break;
}
case ICESHROOM:
{
IceShroom* tmpIceShroom = new IceShroom();
tmpIceShroom->type = tmpPlantType;
fread(&tmpIceShroom->frameNo, sizeof(int), 1, fp);
fread(&tmpIceShroom->No, sizeof(int), 1, fp);
fread(&tmpIceShroom->x, sizeof(int), 1, fp);
fread(&tmpIceShroom->y, sizeof(int), 1, fp);
fread(&tmpIceShroom->changeFrameCountDown, sizeof(int), 1, fp);
fread(&tmpIceShroom->frozenCountDown, sizeof(int), 1, fp);
fread(&tmpIceShroom->slowingCountDown, sizeof(int), 1, fp);
plants.InsertNode(tmpIceShroom);
break;
}
}
}
else break;
}
// 添加锤击状态
while (1)
{
fread(&separator, sizeof(int), 1, fp);
// 357421 分隔信息
if (separator != 357421)
{
Bang* tmpBang = new Bang(0,0);
fseek(fp, -(int)sizeof(int), SEEK_CUR);
fread(&tmpBang->No, sizeof(int), 1, fp);
fread(&tmpBang->x, sizeof(int), 1, fp);
fread(&tmpBang->y, sizeof(int), 1, fp);
fread(&tmpBang->countDown, sizeof(int), 1, fp);
bangs.InsertNode(tmpBang);
}
else
break;
}
// 添加阳光状态
while (1)
{
Sun* tmpSun = new Sun(0, 0);
fread(&tmpSun->x, sizeof(int), 1, fp);
fread(&tmpSun->y, sizeof(int), 1, fp);
fread(&tmpSun->frame, sizeof(int), 1, fp);
fread(&tmpSun->No, sizeof(int), 1, fp);
fread(&tmpSun->changeFrameCountDown, sizeof(int), 1, fp);
fread(&tmpSun->goToCount, sizeof(int), 1, fp);
fread(&tmpSun->goToCountFrame, sizeof(int), 1, fp);
fread(&tmpSun->tempX, sizeof(int), 1, fp);
fread(&tmpSun->tempY, sizeof(int), 1, fp);
suns.InsertNode(tmpSun);
if (!fread(&separator, sizeof(int), 1, fp))
break;
}
fclose(fp);
}
// 记录存档
void writeArchive(char name[])
{
char path[] = "./archives/", tmppath[200] = { 0 };
strcat(strcat(tmppath, path), name);
FILE* fp = fopen(tmppath, "wb");
::fwrite(mapState, sizeof(mapState), 1, fp);
// 写入割草机状态
for (int i = 0; i < 5; i++)
{
::fwrite(&lawnmowers[i]->location, sizeof(int), 1, fp);
::fwrite(&lawnmowers[i]->isActivated, sizeof(int), 1, fp);
::fwrite(&lawnmowers[i]->isOut, sizeof(int), 1, fp);
}
// 写入存档参数
::fwrite(¤tSunshine, sizeof(int), 1, fp);
::fwrite(&normalfrequency, sizeof(double), 1, fp);
::fwrite(&coneheadfrequency, sizeof(double), 1, fp);
::fwrite(&bucketheadfrequency, sizeof(double), 1, fp);
::fwrite(&SunsFrequency, sizeof(double), 1, fp);
::fwrite(&isNewGame, sizeof(int), 1, fp);
::fwrite(&isHitting, sizeof(int), 1, fp);
::fwrite(&hammerRadius, sizeof(int), 1, fp);
::fwrite(&drawingHint, sizeof(int), 1, fp);
::fwrite(&hintCountDown, sizeof(int), 1, fp);
::fwrite(&snowCountDown, sizeof(int), 1
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7527
最新资源
- springboot项目山西大同大学学生公寓管理系统boot.zip
- springboot项目社区帮扶对象管理系统.zip
- springboot项目社区待就业人员信息管理系统的设计与实现.zip
- springboot项目社区网格化管理平台的构建.zip
- springboot项目社区防疫物资申报系统.zip
- abaqus桩基础 桥墩拟静力试验 包涵实体建模、钢筋建模、材料定义、装配模型、分析步、网格划分、相互作用、载荷、计算等超详细教程(带源文件)
- springboot项目社区医疗服务系统.zip
- springboot项目社区物资交易互助平台.zip
- springboot项目社区医疗服务可视化系统.zip
- springboot项目社区疫情返乡管控系统.zip
- springboot项目社区疫情管理系统.zip
- springboot项目实习生管理系统设计和实现.zip
- COCOS经典小游戏案例,游戏引擎是COCOS,TS开发,包含2048,俄罗斯方块,飞行的小鸟,黄金矿工 4个经典的小游戏,代码工整,逻辑清晰,无论是想学习cocos还是想尝试开发小游戏都非常有帮助
- springboot项目水产养殖系统.zip
- springboot项目数字化农家乐管理平台的设计与实现.zip
- 1.Matlab实现SSA-CNN-BiLSTM麻雀算法优化卷积双向长短期记忆神经网络时间序列预测; 2.输入数据为单变量时间序列数据,即一维数据; 3.运行环境Matlab2020b及以上,data
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈