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

📄 mdesign.lst

📁 单片机版俄罗斯方块游戏
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.06   MDESIGN                                                               11/12/2008 09:12:22 PAGE 1   


C51 COMPILER V7.06, COMPILATION OF MODULE MDESIGN
OBJECT MODULE PLACED IN mdesign.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.EXE mdesign.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /*-------------------------------------------------------------单片机版俄罗斯方块-*/
   2          /*----------------------------------------------write by codekey, codekey@126.com-*/
   3          /*-------------------------------------------------------------------------2008-3-*/
   4          /*---------------------------------------------欢迎使用和修改,但需保留原作者信息-*/
   5          /*--------------------------------------------------------------------------------*/
   6          #include <reg52.h>
   7          #include <intrins.h>
   8          #include <stdlib.h>
   9          #include <math.h>
  10          #include "KS0108.H"
  11          
  12          #include "BlockGame.h"
  13          #include "KS0108.H"
  14          
  15          #define BLOCKSIZE 4 
  16          #define KEY  P0
  17          #define MAX_TIMER 0x5fff
  18          
  19          sbit kAutoRun = KEY^0;
  20          sbit kMoveTurn = KEY^1;
  21          sbit kMoveLeft = KEY^2;
  22          sbit kMoveRight = KEY^3;
  23          sbit kMoveDown = KEY^4;
  24          sbit kBegin = KEY^5;
  25          
  26          
  27          UINT16 timer=0;
  28          UINT8 LastKey=0xFF;
  29          
  30          BLOCK_GAME idata myGame;
  31          
  32          UINT8 LastPoint[4][2]={0,0,0,0,0,0,0,0};
  33          
  34          void Delay(UINT16 i)
  35          {
  36   1              while(--i);
  37   1      }
  38          
  39          void ClrLastPoint(void)
  40          {
  41   1              UINT8 i;
  42   1              for(i=0;i<4;i++)
  43   1              {
  44   2                      LastPoint[i][0]=0;
  45   2                      LastPoint[i][1]=0;
  46   2              }
  47   1      }
  48          
  49          void ClrLastBlock(void)
  50          {
  51   1              UINT8 i;
  52   1              if( (0==LastPoint[0][0] &&0==LastPoint[0][1])
  53   1                 &(0==LastPoint[1][0] &&0==LastPoint[1][1])
  54   1                 &(0==LastPoint[2][0] &&0==LastPoint[2][1])
  55   1                 &(0==LastPoint[3][0] &&0==LastPoint[3][1])
C51 COMPILER V7.06   MDESIGN                                                               11/12/2008 09:12:22 PAGE 2   

  56   1                ) return;
  57   1      
  58   1              for(i=0;i<4;i++)
  59   1              {               
  60   2                      DrawRect(LastPoint[i][0],LastPoint[i][1],
  61   2                       LastPoint[i][0]+BLOCKSIZE,
  62   2                       LastPoint[i][1]+BLOCKSIZE,0);
  63   2              }
  64   1      }
  65          
  66          void DrawCurBlock(void)
  67          {
  68   1              struct{
  69   1                  UINT8 i:4;
  70   1                  UINT8 j:4;
  71   1                  UINT8 r;
  72   1                  UINT8 c;
  73   1                  UINT8 nCount;
  74   1              }st_tmp;
  75   1              
  76   1      
  77   1              st_tmp.nCount=0;
  78   1              for(st_tmp.i=0;st_tmp.i<4;st_tmp.i++)
  79   1              {
  80   2                      st_tmp.r=6*(myGame.GameBlock.nFirstBlockRow+st_tmp.i-GAME_FIRST_ROW)+1; 
  81   2                      for(st_tmp.j=0;st_tmp.j<4;st_tmp.j++)
  82   2                      {       
  83   3                              st_tmp.c=6*(myGame.GameBlock.nFirstBlockCol+st_tmp.j-GAME_FIRST_COL)+2;
  84   3                              if((myGame.GameBlock.BlocksInfo>>(st_tmp.i*4+st_tmp.j))&0x0001) 
  85   3                              {
  86   4                                      LastPoint[st_tmp.nCount][0]=st_tmp.r;
  87   4                                      LastPoint[st_tmp.nCount++][1]=st_tmp.c;
  88   4                                      DrawRect(st_tmp.r,st_tmp.c,st_tmp.r+BLOCKSIZE,st_tmp.c+BLOCKSIZE,1);    
  89   4                              }
  90   3                      }
  91   2              }
  92   1      }
  93          
  94          void DrawBackGrid(void)
  95          {
  96   1              UINT8 i,j,r,c;
  97   1              for(i=GAME_FIRST_ROW;i<=GAME_LAST_ROW;i++)      
  98   1              {
  99   2                      r=6*(i-GAME_FIRST_ROW)+1;
 100   2                      for(j=GAME_FIRST_COL;j<=GAME_LAST_COL;j++)
 101   2                      {                               
 102   3                              c=6*(j-GAME_FIRST_COL)+2;
 103   3                              if((myGame.GameGrid.Grid[i]>>j)&0x0001)
 104   3                              {                       
 105   4                                      DrawRect(r,c,r+BLOCKSIZE,c+BLOCKSIZE,1);
 106   4                              }
 107   3                              else{
 108   4                                      DrawRect(r,c,r+BLOCKSIZE,c+BLOCKSIZE,0);
 109   4                              }
 110   3                      }
 111   2              }
 112   1      }
 113          
 114          BOOL DriveBlockDown(BLOCK_GAME* pGame)
 115          {
 116   1              if(!MoveBlock(pGame, eMoveDown))
 117   1              {
C51 COMPILER V7.06   MDESIGN                                                               11/12/2008 09:12:22 PAGE 3   

 118   2                      ClrLastPoint(); 
 119   2                      FixCurBlock(pGame);
 120   2                      if(AdjustGrid(pGame))
 121   2                              DrawBackGrid();
 122   2                      if(!NewBlock(pGame)){
 123   3                              GameOver(pGame);
 124   3                              DrawBackGrid(); 
 125   3                      }
 126   2                      return 0;
 127   2              }
 128   1              return 1;
 129   1      }
 130          
 131          // evaluating function
 132          BOOL JudgeBetterAttr(const GRID_ATTR* CurAttr, const GRID_ATTR* BestAttr)
 133          {
 134   1              if(CurAttr->nFullRowCount > BestAttr->nFullRowCount){           
 135   2                      return myTrue;
 136   2              }
 137   1              else if((CurAttr->nFullRowCount==BestAttr->nFullRowCount)
 138   1                      || (BestAttr->nFullRowCount==1) )
 139   1              {               
 140   2                      if(CurAttr->nIdleBankCount<BestAttr->nIdleBankCount){                   
 141   3                              return myTrue;
 142   3                      }
 143   2                      else if(CurAttr->nIdleBankCount==BestAttr->nIdleBankCount)
 144   2                      {
 145   3                              if(CurAttr->nGrideHeight<BestAttr->nGrideHeight){
 146   4                                      return myTrue;
 147   4                              }
 148   3                              else if(CurAttr->nGrideHeight==BestAttr->nGrideHeight)
 149   3                              {
 150   4                                      if(CurAttr->nLastBlockFirstRow >BestAttr->nLastBlockFirstRow){                                  
 151   5                                              return myTrue;
 152   5                                      }
 153   4                                      else if(CurAttr->nLastBlockFirstRow==BestAttr->nLastBlockFirstRow)
 154   4                                      {
 155   5                                              if(CurAttr->nMostHighEdgeHeight < BestAttr->nMostHighEdgeHeight)
 156   5                                                      return myTrue;
 157   5                                              else if(CurAttr->nMostHighEdgeHeight==BestAttr->nMostHighEdgeHeight)
 158   5                                              {                                               
 159   6                                                      if(CurAttr->nHighEdgeCount < BestAttr->nHighEdgeCount)
 160   6                                                      {                                                       
 161   7                                                              return myTrue;
 162   7                                                      }
 163   6                                              }
 164   5                                      }
 165   4                              }
 166   3                      }
 167   2              }
 168   1              return myFalse;
 169   1      }
 170          
 171          void DriveBlockRun( int status, int col)
 172          {
 173   1              while(status-->0)
 174   1              {
 175   2                      TurnBlock(&myGame); 
 176   2                      ClrLastBlock();
 177   2                      DrawCurBlock(); 
 178   2                      Delay(10000);
 179   2              }
C51 COMPILER V7.06   MDESIGN                                                               11/12/2008 09:12:22 PAGE 4   

 180   1              while(myGame.GameBlock.nFirstBlockCol>col)
 181   1              {
 182   2                      MoveBlock(&myGame,eMoveLeft);
 183   2                      ClrLastBlock();
 184   2                      DrawCurBlock();
 185   2                      Delay(10000);
 186   2              }
 187   1              while(myGame.GameBlock.nFirstBlockCol<col)
 188   1              {
 189   2                      MoveBlock(&myGame,eMoveRight);
 190   2                      ClrLastBlock();
 191   2                      DrawCurBlock();
 192   2                      Delay(10000);
 193   2              }
 194   1              while(DriveBlockDown(&myGame))

⌨️ 快捷键说明

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