feat(MCU课设):方块增加计分

This commit is contained in:
iridiumR 2022-06-06 17:01:36 +08:00
parent 2a879fa682
commit 8c19878cc9
5 changed files with 1073 additions and 957 deletions

File diff suppressed because it is too large Load diff

View file

@ -4,7 +4,7 @@
#include <reg52.h>
char base[MAX_X][MAX_Y] = {0}; //x*y //0为空 1为下落完成 2为正在下落
enum BLK_TP type = none;
extern unsigned char score;
extern enum OPR opr;
void blockInit()
@ -162,10 +162,11 @@ void moveLeftPiece()
char i, j;
for(i = 0; i < MAX_X; i++)
for(j = 0; j < MAX_Y; j++)
if(base[i][j] == 2 && isIegal(i - 1, j))
if(base[i][j] == 2 && !isIegal(i - 1, j))
{
base[i - 1][j] = 2;
base[i][j] = 0;
return;
}
}
void moveRightPiece()
@ -199,9 +200,12 @@ void judgeBlock()
}
//计数足则整体下移
if(count == 8)
{
score++;
for(k = 0; k < MAX_X; k++)
for(h = j ; h < MAX_Y-1; h++)
base[k][h] = base[k][h + 1];
}
}
}

View file

@ -159,10 +159,10 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==1)
P1 = ~MAINMANU_PAGE2[j];
else
P1 = MAINMANU_PAGE2[j];
if(i == 1)
P1 = ~MAINMANU_PAGE2[j];
else
P1 = MAINMANU_PAGE2[j];
write();
RS = 0;
@ -174,10 +174,10 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==1)
P1 = ~MAINMANU_PAGE3[j];
else
P1 = MAINMANU_PAGE3[j];
if(i == 1)
P1 = ~MAINMANU_PAGE3[j];
else
P1 = MAINMANU_PAGE3[j];
write();
RS = 0;
@ -189,10 +189,10 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==2)
P1 = ~MAINMANU_PAGE4[j];
else
P1 = MAINMANU_PAGE4[j];
if(i == 2)
P1 = ~MAINMANU_PAGE4[j];
else
P1 = MAINMANU_PAGE4[j];
write();
RS = 0;
@ -204,10 +204,10 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==2)
P1 = ~MAINMANU_PAGE5[j];
else
P1 = MAINMANU_PAGE5[j];
if(i == 2)
P1 = ~MAINMANU_PAGE5[j];
else
P1 = MAINMANU_PAGE5[j];
write();
RS = 0;
@ -219,10 +219,10 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==3)
P1 = ~MAINMANU_PAGE6[j];
else
P1 = MAINMANU_PAGE6[j];
if(i == 3)
P1 = ~MAINMANU_PAGE6[j];
else
P1 = MAINMANU_PAGE6[j];
write();
RS = 0;
@ -234,17 +234,17 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==3)
P1 = ~MAINMANU_PAGE7[j];
else
P1 = MAINMANU_PAGE7[j];
if(i == 3)
P1 = ~MAINMANU_PAGE7[j];
else
P1 = MAINMANU_PAGE7[j];
write();
}
}
void placeIMG_BLOCK(unsigned char x,unsigned char y)
}
void placeIMG_BLOCK(unsigned char x, unsigned char y)
{
char j;
char j;
for(j = 0 ; j < 8; j++)
{
@ -254,7 +254,7 @@ void placeIMG_BLOCK(unsigned char x,unsigned char y)
RW = 0;
P1 = 0xb8 + 7 - y;
write();
P1 = 0X40 + x*8 + j;
P1 = 0X40 + x * 8 + j;
write(); //Ò³7-yÁÐx*8+jÆÁA
RS = 1;
@ -264,9 +264,9 @@ void placeIMG_BLOCK(unsigned char x,unsigned char y)
}
}
void placeVOID_BLOCK(unsigned char x,unsigned char y)
void placeVOID_BLOCK(unsigned char x, unsigned char y)
{
char j;
char j;
for(j = 0 ; j < 8; j++)
{
@ -276,7 +276,7 @@ void placeVOID_BLOCK(unsigned char x,unsigned char y)
RW = 0;
P1 = 0xb8 + 7 - y;
write();
P1 = 0X40 + x*8 + j;
P1 = 0X40 + x * 8 + j;
write(); //Ò³7-yÁÐx*8+jÆÁA
RS = 1;
@ -288,19 +288,20 @@ void placeVOID_BLOCK(unsigned char x,unsigned char y)
void drawVerticalDottedLine(char x)
{
unsigned int j;
if(x<0||x>127)
return;
else if(x<64)
{
}
else
{
x=x-63;
CSA = 0;
unsigned int j;
if(x < 0 || x > 127)
return;
else if(x < 64)
{
CSA = 1;
CSB = 0;
}
else
{
x = x - 63;
CSA = 0;
CSB = 1;
}
}
for(j = 0 ; j < 8; j++)
{
@ -310,7 +311,7 @@ void drawVerticalDottedLine(char x)
P1 = 0xb8 + j;
write();
P1 = 0X40 + x;
write(); //Ò³2ÁÐjÆÁA
write(); //Ò³jÁÐx
RS = 1;
RW = 0;
@ -322,7 +323,7 @@ void drawVerticalDottedLine(char x)
void drawBLOCKSCORE()
{
unsigned int j;
unsigned int j;
for(j = 0; j < 32; j++)
{
@ -332,7 +333,7 @@ void drawBLOCKSCORE()
RW = 0;
P1 = 0xb8 + 0;
write();
P1 = 0X40 +5+ j;
P1 = 0X40 + 5 + j;
write(); //Ò³0ÁÐ5+jÆÁB
RS = 1;
@ -344,7 +345,7 @@ void drawBLOCKSCORE()
RW = 0;
P1 = 0xb8 + 1;
write();
P1 = 0X40 + 5+ j;
P1 = 0X40 + 5 + j;
write(); //Ò³1ÁÐ5+jÆÁB
RS = 1;
@ -353,3 +354,47 @@ void drawBLOCKSCORE()
write();
}
}
void drawSUPNUM(unsigned char x, unsigned char y, unsigned char num)
{
unsigned int j;
if(x < 0 || x > 127)
return;
else if(x < 64)
{
CSA = 1;
CSB = 0;
}
else
{
x = x - 63;
CSA = 0;
CSB = 1;
}
for(j = 0; j < 8; j++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + y;
write();
P1 = 0X40 + x + j;
write(); //Ò³yÁÐx+j
RS = 1;
RW = 0;
P1 = SUPER_NUM0[8*num+j];
write();
RS = 0;
RW = 0;
P1 = 0xb8 + y + 1;
write();
P1 = 0X40 + x + j;
write(); //Ò³y+1ÁÐx+j
RS = 1;
RW = 0;
P1 = SUPER_NUM1[8*num+j];
write();
}
}

View file

@ -4,7 +4,7 @@
void drawNAME();
void drawNUMBER();
void drawMAINMENU(unsigned char);
void drawSUPNUM(unsigned char x,unsigned char y,unsigned char num);
////=================== 方块 ==================

View file

@ -24,7 +24,7 @@ Menu* LAST = NULL; //
enum OPR opr = idle;
static unsigned char local[10] = {0};
extern unsigned char score=0;
//初始化显示
void m_startup(struct _menu* this)
@ -93,8 +93,8 @@ void m_mainmenu(struct _menu* this)
break;
}
local[0]=0;
clear();
local[0] = 0;
clear();
opr = idle;
}
}
@ -103,41 +103,43 @@ void m_mainmenu(struct _menu* this)
//方块游戏
void m_block(struct _menu* this)
{
if(LAST != &M_BLOCK)
if(LAST != &M_BLOCK)
{
LAST = &M_BLOCK;
drawVerticalDottedLine(64);
drawBLOCKSCORE();
blockInit();
drawVerticalDottedLine(64);
drawBLOCKSCORE();
blockInit();
}
//重置
//重置
if(opr == confirm)
{
opr = idle;
blockDestroy();
drawBlock();
return;
}
if(opr == left)
opr = idle;
blockDestroy();
drawBlock();
return;
}
if(opr == left)
{
opr = idle;
moveLeftPiece();
drawBlock();
return;
}
if(opr == right)
opr = idle;
moveLeftPiece();
dropPiece();
drawBlock();
return;
}
if(opr == right)
{
opr = idle;
moveRightPiece();
drawBlock();
return;
}
genPiece(); //若有需要,生成新块
dropPiece(); //若有需要,块下落
judgeBlock(); //若有需要,清除一行
drawBlock(); //绘制界面
delay(200);
opr = idle;
moveRightPiece();
dropPiece();
drawBlock();
return;
}
drawSUPNUM(110, 0, score);
genPiece(); //若有需要,生成新块
dropPiece(); //若有需要,块下落
judgeBlock(); //若有需要,清除一行
drawBlock(); //绘制界面
delay(200);
}
@ -147,11 +149,11 @@ void menuInit()
M_STARTUP.f = m_startup;
M_MAINMENU.f = m_mainmenu;
M_BLOCK.f = m_block;
M_BLOCK.f = m_block;
#ifdef DEBUG_MODE
NOW = &M_DEBUG;
#else
#ifdef DEBUG_MODE
NOW = &M_DEBUG;
#else
NOW = &M_STARTUP;
#endif
#endif
}