⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tetrisgame.java

📁 CreatLog luke 俄罗斯方块
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  

  for ( iRow = 0 ; TEGlobal_p . shCurrentShape . bottomY - iRow >= 0 && iRow < 4 ; iRow ++ ) 
  { 
    for ( iCol = 0 , uBit = 0x80 ; iCol < 8 ; iCol ++ , uBit >>= 1 ) 
    { 
      if ( ( TEGlobal_p . shCurrentShape . chFigure [ 3 - iRow ] & uBit ) != 0 ) 
      { 
        TEDrawBlock ( iCol , ( /* uns */ int ) ( TEGlobal_p . shCurrentShape . bottomY - iRow ) , TEGlobal_p . BlockSize , true , TEGlobal_p . shCurrentShape . chShape ) ; 
      } 
    } 
  } 

} 



void 
TERedraw ( ) 
{ 
    //System.out.println("TERedraw");
  int t ; 
  int x ; 
  int y ; 
  //boolean BackgroundMode ; 
  
  g.setColor(clearColor);
  g.fillRect ( 0 , 0 , DISPLAY_WIDTH , DISPLAY_HEIGHT ) ; 
  
  t = TEGlobal_p . chLevel % 12 ; 
  t += 256 ; 

  //BackgroundMode = GASetBitmapBackgroundMode ( false ) . value ; 
  

  GASetCurrColour ( GACOLOR_BLACK ) ; 
  //  GASelectFont ( SystemFontTetrisBitmaps_8bit ) ; 
  
  y = 0 ; 
  while ( y < DISPLAY_HEIGHT ) 
  { 
    x = 0 ; 
    while ( x < DISPLAY_WIDTH ) 
    { 
      GACharOut ( t , (short)x , (short)y ) ; 
      x += 10 ; 
    } 
    y += 10 ; 
  } 
  

  //GASetBitmapBackgroundMode ( BackgroundMode ) . value ; 
  


  TEDrawPanel ( ) ; 
  TEDrawTetrisBasic ( ) ; 
  TERedrawPlFldAndShape ( ) ; 


} 



void 
TEShiftChar ( /* uns */ int[] ptrCh , 
int right ) 
{ 
    //System.out.println("TEShiftChar");
  if ( right > 0 ) 
    ptrCh[0] = (ptrCh[0] >> right)&0xFF ; 
  else 
    ptrCh[0] = (ptrCh[0] << ( - right ))&0xFF ; 
} 


void 
TEShiftTemp ( int right ) 
{ 
//System.out.println("TEShiftTemp");
  /* uns */ int chCt ; 
  int[] tmp = new int[1];
 
  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) {
    tmp[0] = TEGlobal_p . shTempShape . chFigure[chCt];
    TEShiftChar(tmp, right) ; 
    TEGlobal_p . shTempShape . chFigure[chCt] = tmp[0];
  }

} 


void 
TERotateTemp ( ) 
{ 
//System.out.println("TERotateTemp");
  /* uns */ int chCt1 ; 
  int chCt2 = TEGlobal_p . shTempShape . xShift ; 
  
  for ( chCt1 = 0 ; chCt1 < 4 ; chCt1 ++ ) 
  { 
    TEGlobal_p . shTempShape . chFigure [ chCt1 ] = g_Shapes [ TEGlobal_p . shTempShape . chShape ] [ TEGlobal_p . shTempShape . chRotation ] [ chCt1 ] ; 
  } 
  TEShiftTemp ( chCt2 ) ; 
} 


void 
TEMergeLines ( /* uns */ int[] ptrA , 
/* uns */ int chB ) 
{ 
//System.out.println("TEMergeLines");
  ptrA[0] |= chB ; 
} 


void 
TEMergeShapeAndPlFld ( ) 
{ 
//System.out.println("TEMergeShapeAndPlFld");
  /* uns */ int chCt ; 
  int[] tmp = new int[1];

  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) 
  { 
    //System.out.println("TEGlobal_p . shCurrentShape . bottomY - 3 + chCt = "+(TEGlobal_p . shCurrentShape . bottomY - 3 + chCt));
    /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    if(TEGlobal_p . shCurrentShape . bottomY - 3 + chCt >= 0 && TEGlobal_p . shCurrentShape . bottomY - 3 + chCt < 16) {
	tmp[0] = TEGlobal_p . chPlFld [ TEGlobal_p . shCurrentShape . bottomY - 3 + chCt ];
	TEMergeLines ( tmp , TEGlobal_p . shCurrentShape . chFigure [ chCt ] ) ; 
	TEGlobal_p . chPlFld [ TEGlobal_p . shCurrentShape . bottomY - 3 + chCt ] = tmp[0];
    }
  } 
} 



void 
TESetShape ( Shape ptrA , 
Shape ptrB ) 
{ 
//System.out.println("TESetShape");
  /* uns */ int chCt ; 
  
  ptrA . xShift = ptrB . xShift ; 
  ptrA . bottomY = ptrB . bottomY ; 
  ptrA . chShape = ptrB . chShape ; 
  ptrA . chRotation = ptrB . chRotation ; 
  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) 
    ptrA . chFigure [ chCt ] = ptrB . chFigure [ chCt ] ; 
} 


void 
TERedrawFigure ( ) 
{ 
//System.out.println("TERedrawFigure");
  if ( TEGlobal_p . shCurrentShape . bottomY == TEGlobal_p . shTempShape . bottomY ) 
  { 
    int chCt ; 
    int[] tmp = new int[1];
    
    for ( chCt = 3 ; chCt >= 0 && ( TEGlobal_p . shTempShape . bottomY - 3 + chCt ) >= 0 ; chCt -- ) 
    { 
      tmp[0] = TEGlobal_p . shCurrentShape . chFigure [ chCt ];
      TEReplaceLine ( tmp , 
		      TEGlobal_p . shCurrentShape . bottomY - 3 + chCt ,
		      TEGlobal_p . shTempShape . chFigure [ chCt ] ,
		      TEGlobal_p . shTempShape . chShape ) ; 
      TEGlobal_p . shCurrentShape . chFigure [ chCt ] = tmp[0];
    } 
  } 
  else 
  { 
    /* uns */ int chA = 0x00 ; 
    final /* uns */ int chBottom = TEGlobal_p . shTempShape . bottomY ; 
    int chCt = 1 ; 
    int[] tmp = new int[1];
    int chTemp = chBottom ; 
    
    while ( ( chTemp >= 0 ) && ( chTemp >= chBottom - 4 ) ) 
    { 
      if ( chTemp < chBottom ) 
      { 
        if ( chTemp >= chBottom - 3 ) 
        { 
	  tmp[0]=TEGlobal_p . shCurrentShape . chFigure [ 3 - chCt + 1 ];
          TEReplaceLine ( tmp, 
			  chTemp ,
			  TEGlobal_p . shTempShape . chFigure [ 3 - chCt ] , 
			  TEGlobal_p . shTempShape . chShape ) ; 
	  TEGlobal_p . shCurrentShape . chFigure [ 3 - chCt + 1 ] = tmp[0];
          chCt ++ ; 
        } 
        else 
        { 
          tmp[0]=TEGlobal_p . shCurrentShape . chFigure [ 0 ];
          TEReplaceLine ( tmp , 
			  chTemp , 
			  0x00 , 
			  TEGlobal_p . shTempShape . chShape ) ; 
	  TEGlobal_p . shCurrentShape . chFigure [ 0 ]=tmp[0];
        } 
      } 
      else 
      {
	tmp[0]=chA;
        TEReplaceLine ( tmp ,
			chTemp ,
			TEGlobal_p . shTempShape . chFigure [ 3 ] , 
			TEGlobal_p . shTempShape . chShape ) ; 
	chA=tmp[0];
      } 
      chTemp -- ; 
    } 
  } 
  TESetShape ( TEGlobal_p . shCurrentShape , TEGlobal_p . shTempShape ) ; 
} 


boolean 
TECheckFullLine ( /* uns */ int chA ) 
{ 
  //System.out.println("TECheckFullLine");
  //System.out.println("   chA = "+ chA);
  return chA == 0xFF ; 
} 


boolean 
TECheckMove ( ) 
{ 
//System.out.println("TECheckMove");
  /* uns */ int [] sTestArea = new int [ 4 ] ; 
  /* uns */ int [] sTestFigure = new int [ 4 ] ; 
  int chBottom = TEGlobal_p . shTempShape . bottomY ; 
  final /* uns */ int sBorders = 0xf00f ; 
  boolean bMoveOk = true ; 
  int chCt ; 
  
  //System.out.println("TECheckMove check 000");
  //System.out.println("   chBottom = "+ chBottom);

  /* Very strange. chBottom-chCt can be negative. */
  /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) 
  { 
    if ( ( chBottom - chCt ) < 16 && ( chBottom - chCt )>=0 ) 
      sTestArea [ 3 - chCt ] = TEGlobal_p . chPlFld [ chBottom - chCt ] ; 
    else if (( chBottom - chCt )>=0)
      sTestArea [ 3 - chCt ] = 0xFF ; 
    sTestArea [ 3 - chCt ] = (sTestArea [ 3 - chCt ] << 4)&0xFFFF ; 
    sTestArea [ 3 - chCt ] += sBorders ; 
  } 
  

  //System.out.println("TECheckMove check 001");
  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) 
  { 
    sTestFigure [ chCt ] = g_Shapes [ TEGlobal_p . shTempShape . chShape ] [ TEGlobal_p . shTempShape . chRotation ] [ chCt ] ; 
    sTestFigure [ chCt ] = (sTestFigure [ chCt ]<<4)&0xFFFF ; 
    if ( ( TEGlobal_p . shTempShape . xShift ) > 0 ) 
    { 
      sTestFigure [ chCt ] = (sTestFigure [ chCt ]>>TEGlobal_p . shTempShape . xShift)&0xFFFF ; 
    } 
    else 
    { 
      sTestFigure [ chCt ] = (sTestFigure [ chCt ]<< ( - TEGlobal_p . shTempShape . xShift ))&0xFFFF ; 
    } 
  } 
  
  //System.out.println("TECheckMove check 002");
  for ( chCt = 3 ; chCt >= 0 && bMoveOk ; chCt -- ) 
  { 
    bMoveOk = ( sTestArea [ chCt ] & sTestFigure [ chCt ] ) == 0 ; 
  } 
  //System.out.println("TECheckMove has determined that this move is " + bMoveOk);
  return bMoveOk ; 
} 


void 
TESavePlFld ( ) 
{ 
//System.out.println("TESavePlFld");
  /* uns */ int chTemp ; 
  
  for ( chTemp = 0 ; chTemp < 16 ; chTemp ++ ) 
  TE_SaveData_p . sgSaveGame . chPlFld [ chTemp ] = TEGlobal_p . chPlFld [ chTemp ] ; 
} 


void 
TELoadPlFld ( ) 
{ 
//System.out.println("TELoadPlFld");
  /* uns */ int chTemp ; 
  
  for ( chTemp = 0 ; chTemp < 16 ; chTemp ++ ) 
  TEGlobal_p . chPlFld [ chTemp ] = TE_SaveData_p . sgSaveGame . chPlFld [ chTemp ] ; 
} 


void 
TEHighScoreInit ( ) 
{ 
    //System.out.println("TEHighScoreInit");
  GAKillTimer ( GATimerAll ) ; 
  g.setColor(clearColor);
  g.fillRect ( 0 , 0 , DISPLAY_WIDTH , DISPLAY_HEIGHT ) ; 
  GAHighScoreListShow ( TE_HighScoreList_p , TE_SaveData_p . HighScoreListEntries ) ; 
  GASetTimer ( GATimer3 , 100 ) ; 

} 


void 
SGScoreAndStartLevel ( /* uns */ int[] ptrSave , 
/* uns */ int lScore , 
/* uns */ int chLevel ) 
{ 
//System.out.println("SGScoreAndStartLevel");
  ; 
  
  lScore = (lScore << 12)&0xFFFFFFFF ; 
  lScore = (lScore >> 12)&0xFFFFFFFF ; 
  ptrSave[0] = lScore & 0xFF ; 
  lScore = (lScore >> 8)&0xFFFFFFFF ; 
  ptrSave[1] = lScore & 0xFF ; 
  lScore = (lScore >> 8)&0xFFFFFFFF ; 
  ptrSave[2] = lScore & 0xFF ; 
  ptrSave[2] = (ptrSave[2]<<4)&0xFF ; 
  ptrSave[2] = (ptrSave[2]>>4)&0xFF ; 
  ptrSave[2] += ( chLevel << 4 )&0xFF ; 
  ; 
} 





void 
TEPostEE ( ) 
{ 

  //System.out.println("TEPostEE"); 
  


  ; 
  

  TE_SaveData_p . sgSaveGame . xShift = TEGlobal_p . shCurrentShape . xShift ; 
  TE_SaveData_p . sgSaveGame . bottomY = TEGlobal_p . shCurrentShape . bottomY ; 
  
  TE_SaveData_p . sgSaveGame . chShapeAndRotation = SGCompressFiveCharThreeChar ( TEGlobal_p . shCurrentShape . chShape , TEGlobal_p . shCurrentShape . chRotation ) ; 
  
  TE_SaveData_p . sgSaveGame . chNextShape = SGCompressFiveCharThreeChar ( TEGlobal_p . nsNextShape . chNShape , TEGlobal_p . nsNextShape . chNRotation ) ; 
  
  SGScoreAndStartLevel ( TE_SaveData_p . sgSaveGame . chScoreAndStartLevel , TEGlobal_p . lScore , TEGlobal_p . chStartLevel ) ; 
  
  TE_SaveData_p . sgSaveGame . chBlockCnt = TEGlobal_p . chBlockCnt ; 
  TE_SaveData_p . sgSaveGame . chLevel = TEGlobal_p . chLevel ; 
  


  TESavePlFld ( ) ; 
  

  ;
} 


void 
TENewShape ( boolean bPaused ) 
{ 
//System.out.println("TENewShape");
  int chCt ; 
  int chScoreMul ; 
  boolean RedrawScreen = false ; 
  

  NextShape nsNextS = new NextShape () ; 
  
  nsNextS . chNShape = TEGlobal_p . nsNextShape . chNShape ; 
  nsNextS . chNRotation = TEGlobal_p . nsNextShape . chNRotation ; 
  





  TEGlobal_p . shTempShape . xShift = 0 ; 
  /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  TEGlobal_p . shTempShape . bottomY = 1 ; 
  TEGlobal_p . shTempShape . chShape = nsNextS . chNShape ; 
  TEGlobal_p . shTempShape . chRotation = nsNextS . chNRotation ; 

  //System.out.println("TENewShape check 000");   
  for ( chCt = 0 ; chCt < 4 ; chCt ++ ) {
    TEGlobal_p . shTempShape . chFigure [ chCt ] = g_Shapes [ TEGlobal_p . shTempShape . chShape ] [ TEGlobal_p . shTempShape . chRotation ] [ chCt ] ; 
  }

  //System.out.println("TENewShape check 001");
  if ( TEGlobal_p . shCurrentShape . chShape != - 1 ) 
  { 
    int chTemp = TEGlobal_p . shCurrentShape . bottomY ; 
    

    TEMergeShapeAndPlFld ( ) ; 
    
    TEGlobal_p . shCurrentShape . chShape = - 1 ; 
    

    chScoreMul = 0 ; 
    int[] tmp = new int[1];
    /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
    //System.out.println("   ABOUT TO ENTER KRAZY LOOP: chTemp = "+chTemp);
    for ( chCt = 0 ; chCt < 4 && chTemp - chCt >= 0 && chTemp - chCt <= 16 ; chCt ++ ) {
	//System.out.println("TENewShape check 001.1: chScoreMul = "+chScoreMul);
	//System.out.println("   chTemp - chCt = "+(chTemp - chCt));
	//System.out.println("   The statement The Line Is Full is "+TECheckFullLine ( TEGlobal_p . chPlFld [ chTemp - chCt ] ));
	//System.out.println("   ARE WE CHECKING FOR FULL LINE? chTemp - chCt = " + (chTemp-chCt));
	if ( TECheckFullLine ( TEGlobal_p . chPlFld [ chTemp - chCt ] ) ) 
	    chScoreMul ++ ; 
	else if ( chScoreMul > 0 ) {
	    tmp[0]=TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul ];
	    TEReplaceLine ( tmp , 
			    chTemp - chCt + chScoreMul , 
			    TEGlobal_p . chPlFld [ chTemp - chCt ] ,
			    TEGlobal_p . shTempShape . chShape ) ; 
	    TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul ]=tmp[0];
	}
    }
    //System.out.println("TENewShape check 002");
    if ( chScoreMul > 0 ) 
    { 
      int chCt2 ; 
      
      while ( ( ( chTemp - chCt ) >= 0 ) && ( TEGlobal_p . chPlFld [ chTemp - chCt ] != 0x00 ) ) 
      { 
        tmp[0]=TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul ];
        TEReplaceLine ( tmp , 
			chTemp - chCt + chScoreMul , 
			TEGlobal_p . chPlFld [ chTemp - chCt ] ,
			TEGlobal_p . shTempShape . chShape ) ;
        TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul ]=tmp[0];
        chCt ++ ; 
      } 
      for ( chCt2 = 0 ; chCt2 < chScoreMul ; chCt2 ++ ) {
	tmp[0]=TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul - chCt2 ];
        TEReplaceLine ( tmp ,
			chTemp - chCt + chScoreMul - chCt2 , 
			0x00 , 
			TEGlobal_p . shTempShape . chShape ) ; 
	TEGlobal_p . chPlFld [ chTemp - chCt + chScoreMul - chCt2 ]=tmp[0];
      }
      if ( chScoreMul > 0 ) 
      { 
      
      } 
      if ( !bPaused ) 
      { 
        TEGlobal_p . lScore += g_nScoreLayer [ chScoreMul ] + g_nScoreLayerBonus [ chScoreMul ] * ( TEGlobal_p . chLevel + 1 ) ; 
      } 
      
      if ( !GASoundEffectPlay ( "newlev" ) ) 
      { 
        GASound ( 800 , 50 , 0 ) ; 
      } 
      
      TEGlobal_p . chBlockCnt += chScoreMul ; 

      //System.out.println("TENewShape check 003");      
      if ( TEGlobal_p . chLevel != ( 10 - 1 ) && TEGlobal_p . chBlockCnt >= g_nNextLevel [ TEGlobal_p . chLevel ] ) 
      { 
        TEGlobal_p . chBlockCnt = 0 ; 
        TEGlobal_p . chLevel = ( TEGlobal_p . chLevel + 1 ) % 10 ; 
        TEGlobal_p . nSpeed = g_nStartSpeeds [ TEGlobal_p . chLevel ] ; 
        GASetTimer ( GATimer1 , TEGlobal_p . nSpeed ) ; 
        
        RedrawScreen = true ; 
      

      } 
    } 
  } 
  else 
  { 
    TEGlobal_p . chBlockCnt = 0 ; 
  } 
  

  TEDrawNextShape ( GACOLOR_WHITE ) ; 
  

  TEGlobal_p . nsNextShape . chNShape = ( ( /* uns */ int ) GARand ( ) % 7 ) ; 
  TEGlobal_p . nsNextShape . chNRotation = ( ( /* uns */ int ) GARand ( ) % 4 ) ; 
  



  TEDrawNextShape ( GACOLOR_BLACK ) ; 
  

  TEGlobal_p . bGameOver = ! TECheckMove ( ) ; 
  
  //System.out.println("TENewShape check 004");
  if ( TEGlobal_p . bGameOver ) 
  { 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -