last commit

master
bridgeL 6 years ago
parent ac6228fb52
commit 1fdc90a306

Binary file not shown.

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "S", "S\S.vcxproj", "{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}"
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
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Debug|x64.ActiveCfg = Debug|x64
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Debug|x64.Build.0 = Debug|x64
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Debug|x86.ActiveCfg = Debug|Win32
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Debug|x86.Build.0 = Debug|Win32
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Release|x64.ActiveCfg = Release|x64
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Release|x64.Build.0 = Release|x64
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Release|x86.ActiveCfg = Release|Win32
{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3D14E0C6-96EE-4EA7-8F5E-730508001FA8}
EndGlobalSection
EndGlobal

Binary file not shown.

Binary file not shown.

@ -0,0 +1,87 @@
// Microsoft Visual C++ generated resource script.
//
#pragma code_page(65001)
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// 中文(简体,中国) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// PNG
//
IDB_PNG1 PNG "image\\Blinky.png"
IDB_PNG2 PNG "image\\Clyde.png"
IDB_PNG3 PNG "image\\Inky.png"
IDB_PNG4 PNG "image\\Pacman.png"
IDB_PNG5 PNG "image\\Pinky.png"
/////////////////////////////////////////////////////////////////////////////
//
// TXT
//
IDR_TXT1 TXT "image\\data.txt"
#endif // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<ProjectGuid>{41CAD22E-7D1B-42E4-BD42-BF671AE0AF91}</ProjectGuid>
<RootNamespace>S</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.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="define.h" />
<ClInclude Include="game.h" />
<ClInclude Include="map.h" />
<ClInclude Include="monster.h" />
<ClInclude Include="mover.h" />
<ClInclude Include="player.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="tool.h" />
</ItemGroup>
<ItemGroup>
<Image Include="bitmap1.bmp" />
<Image Include="image\Blinky.png" />
<Image Include="image\Clyde.png" />
<Image Include="image\Inky.png" />
<Image Include="image\Pacman.png" />
<Image Include="image\Pinky.png" />
</ItemGroup>
<ItemGroup>
<Text Include="image\data.txt" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="S.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="game.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="map.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="mover.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="player.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="tool.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="monster.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="game.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="map.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="define.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mover.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="player.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="tool.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="monster.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="image\Blinky.png">
<Filter>资源文件</Filter>
</Image>
<Image Include="image\Clyde.png">
<Filter>资源文件</Filter>
</Image>
<Image Include="image\Inky.png">
<Filter>资源文件</Filter>
</Image>
<Image Include="image\Pacman.png">
<Filter>资源文件</Filter>
</Image>
<Image Include="image\Pinky.png">
<Filter>资源文件</Filter>
</Image>
<Image Include="bitmap1.bmp">
<Filter>资源文件</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<Text Include="image\data.txt">
<Filter>资源文件</Filter>
</Text>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="S.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

@ -0,0 +1,30 @@
#pragma once
#define BLOCK_SIZE 20
#define PERSON_SIZE 36 // 20*1.8
#define POINT_SIZE 1
#define POINT_BIG_SIZE 3
#define MAP_SIZE BLOCK_SIZE
#define MOVE_TOLERENCE 10
#define EAT_TOLERANCE 8
#define MAP_COLUMN 28
#define MAP_ROW 31
#define MAP_CNT (MAP_COLUMN * MAP_ROW)
#define GAME_WIDTH (MAP_COLUMN*BLOCK_SIZE)
#define GAME_HEIGHT (MAP_ROW*BLOCK_SIZE)
#define DIR_NONE 0
#define DIR_UP 1
#define DIR_DOWN -1
#define DIR_LEFT 2
#define DIR_RIGHT -2
#define IMG_RIGHT 0
#define IMG_LEFT 1
#define IMG_UP 2
#define IMG_DOWN 3
#define SCORE_HEIGHT 50

@ -0,0 +1,181 @@
#include "game.h"
#include <time.h>
Game::Game()
{
floor = new IMAGE(GAME_WIDTH, GAME_HEIGHT);
map = Map(floor);
player = Player(floor, &map);
for (int i = 0; i < 4; i++)
monster[i] = Monster(floor, &map);
srand(time(NULL));
}
void Game::Start()
{
cleardevice();
floor = new IMAGE(GAME_WIDTH, GAME_HEIGHT);
map = Map(floor);
map.Test();
map.DrawFloor();
player = Player(floor, &map);
player.SetSpeed(2);
player.SetXY(14 * MAP_SIZE, 23.5 * MAP_SIZE);
monster[0] = MA(floor, &map);
monster[1] = MB(floor, &map);
monster[2] = MC(floor, &map);
monster[3] = MD(floor, &map);
monster[0].SetXY(1.5 * MAP_SIZE, 1.5 * MAP_SIZE);
monster[1].SetXY(26.5 * MAP_SIZE, 1.5 * MAP_SIZE);
monster[2].SetXY(1.5 * MAP_SIZE, 29.5 * MAP_SIZE);
monster[3].SetXY(26.5 * MAP_SIZE, 29.5 * MAP_SIZE);
putimage(0, 0, floor);
for (int i = 0; i < 4; i++)
monster[i].Draw();
player.Draw();
player.DrawScore();
}
bool Game::Loop()
{
char key;
// 默认不操作,即不移动
int dir = DIR_NONE;
_getch();
while (1)
{
key = GetKey();
// 输入 o 立即退出游戏
switch (key)
{
case 'o': return false;
case 'w': dir = DIR_UP; break;
case 's': dir = DIR_DOWN; break;
case 'a': dir = DIR_LEFT; break;
case 'd': dir = DIR_RIGHT; break;
}
player.SetDir(dir);
if (player.Move())
{
int tb = player.TryEatBean();
if (tb!=0)
{
if (map.IsEmpty())
{
return true;
}
if (tb == 2)
{
for (int i = 0; i < 4; i++)
{
if(monster[i].GetFear()>=0)
monster[i].SetFear(1000);
}
}
}
}
int px, py;
player.GetXY(px, py);
for (int i = 0; i < 4; i++)
{
int tm = monster[i].Update(px, py);
if (tm == -1)
return false;
if (tm == 1)
player.EatMonster();
}
for (int i = 0; i < 4; i++)
monster[i].Draw();
player.Draw();
// 适当延时
Sleep(10);
}
return false;
}
bool Game::End(bool result)
{
RECT r = { 0, GAME_HEIGHT, GAME_WIDTH, GAME_HEIGHT + SCORE_HEIGHT };
if (result)
{
// 恭喜通过,是否重玩
drawtext(_T(" you win! "), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else
{
// 游戏失败,下次加油
drawtext(_T(" you lose. "), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
_getch();
drawtext(_T("[o] out [r] reset"), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
char key = _getch();
while (key != 'o' && key != 'r')
key = _getch();
if (key == 'o')
return true;
else
return false;
}
void Game::Load()
{
initgraph(GAME_WIDTH, GAME_HEIGHT + SCORE_HEIGHT);
while (1)
{
Start();
bool s = Loop();
bool r = End(s);
if (r)
break;
}
closegraph(); // 关闭绘图窗口
}
char Game::GetKey()
{
char key = 0;
if (_kbhit())
{
key = _getch();
if (key == -32)
{
key = _getch();
if (key == 72)
key = 'w';
if (key == 80)
key = 's';
if (key == 75)
key = 'a';
if (key == 77)
key = 'd';
}
}
return key;
}

@ -0,0 +1,31 @@
#pragma once
#include <conio.h>
#include "map.h"
#include "mover.h"
#include "player.h"
#include "monster.h"
class Game
{
private:
Map map;
Player player;
Monster monster[4];
IMAGE* floor;
public:
Game();
void Start();
bool Loop();
bool End(bool result);
void Load();
char GetKey();
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

@ -0,0 +1,31 @@
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 3
3 1 3 3 3 3 1 3 3 3 3 3 1 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3
3 1 3 0 0 3 1 3 0 0 0 3 1 3 3 1 3 0 0 0 3 1 3 0 0 3 1 3
3 1 3 3 3 3 1 3 3 3 3 3 1 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3
3 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3
3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 3 1 3 3 1 3 3 3 3 1 3
3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 3 1 3 3 1 3 3 3 3 1 3
3 1 1 1 1 1 1 3 3 1 1 1 1 3 3 1 1 1 1 3 3 1 1 1 1 1 1 3
3 3 3 3 3 3 1 3 3 3 3 3 0 3 3 0 3 3 3 3 3 1 3 3 3 3 3 3
3 0 0 0 0 3 1 3 3 3 3 3 0 3 3 0 3 3 3 3 3 1 3 0 0 0 0 3
3 0 0 0 0 3 1 3 3 0 0 0 0 0 0 0 0 0 0 3 3 1 3 0 0 0 0 3
3 0 0 0 0 3 1 3 3 0 3 3 3 0 0 3 3 3 0 3 3 1 3 0 0 0 0 3
3 3 3 3 3 3 1 3 3 0 3 0 0 0 0 0 0 3 0 3 3 1 3 3 3 3 3 3
0 0 0 0 0 0 1 0 0 0 3 0 0 0 0 0 0 3 0 0 0 1 0 0 0 0 0 0
3 3 3 3 3 3 1 3 3 0 3 0 0 0 0 0 0 3 0 3 3 1 3 3 3 3 3 3
3 0 0 0 0 3 1 3 3 0 3 3 3 3 3 3 3 3 0 3 3 1 3 0 0 0 0 3
3 0 0 0 0 3 1 3 3 0 0 0 0 0 0 0 0 0 0 3 3 1 3 0 0 0 0 3
3 0 0 0 0 3 1 3 3 0 3 3 3 3 3 3 3 3 0 3 3 1 3 0 0 0 0 3
3 3 3 3 3 3 1 3 3 0 3 3 3 3 3 3 3 3 0 3 3 1 3 3 3 3 3 3
3 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 3
3 1 3 3 3 3 1 3 3 3 3 3 1 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3
3 1 3 3 3 3 1 3 3 3 3 3 1 3 3 1 3 3 3 3 3 1 3 3 3 3 1 3
3 2 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 1 2 3
3 3 3 1 3 3 1 3 3 1 3 3 3 3 3 3 3 3 1 3 3 1 3 3 1 3 3 3
3 3 3 1 3 3 1 3 3 1 3 3 3 3 3 3 3 3 1 3 3 1 3 3 1 3 3 3
3 1 1 1 1 1 1 3 3 1 1 1 1 3 3 1 1 1 1 3 3 1 1 1 1 1 1 3
3 1 3 3 3 3 3 3 3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 3 3 3 1 3
3 1 3 3 3 3 3 3 3 3 3 3 1 3 3 1 3 3 3 3 3 3 3 3 3 3 1 3
3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

@ -0,0 +1,40 @@
#include "game.h"
int main()
{
Game game;
game.Load();
//// 读取资源包文件
//HRSRC hRsrc = FindResource(NULL, RT_BITMAP, "PNG");
//if (NULL == hRsrc)
// return FALSE;
////获取资源的大小
//DWORD dwSize = SizeofResource(NULL, hRsrc);
//if (0 == dwSize)
// return FALSE;
////加载资源
//HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
//if (NULL == hGlobal)
// return FALSE;
////锁定资源
//LPVOID pBuffer = LockResource(hGlobal);
//if (NULL == pBuffer)
// return FALSE;
//// 这里转换为IMAGE*,根据自己业务需要,也可转换为其它类型
//IMAGE* pByte = new IMAGE[dwSize + 1];
//memcpy(pByte, pBuffer, dwSize);
//GlobalUnlock(hGlobal);
//initgraph(1000,1000);
//putimage(0, 0, pByte);
//_getch();
//closegraph();
return 0;
}

@ -0,0 +1,189 @@
#include "map.h"
Map::Map(IMAGE* floor):floor(floor)
{
map = new char[MAP_CNT];
for (int i = 0; i < MAP_CNT; i++)
map[i] = 0;
}
void Map::SetMap(int column, int row, char data)
{
map[row * MAP_COLUMN + column] = data;
}
char Map::GetMap(int column, int row)
{
if (row < 0 || row >= MAP_ROW || column < 0 || column >= MAP_COLUMN)
return -1;
else
return map[row * MAP_COLUMN + column];
}
bool Map::IsEmpty()
{
for (int i = 0; i < MAP_CNT; i++)
{
if (map[i] == 1 || map[i] == 2)
return false;
}
return true;
}
void Map::ClearBean(int column, int row)
{
if (row < 0 || row >= MAP_ROW || column < 0 || column >= MAP_COLUMN)
return;
int d = map[row * MAP_COLUMN + column];
if (d == 1 || d == 2)
{
SetMap(column, row, 0);
SetWorkingImage(floor);
setfillcolor(BLACK);
int draw_x, draw_y;
draw_x = column * MAP_SIZE + MAP_SIZE / 2;
draw_y = row * MAP_SIZE + MAP_SIZE / 2;
solidcircle(draw_x, draw_y, POINT_BIG_SIZE);
SetWorkingImage(NULL);
}
}
void Map::DrawFloor()
{
SetWorkingImage(floor);
setlinecolor(BLUE);
POINT* ps = new POINT[2];
for (int i = 0; i < MAP_ROW; i++)
{
ps[0].y = i * MAP_SIZE + MAP_SIZE / 2;
ps[1].y = i * MAP_SIZE + MAP_SIZE / 2;
for (int j = 0; j < MAP_COLUMN - 1; j++)
{
int k = i * MAP_COLUMN + j;
if (map[k] == 3 && map[k + 1] == 3)
{
ps[0].x = j * MAP_SIZE + MAP_SIZE / 2;
ps[1].x = (j + 1) * MAP_SIZE + MAP_SIZE / 2;
polyline(ps, 2);
}
}
}
for (int i = 0; i < MAP_COLUMN; i++)
{
ps[0].x = i * MAP_SIZE + MAP_SIZE / 2;
ps[1].x = i * MAP_SIZE + MAP_SIZE / 2;
for (int j = 0; j < MAP_ROW - 1; j++)
{
int k = j * MAP_COLUMN + i;
if (map[k] == 3 && map[k + MAP_COLUMN] == 3)
{
ps[0].y = j * MAP_SIZE + MAP_SIZE / 2;
ps[1].y = (j + 1) * MAP_SIZE + MAP_SIZE / 2;
polyline(ps, 2);
}
}
}
int draw_x, draw_y, size;
for (int i = 0; i < MAP_CNT; i++)
{
draw_y = (i / MAP_COLUMN) * MAP_SIZE + MAP_SIZE / 2;
draw_x = (i % MAP_COLUMN) * MAP_SIZE + MAP_SIZE / 2;
switch (map[i])
{
case 1: setfillcolor(WHITE); size = POINT_SIZE; break;
case 2: setfillcolor(YELLOW); size = POINT_BIG_SIZE; break;
default:
continue;
}
solidcircle(draw_x, draw_y, size);
}
SetWorkingImage(NULL);
}
void Map::Test()
{
fstream f;
f.open("image/data.txt", ios::in);
//文件打开方式选项:
// ios::in    = 0x01, //供读,文件不存在则创建(ifstream默认的打开方式)
// ios::out    = 0x02, //供写,文件不存在则创建,若文件已存在则清空原内容(ofstream默认的打开方式)
// ios::ate    = 0x04, //文件打开时指针在文件最后。可改变指针的位置常和in、out联合使用
// ios::app    = 0x08, //供写,文件不存在则创建,若文件已存在则在原文件内容后写入新的内容,指针位置总在最后
// ios::trunc   = 0x10, //在读写前先将文件长度截断为0默认
// ios::nocreate = 0x20, //文件不存在时产生错误常和in或app联合使用
// ios::noreplace = 0x40, //文件存在时产生错误常和out联合使用
// ios::binary  = 0x80  //二进制格式文件
if (!f)
{
//cout << "打开文件出错" << endl;
return;
}
//按字节读入并输出
char ch;
int i = 0, j = 0;
while (EOF != (ch = f.get()))
{
if (ch == ' ')
continue;
else if (ch == '\n')
{
i++;
j = 0;
}
else
{
SetMap(j, i, ch - '0');
j++;
}
}
f.close();
// string map_str =
//"3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \
//3 1 1 1 1 1 1 3 1 1 1 1 1 1 3 \
//3 1 3 3 1 3 1 3 1 3 3 1 3 1 3 \
//3 1 3 3 1 1 1 1 1 1 1 1 3 1 3 \
//3 1 3 3 1 3 1 3 3 3 1 3 3 1 3 \
//3 1 1 1 1 3 1 1 1 1 1 3 3 1 3 \
//3 1 3 1 3 3 3 1 3 3 1 1 1 1 3 \
//3 1 3 1 3 3 3 1 3 3 1 3 3 1 3 \
//3 1 1 1 1 1 1 1 1 1 1 1 1 1 3 \
//3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \
//e";
// int k = 0;
// int len = map_str.length();
// for (int i = 0; i <len; i++)
// {
// if (map_str[i] == 'e')
// break;
// if (map_str[i] == ' ')
// continue;
// if (map_str[i] == '3')
// map[k++] = 3;
// else if (map_str[i] == '1')
// map[k++] = 1;
// else
// map[k++] = 0;
// }
}

@ -0,0 +1,78 @@
#pragma once
#include <easyx.h>
#include <string>
#include <fstream>
using namespace std;
#include "define.h"
#include "tool.h"
class Map
{
private:
// 地图数据:
// -1 地图外
// 0 无
// 1 豆子
// 2 金豆子
// 3 墙
char* map; // 行列式 存储
IMAGE* floor;
public:
Map() :map(NULL), floor(NULL) {};
Map(IMAGE* floor);
// 设置地图某点数据
void SetMap(int column, int row, char data);
// 获取地图某点数据
char GetMap(int column, int row);
// 是否吃光了所有豆子
bool IsEmpty();
// 清除地图上的某个豆子
void ClearBean(int column, int row);
// 在地板图片上 绘制地图图像
void DrawFloor();
// 测试用
void Test();
//void ImportMap(std::string path);
//void ImportMap(char* path);
};
/* 被弃用的旧版本代码 */
//class Map
//{
////private:
//// COLORREF color;
//// bool* map;
////
////public:
//// Map();
////
//// void SetColor(int r, int g, int b);
////
//// bool GetMap(int i, int j);
////
//// void SetMap(int i, int j, bool value);
//
// //bool IsEmpty();
//
// //void DrawMap();
//
// //void DrawMap(int i, int j);
//
// void ImportMap(std::string path);
// void ImportMap(char* path);
//
//};

@ -0,0 +1,130 @@
#include "monster.h"
Monster::Monster(IMAGE* floor, Map* map) :Mover(floor, map)
{
fear = 0;
x = BLOCK_SIZE * 9 + BLOCK_SIZE / 2;
y = BLOCK_SIZE * 6 + BLOCK_SIZE / 2;
speed = 1;
ImportImage("image/Pinky.png");
}
int Monster::Update(int px, int py)
{
if (fear == 0)
{
if (TryEatPlayer(px, py))
return -1;
}
else if (fear > 0)
{
fear--;
if (EscapePlayer(px, py))
{
fear = -1000;
return 1;
}
}
else
{
// 死亡,返回重生区
// 待补充代码
fear++;
}
return 0;
}
bool Monster::TryEatPlayer(int px, int py)
{
dir = GainDirToEatPlayer(px,py);
if (Move())
{
int dx = px - x;
int dy = py - y;
if (abs(dx) < EAT_TOLERANCE && abs(dy) < EAT_TOLERANCE)
return true;
}
else
{
dir += 1;
dir %= 2;
Move();
}
return false;
}
bool Monster::EscapePlayer(int px, int py)
{
dir = -GainDirToEatPlayer(px, py);
if (Move())
{
int dx = px - x;
int dy = py - y;
if (abs(dx) < EAT_TOLERANCE && abs(dy) < EAT_TOLERANCE)
return true;
}
else
{
dir += 1;
dir %= 2;
Move();
}
return false;
}
void Monster::SetFear(int f)
{
fear = f;
}
int Monster::GetFear()
{
return fear;
}
int Monster::GainDirToEatPlayer(int px, int py)
{
int dir = DIR_NONE;
if (px < x - MOVE_TOLERENCE / 2)
{
dir = DIR_LEFT;
}
else if (px > x + MOVE_TOLERENCE / 2)
{
dir = DIR_RIGHT;
}
else if (py < y - MOVE_TOLERENCE / 2)
{
dir = DIR_UP;
}
else if (py > y + MOVE_TOLERENCE / 2)
{
dir = DIR_DOWN;
}
/*
int dir = this->dir;
static int ddd = 1000;
ddd--;
if (ddd == 0)
{
dir = rand() % 5 - 2;
while (dir == 0)
{
dir = rand() % 5 - 2;
}
ddd = 1000;
}
*/
return dir;
}

@ -0,0 +1,60 @@
#pragma once
#include "mover.h"
class Monster:public Mover
{
protected:
int fear;
public:
Monster() :fear(0) {};
Monster(IMAGE* floor, Map* map);
void SetFear(int f);
int GetFear();
int Update(int px,int py);
bool TryEatPlayer(int px,int py);
bool EscapePlayer(int px, int py);
int GainDirToEatPlayer(int px, int py);
};
class MA :public Monster
{
public:
MA(IMAGE* floor, Map* map) :Monster(floor, map)
{
ImportImage("image/Pinky.png");
}
};
class MB :public Monster
{
public:
MB(IMAGE* floor, Map* map) :Monster(floor, map)
{
ImportImage("image/Blinky.png");
}
};
class MC :public Monster
{
public:
MC(IMAGE* floor, Map* map) :Monster(floor, map)
{
ImportImage("image/Clyde.png");
}
};
class MD :public Monster
{
public:
MD(IMAGE* floor, Map* map) :Monster(floor, map)
{
ImportImage("image/Inky.png");
}
};

@ -0,0 +1,263 @@
#include "mover.h"
Mover::Mover()
{
x = 0; y = 0;
px = 0; py = 0;
speed = 0;
dir = 0; pdir = 0;
move_status = 0;
move_status_max = 0;
move_status_buf = 0;
move_status_buf_max = 0;
floor = NULL;
map = NULL;
}
Mover::Mover(IMAGE* floor, Map* map) :floor(floor), map(map)
{
x = BLOCK_SIZE * 1 + BLOCK_SIZE / 2;
y = BLOCK_SIZE * 1 + BLOCK_SIZE / 2;
px = 0;
py = 0;
speed = 2;
dir = DIR_NONE;
pdir = DIR_NONE;
move_status = 0;
move_status_max = 2;
move_status_buf = 0;
move_status_buf_max = 10;
ImportImage("image/Pinky.png");
}
bool Mover::Move()
{
if (dir == DIR_NONE)
return false;
bool ss = true;
int nx = x;
int ny = y;
int dx = (nx % BLOCK_SIZE) - BLOCK_SIZE / 2;
int dy = (ny % BLOCK_SIZE) - BLOCK_SIZE / 2;
switch (dir)
{
case DIR_UP:
{
if (abs(dx) < MOVE_TOLERENCE)
{
ny -= speed;
nx -= dx;
}
else
ss = false;
break;
}
case DIR_DOWN:
{
if (abs(dx) < MOVE_TOLERENCE)
{
ny += speed;
nx -= dx;
}
else
ss = false;
break;
}
case DIR_LEFT:
{
if (abs(dy) < MOVE_TOLERENCE)
{
nx -= speed;
ny -= dy;
}
else
ss = false;
break;
}
case DIR_RIGHT:
{
if (abs(dy) < MOVE_TOLERENCE)
{
nx += speed;
ny -= dy;
}
else
ss = false;
break;
}
}
if (ss == false)
{
if (dir != pdir)
{
dir = pdir;
return Move();
}
else
{
return false;
}
}
if (nx < 0)
nx = GAME_WIDTH;
else if (nx > GAME_WIDTH)
nx = 0;
if (ny < 0)
ny = GAME_HEIGHT;
else if (ny > GAME_HEIGHT)
ny = 0;
// 判断是否撞墙
int ni = (nx - BLOCK_SIZE / 2) / BLOCK_SIZE;
int nj = (ny - BLOCK_SIZE / 2) / BLOCK_SIZE;
switch (dir)
{
case DIR_UP:
case DIR_LEFT:
{
if (map->GetMap(ni, nj)==3)
ss = false;
break;
}
case DIR_DOWN:
{
if (map->GetMap(ni, nj + 1)==3)
ss = false;
break;
}
case DIR_RIGHT:
{
if (nx == 0)
{
if(map->GetMap(ni, nj)==3)
ss = false;
}
else if (map->GetMap(ni + 1, nj)==3)
ss = false;
break;
}
}
if (ss == false)
{
if (dir != pdir)
{
dir = pdir;
return Move();
}
else
{
return false;
}
}
move_status_buf++;
if (move_status_buf >= move_status_buf_max)
{
move_status_buf = 0;
move_status++;
if (move_status >= move_status_max)
move_status = 0;
}
x = nx;
y = ny;
pdir = dir;
return true;
}
void Mover::SetXY(int x, int y)
{
this->x = x;
this->y = y;
}
void Mover::GetXY(int& px, int& py)
{
px = x;
py = y;
}
void Mover::SetDir(int dir)
{
if (dir == DIR_NONE)
return;
this->dir = dir;
}
void Mover::Draw()
{
// 根据图像中心坐标 计算 左上角坐标
int draw_x, draw_y;
draw_x = px - PERSON_SIZE / 2;
draw_y = py - PERSON_SIZE / 2;
// 计算 对应地板图像
SetWorkingImage(floor);
IMAGE foot = IMAGE(PERSON_SIZE, PERSON_SIZE);
getimage(&foot, draw_x, draw_y, PERSON_SIZE, PERSON_SIZE);
//// 擦除旧图像(使用地板图像覆盖)
SetWorkingImage(NULL);
putimage(draw_x, draw_y, &foot);
// 绘制新图像
draw_x = x - PERSON_SIZE / 2;
draw_y = y - PERSON_SIZE / 2;
int num = 0;
switch (dir)
{
case DIR_UP: num = IMG_UP + move_status * 4; break;
case DIR_DOWN: num = IMG_DOWN + move_status * 4; break;
case DIR_LEFT: num = IMG_LEFT + move_status * 4; break;
case DIR_RIGHT: num = IMG_RIGHT + move_status * 4; break;
}
putimage(draw_x, draw_y, &img[num]);
// 替换旧坐标
px = x;
py = y;
}
void Mover::ImportImage(std::string path)
{
char* pathc = str2char(path);
ImportImage(pathc);
}
void Mover::ImportImage(char* path)
{
IMAGE whole_img;
loadimage(&whole_img, _T(path), PERSON_SIZE * move_status_max, PERSON_SIZE * 4, true);
SetWorkingImage(&whole_img);
int num = 0;
for (int i = 0; i < move_status_max; i++)
{
for (int j = 0; j < 4; j++)
{
num = i * 4 + j;
getimage(&img[num], i * PERSON_SIZE, j * PERSON_SIZE, PERSON_SIZE, PERSON_SIZE);
}
}
SetWorkingImage();
}

@ -0,0 +1,51 @@
#pragma once
#include <easyx.h>
#include <string>
using namespace std;
#include "map.h"
#include "define.h"
#include "tool.h"
class Mover
{
protected:
int x, y; // 列、横坐标
int px, py; // 旧的 列、横坐标
int speed; // 移动速度
int dir;
int pdir;
int move_status; // 移动时的状态,比如迈左脚还是右脚
int move_status_max; // 移动时最多具有几个状态
int move_status_buf; // 缓冲,让移动状态间的转换多几次移动
int move_status_buf_max;
IMAGE img[12]; // 人物图像
IMAGE* floor; // 人物足底图像
Map* map;
public:
Mover();
Mover(IMAGE* floor,Map* map);
bool Move();
void SetXY(int x, int y);
void GetXY(int& px, int& py);
void SetDir(int dir);
void SetSpeed(int speed)
{
this->speed = speed;
}
void Draw();
void ImportImage(std::string path);
void ImportImage(char* path);
};

@ -0,0 +1,61 @@
#include "player.h"
Player::Player(IMAGE* floor, Map* map) :Mover(floor, map)
{
score = 0;
move_status_max = 3;
ImportImage("image/Pacman.png");
}
int Player::TryEatBean()
{
int dx = (x % BLOCK_SIZE) - BLOCK_SIZE / 2;
int dy = (y % BLOCK_SIZE) - BLOCK_SIZE / 2;
if (abs(dx) < EAT_TOLERANCE && abs(dy) < EAT_TOLERANCE)
{
int bi = (x - dx - BLOCK_SIZE / 2) / BLOCK_SIZE;
int bj = (y - dy - BLOCK_SIZE / 2) / BLOCK_SIZE;
if (map->GetMap(bi, bj) ==1)
{
map->ClearBean(bi, bj);
score++;
DrawScore();
return 1;
}
else if (map->GetMap(bi, bj) == 2)
{
map->ClearBean(bi, bj);
score+=10;
DrawScore();
return 2;
}
}
return 0;
}
void Player::EatMonster()
{
score += 100;
DrawScore();
}
void Player::DrawScore()
{
string str;
str = "score: ";
str += num2str(score);
RECT r = { 0, GAME_HEIGHT, GAME_WIDTH, GAME_HEIGHT + SCORE_HEIGHT };
drawtext(_T(str2char(str)), &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}

@ -0,0 +1,18 @@
#pragma once
#include <easyx.h>
#include "mover.h"
class Player:public Mover
{
private:
int score;
public:
Player() :score(0) {};
Player(IMAGE* floor, Map* map);
int TryEatBean();
void EatMonster();
void DrawScore();
};

@ -0,0 +1,22 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 S.rc 使用
//
#define IDB_BITMAP1 101
#define IDB_PNG1 102
#define IDB_PNG2 103
#define IDR_TXT1 104
#define IDB_PNG3 105
#define IDB_PNG4 106
#define IDB_PNG5 107
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

@ -0,0 +1,22 @@
#include "tool.h"
char* str2char(string str)
{
rsize_t num = str.length() + 1;
char* strc = new char[num];
strcpy_s(strc, num, str.c_str());
return strc;
}
string num2str(int num)
{
stringstream ss;
string str_num;
ss << num;
ss >> str_num;
return str_num;
}

@ -0,0 +1,9 @@
#pragma once
#include <string>
#include <sstream>
using namespace std;
char* str2char(string str);
string num2str(int num);

@ -0,0 +1,2 @@
 main.cpp
S.vcxproj -> E:\2019 编程语言学习\C\2019\C++课程学习\eatbean\S2\x64\Debug\S.exe

@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0
Debug|x64|E:\2019 编程语言学习\C\2019\C++课程学习\eatbean\S2\|

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save