#pragma comment(lib, "msimg32.lib")
#include <windows.h>
#include "Game.h"
#include "Image.h"
#include "Input.h"
#include "MCI.h"
#include<time.h>
//定义全局指针变量
Game *g_pgame = NULL;
Sprite *g_pspr = NULL;
Sprite *g_psprmenu = NULL;
Sprite *g_psprHelp = NULL;
Sprite *g_psprback = NULL;
SpriteAni *g_psprdig = NULL;
SpriteAni *g_psprplay = NULL;
SpriteAni *g_psprsezi = NULL;
SpriteAni *g_psprgo = NULL;
SpriteAni *g_psprngo = NULL;
SpriteAni *g_pspremn= NULL;
SpriteAni *g_psprspace= NULL;
SpriteAni *g_psprfang= NULL;
SpriteAni *g_psprfang1= NULL;
SpriteAni *g_psprfang2= NULL;
SpriteAni *g_psprefang= NULL;
SpriteAni *g_psprefang1= NULL;
SpriteAni *g_psprefang2= NULL;
BackBuffer *g_pbb = NULL;
MCI *g_pwav = NULL;
//定义全局变量
GameInput g_input;
int menu=0;//菜单
int moves=0;//人物的移动量
int emoves=0;
int index=0;//色子图片下标
int shuiji=1;//随机数
int eshuiji=1;//随机数
int house[63][3]={0};
int jishi=0;
int start=0;//true:人物开始丢色子;false:电脑开始丢色子
int money=200000;//玩家的金钱
int enmoney=200000;
BOOL InitGame(HWND hwnd)
{
if(NULL == g_pwav)g_pwav = new MCI(hwnd, L"audio\\bubbles1.wav", MCI_WAV);
if(NULL == g_pbb)g_pbb = new BackBuffer(hwnd);
if(NULL == g_pspr)g_pspr = new SpriteAni(L"Image\\map.bmp"); // 2
if(NULL == g_psprmenu)g_psprmenu = new SpriteAni(L"Image\\menu.bmp"); // 2
if(NULL == g_psprHelp)g_psprHelp = new SpriteAni(L"Image\\DFWhelp.bmp");
if(NULL == g_psprback)g_psprback = new SpriteAni(L"Image\\back.bmp");
g_psprback->dest_x=700;
g_psprback->dest_y=530;
if(NULL == g_psprdig)g_psprdig = new SpriteAni(L"Image\\dilogo.bmp");
if(NULL == g_psprplay)g_psprplay = new SpriteAni(L"Image\\player.bmp");
g_psprplay->dest_x=490;
g_psprplay->dest_y=178;
if(NULL == g_psprsezi)g_psprsezi = new SpriteAni(L"Image\\sezi.bmp");
g_psprsezi->dest_x=300;
g_psprsezi->dest_y=400;
if(NULL == g_psprgo)g_psprgo = new SpriteAni(L"Image\\go2.bmp");
g_psprgo->dest_x=420;
g_psprgo->dest_y=380;
if(NULL == g_psprngo)g_psprngo = new SpriteAni(L"Image\\go1.bmp");
g_psprngo->dest_x=420;
g_psprngo->dest_y=380;
if(NULL == g_pspremn)g_pspremn = new SpriteAni(L"Image\\eminey.bmp");
g_pspremn->dest_x=50;
g_pspremn->dest_y=458;
g_pspremn->indexX=0;
g_pspremn->indexY=3;
g_pspremn->speedx=0;
g_pspremn->speedy=-5;
g_pspremn->ptudi=32;
if(NULL == g_psprspace)g_psprspace = new SpriteAni(L"Image\\space.bmp");
if(NULL == g_psprfang)g_psprfang = new SpriteAni(L"Image\\fanzi0.bmp");
if(NULL == g_psprfang1)g_psprfang1 = new SpriteAni(L"Image\\fanzi1.bmp");
if(NULL == g_psprfang2)g_psprfang2= new SpriteAni(L"Image\\fanzi2.bmp");
if(NULL == g_psprefang)g_psprefang = new SpriteAni(L"Image\\efanzi0.bmp");
if(NULL == g_psprefang1)g_psprefang1 = new SpriteAni(L"Image\\efanzi1.bmp");
if(NULL == g_psprefang2)g_psprefang2 = new SpriteAni(L"Image\\efanzi2.bmp");
for(int i=2;i<6;i++)
{
house[i][0]=10;
house[i][1]=490+i*40;
house[i][2]=218;
}
for(int i=9;i<13;i++)
{
house[i][0]=10;
house[i][1]=710;
house[i][2]=178+(i-7)*40;
}
for(int i=16;i<31;i++)
{
house[i][0]=10;
house[i][1]=770-(i-14)*40;
house[i][2]=500;
}
for(int i=35;i<40;i++)
{
house[i][0]=10;
house[i][1]=100;
house[i][2]=458-(i-32)*40;
}
for(int i=44;i<47;i++)
{
house[i][0]=10;
house[i][1]=50+(i-42)*40;
house[i][2]=140;
}
for(int i=50;i<53;i++)
{
house[i][0]=10;
house[i][1]=320;
house[i][2]=58+(i-48)*40;
}
for(int i=56;i<58;i++)
{
house[i][0]=10;
house[i][1]=290+(i-54)*40;
house[i][2]=340;
}
for(int i=60;i<=61;i++)
{
house[i][0]=10;
house[i][1]=520;
house[i][2]=298-(i-59)*40;
}
return true;
}
void Drawmenu(HDC hdc)
{
HFONT sfont;
LOGFONTW font;
ZeroMemory(&font, sizeof(font));
font.lfCharSet = GB2312_CHARSET;
wcscpy(font.lfFaceName, L"宋体");
font.lfWidth = 20;
font.lfHeight = 20;
sfont = CreateFontIndirectW(&font);
SelectObject(g_pbb->m_hdc, sfont);
SetBkMode(g_pbb->m_hdc, 1);
SetTextColor(g_pbb->m_hdc, RGB(100,100,255));
TransparentBlt(g_pbb->m_hdc, g_psprmenu->dest_x, g_psprmenu->dest_y,
g_psprmenu->m_width, g_psprmenu->m_height,
g_psprmenu->m_hdc, 0,0,
g_psprmenu->m_width, g_psprmenu->m_height,
0);
g_psprdig->dest_x=200;
g_psprdig->dest_y=200;
TransparentBlt(g_pbb->m_hdc, g_psprdig->dest_x, g_psprdig->dest_y,
g_psprdig->m_width, g_psprdig->m_height,
g_psprdig->m_hdc, 0,0,
g_psprdig->m_width, g_psprdig->m_height,
RGB(172,234,240));
RECT rect0 = {203, 205, 328,237};
DrawTextW(g_pbb->m_hdc, L"新游戏", -1, &rect0, DT_CENTER);
g_psprdig->dest_x=300;
g_psprdig->dest_y=300;
TransparentBlt(g_pbb->m_hdc, g_psprdig->dest_x, g_psprdig->dest_y,
g_psprdig->m_width, g_psprdig->m_height,
g_psprdig->m_hdc, 0,0,
g_psprdig->m_width, g_psprdig->m_height,
RGB(172,234,240));
RECT rect1 = {303, 305, 428,337};
DrawTextW(g_pbb->m_hdc, L"帮助", -1, &rect1, DT_CENTER);
g_psprdig->dest_x=400;
g_psprdig->dest_y=400;
TransparentBlt(g_pbb->m_hdc, g_psprdig->dest_x, g_psprdig->dest_y,
g_psprdig->m_width, g_psprdig->m_height,
g_psprdig->m_hdc, 0,0,
g_psprdig->m_width, g_psprdig->m_height,
RGB(172,234,240));
RECT rect2 = {403, 405, 528,437};
DrawTextW(g_pbb->m_hdc, L"退出", -1, &rect2, DT_CENTER);
ZeroMemory(&font, sizeof(font));
font.lfCharSet = GB2312_CHARSET;
wcscpy(font.lfFaceName, L"黑体");
font.lfWidth = 11;
font.lfHeight = 12;
sfont = CreateFontIndirectW(&font);
SelectObject(g_pbb->m_hdc, sfont);
SetBkMode(g_pbb->m_hdc, 1);
SetTextColor(g_pbb->m_hdc, RGB(0,0,0));
}
void DrawHelp(HDC hdc)
{
TransparentBlt(g_pbb->m_hdc, g_psprHelp->dest_x, g_psprHelp->dest_y,
g_psprHelp->m_width, g_psprHelp->m_height,
g_psprHelp->m_hdc, 0,0,
g_psprHelp->m_width, g_psprHelp->m_height,
0);
TransparentBlt(g_pbb->m_hdc, g_psprback->dest_x, g_psprback->dest_y,
g_psprback->m_width, g_psprback->m_height,
g_psprback->m_hdc, 0,0,
g_psprback->m_width, g_psprback->m_height,
0);
}
void DrawRW(HDC hdc)
{
// -------------画地图------------
TransparentBlt(g_pbb->m_hdc, g_pspr->dest_x, g_pspr->dest_y,
g_pspr->m_width, g_pspr->m_height,
g_pspr->m_hdc, 0,0,
g_pspr->m_width, g_pspr->m_height,
0);
// -------------画人物------------
TransparentBlt(g_pbb->m_hdc, g_psprplay->dest_x, g_psprplay->dest_y,
g_psprplay->m_width/4, g_psprplay->m_height/4,
g_psprplay->m_hdc, g_psprplay->m_width/4*g_psprplay->indexX,g_psprplay->m_height/4*g_psprplay->indexY,
g_psprplay->m_width/4, g_psprplay->m_height/4,
0xffffff);
// -------------画色子------------
TransparentBlt(g_pbb->m_hdc, g_psprsezi->dest_x, g_psprsezi->dest_y,
g_psprsezi->m_width/3, g_psprsezi->m_height/2,
g_psprsezi->m_hdc, ((g_psprsezi->m_width)/3)*((shuiji-1)%3),g_psprsezi->m_height/2*((shuiji-1)/3),
(g_psprsezi->m_width)/3, g_psprsezi->m_height/2,
0);
// -------------画敌人------------
TransparentBlt(g_pbb->m_hdc, g_pspremn->dest_x, g_pspremn->dest_y,
g_pspremn->m_width/4, g_pspremn->m_height/4,
g_pspremn->m_hdc, g_pspremn->m_width/4*g_pspremn->indexX,g_pspremn->m_height/4*g_pspremn->indexY,
g_pspremn->m_width/4, g_pspremn->m_height/4,
RGB(105,142,125));
//---------------画go图片-----------------
if(start==0)
{
TransparentBlt(g_pbb->m_hdc, g_psprgo->dest_x, g_psprgo->dest_y,
g_psprgo->m_width, g_psprgo->m_height,
g_psprgo->m_hdc, 0,0,
g_psprgo->m_width, g_psprgo->m_height,
RGB(49,25,143));
}
else
{
TransparentBlt(g_pbb->m_hdc, g_psprngo->dest_x, g_psprngo->dest_y,
g_psprngo->m_width, g_psprngo->m_height,
g_psprngo->m_hdc, 0,0,
g_psprngo->m_width, g_psprngo->m_height,
RGB(49,25,143));
}
//--------------------------------------
wchar_t buff[256];
wsprintfW(buff, L"玩家�