永发信息网

C++编好的一个俄罗斯方块游戏。生成了EXE文件,有源代码。怎么修改界面背景。就是游戏中的背景图片。

答案:2  悬赏:0  手机版
解决时间 2021-03-17 08:55
这个程序是从网上找的,是我们要交的作业,不知道怎么改背景图片,求高手帮忙
最佳答案
具体问题具体分析。可以先看看背景是不是在资源里存在,如果存在那直接替换估计就OK了。如果是代码中写的,那就修改代码了。
全部回答
#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 ); }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
固体饮料办理QS,还需要制定企业标准吗,有没
《哦我的鬼神大人》里副主厨唱的Congratulati
干什么能赚大钱?我家穷怎么办?我爸爸48了怎
万达鞋城在哪里啊,我有事要去这个地方
唐代开科考试共设立了几科?
婴儿一天拉三次大便,正不正常
曲靖慧谷幼儿园老师的工资多少,待遇怎么样?
喝酒之前喝点什么或吃点什么 之后就能喝多点
女孩进来,做,爱时男的舒服。女的表情很痛苦。
合租房子的美女,她男友在外面当兵,我想让她
海霞美容美发怎么去啊,有知道地址的么
是歇后语【拉着手走路】 后面的一句(百度一
形容亲自上任的成语有哪些
求六年级下册语文1到4单元的所有多音字。谢谢
纤体西梅是多少钱一盒呢一盒是多少个
推荐资讯
895、美国心理学家、行为学家马斯洛把人的需
工行账户购买加拿大元在加拿大可以取用吗
凌度行车记录仪声音关掉会翻查出来吗
一道初一学生的寒假作业题。谢啦!
我只对女朋友一个人好,但是女朋友对所有人都
家里突然出现了长得像蟑螂的虫 有谁知道是什
中国礼品行业究竟最缺什么
职业病鉴定时个人书面陈述材料怎么写
老舍先生现代文阅读答案
UG10.0怎么复制图层图层
学院路检测场新车手续大厅在什么地方啊,我要
1+1=13(什么情况下等式成立?)
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?