C++编好的一个俄罗斯方块游戏。生成了EXE文件,有源代码。怎么修改界面背景。就是游戏中的背景图片。
答案:2 悬赏:0 手机版
解决时间 2021-03-17 08:55
- 提问者网友:战魂
- 2021-03-16 14:29
这个程序是从网上找的,是我们要交的作业,不知道怎么改背景图片,求高手帮忙
最佳答案
- 五星知识达人网友:北城痞子
- 2021-03-16 15:39
具体问题具体分析。可以先看看背景是不是在资源里存在,如果存在那直接替换估计就OK了。如果是代码中写的,那就修改代码了。
全部回答
- 1楼网友:春色三分
- 2021-03-16 17:13
#pragma once
#include "afxwin.h"
#include "resource.h"
const int block_line = 20;
const int block_row = 10;
class cblock
{
public:
cblock(void);
~cblock(void);
private:
int m_blockshape;
int m_nextblockshape;
int m_blockstate;
int m_blocklevel;
int m_blockcurdelline;
bool m_blockrunning;
point m_blockpos[4];
point m_nextblockpos[4];
int m_blockmap[block_line][block_row];
public:
void blockinit( void );
private:
cbitmap m_bmpblock[7];
public:
void createnewblock(void);
void makenewblock(int shape, point pt[], int xpos);
//cdc memdc;
void drawblock(cdc* pdc);
void blockdropdown(cdc* pdc);
void hideblock(cdc* pdc);
private:
cbitmap m_bmpbkgnd;
public:
void drawnextblock( cdc* pdc );
void blockleft(cdc* pdc);
void blockright(cdc* pdc);
void blockfastdown(cdc* pdc);
void changestate(cdc* pdc);
void deleteline(cdc* pdc, int linenum, bool start);
bool blockgameover(void);
void blockscore(int del, cdc* pdc);
bool blocklevelup(void);
int blockspeed(void);
};
#include "stdafx.h"
#include "block.h"
cblock::cblock(void)
{
srand( (unsigned)time(null) );
m_blockshape = 0;
m_nextblockshape = rand()%7;
m_blockstate = 0;
m_blocklevel = 1;
m_blockcurdelline = 0;
m_blockrunning = false;
memset(m_blockmap, 0, sizeof(m_blockmap) );
}
cblock::~cblock(void)
{
}
void cblock::blockinit( void )
{
for( int i=0; i<7; i++)
{
m_bmpblock[i].loadbitmapw( idb_blockbar+i );
}
m_bmpbkgnd.loadbitmapw( idb_bmpback );
}
void cblock::createnewblock(void)
{
m_blockshape = m_nextblockshape;
m_nextblockshape = rand()%7;
m_blockstate = 0;
makenewblock( m_blockshape, m_blockpos, 4 );
}
void cblock::makenewblock(int shape, point pt[], int xpos)
{
switch(shape)
{
case 0:
for(int i=0; i<4; i++)
{
pt[i].x=i+xpos;
pt[i].y=0;
}
break;
case 1:
pt[0].x = 1+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 2:
pt[0].x = 0+xpos;
pt[0].y = 0;
pt[1].x = 1+xpos;
pt[1].y = 0;
pt[2].x = 1+xpos;
pt[2].y = 1;
pt[3].x = 2+xpos;
pt[3].y = 1;
break;
case 3:
pt[0].x = 0+xpos;
pt[0].y = 1;
pt[1].x = 1+xpos;
pt[1].y = 1;
pt[2].x = 1+xpos;
pt[2].y = 0;
pt[3].x = 2+xpos;
pt[3].y = 0;
break;
case 4:
pt[0].x = 0+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 5:
pt[0].x = 2+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 6:
for(int i=0; i<2; i++)
{
pt[i].x = i+xpos;
pt[i].y = 0;
pt[i+2].x = i+xpos;
pt[i+2].y = 1;
}
break;
default:
break;
}
}
void cblock::drawblock(cdc* pdc)
{
//blockinit();
//makenewblock( m_blockshape, m_blockpos, 4 );
cdc memdc;
memdc.createcompatibledc(pdc);
memdc.selectobject( &m_bmpblock[m_blockshape] ) ;
int x = block_x;
int y = block_y;
for( int i = 0; i<4; i++ )
{
x = block_x + m_blockpos[i].x*block_width;
y = block_y + m_blockpos[i].y*block_height;
pdc->bitblt( x, y, 20, 20, &memdc, 0, 0, srccopy );
}
}
void cblock::blockdropdown( cdc* pdc )
{
int i,j;
bool babledrop = true;
for( i=0; i<4; i++ )
{
if( 19 == m_blockpos[i].y || 0 != m_blockmap[m_blockpos[i].y+1][m_blockpos[i].x] )
{
babledrop = false;
break;
}
}
if( true == babledrop )
{
hideblock( pdc );
for( i=0; i<4; i++ )
{
m_blockpos[i].y++;
}
drawblock( pdc );
}
else
{
for( i=0; i<4; i++ )
{
m_blockmap[m_blockpos[i].y][m_blockpos[i].x] = m_blockshape+1;
}
for( i=0; i<20; i++ )
{
for( j=0; j<10; j++ )
{
if( 0 == m_blockmap[i][j] )
{
break;
}
}
if( 10 == j )
{
deleteline( pdc, i, false );
m_blockcurdelline++;
blockscore(1, pdc );
}
}
createnewblock();
makenewblock( m_blockshape, m_blockpos, 4 );
drawblock( pdc );
drawnextblock( pdc );
}
}
void cblock::hideblock(cdc* pdc)
{
cdc bkdc;
bkdc.createcompatibledc(pdc);
bkdc.selectobject(m_bmpbkgnd);
int x, y;
for( int i=0; i<4; i++ )
{
x = block_x+block_width*m_blockpos[i].x;
y = block_y+block_height*m_blockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, x, y, srccopy );
}
bkdc.deletedc();
}
void cblock::drawnextblock( cdc* pdc )
{
cdc bkdc;
bkdc.createcompatibledc( pdc );
bkdc.selectobject( m_bmpbkgnd );
int x ,y;
pdc->bitblt( nextblock_x, nextblock_y, nextblock_width, nextblock_height,
&bkdc, nextblock_x, nextblock_y, srccopy );
makenewblock( m_nextblockshape, m_nextblockpos, 0 );
bkdc.selectobject( m_bmpblock[m_nextblockshape] );
if( 0 == m_nextblockshape )
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 15 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 47 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
else if( 6 == m_nextblockshape )
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 35 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 38 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
else
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 24 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 38 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
}
void cblock::blockleft(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].x <= 0 )
return;
if( 0 != m_blockmap[m_blockpos[i].y][m_blockpos[i].x-1] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].x -= 1;
}
drawblock( pdc );
}
void cblock::blockright(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].x >= 9 )
return;
if( 0 != m_blockmap[m_blockpos[i].y][m_blockpos[i].x+1] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].x += 1;
}
drawblock( pdc );
}
void cblock::blockfastdown(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].y >= 19 )
return;
if( 0 != m_blockmap[m_blockpos[i].y+1][m_blockpos[i].x] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].y += 1;
}
drawblock( pdc );
}
#include "stdafx.h"
#include "block.h"
cblock::cblock(void)
{
srand( (unsigned)time(null) );
m_blockshape = 0;
m_nextblockshape = rand()%7;
m_blockstate = 0;
m_blocklevel = 1;
m_blockcurdelline = 0;
m_blockrunning = false;
memset(m_blockmap, 0, sizeof(m_blockmap) );
}
cblock::~cblock(void)
{
}
void cblock::blockinit( void )
{
for( int i=0; i<7; i++)
{
m_bmpblock[i].loadbitmapw( idb_blockbar+i );
}
m_bmpbkgnd.loadbitmapw( idb_bmpback );
}
void cblock::createnewblock(void)
{
m_blockshape = m_nextblockshape;
m_nextblockshape = rand()%7;
m_blockstate = 0;
makenewblock( m_blockshape, m_blockpos, 4 );
}
void cblock::makenewblock(int shape, point pt[], int xpos)
{
switch(shape)
{
case 0:
for(int i=0; i<4; i++)
{
pt[i].x=i+xpos;
pt[i].y=0;
}
break;
case 1:
pt[0].x = 1+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 2:
pt[0].x = 0+xpos;
pt[0].y = 0;
pt[1].x = 1+xpos;
pt[1].y = 0;
pt[2].x = 1+xpos;
pt[2].y = 1;
pt[3].x = 2+xpos;
pt[3].y = 1;
break;
case 3:
pt[0].x = 0+xpos;
pt[0].y = 1;
pt[1].x = 1+xpos;
pt[1].y = 1;
pt[2].x = 1+xpos;
pt[2].y = 0;
pt[3].x = 2+xpos;
pt[3].y = 0;
break;
case 4:
pt[0].x = 0+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 5:
pt[0].x = 2+xpos;
pt[0].y = 0;
for(int i=1; i<4; i++)
{
pt[i].x = i-1+xpos;
pt[i].y = 1;
}
break;
case 6:
for(int i=0; i<2; i++)
{
pt[i].x = i+xpos;
pt[i].y = 0;
pt[i+2].x = i+xpos;
pt[i+2].y = 1;
}
break;
default:
break;
}
}
void cblock::drawblock(cdc* pdc)
{
cdc memdc;
memdc.createcompatibledc(pdc);
memdc.selectobject( &m_bmpblock[m_blockshape] ) ;
int x = block_x;
int y = block_y;
for( int i = 0; i<4; i++ )
{
x = block_x + m_blockpos[i].x*block_width;
y = block_y + m_blockpos[i].y*block_height;
pdc->bitblt( x, y, 20, 20, &memdc, 0, 0, srccopy );
}
}
void cblock::blockdropdown( cdc* pdc )
{
int i,j;
bool babledrop = true;
for( i=0; i<4; i++ )
{
if( 19 == m_blockpos[i].y || 0 != m_blockmap[m_blockpos[i].y+1][m_blockpos[i].x] )
{
babledrop = false;
break;
}
}
if( true == babledrop )
{
hideblock( pdc );
for( i=0; i<4; i++ )
{
m_blockpos[i].y++;
}
drawblock( pdc );
}
else
{
for( i=0; i<4; i++ )
{
m_blockmap[m_blockpos[i].y][m_blockpos[i].x] = m_blockshape+1;
}
for( i=0; i<20; i++ )
{
for( j=0; j<10; j++ )
{
if( 0 == m_blockmap[i][j] )
{
break;
}
}
if( 10 == j )
{
deleteline( pdc, i, false );
m_blockcurdelline++;
blockscore(1, pdc );
}
}
createnewblock();
makenewblock( m_blockshape, m_blockpos, 4 );
drawblock( pdc );
drawnextblock( pdc );
}
}
void cblock::hideblock(cdc* pdc)
{
cdc bkdc;
bkdc.createcompatibledc(pdc);
bkdc.selectobject(m_bmpbkgnd);
int x, y;
for( int i=0; i<4; i++ )
{
x = block_x+block_width*m_blockpos[i].x;
y = block_y+block_height*m_blockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, x, y, srccopy );
}
bkdc.deletedc();
}
void cblock::drawnextblock( cdc* pdc )
{
cdc bkdc;
bkdc.createcompatibledc( pdc );
bkdc.selectobject( m_bmpbkgnd );
int x ,y;
pdc->bitblt( nextblock_x, nextblock_y, nextblock_width, nextblock_height,
&bkdc, nextblock_x, nextblock_y, srccopy );
makenewblock( m_nextblockshape, m_nextblockpos, 0 );
bkdc.selectobject( m_bmpblock[m_nextblockshape] );
if( 0 == m_nextblockshape )
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 15 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 47 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
else if( 6 == m_nextblockshape )
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 35 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 38 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
else
{
for( int i=0; i<4; i++ )
{
x = nextblock_x + 24 + block_width*m_nextblockpos[i].x;
y = nextblock_y + 38 + block_height*m_nextblockpos[i].y;
pdc->bitblt( x, y, block_width, block_height, &bkdc, 0, 0, srccopy );
}
}
}
void cblock::blockleft(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].x <= 0 )
return;
if( 0 != m_blockmap[m_blockpos[i].y][m_blockpos[i].x-1] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].x -= 1;
}
drawblock( pdc );
}
void cblock::blockright(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].x >= 9 )
return;
if( 0 != m_blockmap[m_blockpos[i].y][m_blockpos[i].x+1] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].x += 1;
}
drawblock( pdc );
}
void cblock::blockfastdown(cdc* pdc)
{
for( int i=0; i<4; i++ )
{
if( m_blockpos[i].y >= 19 )
return;
if( 0 != m_blockmap[m_blockpos[i].y+1][m_blockpos[i].x] )
return;
}
hideblock( pdc );
for( int i=0; i<4; i++ )
{
m_blockpos[i].y += 1;
}
drawblock( pdc );
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯