用c++写游戏----简单的推箱子游戏
用的是vs2013新建的一个win32控制台程序
// 2019.7.19.1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
enum GameState
{
E_STATE_MENUE,
E_STATE_MAP,
E_STATE_PASS,
};
enum MenuState
{
E_MENU_START,
E_MENU_OVER,
E_MENU_EXIT,
};
struct SPlayer
{
SPlayer(int nInRow,int nInCol){
nRow = nInRow;
nCol = nInCol;
nRowBk = nInRow;
nColBk = nInCol;
}
int nRow;
int nCol;
int nRowBk;
int nColBk;
};
SPlayer g_Player1(2, 2);
SPlayer g_Player(1,1);
struct SBox
{
int nRow;
int nCol;
int nRowBk;
int nColBk;
};
SBox g_arrBox[3];
struct SBonus
{
int nRow;
int nCol;
int nRowBk;
int nColBk;
};
SBonus g_arrBonus[3];
using namespace std;
#define KEY_DOWN(vk_code)(GetAsyncKeyState(vk_code)&0x8000?1:0)
//人物和箱子不能绑定在地图上
int _tmain(int argc, _TCHAR* argv[])
{
int nMenuState = E_MENU_START;
int nGameState = E_STATE_MENUE;
int arrMap[20][20] = {
{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{
1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{
1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 },
{
1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 },
{
1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 },
{
1, 0, 0, 0, 0