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,7 +159,7 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==1)
if(i == 1)
P1 = ~MAINMANU_PAGE2[j];
else
P1 = MAINMANU_PAGE2[j];
@ -174,7 +174,7 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==1)
if(i == 1)
P1 = ~MAINMANU_PAGE3[j];
else
P1 = MAINMANU_PAGE3[j];
@ -189,7 +189,7 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==2)
if(i == 2)
P1 = ~MAINMANU_PAGE4[j];
else
P1 = MAINMANU_PAGE4[j];
@ -204,7 +204,7 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==2)
if(i == 2)
P1 = ~MAINMANU_PAGE5[j];
else
P1 = MAINMANU_PAGE5[j];
@ -219,7 +219,7 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==3)
if(i == 3)
P1 = ~MAINMANU_PAGE6[j];
else
P1 = MAINMANU_PAGE6[j];
@ -234,15 +234,15 @@ void drawMAINMENU(unsigned char i)
RS = 1;
RW = 0;
if(i==3)
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;
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,7 +264,7 @@ 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;
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;
@ -289,15 +289,16 @@ void placeVOID_BLOCK(unsigned char x,unsigned char y)
void drawVerticalDottedLine(char x)
{
unsigned int j;
if(x<0||x>127)
if(x < 0 || x > 127)
return;
else if(x<64)
else if(x < 64)
{
CSA = 1;
CSB = 0;
}
else
{
x=x-63;
x = x - 63;
CSA = 0;
CSB = 1;
}
@ -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;
@ -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,7 +93,7 @@ void m_mainmenu(struct _menu* this)
break;
}
local[0]=0;
local[0] = 0;
clear();
opr = idle;
}
@ -122,6 +122,7 @@ void m_block(struct _menu* this)
{
opr = idle;
moveLeftPiece();
dropPiece();
drawBlock();
return;
}
@ -129,10 +130,11 @@ void m_block(struct _menu* this)
{
opr = idle;
moveRightPiece();
dropPiece();
drawBlock();
return;
}
drawSUPNUM(110, 0, score);
genPiece(); //若有需要,生成新块
dropPiece(); //若有需要,块下落
judgeBlock(); //若有需要,清除一行
@ -149,9 +151,9 @@ void menuInit()
M_MAINMENU.f = m_mainmenu;
M_BLOCK.f = m_block;
#ifdef DEBUG_MODE
#ifdef DEBUG_MODE
NOW = &M_DEBUG;
#else
#else
NOW = &M_STARTUP;
#endif
#endif
}