📄 ftf.c
字号:
/*
名称: 俄罗斯方块 源程 For Turbo C 2.0
软件编写:
中国 北京 幻想空间软件创作群
Illusion Space Software Design Groups.
BBS: 1601118 Ext (Illusion Space)
Email: ILLUSION@peony.ioa.ac.cn
W.G. & Lee.k.
BP: (010) 2561155 Call 1615
8271188 Call 89161
请同我们联系, 或许我们还可以交个朋友.
另外, 欢迎各位编程高手加入幻想空间软件创作群 - 程序员们的乐园
*/
/* text mode */
/* Turbo C */
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <time.h>
#define L 1
#define R 2
#define RX 47
#define RY 4
#define LX 15
#define LY 4
static struct BLOCK{
int x0;
int y0;
int x1;
int y1;
int x2;
int y2;
int x3;
int y3;
int color;
int next;
}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 } };
static int d[10]={ 1500,3000,1600,1200,900,800,600,400,300,200 };
int Llevel, Lcurrent, Lnext, Lable, lx, ly, Lsum;
int Rlevel, Rcurrent, Rnext, Rable, rx, ry, Rsum;
unsigned Lpoint, Rpoint;
int La[19][10], Ra[19][10], FLAG, bell, sum;
unsigned ldelay, rdelay;
void scrinit( ),datainit( ),dispb( ), eraseb( );
void throw( ), judge( ), delayp( ), move( ), note( ), show( );
int Ldrop( ), Rdrop( ), Ljudge( ), Rjudge( ), nextb( ), routejudge( );
main( )
{
char c;
do{
scrinit( );
datainit( );
// note( );
while( nextb(R) == 0 && nextb(L) == 0 && FLAG == 0){
while( FLAG == 0 ){
Lable = Ldrop( );
Rable = Rdrop( );
while( 1 ){
delayp( );
if( Lable != 0 ){
Ljudge( );
Lable = nextb( L );
}
if( Rable != 0 ){
Rjudge( );
Rable = nextb( R );
}
ldelay--;
rdelay--;
if( ldelay == 0 ){
Lable = Ldrop( );
ldelay = d[0];
}
if( rdelay == 0 ){
Rable = Rdrop( );
rdelay = d[0];
}
if( FLAG != 0 )
break;
}
if( FLAG != 0 )
break;
}
if( FLAG != 0 )
break;
}
show( FLAG );
c = getch( );
}while( c!='n' && c!='N' );
clrscr( );
_setcursortype( _SOLIDCURSOR );
}
int nextb( LRflag )
int LRflag;
{
if( LRflag == R ){
if( Ra[(b[Rnext].y0)][(3+b[Rnext].x0)] != 0 ||
Ra[(b[Rnext].y1)][(3+b[Rnext].x1)] != 0 ||
Ra[(b[Rnext].y2)][(3+b[Rnext].x2)] != 0 ||
Ra[(b[Rnext].y3)][(3+b[Rnext].x3)] != 0 ){
FLAG = R;
return( -1 );
}
eraseb( 0, 71, 5, Rnext );
Rcurrent = Rnext;
rx = 3;
ry = 0;
Rable = 0;
rdelay = d[0];
Rsum ++;
Rpoint += 1;
Rnext = random( 26 );
if( Rnext==23 ) Rnext = 0;
if( Rnext==24 || Rnext==25 ) Rnext = 2;
dispb( 0, 71, 5, Rnext );
}else{
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( 26 );
if( Lnext==23 ) Lnext = 0;
if( Lnext==24 || Lnext==25 ) Lnext = 2;
dispb( 0, 3, 5, Lnext );
}
textcolor( 7 );
gotoxy( 3, 14 ); cprintf( "%#5d", Lsum );
gotoxy( 3, 17 ); cprintf( "%#5d", Lpoint );
gotoxy( 72, 14 ); cprintf( "%#5d", Rsum );
gotoxy( 72, 17 ); cprintf( "%#5d", Rpoint );
return( 0 );
}
void delayp( )
{
char key;
if( kbhit( ) != 0 ){
key = getch( );
move( key );
if( key== '\\' )
getch( );
if( key== 'b' )
bell ^= 1;
}
}
void move( funckey )
char funckey;
{
int tempcode;
switch( funckey ){
case '4':
case 'p': if( rx+b[Rcurrent].x0 > 0 )
if( Ra[ry+(b[Rcurrent].y0)][rx-1+(b[Rcurrent].x0)]==0 &&
Ra[ry+(b[Rcurrent].y1)][rx-1+(b[Rcurrent].x1)]==0 &&
Ra[ry+(b[Rcurrent].y2)][rx-1+(b[Rcurrent].x2)]==0 &&
Ra[ry+(b[Rcurrent].y3)][rx-1+(b[Rcurrent].x3)]==0 ){
eraseb( R, rx, ry, Rcurrent );
rx --;
dispb( R, rx, ry, Rcurrent );
}
break;
case '5':
case '@': tempcode = b[Rcurrent].next;
if( rx+b[tempcode].x0 >= 0 && rx+b[tempcode].x3 <= 9 &&
ry+b[tempcode].y1 <=19 && ry+b[tempcode].y2 <= 19 )
if( routejudge( R ) != -1 )
if( Ra[ry+(b[tempcode].y0)][rx+(b[tempcode].x0)]==0 &&
Ra[ry+(b[tempcode].y1)][rx+(b[tempcode].x1)]==0 &&
Ra[ry+(b[tempcode].y2)][rx+(b[tempcode].x2)]==0 &&
Ra[ry+(b[tempcode].y3)][rx+(b[tempcode].x3)]==0 ){
eraseb( R, rx, ry, Rcurrent );
Rcurrent = tempcode;
dispb( R, rx, ry, Rcurrent );
}
break;
case '6':
case '[': if( rx+b[Rcurrent].x3 < 9 )
if( Ra[ry+(b[Rcurrent].y0)][rx+1+(b[Rcurrent].x0)]==0 &&
Ra[ry+(b[Rcurrent].y1)][rx+1+(b[Rcurrent].x1)]==0 &&
Ra[ry+(b[Rcurrent].y2)][rx+1+(b[Rcurrent].x2)]==0 &&
Ra[ry+(b[Rcurrent].y3)][rx+1+(b[Rcurrent].x3)]==0 ){
eraseb( R, rx, ry, Rcurrent );
rx ++;
dispb( R, rx, ry, Rcurrent );
}
break;
case '0':
case ',': throw( R );
break;
case '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -