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

View file

@ -159,10 +159,10 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==1) if(i == 1)
P1 = ~MAINMANU_PAGE2[j]; P1 = ~MAINMANU_PAGE2[j];
else else
P1 = MAINMANU_PAGE2[j]; P1 = MAINMANU_PAGE2[j];
write(); write();
RS = 0; RS = 0;
@ -174,10 +174,10 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==1) if(i == 1)
P1 = ~MAINMANU_PAGE3[j]; P1 = ~MAINMANU_PAGE3[j];
else else
P1 = MAINMANU_PAGE3[j]; P1 = MAINMANU_PAGE3[j];
write(); write();
RS = 0; RS = 0;
@ -189,10 +189,10 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==2) if(i == 2)
P1 = ~MAINMANU_PAGE4[j]; P1 = ~MAINMANU_PAGE4[j];
else else
P1 = MAINMANU_PAGE4[j]; P1 = MAINMANU_PAGE4[j];
write(); write();
RS = 0; RS = 0;
@ -204,10 +204,10 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==2) if(i == 2)
P1 = ~MAINMANU_PAGE5[j]; P1 = ~MAINMANU_PAGE5[j];
else else
P1 = MAINMANU_PAGE5[j]; P1 = MAINMANU_PAGE5[j];
write(); write();
RS = 0; RS = 0;
@ -219,10 +219,10 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==3) if(i == 3)
P1 = ~MAINMANU_PAGE6[j]; P1 = ~MAINMANU_PAGE6[j];
else else
P1 = MAINMANU_PAGE6[j]; P1 = MAINMANU_PAGE6[j];
write(); write();
RS = 0; RS = 0;
@ -234,17 +234,17 @@ void drawMAINMENU(unsigned char i)
RS = 1; RS = 1;
RW = 0; RW = 0;
if(i==3) if(i == 3)
P1 = ~MAINMANU_PAGE7[j]; P1 = ~MAINMANU_PAGE7[j];
else else
P1 = MAINMANU_PAGE7[j]; P1 = MAINMANU_PAGE7[j];
write(); 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++) for(j = 0 ; j < 8; j++)
{ {
@ -254,7 +254,7 @@ void placeIMG_BLOCK(unsigned char x,unsigned char y)
RW = 0; RW = 0;
P1 = 0xb8 + 7 - y; P1 = 0xb8 + 7 - y;
write(); write();
P1 = 0X40 + x*8 + j; P1 = 0X40 + x * 8 + j;
write(); //Ò³7-yÁÐx*8+jÆÁA write(); //Ò³7-yÁÐx*8+jÆÁA
RS = 1; 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++) for(j = 0 ; j < 8; j++)
{ {
@ -276,7 +276,7 @@ void placeVOID_BLOCK(unsigned char x,unsigned char y)
RW = 0; RW = 0;
P1 = 0xb8 + 7 - y; P1 = 0xb8 + 7 - y;
write(); write();
P1 = 0X40 + x*8 + j; P1 = 0X40 + x * 8 + j;
write(); //Ò³7-yÁÐx*8+jÆÁA write(); //Ò³7-yÁÐx*8+jÆÁA
RS = 1; RS = 1;
@ -288,20 +288,21 @@ void placeVOID_BLOCK(unsigned char x,unsigned char y)
void drawVerticalDottedLine(char x) void drawVerticalDottedLine(char x)
{ {
unsigned int j; unsigned int j;
if(x<0||x>127) if(x < 0 || x > 127)
return; return;
else if(x<64) else if(x < 64)
{ {
CSA = 1;
} CSB = 0;
else }
{ else
x=x-63; {
CSA = 0; x = x - 63;
CSA = 0;
CSB = 1; CSB = 1;
} }
for(j = 0 ; j < 8; j++) for(j = 0 ; j < 8; j++)
{ {
@ -310,7 +311,7 @@ void drawVerticalDottedLine(char x)
P1 = 0xb8 + j; P1 = 0xb8 + j;
write(); write();
P1 = 0X40 + x; P1 = 0X40 + x;
write(); //Ò³2ÁÐjÆÁA write(); //Ò³jÁÐx
RS = 1; RS = 1;
RW = 0; RW = 0;
@ -322,7 +323,7 @@ void drawVerticalDottedLine(char x)
void drawBLOCKSCORE() void drawBLOCKSCORE()
{ {
unsigned int j; unsigned int j;
for(j = 0; j < 32; j++) for(j = 0; j < 32; j++)
{ {
@ -332,7 +333,7 @@ void drawBLOCKSCORE()
RW = 0; RW = 0;
P1 = 0xb8 + 0; P1 = 0xb8 + 0;
write(); write();
P1 = 0X40 +5+ j; P1 = 0X40 + 5 + j;
write(); //Ò³0ÁÐ5+jÆÁB write(); //Ò³0ÁÐ5+jÆÁB
RS = 1; RS = 1;
@ -344,7 +345,7 @@ void drawBLOCKSCORE()
RW = 0; RW = 0;
P1 = 0xb8 + 1; P1 = 0xb8 + 1;
write(); write();
P1 = 0X40 + 5+ j; P1 = 0X40 + 5 + j;
write(); //Ò³1ÁÐ5+jÆÁB write(); //Ò³1ÁÐ5+jÆÁB
RS = 1; RS = 1;
@ -352,4 +353,48 @@ void drawBLOCKSCORE()
P1 = FONT_SCORE1[j]; P1 = FONT_SCORE1[j];
write(); 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 drawNAME();
void drawNUMBER(); void drawNUMBER();
void drawMAINMENU(unsigned char); 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; enum OPR opr = idle;
static unsigned char local[10] = {0}; static unsigned char local[10] = {0};
extern unsigned char score=0;
//初始化显示 //初始化显示
void m_startup(struct _menu* this) void m_startup(struct _menu* this)
@ -92,9 +92,9 @@ void m_mainmenu(struct _menu* this)
NOW = &M_STARTUP; //转向下一菜单 NOW = &M_STARTUP; //转向下一菜单
break; break;
} }
local[0]=0; local[0] = 0;
clear(); clear();
opr = idle; opr = idle;
} }
} }
@ -103,43 +103,45 @@ void m_mainmenu(struct _menu* this)
//方块游戏 //方块游戏
void m_block(struct _menu* this) void m_block(struct _menu* this)
{ {
if(LAST != &M_BLOCK) if(LAST != &M_BLOCK)
{ {
LAST = &M_BLOCK; LAST = &M_BLOCK;
drawVerticalDottedLine(64); drawVerticalDottedLine(64);
drawBLOCKSCORE(); drawBLOCKSCORE();
blockInit(); blockInit();
} }
//重置 //重置
if(opr == confirm) if(opr == confirm)
{ {
opr = idle; opr = idle;
blockDestroy(); blockDestroy();
drawBlock(); drawBlock();
return; return;
} }
if(opr == left) if(opr == left)
{ {
opr = idle; opr = idle;
moveLeftPiece(); moveLeftPiece();
drawBlock(); dropPiece();
return; drawBlock();
} return;
if(opr == right) }
if(opr == right)
{ {
opr = idle; opr = idle;
moveRightPiece(); moveRightPiece();
drawBlock(); dropPiece();
return; drawBlock();
} return;
}
genPiece(); //若有需要,生成新块 drawSUPNUM(110, 0, score);
dropPiece(); //若有需要,块下落 genPiece(); //若有需要,生成新块
judgeBlock(); //若有需要,清除一行 dropPiece(); //若有需要,块下落
drawBlock(); //绘制界面 judgeBlock(); //若有需要,清除一行
delay(200); drawBlock(); //绘制界面
delay(200);
} }
void menuInit() void menuInit()
{ {
@ -147,11 +149,11 @@ void menuInit()
M_STARTUP.f = m_startup; M_STARTUP.f = m_startup;
M_MAINMENU.f = m_mainmenu; M_MAINMENU.f = m_mainmenu;
M_BLOCK.f = m_block; M_BLOCK.f = m_block;
#ifdef DEBUG_MODE #ifdef DEBUG_MODE
NOW = &M_DEBUG; NOW = &M_DEBUG;
#else #else
NOW = &M_STARTUP; NOW = &M_STARTUP;
#endif #endif
} }