<>第20章 吃豆豆Pacman的地图关卡问题请教
发表在C语言图书答疑 2015-06-24
是否精华
版块置顶:
[font size=4]1.《C++开发实战》这本书的第20章 的  pacman游戏
2.随书附赠的源程序是用 vs2010 版本,我所用的是vs2013版本。
3.现在所遇到的问题是 在我的大嘴吃完所有豆豆之后, [font color=#FF0000]它不能按照所写的程序,进行到下一张地图,而是程序挂掉了,并不能出现对话框提示顺利过关。[/font]  当然,游戏过程中遇到敌人挂掉可以出现对话框提示。
4.想请教老师,这是怎么回事,为什么不能顺利的到下一关卡[/font]而是出现白屏没反应

[font color=#FF0000]pacman.cpp  代码如下:[/font]
// TODO: 在此放置代码。
int s_n = 0;//进行到的关卡数
p = new PacMan(P_ROW,P_ARRAY);
e1 =new RedOne(E_ROW,E_ARRAY);
e2 =new RedOne(E_ROW,E_ARRAY);
e3 = new BlueOne(E_ROW,E_ARRAY);
e4 = new YellowOne(E_ROW,E_ARRAY);
GMap* MapArray[STAGE_COUNT] = {new Stage_1(),new Stage_2(),new Stage_3()};
GObject::pStage =MapArray[s_n];//初始化为第一关地图
Enermy::player = p;
MSG msg;
HACCEL hAccelTable;

// 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_PACMAN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// 执行应用程序初始化:
HWND hWnd;
if (!InitInstance (hInstance, nCmdShow,hWnd))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_PACMAN));
DWORD t =0;
// 主消息循环:
while(p->GetTw()!=OVER && s_n<3)
{
if(p->Win())
{
HDC hdc = GetDC(hWnd);
s_n++;
ResetGObjects();
if(s_n <3)
{
MessageBoxA(hWnd,"恭喜您过关","吃豆子提示",MB_OK);
GObject::pStage = MapArray[s_n];
RECT screenRect;
screenRect.top = 0;
screenRect.left = 0;
screenRect.right = WLENTH;
screenRect.bottom = WHIGHT;
::FillRect(hdc,&screenRect,CreateSolidBrush(RGB(255,255,255)));
GObject::pStage->DrawMap(hdc);
}
continue;
}
if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(GetAsyncKeyState(VK_DOWN)&0x8000)
{
p->SetTwCommand(DOWN);
}
if(GetAsyncKeyState(VK_LEFT)&0x8000)
{
p->SetTwCommand(LEFT);
}
if(GetAsyncKeyState(VK_RIGHT)&0x8000)
{
p->SetTwCommand(RIGHT);
}
if(GetAsyncKeyState(VK_UP)&0x8000)
{
p->SetTwCommand(UP);
}

else
{
if(GetTickCount()-t>58)
{
HDC hdc = GetDC(hWnd);
e1->action();
e2->action();
e3->action();
e4->action();
p->action();
GObject::pStage->DrawPeas(hdc);
e1->DrawBlank(hdc);
e2->DrawBlank(hdc);
e3->DrawBlank(hdc);
e4->DrawBlank(hdc);
p->DrawBlank(hdc);
e1->Draw(hdc);
e2->Draw(hdc);
e3->Draw(hdc);
e4->Draw(hdc);
p->Draw(hdc);
DeleteDC(hdc);
t = GetTickCount();
}
}
    }
Realese(e1);
Realese(e2);
Realese(e3);
Realese(e4);
for(int i = 0;i<STAGE_COUNT;i++)
{
Realese(MapArray[i]);
}
if(p->GetTw()==OVER)
{
MessageBoxA(hWnd,"出师未捷","吃豆子提示",MB_OK);
}
else
{
MessageBoxA(hWnd,"恭喜您赢得了胜利","吃豆子提示",MB_OK);
}
Realese(p);
return (int) msg.wParam;
}

[font color=#0000FF]gmap.cpp  部分代码如下[/font]
 GMap::~GMap()
{

}
 //Stage_1成员定义:
 #define A true
#define B false
bool Stage_1::initData[MAPLENTH][MAPLENTH]=
 {    此处地图代码省略};
#undef A
#undef B
Stage_1::Stage_1()
{
color =RGB(140,240,240);
for(int i= 0;i<MAPLENTH;i++)
{
for(int j =0;j<MAPLENTH;j++)
{
this->mapData[i][j] = this->initData[i][j]; 
this->peaMapData[i][j] =this->initData[i][j];
}
}
//敌我双方出现位置没有豆子出现
this->InitOP();
}
//Stage_2成员定义
#define A true
#define B false
bool Stage_2::initData[MAPLENTH][MAPLENTH]=
     {    此处代码省略};
#undef A
#undef B
Stage_2::Stage_2()
{
color = RGB(240,140,140);
for(int i= 0;i<MAPLENTH;i++)
{
for(int j =0;j<MAPLENTH;j++)
{
this->mapData[i][j] = this->initData[i][j]; 
this->peaMapData[i][j] = this->initData[i][j];
}
}
//敌我双方出现位置没有豆子出现
this->InitOP();
}
//Stage_3成员定义
#define A true
#define B false
bool Stage_3::initData[MAPLENTH][MAPLENTH]=
   {    此处代码省略};
#undef A
#undef B
Stage_3::Stage_3()
{
color = RGB(100,300,100);
for(int i= 0;i<MAPLENTH;i++)
{
for(int j =0;j<MAPLENTH;j++)
{
this->mapData[i][j] = this->initData[i][j]; 
this->peaMapData[i][j] = this->initData[i][j];
}
}
//敌我双方出现位置没有豆子出现
this->InitOP();
}



[font color=#00FF00]gmap.h[/font]
#pragma once
#include "stdafx.h"
#include <list>
#define  MAPLENTH 19  //逻辑地图大小
#define P_ROW 10
#define P_ARRAY 9
#define E_ROW 8
#define E_ARRAY 9
using std::list;
//抽象类GMap
class GMap{

protected:
static int LD ;//障碍物尺寸
static int PD;//豆子的半径
void InitOP();//敌我双方出现位置没有豆子出现
bool mapData[MAPLENTH ][MAPLENTH ];//障碍物逻辑地图点阵
bool peaMapData[MAPLENTH ][MAPLENTH ];//豆子逻辑地图点阵
COLORREF color;
public:
void  DrawMap(HDC& hdc);//绘制地图
void  DrawPeas(HDC& hdc);//绘制豆子
virtual ~GMap();
GMap(){

}
friend class GObject;//允许物体类使用直线的起点和终点的信息做碰撞检测
friend class PacMan;//允许"大嘴"访问豆子地图
};
//"第一关"
class Stage_1:public GMap 
{
private: 
 bool static initData[MAPLENTH][MAPLENTH];
public:
Stage_1();
};
class Stage_2:public GMap
{
private: 
 bool static initData[MAPLENTH][MAPLENTH];
public:
Stage_2();
};
class Stage_3:public GMap
{
private: 
 bool static initData[MAPLENTH][MAPLENTH];
public:
Stage_3();
};

拜托老师了
分享到:
精彩评论 2
爱学习
学分:0 LV1
TA的每日心情
开心
2020-03-23 20:54:03
2015-06-24
沙发
您好,由于时间关系,这个代码需要进行调试,6月27号下班之前给您回复,感谢您对明日科技的关注与支持!
爱学习
学分:0 LV1
TA的每日心情
开心
2020-03-23 20:54:03
2015-06-27
板凳
尊敬的读者,很抱歉,最近时间比较紧张,这个程序时间比较久远,所以调试还需要些时间,真的很抱歉,我们会尽快调试出结果,感谢您对明日科技的关注。
首页上一页 1 下一页尾页 2 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照