master
bridgeL 6 years ago
parent 54d7a02002
commit a4a5e454b2

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project4", "Project4\Project4.vcxproj", "{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Debug|x64.ActiveCfg = Debug|x64
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Debug|x64.Build.0 = Debug|x64
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Debug|x86.ActiveCfg = Debug|Win32
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Debug|x86.Build.0 = Debug|Win32
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Release|x64.ActiveCfg = Release|x64
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Release|x64.Build.0 = Release|x64
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Release|x86.ActiveCfg = Release|Win32
{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B99F3F3-805C-4132-BE71-BAB45C040DDE}
EndGlobalSection
EndGlobal

@ -1,5 +0,0 @@
#include "bean.h"
void Bean::ClearBean(int x, int y)
{
}

@ -1,10 +0,0 @@
#pragma once
#include "map.h"
class Bean: public Map
{
public:
// 清除玩家在坐标(xy)上拾取到的豆子
void ClearBean(int x, int y);
};

@ -1,22 +0,0 @@
#pragma once
#define MOVER_WIDTH 50
#define MOVER_HEIGHT 50
#define DIR_NONE 0
#define DIR_UP 1
#define DIR_DOWN 2
#define DIR_LEFT 3
#define DIR_RIGHT 4
// 实际宽度为 28*50 高度为 30*50
#define MAP_WIDTH 28
#define MAP_HEIGHT 30
// 游戏界面的宽度
#define GAME_WIDTH 1400
#define GAME_HEIGHT 1800
// 展示分数的区域
#define SCORE_X 10
#define SCORE_Y 1600

@ -1,60 +0,0 @@
#include "game.h"
Game::Game()
{
}
void Game::Load()
{
}
void Game::Loop()
{
}
char Game::GetKey()
{
return 0;
}
void Game::Begin()
{
}
void Game::End()
{
}
bool Game::PlayerMove(int dir)
{
return false;
}
void Game::PlayerGetBean()
{
}
void Game::PlayerGetGoldBean()
{
}
bool Game::PlayerMeetMonster()
{
return false;
}
void Game::MonsterMove()
{
}
void Game::MonsterChase()
{
}
void Game::MonsterEscape()
{
}
void Game::MonsterPhoenix()
{
}

@ -1,61 +0,0 @@
#pragma once
// 系统库
#include <easyx.h>
// 项目库
#include "define.h"
#include "tool.h"
#include "wall.h"
#include "bean.h"
#include "player.h"
#include "monster.h"
class Game
{
private:
Wall wall;
Bean bean, goldBean;
Player p;
Monster m[4];
public:
Game();
void Load();
// 游戏主体循环
void Loop();
// 非阻塞获取键盘输入
char GetKey();
// 游戏开始、结束菜单
void Begin();
void End();
// 调用 p, wall 判断玩家这次移动是否会遇到墙,实现玩家的移动
// 若玩家移动失败(如撞墙), 返回false否则为true
bool PlayerMove(int dir);
// 调用 p, bean判断玩家这次移动是否能吃到豆子实现玩家吃豆子
void PlayerGetBean();
// 调用 p, goldBean判断玩家这次移动是否能吃到金豆子实现玩家吃金豆子
void PlayerGetGoldBean();
// 调用 p, m[4] 判断玩家是否会遇到怪物,并根据怪物状态,实现玩家吃怪物或怪物吃玩家,
// 若怪物吃掉玩家, 返回false否则为true
bool PlayerMeetMonster();
// 调用 p, m[4], wall 实现怪物移动
void MonsterMove();
// 怪物移动有三种方式
// 追逐玩家
void MonsterChase();
// 逃避玩家
void MonsterEscape();
// 返回重生区
void MonsterPhoenix();
};

@ -1,26 +0,0 @@
#include "map.h"
Map::Map()
{
}
void Map::SetFrontImg(IMAGE img)
{
}
void Map::SetGroundImg(IMAGE img)
{
}
void Map::SetMap(int* _map)
{
}
bool Map::IsMapTrueArea(int x, int y)
{
return false;
}
void Map::DrawAllArea()
{
}

@ -1,27 +0,0 @@
#pragma once
// 系统库
#include <easyx.h>
// 项目库
#include "define.h"
class Map
{
protected:
IMAGE front, ground; // 前景(true)元素图案,后景(false)元素图案
bool map[MAP_WIDTH][MAP_HEIGHT];
public:
Map();
void SetFrontImg(IMAGE img);
void SetGroundImg(IMAGE img);
void SetMap(int* _map);
// 判断玩家或者怪物在xy坐标是否在map为true的区域内
bool IsMapTrueArea(int x, int y);
// 画出所有的区域
void DrawAllArea();
};

@ -1,9 +0,0 @@
#pragma once
#include "mover.h"
class Monster :public Mover
{
};

@ -1,34 +0,0 @@
#include "mover.h"
Mover::Mover()
{
}
void Mover::SetImg(IMAGE _img)
{
}
void Mover::SetXY(int _x, int _y)
{
}
void Mover::SetSpeed(int _speed)
{
}
void Mover::Move(int dir)
{
}
void Mover::NextMove(int dir, int& nx, int& ny)
{
}
void Mover::Draw()
{
}
void Mover::DrawClear()
{
}

@ -1,34 +0,0 @@
#pragma once
// 系统库
#include <easyx.h>
// 项目库
#include "define.h"
#include "wall.h"
class Mover
{
protected :
IMAGE img; // 图像
int x, y; // 坐标 列、行
int speed; // 移动速度
public :
Mover();
void SetImg(IMAGE _img);
void SetXY(int _x, int _y);
void SetSpeed(int _speed);
// 按dir方向移动这个操作仅仅是根据dir改变mover的坐标并没有考虑撞墙的问题
// 要想规避撞墙请完善game类里的玩家移动函数
// 以及、、清除残影。。也请完善game类里的玩家移动函数。。
void Move(int dir);
// 返回 按dir方向移动下一次的坐标
void NextMove(int dir,int& nx, int& ny);
void Draw(); // 在当前坐标画出自己图像
void DrawClear(); // 在当前坐标清除自己图像
};

@ -1,17 +0,0 @@
#include "player.h"
void Player::GetBean()
{
}
void Player::GetGoldBean()
{
}
void Player::GetMonster()
{
}
void Player::DrawScore()
{
}

@ -1,16 +0,0 @@
#pragma once
#include "mover.h"
class Player : public Mover
{
private :
int score;
public :
void GetBean();
void GetGoldBean();
void GetMonster();
void DrawScore();
};

@ -1,36 +0,0 @@
#include "tool.h"
Wall Tool::ImportWall(int num)
{
return Wall();
}
Bean Tool::ImportBean(int num)
{
return Bean();
}
Player Tool::ImportPlayer(int num)
{
return Player();
}
Monster Tool::ImportMonster(int num)
{
return Monster();
}
string Tool::num2str(int num)
{
return string();
}
int Tool::str2num(string str)
{
return 0;
}
char* Tool::str2char(string str)
{
return nullptr;
}

@ -1,31 +0,0 @@
#pragma once
// 系统库
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <easyx.h>
using namespace std;
// 项目库
#include "define.h"
#include "wall.h"
#include "bean.h"
#include "player.h"
#include "monster.h"
class Tool
{
public:
Wall ImportWall(int num);
Bean ImportBean(int num);
Player ImportPlayer(int num);
Monster ImportMonster(int num);
string num2str(int num);
int str2num(string str);
char* str2char(string str);
};

@ -1,8 +0,0 @@
#pragma once
#include "map.h"
class Wall: public Map
{
};

@ -20,8 +20,8 @@
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{88B6082D-DD58-4BA5-B4C0-82CA75B9A262}</ProjectGuid>
<RootNamespace>Project4</RootNamespace>
<ProjectGuid>{66D5DAC4-F191-466B-9A67-3B11F3C3EDC2}</ProjectGuid>
<RootNamespace>ProjectFinal1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
@ -123,24 +123,19 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="APP.cpp" />
<ClCompile Include="bean.cpp" />
<ClCompile Include="app.cpp" />
<ClCompile Include="game.cpp" />
<ClCompile Include="map.cpp" />
<ClCompile Include="monster.cpp" />
<ClCompile Include="mover.cpp" />
<ClCompile Include="player.cpp" />
<ClCompile Include="tool.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="bean.h" />
<ClInclude Include="define.h" />
<ClInclude Include="game.h" />
<ClInclude Include="map.h" />
<ClInclude Include="monster.h" />
<ClInclude Include="mover.h" />
<ClInclude Include="player.h" />
<ClInclude Include="tool.h" />
<ClInclude Include="wall.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

@ -15,7 +15,7 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="APP.cpp">
<ClCompile Include="app.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="mover.cpp">
@ -24,16 +24,10 @@
<ClCompile Include="player.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="map.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="bean.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="tool.cpp">
<ClCompile Include="game.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="game.cpp">
<ClCompile Include="monster.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
@ -41,22 +35,13 @@
<ClInclude Include="game.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mover.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="tool.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="bean.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="define.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="player.h">
<ClInclude Include="mover.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="wall.h">
<ClInclude Include="player.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="map.h">

@ -4,6 +4,5 @@ int main()
{
Game game;
game.Load();
return 0;
}

@ -0,0 +1,16 @@
#pragma once
#define MAP_WIDTH 10
#define MAP_HEIGHT 10
#define DIR_NONE 0
#define DIR_UP 1
#define DIR_DOWN 2
#define DIR_LEFT 3
#define DIR_RIGHT 4
#define MONSTER_CHASE_SPEED 0.2
#define MONSTER_ESCAPE_SPEED 0.05
#define MONSTER_ESCAPE_STATUS 100
#define MAP_POINT_SIZE 10

@ -0,0 +1,66 @@
#include <conio.h>
#include "game.h"
#include "define.h"
void Game::Load()
{
Start();
End(Loop());
}
bool Game::Loop()
{
char key;
int dir = DIR_NONE, last_dir;
while (1)
{
key = GetKey();
last_dir = dir;
switch (key)
{
case 'p': Pause(); break;
case 'q': return false; break;
case 'w': dir = DIR_UP; break;
case 's': dir = DIR_DOWN; break;
case 'a': dir = DIR_LEFT; break;
case 'd': dir = DIR_RIGHT; break;
default: dir = last_dir; break;
}
if (player.PlayerMove(wall, dir))
{
if (player.TryEatBean(bean))
{
if (bean.IsEmpty() && goldBean.IsEmpty())
return true;
}
if (player.TryEatGoldBean(goldBean))
{
if (bean.IsEmpty() && goldBean.IsEmpty())
return true;
for (int i = 0; i < 4; i++)
{
monster[i].SetSpeed(MONSTER_ESCAPE_SPEED);
monster[i].SetStatus(MONSTER_ESCAPE_STATUS);
}
}
}
for (int i = 0; i < 4; i++)
{
if (monster[i].TryEatPlayer(player))
return false;
monster[i].MonsterMove(wall, player, bean, goldBean);
}
}
return false;
}
char Game::GetKey()
{
char key = 0;
if (_kbhit())
{
key = _getch();
}
return key;
}

@ -0,0 +1,36 @@
#pragma once
#include "map.h"
#include "player.h"
#include "monster.h"
class Game
{
private:
Map wall, bean, goldBean;
Player player;
Monster monster[4];
public:
Game();
// 游戏加载
void Load();
private:
// 游戏开始界面
void Start();
// 根据游戏胜负结果,绘制游戏结束界面
void End(bool result);
// 游戏主体循环,返回true代表玩家胜利通关false代表玩家失败
bool Loop();
// 游戏暂停界面
void Pause();
// 非阻塞按键获取
char GetKey();
};

@ -0,0 +1,33 @@
#pragma once
#include <easyx.h>
#include "define.h"
class Map
{
private:
IMAGE img;
bool map[MAP_WIDTH * MAP_HEIGHT];
public:
Map();
// 获得map某点的值
bool GetOnePoint(int x, int y);
// 给map的某个点置true
void SetOnePoint(int x, int y);
void SetImage(IMAGE _img);
// 给map的某个点置false
void ClearOnePoint(int x, int y);
// 判断地图是否所有点都为false 若是则返回true
bool IsEmpty();
// 画出某个点
void DrawOnePoint(int x, int y);
// 画出所有点
void DrawAllPoint();
};

@ -0,0 +1,43 @@
#include "monster.h"
#include "define.h"
void Monster::MonsterMove(const Map& wall, Player player, const Map& bean, const Map& goldBean)
{
int dir;
if (status < 0)
{
dir = WaitingBorn(wall);
}
else if (status > 0)
{
dir = Escape(wall, player);
status--;
}
else
{
dir = Chase(wall, player);
}
Move(dir);
// 恢复绘制走过的bean和goldBean
// ....
}
int Monster::Escape(const Map& wall, Player player)
{
int dir = Chase(wall, player);
// 反向逃避即可
switch (dir)
{
case DIR_UP: dir = DIR_DOWN; break;
case DIR_DOWN: dir = DIR_UP; break;
case DIR_LEFT: dir = DIR_RIGHT; break;
case DIR_RIGHT: dir = DIR_LEFT; break;
default: dir = DIR_LEFT; break;
}
return dir;
}

@ -0,0 +1,33 @@
#pragma once
#include "mover.h"
#include "player.h"
#include "map.h"
class Monster : public Mover
{
private:
int status;
public:
Monster();
int GetStatus();
void SetStatus(int _status);
// 如果monster成功打败了player返回true否则为false包括没遇见player、被player打败
bool TryEatPlayer(Player player);
// 怪物移动时不仅要选择适当的移动策略还要注意恢复绘制走过的bean和goldBean
void MonsterMove(const Map& wall,Player player, const Map& bean, const Map& goldBean);
// 追逐玩家
int Chase(const Map& wall, Player player);
// 逃避玩家
int Escape(const Map& wall, Player player);
// 等待重生
int WaitingBorn(const Map& wall);
};

@ -0,0 +1,6 @@
#include "mover.h"
#include "define.h"
void Mover::Move(int dir)
{
}

@ -0,0 +1,34 @@
#pragma once
#include <easyx.h>
class Mover
{
private:
IMAGE img;
double x, y;
double speed;
public:
Mover();
double GetX();
double GetY();
double GetSpeed();
void SetXY(double _x, double _y);
void SetSpeed(double _speed);
void SetImage(IMAGE _img);
// mover按照dir指示的方向前进删除旧坐标处的图像在新坐标处绘制新图像
void Move(int dir);
// 返回预测mover按照dir指示的方向前进后下一时刻的坐标(nx,ny)
void NextXY(int dir, double& nx, double& ny);
// 按照当前坐标绘制图像
void Draw();
// 按照当前坐标清除图像
void ClearDraw();
};

@ -0,0 +1 @@
#include "player.h"

@ -0,0 +1,27 @@
#pragma once
#include "mover.h"
#include "map.h"
class Player : public Mover
{
private:
int score;
public:
Player();
int GetScore();
void SetScore(int _score);
// 根据wall判断玩家是否能按照dir指示的方向前进若能Move(dir)并返回true否则返回false
bool PlayerMove(const Map& wall, int dir);
// 根据当前位置判断是否能吃到豆子若能吃到增加自己的得分清除掉被删除的豆子并返回true
bool TryEatBean(Map& bean);
bool TryEatGoldBean(Map& goldBean);
void DrawScore();
};
Loading…
Cancel
Save