编写俄罗斯的一些问题?新手
小弟刚刚学完~那个谭老师的《C程序设计》,想自己试着编一个俄罗斯游戏出来,但我遇到几个问题?
1:图象怎么处理?
2:用什么来接受方向键?
谢谢高手指点一下!
[解决办法]
先看《windows 程序设计》,了解如何在windows上编程
[解决办法]
要知道如何处理GDI,如何消息处理,lz还有很多要学的
[解决办法]
http://blog.csdn.net/hoya5121/archive/2007/01/09/1477960.aspx
[解决办法]
/* Turbo C */
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <time.h>
#include <graphics.h>
#defineL 1
#defineLX15
#defineLY 4
staticstruct BLOCK{
intx0;
inty0;
intx1;
inty1;
intx2;
inty2;
intx3;
inty3;
intcolor;
intnext;
}b[23] = {{0, 1, 1, 1, 2, 1, 3, 1, 4, 1},
{1, 0, 1, 3, 1, 2, 1, 1, 4, 0 },
{1, 1, 2, 2, 1, 2, 2, 1, 1, 2 },
{0, 1, 1, 1, 1, 0, 2, 0, 2, 4 },
{1, 0, 1, 1, 2, 2, 2, 1, 2, 5 },
{0, 2, 1, 2, 1, 1, 2, 1, 2, 6 },
{0, 0, 0, 1, 1, 2, 1, 1, 2, 3 },
{0, 0, 1, 0, 1, 1, 2, 1, 3, 8 },
{0, 1, 0, 2, 1, 1, 1, 0, 3, 9 },
{0, 1, 1, 1, 1, 2, 2, 2, 3, 10 },
{1, 1, 1, 2, 2, 1, 2, 0, 3, 7 },
{1, 0, 1, 1, 1, 2, 2, 2, 7, 12 },
{0, 1, 1, 1, 2, 1, 2, 0, 7, 13 },
{0, 0, 1, 2, 1, 1, 1, 0, 7, 14 },
{0, 1, 0, 2, 1, 1, 2, 1, 7, 11 },
{0, 2, 1, 2, 1, 1, 1, 0, 5, 16 },
{0, 1, 1, 1, 2, 2, 2, 1, 5, 17 },
{1, 0, 1, 1, 1, 2, 2, 0, 5, 18 },
{0, 0, 0, 1, 1, 1, 2, 1, 5, 15 },
{0, 1, 1, 1, 1, 0, 2, 1, 6, 20 },
{0, 1, 1, 2, 1, 1, 1, 0, 6, 21 },
{0, 1, 1, 2, 1, 1, 2, 1, 6, 22 },
{1, 0, 1, 1, 1, 2, 2, 1, 6, 19 }};
staticintd[10]={ 33000,3000,1600,1200,900,800,600,400,300,200 };
intLlevel, Lcurrent, Lnext, Lable, lx, ly, Lsum;
unsignedLpoint;
intLa[19][10], FLAG, sum;
unsignedldelay;
voidscrinit( ),datainit( ),dispb( ), eraseb( );
voidthrow( ), judge( ), delayp( ), move( ), note( ), show( );
intLdrop( ), Ljudge( ), nextb( ), routejudge( );
main( )
{
charc;
do{
scrinit( );
datainit( );
Lable=nextb();
Lable = Ldrop( );
while( 1 ){
delayp( );
if( Lable != 0 ){
Ljudge( );
Lable = nextb( );
}
ldelay--;
if( ldelay == 0 ){
Lable = Ldrop( );
ldelay = d[0];
}
if( FLAG != 0 )
break;
}
while( getch( )!= '\r ' );
gotoxy( 38, 16 );
cputs( "again? " );
c = getch( );
}while( c!= 'n ' && c!= 'N ' );
clrscr( );
}
intnextb( )
{
if( La[(b[Lnext].y0)][(3+b[Lnext].x0)] != 0 ||
La[(b[Lnext].y1)][(3+b[Lnext].x1)] != 0 ||
La[(b[Lnext].y2)][(3+b[Lnext].x2)] != 0 ||
La[(b[Lnext].y3)][(3+b[Lnext].x3)] != 0 ){
FLAG = L;
return( -1 );
}
eraseb( 0, 3, 5, Lnext );
Lcurrent = Lnext;
lx = 3;
ly = 0;
Lable = 0;
ldelay = d[0];
Lsum ++;
Lpoint += 1;
Lnext = random( 23 );
dispb( 0, 3, 5, Lnext );
textcolor( 7 );
gotoxy( 3, 14 );cprintf( "%#5d ", Lsum );
gotoxy( 3, 17 );cprintf( "%#5d ", Lpoint );
return( 0 );
}
voiddelayp( )
{
charkey;
if( kbhit( ) != 0 ){
key = getch( );
move( key );
if( key== '\\ ' )
getch( );
}
}
voidmove( funckey )
charfunckey;
{
inttempcode;
switch( funckey ){
case 'K ': if( lx+b[Lcurrent].x0 > 0 )
if( La[ly+(b[Lcurrent].y0)][lx-1+(b[Lcurrent].x0)]==0 &&
La[ly+(b[Lcurrent].y1)][lx-1+(b[Lcurrent].x1)]==0 &&
La[ly+(b[Lcurrent].y2)][lx-1+(b[Lcurrent].x2)]==0 &&
La[ly+(b[Lcurrent].y3)][lx-1+(b[Lcurrent].x3)]==0 ){
eraseb( L, lx, ly, Lcurrent );
lx --;
dispb( L, lx, ly, Lcurrent );
}
break;
case 0x20: tempcode = b[Lcurrent].next;
if( lx+b[tempcode].x0 > = 0 && lx+b[tempcode].x3 <= 9 &&
ly+b[tempcode].y1 <=19 && ly+b[tempcode].y2 <= 19 )
if( routejudge( ) != -1 )
if( La[ly+(b[tempcode].y0)][lx+(b[tempcode].x0)]==0 &&
La[ly+(b[tempcode].y1)][lx+(b[tempcode].x1)]==0 &&
La[ly+(b[tempcode].y2)][lx+(b[tempcode].x2)]==0 &&
La[ly+(b[tempcode].y3)][lx+(b[tempcode].x3)]==0 ){
eraseb( L, lx, ly, Lcurrent );
Lcurrent = tempcode;
dispb( L, lx, ly, Lcurrent );
}
break;
case 'M ': if( lx+b[Lcurrent].x3 < 9 )
if( La[ly+(b[Lcurrent].y0)][lx+1+(b[Lcurrent].x0)]==0 &&
La[ly+(b[Lcurrent].y1)][lx+1+(b[Lcurrent].x1)]==0 &&
La[ly+(b[Lcurrent].y2)][lx+1+(b[Lcurrent].x2)]==0 &&
La[ly+(b[Lcurrent].y3)][lx+1+(b[Lcurrent].x3)]==0 ){
eraseb( L, lx, ly, Lcurrent );
lx ++;
dispb( L, lx, ly, Lcurrent );
}
break;
case 'P ': throw( );
break;
case 0x1b:clrscr( );
exit(0);
break;
default:break;
}
}