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

📄 tetrisgame.java

📁 CreatLog luke 俄罗斯方块
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
final int [] rotation1 /* expr */ = { 3  , 0  , 0  , 3  , 0  } ; 


final int [] rotation2 /* expr */ = { 3  , 0  , 0  , 1  , 0  , 1  } ; 




final int [] rotation3 /* expr */ = { 3  , 0  , 0  , 3  , 0  } ; 


final int [] rotation4 /* expr */ = { 0  , 0  , 0  , 1  , 0  , 1  } ; 


final int [] rotation5 /* expr */ = { 0  , 0  } ; 


final int [] rotation6 /* expr */ = { 2  , 0  , 0  , 0  , 0  } ; 

//was letter
Letter[] g_screen = new Letter[6];

/* typedef enum TetrisState */
public static final byte TMenuState = 0 ; 
public static final byte TGameState = 1 ; 
public static final byte TStartState = 2 ; 
public static final byte THighScoreInitState = 3 ; 
public static final byte THighScoreState = 4 ; 
public static final byte TTerminateState = 5 ;






/* typedef enum TetrisGameState */
public static final byte TGameStartInit = 0 ; 
public static final byte TGameStart = 1 ; 
public static final byte TGameRunning = 2 ; 
public static final byte TGamePausedInit = 3 ; 
public static final byte TGamePaused = 4 ; 
public static final byte TGameOverInit = 5 ; 
public static final byte TGameOverWait = 6 ; 
public static final byte TGameOver = 7 ;
 





/* typedef struct */ class 
TEGlobals_t { 
  public boolean bTerminate ; 
  
  public /* uns */ int nSpeed ; 
  public NextShape nsNextShape = new NextShape () ; 
  public boolean bGameOver ; 
  public boolean bTurbo ; 
  /*!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  public /* uns */ int [] chPlFld = new int [ 17 ] ; 
  
  public /* uns */ int lScore ; 
  
  public /* uns */ int chLevel ; 
  public /* uns */ int chStartLevel ; 
  public /* uns */ int chBlockCnt ; 
  
  public Shape shCurrentShape = new Shape () ; 
  public Shape shTempShape = new Shape () ; 
  
  public byte state; // enum TetrisState
  public byte oldState; // enum TetrisState
  
  public boolean bTime ; 
  public boolean bNoBz ; 
  public boolean bPress ; 
  public /* uns */ int nDelayMs ; 
  
  public boolean mwait ; 
  
  public int mchMenu ; 
  public int mchSelection ; 
  
  public boolean bFirstTimeSideShift ; 
  public boolean bRightMove ; 
  
  public byte GameState ; // enum TetrisGameState
  





  public boolean infoShown ; 
  public int splash_cnt ; 
  

  //  public GAPI_Menu_t Menu = new GAPI_Menu_t () ; 
  

  public int BlockSize ; 
  
  public int LINE_POS ; 
  public int LINE_POS_DY ; 
  
  public int Yoffset ; 
  
  public /* uns */ int BackGroundPicId ; 
  public /* uns */ int BackGroundPicSelection ; 
  
  public boolean NormalSplash ; 
  public /* uns */ int EastCnt ; 

} 
; 


/* NPOINTERGROUP */ TEGlobals_t TEGlobal_p = null ; 

/* NPOINTERGROUP */ GAMenuSelectObject_t MenuObject = new GAMenuSelectObject_t () ; 

/* NPOINTERGROUP */ GAPI_HighscoreList_t TE_HighScoreList_p = null; 



//boolean ReturnFGameTTMenu ( ) ; 
//void LGDeCompressFiveCharThreeChar ( /* uns */ byte chFive , /* uns */ byte chThree , /* uns */ byte chSave ) ; 



int 
SGCompressFiveCharThreeChar ( int chFive , 
int chThree ) 
{ 
    //System.out.println("SGCompressFiveCharThreeChar");
  int chCompress = 0x00 ; 
  
  ; 
  
  chCompress = chFive ; 
  chCompress = (chCompress << 3)&0xFF ; 
  chCompress += chThree ; 
  
  ; 
  
  return chCompress ; 
} 




void 
TEFillRect ( int x , 
int y , 
int w , 
int h , 
int color ) 
{ 
    //System.out.println("TEFillRect");
  int old_color = GAGetFillColour ( ) ; 
  
  GASetFillColour ( color ) ; 
  g.setColor(fillColor);
  g.fillRect ( x , y , w , h ) ; 
  GASetFillColour ( old_color ) ; 
} 





void 
TEInitEasterSplash ( ) 
{ 
  //System.out.println("TEInitEasterSplash");
  g.setColor(clearColor);
  g.fillRect ( 0 , 0 , DISPLAY_WIDTH , DISPLAY_HEIGHT ) ; 
  GASetCurrColour ( GACOLOR_BLACK ) ; 
  
  TEGlobal_p . EastCnt = 0 ; 

} 



// not working properly?
void 
TEEasterSplash ( ) 
{ 
    //System.out.println("TEEasterSplash");
  if ( TEGlobal_p . EastCnt > 150 ) 
  { 
    TEGlobal_p . NormalSplash = true ; 
    TEGlobal_p . splash_cnt = 0 ; 
  } 
  else 
  { 
    int x1 ; 
    int x2 ; 
    int y ; 
    
    x1 = DISPLAY_WIDTH - TEGlobal_p . EastCnt ; 
    x2 = TEGlobal_p . EastCnt - 72 ; 
    y = DISPLAY_HEIGHT - 30 ; 
    
    if ( x1 < 12 ) 
    { 
      x1 = 12 ; 
    } 
    
    if ( x2 > 12 ) 
    { 
      x2 = 12 ; 
    } 
    
    GASetFillColour ( GACOLOR_WHITE ) ; 
    g.setColor(fillColor);
    g.fillRect ( 0 , y , DISPLAY_WIDTH , 24 ) ; 
    
    g.setColor(lineColor);
    g.drawString ( "Live well" , x1 , y , Graphics.TOP|Graphics.LEFT ) ; 
    g.drawString ( "Be happy" , x2 , ( int ) ( y + 6 ) , Graphics.TOP|Graphics.LEFT ) ; 
  

  } 
  TEGlobal_p . EastCnt += 4 ; 

} 


void 
TEDrawLevel ( ) 
{ 
    //System.out.println("TEDrawLevel");
  StringBuffer chLevel = new StringBuffer(4) ; 
  int x ; 
  int y ; 
  //boolean BackgroundMode ; 
  

  //BackgroundMode = GASetBitmapBackgroundMode ( false ) . value ; 
  
  GAsprintf ( chLevel, "%d" , ( TEGlobal_p . chLevel + 1 ) ) ; 
  
  x = 4 + ( 45 - 6 ) / 2 ; 
  y = ( ( DISPLAY_HEIGHT - 30 ) / 2 ) + 14 ; 
  
  if ( ( TEGlobal_p . chLevel + 1 ) > 10 ) 
  { 
    x -= 3 ; 
  } 
  
  GASetCurrColour ( GACOLOR_BLACK ) ; 
  g.setColor(lineColor);
  g.drawString ( chLevel.toString() , x , y , Graphics.TOP|Graphics.LEFT ) ; 
  


  //GASetBitmapBackgroundMode ( BackgroundMode ) . value ; 
} 


void 
TEDrawScore ( ) 
{ 
    //System.out.println("TEDrawScore");
  StringBuffer chScore = new StringBuffer(10) ; 
  int x ; 
  int y ; 
  int w ; 
  int h ; 
  //boolean BackgroundMode ; 
  

  //BackgroundMode = GASetBitmapBackgroundMode ( false ) . value ; 
  GAsprintf ( chScore , "%06ld" , TEGlobal_p . lScore ) ; 
  


  x = 4 + 3 ; 
  y = ( ( DISPLAY_HEIGHT - 30 ) / 2 ) + 23 ; 
  w = g.getFont().stringWidth( chScore.toString() );
  h = GAGetCurrfontHeight ( ) ; 
  
  TEFillRect ( x , y , w , h , GACOLOR_WHITE ) ; 
  GASetCurrColour ( GACOLOR_BLACK ) ; 
  g.setColor(lineColor);
  g.drawString ( chScore.toString() , x , y , Graphics.TOP|Graphics.LEFT ) ; 
  


  //GASetBitmapBackgroundMode ( BackgroundMode ) . value ; 
} 




void 
TEDrawTetrisBasic ( ) 
{ 
    //System.out.println("TEDrawTetrisBasic");
  int y ; 
  
  GASetCurrColour ( GACOLOR_BLACK ) ; 
  
  y = ( 16 * TEGlobal_p . BlockSize ) + TEGlobal_p . Yoffset ; 
  
  TEFillRect ( TEGlobal_p . LINE_POS , 0 , ( int ) ( TEGlobal_p . LINE_POS_DY - TEGlobal_p . LINE_POS ) , y , GACOLOR_WHITE ) ; 
  
  g.setColor(lineColor);
  g.drawLine ( TEGlobal_p . LINE_POS , 0 , TEGlobal_p . LINE_POS , y ) ; 
  

  g.drawLine ( TEGlobal_p . LINE_POS , y , TEGlobal_p . LINE_POS_DY , y ) ; 
  

  g.drawLine ( TEGlobal_p . LINE_POS_DY , y , TEGlobal_p . LINE_POS_DY , 0 ) ; 



} 



void 
TEDrawBlock ( int x , 
int y , 
int chSize , 
boolean Show , 
/* uns */ int Shape ) 
{ 
    //System.out.println("TEDrawBlock");

  int nx = TEGlobal_p . LINE_POS + ( x * chSize ) + 1 ; 
  int ny = ( ( y ) * chSize ) + TEGlobal_p . Yoffset ; 
  

  if ( Show == false ) 
  { 
    
      //GASetCurrColour ( GACOLOR_WHITE ) ; 
    GASetFillColour ( GACOLOR_WHITE ) ; 
    g.setColor(fillColor);
    g.fillRect ( nx , ny , chSize , chSize ) ; 
  } 
  else 
  { 
      //GASetCurrColour ( GACOLOR_BLACK ) ; 
    GASetFillColour ( GACOLOR_BLACK ) ; 
    g.setColor(fillColor);
    g.fillRect ( nx , ny , chSize , chSize ) ; 
    if ( chSize > 2 ) 
    { 
      GASetFillColour ( TE_BOX_FILL_COLOR [ Shape ] ) ; 
      g.setColor(fillColor);
      g.fillRect ( nx + 1 , ny + 1 , chSize - 2 , chSize - 2 ) ; 
    } 
    
    if ( ( chSize % 2 ) != 0 ) 
    { 
      int t ; 
      



      t = chSize / 2 ; 
      GASetCurrColour ( GACOLOR_BLACK ) ; 
      g.setColor(lineColor);
      g.drawLine ( ( int ) ( nx + t ) , ( int ) ( ny + t ) , ( int ) ( nx + t ) , ( int ) ( ny + t ) ) ; 
    } 
  } 
} 


void 
TEDrawNextShape ( int Color ) 
{ 
    //System.out.println("TEDrawNextShape");
  /* uns */ int chCt1 ; 
  /* uns */ int chCt2 ; 
  int NextShapeSize ; 
  int x ; 
  int y ; 
  int w ; 
  int h ; 
  
  NextShapeSize = ( DISPLAY_WIDTH - TEGlobal_p . LINE_POS ) / 5 ; 
  
  if ( NextShapeSize > 2 ) 
  { 
    NextShapeSize = 2 ; 
  } 
  


  if ( ( DISPLAY_HEIGHT - 3 ) > TEGlobal_p . LINE_POS ) 
  { 
    if ( TEGlobal_p . nsNextShape . chNShape >= 0 && TEGlobal_p . nsNextShape . chNShape <= 7 ) 
    { 
      GASetFillColour ( Color ) ; 
      for ( chCt1 = 0 ; chCt1 < 4 ; chCt1 ++ ) 
      { 
        /* uns */ int chTemp = 0x20 ; 
        
        for ( chCt2 = 0 ; chCt2 < 4 ; chCt2 ++ , chTemp = (chTemp>>1)&0xFF ) 
        { 
          if ( ( chTemp & g_Shapes [ TEGlobal_p . nsNextShape . chNShape ] [ TEGlobal_p . nsNextShape . chNRotation ] [ chCt1 ] ) != 0 ) 
          { 
            x = 4 + 14 + chCt1 * NextShapeSize ; 
            y = ( ( DISPLAY_HEIGHT - 30 ) / 2 ) + 4 + ( ( 3 - chCt2 ) * NextShapeSize ) ; 
            
            x = 4 + 14 + ( chCt2 * NextShapeSize ) ; 
            y = ( ( DISPLAY_HEIGHT - 30 ) / 2 ) + 4 + ( chCt1 * NextShapeSize ) ; 
            w = NextShapeSize ; 
            h = NextShapeSize ; 
            
            TEFillRect ( x , y , w , h , Color ) ; 
            if ( NextShapeSize > 2 ) 
            { 
              x ++ ; 
              y ++ ; 
              w -= 2 ; 
              h -= 2 ; 
              if ( Color == GACOLOR_WHITE ) 
              { 
                TEFillRect ( x , y , w , h , GACOLOR_WHITE ) ; 
              } 
              else 
              { 
                TEFillRect ( x , y , w , h , GACOLOR_BLACK ) ; 
              } 
            } 
          } 
        } 
      } 
    } 
  } 
} 


void 
TEDrawPanel ( ) 
{ 
    //System.out.println("TEDrawPanel");
  GASetFillColour ( GACOLOR_WHITE ) ; 
  g.setColor(fillColor);
  g.fillRect ( 4 , ( ( DISPLAY_HEIGHT - 30 ) / 2 ) , 45 , 30 ) ; 
  GASetCurrColour ( GACOLOR_BLACK ) ; 
  g.setColor(lineColor);
  g.drawRect ( 4 , ( ( DISPLAY_HEIGHT - 30 ) / 2 ) , 44 , 29 ) ; 
  
  TEDrawScore ( ) ; 
  TEDrawNextShape ( GACOLOR_BLACK ) ; 
  TEDrawLevel ( ) ; 

} 


// maybe must change types to byte and short.
boolean 
TEReplaceLine ( /* uns */ int[] ptrA , 
/* uns */ int chLineNbr , 
/* uns */ int chB , 
/* uns */ int Shape ) 
{ 
    //System.out.println("TEReplaceLine");
  int chCt ; 
  int chCount = 0 ; 
  int chTemp = ptrA[0] ^ chB ; 
  boolean Draw ; 
  
  for ( chCt = 0x80 ; chCt >= 0x01 ; chCt >>= 1 , chCount ++ ) 
  { 
    if ( ( chCt & chTemp ) > 0 ) 
    { 
      if ( ( chCt & chB ) > 0 ) 
        Draw = true ; 
      else 
        Draw = false ; 
      TEDrawBlock ( chCount , chLineNbr , TEGlobal_p . BlockSize , Draw , Shape ) ; 
    } 
  } 
  ptrA[0] = chB ; 
  if ( chB == 0x00 ) 
    return true ; 
  else 
    return false ; 
} 


// maybe must change types
void 
TERedrawPlFldAndShape ( ) 
{ 
    //System.out.println("TERedrawPlFldAndShape");
  int iRow ; 
  int iCol ; 
  /* uns */ int uBit ; 
  

  for ( iRow = 16 - 1 ; iRow >= 0 ; iRow -- ) 
  { 
    for ( iCol = 0 , uBit = 0x80 ; iCol < 8 ; iCol ++ , uBit >>= 1 ) 
    { 
      if ( ( TEGlobal_p . chPlFld [ iRow ] & uBit ) != 0 ) 
      { 
        TEDrawBlock ( iCol , iRow , TEGlobal_p . BlockSize , true , 0 ) ; 
      } 
    } 
  } 

⌨️ 快捷键说明

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