sprintf(str,"怪物使用梅肯斯姆...恢复了30点生命值",damage); MsgInsert(str); } break; case 4: //在第30个画面时判断怪物是否逃跑成功 if(f == 30) { if(1== rand()%3 ) //逃跑几率1/3 { over = true; monster.nHp = 0; sprintf(str,"怪物逃跑中...逃跑成功"); MsgInsert(str); } else { sprintf(str,"怪物逃跑中...逃跑失败"); MsgInsert(str); } } break; } } if(f == 30) //回合结束 { attack = false; f = 0; } } BitBlt(hdc,0,0,640,510,mdc,0,0,SRCCOPY); tPre = GetTickCount(); pNum++; if(pNum == 8) pNum = 0; } //****新增的对战消息函数******************************** void MsgInsert(char* str) { if(txtNum < 5) { sprintf(text[txtNum],str); txtNum++; } else { for(int i=0;i sprintf(text[i],text[i+1]); sprintf(text[4],str); } } //****生命值判断函数************************* void CheckDie(int hp,bool player) { char str[100]; if(hp <= 0) { over = true; if(player) { sprintf(str,"胜败乃兵家常事,大侠请重新来过......"); MsgInsert(str); } else { sprintf(str,"少年,你赢了,有两下子啊~~~~~!!!!"); MsgInsert(str); } } } //****消息处理函数*********************************** // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int x,y; switch (message) { case WM_KEYDOWN: //键盘消息 if(wParam==VK_ESCAPE) //按下Esc键 PostQuitMessage(0); break; case WM_LBUTTONDOWN: //鼠标左键消息 if(!attack) { x = LOWORD(lParam); //X坐标 y = HIWORD(lParam); //Y坐标 if(x >= 500 && x <= 550 && y >= 350 && y <= 400) attack = true; } break; case WM_DESTROY: //窗口结束消息 DeleteDC(mdc); DeleteDC(bufdc); DeleteObject(bg); DeleteObject(sheep); DeleteObject(girl); DeleteObject(skill); DeleteObject(skillult); DeleteObject(slash); DeleteObject(magic); DeleteObject(recover); DeleteObject(game); ReleaseDC(hWnd,hdc); PostQuitMessage(0); break; default: //默认消息 return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } #include "stdafx.h" #include
//定义一个结构体 struct chr { int nHp; int fHp; int lv; int w; int kind; };
//全局变量声明 HINSTANCE hInst; HBITMAP bg,sheep,girl,skill,skillult,slash,magic,recover,game; HDC hdc,mdc,bufdc; HWND hW |