📄 tetrisgame.java
字号:
TE_SaveData_p . chInfo = 1 ;
MenuObject . AllowStartMode = GAM_START_NEW ;
MenuObject . SelStartMode = GAM_START_NEW ;
}
TESetShape ( ( TEGlobal_p . shCurrentShape ) , ( TEGlobal_p . shTempShape ) ) ;
for ( chCt = 0 ; chCt < 4 ; chCt ++ )
TEGlobal_p . shCurrentShape . chFigure [ chCt ] = 0x00 ;
TESetShape ( ( TEGlobal_p . shCurrentShape ) , ( TEGlobal_p . shTempShape ) ) ;
if ( RedrawScreen )
{
TERedraw ( ) ;
}
}
void
TELoadShape ( )
{
//System.out.println("TELoadShape");
int chCt ;
for ( chCt = 0 ; chCt < 4 ; chCt ++ )
{
TEGlobal_p . shCurrentShape . chFigure [ chCt ] = g_Shapes [ TEGlobal_p . shCurrentShape . chShape ] [ TEGlobal_p . shCurrentShape . chRotation ] [ chCt ] ;
if ( TEGlobal_p . shCurrentShape . xShift > 0 )
TEGlobal_p . shCurrentShape . chFigure[chCt] >>= TEGlobal_p . shCurrentShape . xShift ;
else
TEGlobal_p . shCurrentShape . chFigure[chCt] <<= ( - TEGlobal_p . shCurrentShape . xShift ) ;
}
}
void
LGDeCompressFiveCharThreeChar ( /* uns */ int[] chFive ,
/* uns */ int[] chThree ,
/* uns */ int chSave )
{
//System.out.println("LGDeCompressFiveCharThreeChar");
chThree[0] = chSave ;
chThree[0] = (chThree[0] << 5)&0xFF ;
chThree[0] = (chThree[0] >> 5)&0xFF ;
chSave = (chSave >> 3)&0xFF ;
chFive[0] = chSave ;
}
void
LGScoreAndStartLevel ( /* uns */ int[] ptrSave ,
/* uns */ int[] plScore ,
/* uns */ int[] pchLevel )
{
//System.out.println("LGScoreAndStartLevel");
int chMsbScore ;
plScore[0] = 0xffffffff ;
pchLevel[0] = 0xff ;
pchLevel[0] = ptrSave[2] ;
pchLevel[0] = (pchLevel[0]>>4)&0xFF ;
chMsbScore = ptrSave[2] ;
chMsbScore = (chMsbScore<<4)&0xFF ;
chMsbScore = (chMsbScore>>4)&0xFF ;
plScore[0] = chMsbScore ;
plScore[0] = (plScore[0]<<8)&0xFFFFFFFF ;
plScore[0] += ptrSave[1] ;
plScore[0] = (plScore[0]<<8)&0xFFFFFFFF ;
plScore[0] += ptrSave[0] ;
}
void
TEGameInit ( boolean bResume )
{
//System.out.println("TEGameInit");
int chCntY ;
TEGlobal_p . bGameOver = false ;
TEGlobal_p . bTurbo = false ;
g.setColor(clearColor);
g.fillRect ( 0 , 0 , DISPLAY_WIDTH , DISPLAY_HEIGHT ) ;
if ( ( ! bResume ) || ( TE_SaveData_p . sgSaveGame . chLevel > ( 10 - 1 ) ) )
{
TEGlobal_p . shCurrentShape . chShape = - 1 ; // Reset shape struct // -1 means "no current shape"
TEGlobal_p . lScore = 0 ;
TEGlobal_p . chLevel = TEGlobal_p . chStartLevel ;
for ( chCntY = 0 ; chCntY < 16 ; chCntY ++ )
TEGlobal_p . chPlFld [ chCntY ] = 0x00 ;
TEGlobal_p . nsNextShape . chNShape = ( ( /* uns */ int ) GARand ( ) % 7 ) ;
TEGlobal_p . nsNextShape . chNRotation = ( ( /* uns */ int ) GARand ( ) % 4 ) ;
//System.out.println(" calling TENewShape from TEGameInit");
TENewShape ( true ) ;
}
else
{
TEGlobal_p . shCurrentShape . xShift = TE_SaveData_p . sgSaveGame . xShift ;
TEGlobal_p . shCurrentShape . bottomY = TE_SaveData_p . sgSaveGame . bottomY ;
int[] tmp0 = new int[1];
int[] tmp1 = new int[1];
tmp0[0] = TEGlobal_p . shCurrentShape . chShape;
tmp1[0] = TEGlobal_p . shCurrentShape . chRotation;
LGDeCompressFiveCharThreeChar ( tmp0 , tmp1 ,
TE_SaveData_p . sgSaveGame . chShapeAndRotation ) ;
TEGlobal_p . shCurrentShape . chShape = tmp0[0];
TEGlobal_p . shCurrentShape . chRotation = tmp1[0];
TELoadShape ( ) ;
tmp0[0] = TEGlobal_p . nsNextShape . chNShape;
tmp1[0] = TEGlobal_p . nsNextShape . chNRotation;
LGDeCompressFiveCharThreeChar ( tmp0 , tmp1 ,
TE_SaveData_p . sgSaveGame . chNextShape ) ;
TEGlobal_p . nsNextShape . chNShape = tmp0[0];
TEGlobal_p . nsNextShape . chNRotation = tmp1[0];
tmp0[0] = TEGlobal_p . lScore;
tmp1[0] = TEGlobal_p . chStartLevel;
LGScoreAndStartLevel ( TE_SaveData_p . sgSaveGame . chScoreAndStartLevel , tmp0 , tmp1 ) ;
TEGlobal_p . lScore = tmp0[0];
TEGlobal_p . chStartLevel = tmp1[0];
TEGlobal_p . chBlockCnt = TE_SaveData_p . sgSaveGame . chBlockCnt ;
TEGlobal_p . chLevel = TE_SaveData_p . sgSaveGame . chLevel ;
TELoadPlFld ( ) ;
}
if ( TEGlobal_p . chLevel >= 10 )
{
TEGlobal_p . chLevel = 10 - 1 ;
}
TEGlobal_p . nSpeed = g_nStartSpeeds [ TEGlobal_p . chLevel ] ;
}
void
IniTEGame ( boolean Resume )
{
//System.out.println("IniTEGame("+Resume+")");
/* uns */ int t ;
if ( Resume )
{
TEGlobal_p . chStartLevel = TE_SaveData_p . sgSaveGame . chLevel ;
}
else
{
switch ( MenuObject . SelLevel )
{
case GAM_LEVEL_VERYEASY :
case GAM_LEVEL_EASY :
TEGlobal_p . chStartLevel = 0 ;
break ;
case GAM_LEVEL_MEDIUM :
TEGlobal_p . chStartLevel = 4 ;
break ;
case GAM_LEVEL_HARD :
case GAM_LEVEL_VERYHARD :
TEGlobal_p . chStartLevel = 8 ;
break ;
}
}
TEGlobal_p . bFirstTimeSideShift = false ;
TEGameInit ( Resume ) ;
TEGlobal_p . state = TGameState ;
TEGlobal_p . GameState = TGameStartInit ;
TEGlobal_p . splash_cnt = 0 ;
t = MenuObject . SelOptions & ( GAM_OPT_BACKGROUND_PIC_NONE | GAM_OPT_BACKGROUND_PIC_TILE | GAM_OPT_BACKGROUND_PIC_CENTER ) ;
if ( t == 0 )
{
t = GAM_OPT_BACKGROUND_PIC_NONE ;
}
TEGlobal_p . BackGroundPicId = 0 ;
if ( TEGlobal_p . BackGroundPicSelection != GAM_OPT_BACKGROUND_PIC_NONE )
{
TEGlobal_p . BackGroundPicId = GAGetImageId ( "bkg_pic" ) ;
if ( TEGlobal_p . BackGroundPicId < 1 )
{
t = GAM_OPT_BACKGROUND_PIC_NONE ;
TEGlobal_p . BackGroundPicId = 0 ;
}
}
TEGlobal_p . BackGroundPicSelection = t ;
TE_SaveData_p . sgSaveGame . BackGroundPicSelection = TEGlobal_p . BackGroundPicSelection ;
}
boolean
TERunGame ( GAEvent event )
{
//System.out.println("TERunGame");
boolean Hitbottom = false ;
TESetShape ( TEGlobal_p . shTempShape , TEGlobal_p . shCurrentShape ) ;
//System.out.println(" TERunGame: new event of type "+ event.type.toString());
switch ( event . type )
{
case GAKeyboardEvent :
switch ( event . key )
{
// rotate counterclockwise
case KeyYes :
case KeyFive :
case KeySeven :
//System.out.println("Attempting to rotate counterclockwise.");
if ( event . press )
{
TEGlobal_p . shTempShape . chRotation = TEGlobal_p . shTempShape . chRotation == 0 ? 3 : TEGlobal_p . shTempShape . chRotation - 1 ;
TERotateTemp ( ) ;
}
break ;
//rotate clockwise
case KeyNine :
case KeyUp :
//System.out.println("Attempting to rotate clockwise.");
if ( event . press )
{
TEGlobal_p . shTempShape . chRotation = TEGlobal_p . shTempShape . chRotation == 3 ? 0 : TEGlobal_p . shTempShape . chRotation + 1 ;
TERotateTemp ( ) ;
}
break ;
// speed
case KeyEight :
case KeyDown :
if ( event . press )
{
TEGlobal_p . bTurbo = true ;
GASetTimer ( GATimer1 , ( /* uns */ int ) ( 30 ) ) ;
}
break ;
// move left
case KeyLeft :
case KeyFour :
case KeyLeftUp :
if ( event . press )
{
TEGlobal_p . shTempShape . xShift -- ;
TEShiftTemp ( - 1 ) ;
TEGlobal_p . bRightMove = false ;
TEGlobal_p . bFirstTimeSideShift = true ;
GASetTimer ( GATimer2 , 2 * 200 ) ;
}
else
{
GAKillTimer ( GATimer2 ) ;
}
break ;
// move right
case KeyRight :
case KeySix :
case KeyRightDown :
if ( event . press )
{
TEGlobal_p . shTempShape . xShift ++ ;
TEShiftTemp ( 1 ) ;
TEGlobal_p . bRightMove = true ;
TEGlobal_p . bFirstTimeSideShift = true ;
GASetTimer ( GATimer2 , 2 * 200 ) ;
}
else
{
GAKillTimer ( GATimer2 ) ;
}
break ;
case KeyNo :
TerminateGameMain ( ) ;
return false ;
// quick pause
case KeyClear :
if ( event . press )
{
TEGlobal_p . GameState = TGamePausedInit ;
return true ;
}
break ;
}
if ( TECheckMove ( ) )
TERedrawFigure ( ) ;
else
{
TESetShape ( TEGlobal_p . shTempShape , TEGlobal_p . shCurrentShape ) ;
}
break ;
case GATimerEvent :
{
switch ( event . timerId )
{
case GATimer1 :
if ( TEGlobal_p . bTurbo && TEGlobal_p . chLevel < 9 )
{
TEGlobal_p . lScore += 1 * ( TEGlobal_p . chLevel + 1 ) ;
}
Hitbottom = false ;
TEGlobal_p . shTempShape . bottomY ++ ;
if ( TECheckMove ( ) )
{
TERedrawFigure ( ) ;
if ( TEGlobal_p . bTurbo )
{
TEGlobal_p . shTempShape . bottomY ++ ;
if ( TECheckMove ( ) )
{
TERedrawFigure ( ) ;
}
else
{
Hitbottom = true ;
}
}
}
else
{
Hitbottom = true ;
}
if ( Hitbottom )
{
GASetTimer ( GATimer1 , ( /* uns */ int ) ( TEGlobal_p . nSpeed ) ) ;
TEGlobal_p . bTurbo = false ;
TEGlobal_p . lScore += 10 ;
TENewShape ( true ) ;
TEDrawScore ( ) ;
TEDrawNextShape ( GACOLOR_BLACK ) ;
GACheckForRefresh ( ) ;
if ( !GASoundEffectPlay ( "drop" ) )
{
GASound ( 300 , 50 , 0 ) ;
}
GASetCurrColour ( GACOLOR_BLACK ) ;
{
int y ;
y = ( 16 * TEGlobal_p . BlockSize ) + TEGlobal_p . Yoffset ;
g.setColor(lineColor);
g.drawLine ( TEGlobal_p . LINE_POS , y , TEGlobal_p . LINE_POS_DY , y ) ;
}
}
break ;
case GATimer2 :
if ( TEGlobal_p . bRightMove )
{
TEGlobal_p . shTempShape . xShift ++ ;
TEShiftTemp ( 1 ) ;
}
else
{
TEGlobal_p . shTempShape . xShift -- ;
TEShiftTemp ( - 1 ) ;
}
if ( TECheckMove ( ) )
TERedrawFigure ( ) ;
else
TESetShape ( TEGlobal_p . shTempShape , TEGlobal_p . shCurrentShape ) ;
if ( TEGlobal_p . bFirstTimeSideShift )
{
TEGlobal_p . bFirstTimeSideShift = false ;
GASetTimer ( GATimer2 , 200 ) ;
}
}
}
if ( TEGlobal_p . bGameOver )
{
TEGlobal_p . GameState = TGameOverInit ;
}
}
return true ;
}
boolean
TEGame ( GAEvent event )
{
//System.out.println("TEGame");
boolean Result = true ;
switch ( TEGlobal_p . GameState )
{
case TGameStartInit :
//System.out.println(" TGameStartInit");
TEGlobal_p . GameState = TGameStart ;
if ( ( TEGlobal_p . nSpeed > g_nStartSpeeds [ 0 ] ) || ( TEGlobal_p . nSpeed < g_nStartSpeeds [ ( 10 - 1 ) ] ) )
{
TEGlobal_p . nSpeed = g_nStartSpeeds [ 0 ] ;
}
GASetTimer ( GATimer1 , TEGlobal_p . nSpeed ) ;
break ;
case TGameStart :
//System.out.println(" TGameStart");
TERedraw ( ) ;
TEGlobal_p . GameState = TGameRunning ;
break ;
case TGameRunning :
//System.out.println(" TGameRunning");
Result = TERunGame ( event ) ;
break ;
case TGamePausedInit :
//System.out.println(" TGamePausedInit");
GAKillTimer ( GATimerAll ) ;
GAMsgBox ( ( 1214 + 0 ) , MessageBoxSmall , 0 ) ;
TEGlobal_p . GameState = TGamePaused ;
break ;
case TGamePaused :
//System.out.println(" TGamePaused");
if ( ( event . type == GAKeyboardEvent ) && ( event . press ) )
{
TEGlobal_p . GameState = TGameRunning ;
GASetTimer ( GATimer1 , TEGlobal_p . nSpeed ) ;
}
break ;
case TGameOverInit :
//System.out.println(" TGameOverInit");
GAKillTimer ( GATimerAll ) ;
GAMsgBox ( ( 1184 + 0 ) , MessageBoxSmall , 0 ) ;
GAHighScoreAddNum ( TE_HighScoreList_p , TE_SaveData_p . HighScoreListEntries , TEGlobal_p . lScore , ( /* uns */ int ) ( TEGlobal_p . chLevel + 1 ) ) ;
TEGlobal_p . GameState = TGameOverWait ;
TEGlobal_p . bGameOver = true ;
TE_SaveData_p . chInfo = 0 ;
break ;
case TGameOverWait :
//System.out.println(" TGameOverWait");
if ( ( event . type == GAKeyboardEvent ) && ( event . press ) )
{
TEGlobal_p . state = THighScoreInitState ;
GASetTimer ( GATimer1 , 400 ) ;
}
break ;
case TGameOver :
//System.out.println(" TGameOver");
TEGlobal_p . state = THighScoreInitState ;
GASetTimer ( GATimer1 , 400 ) ;
break ;
}
return ( Result ) ;
}
void
TEDrawSplashSquare ( int x ,
int y )
{
//System.out.println("TEDrawSplashSquare");
final int squareSize = 3 - 1 ;
final int y_ofset = 20 ;
final int x_ofset = 0 ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -