📄 czdemo.cpp
字号:
}//全部退出
if(PlayerID>=mygame.GetMode())
{
PlayerID=0;
}
}//while
}
/////////////////////////////电脑玩家行走完成///////////////////////////
if(players[PlayerID].IsComp()==true && steps==0 )
{
//1.切换至该角色的图画位置
{
PressKey(VK_RETURN,1);
RECT rect={0,0,266,198};//右上角的菜单。系统提示菜单。
Blt(pPSur,18*32,8*32,pMenu,rect,false);
PrintText(pPSur,18*32+25,8*32+30,"该电脑控制!");
PrintText(pPSur,18*32+25,8*32+60,"请按回车键");
//将画面切换到下一个玩家的场景。
PressKey(VK_RETURN,0);
GL_SwitchPlayer(PlayerID);
}
//控制电脑行走
//1.是否使用收购卡2.是否使用停留卡,3.是否使用乌龟卡,4.是否使用遥控色子,.
//5.是否使用高级汽车,6.是否使用通行证,0:什么都不用
int compsteps=0;
int operation=AI.UseToolOrCardBefore((players[PlayerID].x+16)/32,(players[PlayerID].y+47)/32,\
players[PlayerID].orientation,players[PlayerID].GetMoney(),PlayerID,compsteps);
switch (operation)
{
case 0:
{
//什么也不做
}
break;
case 1://收购卡
{
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑用收购卡",tchoice,1);
MyTool *temp=new MyTool;
for(int i=1;i<=players[PlayerID].tools.listlength();i++)
{
players[PlayerID].tools.getelem(i,temp);
if(temp->kind==BUYCARD)
{
players[PlayerID].tools.delelem(i);
break;
}
}
mygame.bcnum++;
GL_GamePicShowSilence();
Flip();
}
break;
case 2:
{
players[PlayerID].stop=true;
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑使用停留卡",tchoice,1);
MyTool *temp=new MyTool;
for(int i=1;i<=players[PlayerID].tools.listlength();i++)
{
players[PlayerID].tools.getelem(i,temp);
if(temp->kind==STOPCARD)
{
players[PlayerID].tools.delelem(i);
break;
}
}
mygame.stcnum++;
GL_GamePicShowSilence();
Flip();
}
break;
case 3:
{
players[PlayerID].onestep=true;
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑使用乌龟卡",tchoice,1);
MyTool *temp=new MyTool;
for(int i=1;i<=players[PlayerID].tools.listlength();i++)
{
players[PlayerID].tools.getelem(i,temp);
if(temp->kind==TORTCARD)
{
players[PlayerID].tools.delelem(i);
break;
}
}
mygame.tcnum++;
GL_GamePicShowSilence();
Flip();
}
break;
case 4:
{
players[PlayerID].choosestep=compsteps;
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑使用摇控色子",tchoice,1);
MyTool *temp=new MyTool;
for(int i=1;i<=players[PlayerID].tools.listlength();i++)
{
players[PlayerID].tools.getelem(i,temp);
if(temp->kind==REMODICE)
{
players[PlayerID].tools.delelem(i);
break;
}
}
mygame.rdnum++;
GL_GamePicShowSilence();
Flip();
}
break;
case 5://汽车
{
players[PlayerID].doubspeed=true;
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑使用高级轿车",tchoice,1);
MyTool *temp=new MyTool;
for(int i=1;i<=players[PlayerID].tools.listlength();i++)
{
players[PlayerID].tools.getelem(i,temp);
if(temp->kind==SUPERCAR)
{
players[PlayerID].tools.delelem(i);
break;
}
}
mygame.scnum++;
GL_GamePicShowSilence();
Flip();
}
break;
case 6://通行证
{
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("电脑用通行证",tchoice,1);
GL_GamePicShowSilence();
Flip();
}
break;
default://错误
{
MyMenus mymenu(360,260,"pics/menu.fim",280,120,GetRect(0,0,280,120));
char* tchoice[]={"确定"};
PressKey(VK_RETURN,1);
mymenu.ShowtMenu("error:返回值越界",tchoice,1);
GL_GamePicShowSilence();
Flip();
}
}
//2.根据行走模式设置步数
if(players[PlayerID].doubspeed==true)//使用高级汽车
{
steps=rand()%12+1;//产生随机步数。
if(steps>6)
steps-=6;
_itoa(13-steps,showstep,10);
}
else if(players[PlayerID].onestep==true)//使用乌龟卡
{
steps=6;
_itoa(7-steps,showstep,10);
}
else if(players[PlayerID].choosestep!=0)//使用摇控色子
{
steps=7-players[PlayerID].choosestep;
_itoa(7-steps,showstep,10);
}
else if(players[PlayerID].stop==true)//使用停留卡
{
steps=7;
_itoa(7-steps,showstep,10);
}
else
{
steps=rand()%6+1;//产生随机步数。
_itoa(7-steps,showstep,10);
}
//3.计算下一步的方向:
nextori=GetNextDirection((players[PlayerID].x+16)/32,(players[PlayerID].y+47)/32,players[PlayerID].orientation);
//4.显示提示信息:
{
GL_GamePicShowSilence();//显示背景图片。
++playercount; //增加一回合中的行动的角色计数。
RECT rect={0,0,266,198}; //右上角的菜单。
Blt(pPSur,18*32,8*32,pMenu,rect,false);//由于直接帖在pPSur上,这里可能会引发问题,即是在
//背景还有对话框的时候这个对话框也可能出现。
PrintText(pPSur,18*32+25,8*32+30,"电脑要走的步数:");
PrintText(pPSur,18*32+25,8*32+60,"请按回车键");
PrintText(pPSur,18*32+200+25,8*32+30,showstep);
PressKey(VK_RETURN,WAIT);
}
//5.设置定时器:
SetTimer(hWnd,1,100,NULL);//设置定时器。
}//电脑人物行走
//////////////////////////////////////////////////////////////
//玩家人物行走。
else if(players[PlayerID].IsComp()==false && steps==0)
{
//1.切换至该角色的图画位置
{
PressKey(VK_RETURN,1);
RECT rect={0,0,266,198};//右上角的菜单。系统提示菜单。
Blt(pPSur,18*32,8*32,pMenu,rect,false);
PrintText(pPSur,18*32+25,8*32+30,"该玩家控制!");
PrintText(pPSur,18*32+25,8*32+60,"请按回车键");
//将画面切换到下一个玩家的场景。
PressKey(VK_RETURN,0);
GL_SwitchPlayer(PlayerID);
}
//1.1使用物品或菜单
//{
// GL_GamePicShowSilence();
GL_GameMenu(PlayerID);
GL_GamePicShowSilence();
Flip();
//}
//2.根据行走模式设置步数
if(players[PlayerID].doubspeed==true)
{
steps=rand()%12+1;//产生随机步数。
if(steps>6)
steps-=6;
_itoa(13-steps,showstep,10);
}
else if(players[PlayerID].onestep==true)//使用乌龟卡
{
steps=6;
_itoa(7-steps,showstep,10);
}
else if(players[PlayerID].choosestep!=0)//使用遥控色子
{
steps=players[PlayerID].choosestep;
_itoa(7-steps,showstep,10);
GL_GamePicShowSilence();
char* info="使用了遥控色子";
MyMessage::PutMSG(SHOWMSG,info);
mymessage.RunMSG(PlayerID);
}
else if(players[PlayerID].stop==true)//使用了停留卡
{
steps=7;
_itoa(7-steps,showstep,10);
}
else
{
steps=rand()%6+1;//产生随机步数。
_itoa(7-steps,showstep,10);
}
//3.计算下一步的方向:
nextori=GetNextDirection((players[PlayerID].x+16)/32,(players[PlayerID].y+47)/32,players[PlayerID].orientation);
//4.显示提示信息:
{
GL_GamePicShowSilence();//显示背景图片。
++playercount; //增加一回合中的行动的角色计数。
RECT rect={0,0,266,198}; //右上角的菜单。
Blt(pPSur,18*32,8*32,pMenu,rect,false);//由于直接帖在pPSur上,这里可能会引发问题,即是在
//背景还有对话框的时候这个对话框也可能出现。
PrintText(pPSur,18*32+25,8*32+30,"玩家要走的步数:");
PrintText(pPSur,18*32+25,8*32+60,"请按回车键");
PrintText(pPSur,18*32+200+25,8*32+30,showstep);
PressKey(VK_RETURN,WAIT);
}
//5.设置定时器:
SetTimer(hWnd,1,100,NULL);//设置定时器。
}//人物行走处理完成
//吸收无用回车键。
PressKey(VK_RETURN,1);
}
//////////////////////////////////////////////////////////
//(此函数只能用于行走用显示,因为集成了行走声音的播放。)
inline void GL_GamePicShow()
{
MakeGround();
for(int i=0;i<mygame.GetMode();i++)
{
if(players[i].IsExist()==true)
players[i].DrawPlayer(pBBuf,pPlayer[i]);
}
//恢复背景图。
RECT rect={0,0,1024,768};
Blt(pBBuf,0,0,bk,rect,true);//以防人物出现在边框中。
Blt(pBBuf,776,249,sysmenu,GetRect(0,0,245,209),true);
gametime.ShowDate(); //显示游戏时间
ShowBar();//显示属性栏
PlayDirectSound(stepsound);
return;
}
//换到下一个玩家所要做的工作。
void GL_SwitchPlayer(int playerid)
{
players[playerid].SetRxy(); //先将画面进行切换。
MakeGround();
for(int i=0;i<mygame.GetMode();i++)
{
if(players[i].IsExist()==true)
players[i].DrawPlayer(pBBuf,pPlayer[i]);
}
RECT rect={0,0,1024,768};
Blt(pBBuf,0,0,bk,rect,true);//以防人物出现在边框中。
Blt(pBBuf,776,249,sysmenu,GetRect(0,0,245,209),true);
gametime.ShowDate(); //显示游戏时间
ShowBar();//显示属性栏
Flip();
return ;
}
//用于显示地图和背景。(无声)
inline void GL_GamePicShowSilence()
{
MakeGround();
for(int i=0;i<mygame.GetMode();i++)
{
if(players[i].IsExist()==true)
players[i].DrawPlayer(pBBuf,pPlayer[i]);
}
RECT rect={0,0,1024,768};
Blt(pBBuf,0,0,bk,rect,true);//以防人物出现在边框中。
Blt(pBBuf,776,249,sysmenu,GetRect(0,0,245,209),true);
gametime.ShowDate(); //显示游戏时间
ShowBar();//显示属性栏
return;
}
//游戏结束。
void GL_GameOver()
{
LPDIRECTDRAWSURFACE7 gameover;
CreateBitmap(gameover,1024,768,"pics/end.fim",DDSCAPS_SYSTEMMEMORY);
Blt(pBBuf,0,0,gameover,GetRect(0,0,1024,768),false);
Flip();
PrintText(pPSur,100,100,"以下是游戏各玩家得分:",RGB(0,255,0));
PrintText(pPSur,100,130,"姓名 称号 信誉 金钱 工厂数 房屋数 \
状态 总分",RGB(0,255,0), TRANSPARENT, RGB(255,255,255),100);
for(int i=0;i<mygame.GetMode();i++)
{
if(players[i].IsComp()==true)
PrintText(pPSur,30,160+i*30,"电脑",RGB(0,255,0));
else
PrintText(pPSur,30,160+i*30,"玩家",RGB(0,255,0));
PrintText(pPSur,100,160+i*30,players[i].name,RGB(0,255,0));
PrintText(pPSur,100+95,160+i*30,players[i].honour,RGB(0,255,0));
PrintText(pPSur,100+95*2,160+i*30,_ltoa(players[i].GetExp(),showmoney,10),RGB(0,255,0));
PrintText(pPSur,100+95*3,160+i*30,_ltoa(players[i].GetMoney()+mybank.GetStore(PlayerID),\
showmoney,10),RGB(0,255,0));
PrintText(pPSur,100+95*4,160+i*30,_ltoa(players[i].factorynum,showmoney,10),RGB(0,255,0));
PrintText(pPSur,100+95*5,160+i*30,_ltoa(players[i].buildingnum,showmoney,10),RGB(0,255,0));
if(players[i].IsExist()==true)
PrintText(pPSur,100+95*6,160+i*30,"坚持到最后",RGB(0,255,0));
else
PrintText(pPSur,100+95*6,160+i*30,"中途返回",RGB(0,255,0));
/* int score=(players[i].GetMoney()+(int)(mybank.GetStore(i))*0.3)+\
(int)(players[i].GetExp()*0.7)+players[i].factorynum*8+\
(int)(players[i].buildingnum*2.25)+(int)(players[i].contribute*2.4)+\
(int)(players[i].level*3);
*/
int score=(players[i].GetMoney()+mybank.GetStore(i))/100+\
players[i].GetExp()*20+players[i].factorynum*100+\
players[i].buildingnum*20+players[i].contribute*20+\
players[i].level*30;
PrintText(pPSur,100+95*8,160+i*30,_ltoa(score,showmoney,10),RGB(0,255,0));
}
Sleep(3000);
PressKey(VK_CONTROL,1);
PrintText(pPSur,100,700,"请按CTRL键退出游戏,谢谢!",RGB(0,255,0));
gameover->Release();
PressKey(VK_CONTROL,0);
FreeDDraw();//释放所有DirectDraw对象
ReleaseDirectSound();//释放DirectSound
FreeMidi();
PostMessage(hWnd, WM_DESTROY, 0, 0);
return;
}
//显示人物物品并使用
void GL_ShowTools(int playerid)
{
int toollen=players[playerid].tools.listlength();
if(toollen<1)
return;
else
{
GL_GamePicShowSilence();
Blt(pBBuf,6*32,6*32,pDialog1,GetRect(0,0,640,382),false);
int x=7*32+50;
int y=x;
RECT rect={0,0,100,100};
MyTool *tool=new MyTool;
int row=0;
for(int i=0;i<toollen;i++)
{
players[playerid].tools.getelem(i+1,tool);
if(row>3)//从0开始到3共四个
{
y=7*32+50+130;
x=7*32+50-4*100-4*20;
}
switch(tool->kind)
{
case COMPMANAGER:
Blt(pBBuf,x+row*100+row*20,y,cm,rect,true);
row++;
break;
case REMODICE:
Blt(pBBuf,x+row*100+row*20,y,rd,rect,true);
row++;
break;
case PASSPORT:
Blt(pBBuf,x+row*100+row*20,y,pp,rect,true);
row++;
break;
case STOPCARD:
Blt(pBBuf,x+row*100+row*20,y,sc,rect,true);
row++;
break;
case SUPERCAR:
Blt(pBBuf,x+row*100+row*20,y,suc,rect,true);
row++;
break;
case TORTCARD:
Blt(pBBuf,x+row*100+row*20,y,tt,rect,true);
row++;
break;
case BUYCARD:
Blt(pBBuf,x+row*100+row*20,y,bc,rect,true);
row++;
break;
}
}
//Flip();
PrintText(pBBuf,7*32+10,7*32,"请选择要使用的物品,按回车键确定:",RGB(255,255,255),OPAQUE,RGB(0,0,0));
PrintText(pBBuf,7*32+10,7*32+300,"放弃使用请按Ctrl键退出菜单。",RGB(255,255,255),OPAQUE,RGB(0,0,0));
}
}
//显示商店物品
void shopshow()
{
GL_GamePicShowSilence();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -