急求坦克大战C++原程序编码!!!

急求坦克大战C++原程序编码!!!谢谢!... 急求坦克大战C++原程序编码!!!谢谢! 展开
 我来答
伤倏臀w
2010-06-12 · TA获得超过1115个赞
知道大有可为答主
回答量:864
采纳率:60%
帮助的人:609万
展开全部
只是部分代码,太多了,请加分后联系我
// Game.cpp: implementation of the CGame class.
//
//////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include "Game.h"
#include "resource.h"

#define SCREEN_W 640
#define SCREEN_H 480
#define OFFSETX 100
#define OFFSETY 48
#define PLAYER1_STARTX 130
#define PLAYER1_STARTY 386
#define PLAYER2_STARTX 258
#define PLAYER2_STARTY 386

#define SAFE_RELEASE(x) if(x){ x->Release(); x = NULL; }

CGame* g_pGame;

inline int random( int min, int max )
{
return (min + rand() % (max - min + 1));
}

void TRACE( LPCTSTR format, ... )
{
char buf[128];
va_list vl;

va_start(vl, format);
sprintf(buf, format, vl);
OutputDebugString( buf );
va_end(vl);
}

void CGame::OutputText( int x, int y, LPCTSTR string )
{
HDC hdc;
if( m_pddsBackBuffer &&
m_pddsBackBuffer->GetDC(&hdc) == DD_OK )
{
SetBkMode( hdc, TRANSPARENT );
SetTextColor( hdc, RGB(255,255,0) );
TextOut( hdc, x, y, string, lstrlen(string) );
m_pddsBackBuffer->ReleaseDC( hdc );
}
}

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGame::CGame()
{
m_hInst = NULL;
m_hWnd = NULL;
m_bActive = FALSE;
m_bShowStats = FALSE;
m_bFullScreen = TRUE;
m_bSingle = TRUE;

m_pDD = NULL;
m_pddsFrontBuffer = NULL;
m_pddsBackBuffer = NULL;
g_pGame = this;
}

CGame::~CGame()
{

}

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if( g_pGame )
return g_pGame->MsgProc( hWnd, uMsg, wParam, lParam );

return DefWindowProc( hWnd, uMsg, wParam, lParam );
}

LRESULT CGame::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch( uMsg )
{
case WM_ACTIVATEAPP:
if( m_bActive = (BOOL)wParam )
m_DirectInput.Acquire();
return 0;

case WM_SETCURSOR:
if( m_bFullScreen )
{
SetCursor( NULL );
return TRUE;
}
break;

case WM_CLOSE:
PostQuitMessage(0);
return 0;

case WM_MOVE:
m_bActive = TRUE;
GetClientRect( hWnd, &m_rcWindow );
ClientToScreen( hWnd, (LPPOINT)&m_rcWindow );
ClientToScreen( hWnd, (LPPOINT)&m_rcWindow + 1 );
return 0;

case WM_MOVING:
m_bActive = FALSE;
break;

case WM_KEYDOWN:
switch( wParam )
{
case VK_ESCAPE:
if( m_gameState == GS_ACTIVE )
m_gameState = GS_SPLASH;
else if( m_gameState == GS_SPLASH )
PostQuitMessage(0);
else if( m_gameState == GS_OVER )
m_gameState = GS_SPLASH;
break;

case VK_F4:
DDTerm();
m_bFullScreen = !m_bFullScreen;
DDInit();
return 0;

case VK_F5:
m_bShowStats = !m_bShowStats;
return 0;

case VK_DOWN:
case VK_UP:
if( m_gameState == GS_SPLASH )
{
m_bSingle = !m_bSingle;
return 0;
}
break;

case VK_PRIOR:
if( m_gameState == GS_ACTIVE && m_nLevel > 1 )
{
m_nLevel --;
InitLevel();
}
break;
case VK_NEXT:
if( m_gameState == GS_ACTIVE )
{
m_nLevel ++;
InitLevel();
}
break;

case VK_RETURN:
if( m_gameState == GS_SPLASH )
{
ResetGame();
return 0;
}
else if( m_gameState == GS_ACTIVE && !m_bSingle )
{
if( m_player[0].m_nLife > 1 &&
m_player[1].m_nLife <= 0 )
{
m_player[0].m_nLife --;
m_player[1].m_nLife = 1;
ResetPlayer( m_player[1] );
}
else if( m_player[1].m_nLife > 1 &&
m_player[0].m_nLife <= 0 )
{
m_player[1].m_nLife --;
m_player[0].m_nLife = 1;
ResetPlayer( m_player[0] );
}
}
break;
}
break;
}

return DefWindowProc( hWnd, uMsg, wParam, lParam );
}

BOOL CGame::Initialize( HINSTANCE hInst )
{
m_hInst = hInst;

if( !InitApplication() ||
!DDInit() ||
!InitGame() )
{
DDTerm();
return FALSE;
}

return TRUE;
}

BOOL CGame::InitApplication()
{
char szClassName[] = "BATTLECITY";
char szTitle[] = "Battle City";

WNDCLASS wc;
wc.hInstance = m_hInst;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.style = CS_DBLCLKS;
wc.hIcon = LoadIcon( m_hInst, MAKEINTRESOURCE(IDI_TANK) );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );

if( !RegisterClass( &wc ) )
{
TRACE( "Error In RegisterClassEx\n" );
return FALSE;
}

m_hWnd = CreateWindow( szClassName,
szTitle,
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
646, 505,
NULL,
NULL,
m_hInst,
NULL );
if( !m_hWnd )
{
TRACE( "Error In CreateWindow\n" );
return FALSE;
}

UpdateWindow( m_hWnd );
ShowWindow( m_hWnd, SW_NORMAL );

return TRUE;
}

int CGame::Run()
{
MSG msg;

while( TRUE )
{
if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage( &msg, NULL, 0, 0))
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}
else if( m_bActive )
{
UpdateFrame();
}
else
WaitMessage();
}

DDTerm();
return msg.wParam;
}

BOOL CGame::DDInit()
{
HRESULT hr;

hr = DirectDrawCreate( NULL, &m_pDD, NULL );
if( FAILED(hr) )
{
TRACE( "Error Create DirectDraw\n" );
return FALSE;
}

if( m_bFullScreen )
m_pDD->SetCooperativeLevel( m_hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN );
else
m_pDD->SetCooperativeLevel( m_hWnd, DDSCL_NORMAL );
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友52aeb54
2010-06-12 · TA获得超过2996个赞
知道小有建树答主
回答量:1261
采纳率:0%
帮助的人:1169万
展开全部
到C++吧里去找,是贴吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式