fix(MCU课设): 完全修正方块下落bug

This commit is contained in:
iridiumR 2022-06-06 13:55:35 +08:00
parent a7eaddb690
commit f926ffad48
3 changed files with 673 additions and 677 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
#include "block.h" #include "block.h"
#include "draw.h" #include "draw.h"
#include "button.h" #include "button.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; enum BLK_TP type = none;
@ -22,16 +23,17 @@ void genPiece()
{ {
char i, j; char i, j;
//需要一点随机性 //需要一点随机性
int random = rand() % 4; int random = TH0 % 4;
int len = 2 + rand() % 3; int len = 2 + TH0 % 3;
//若存在尚未下落完成的方块则打断 //若存在尚未下落完成的方块则打断
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) if(base[i][j] == 2)
break; return;
//当两个方块的情况 //当两个方块的情况
@ -112,9 +114,9 @@ void dropPiece()
char i, j, flag = 0; char i, j, flag = 0;
//检测是否触底 //检测是否触底
for(i = 0; i < 8; i++) for(i = 0; i < MAX_X; i++)
{ {
for(j = 0; j < 8; j++) for(j = 0; j < MAX_Y; j++)
{ {
if(flag == 1) if(flag == 1)
break; break;
@ -133,9 +135,9 @@ void dropPiece()
break; break;
} }
//转换嵌套 //转换嵌套
for(i = 0; i < 8; i++) for(i = 0; i < MAX_X; i++)
{ {
for(j = 0; j < 8; j++) for(j = 0; j < MAX_Y; j++)
{ {
if(base[i][j] == 2) if(base[i][j] == 2)
{ {
@ -158,8 +160,8 @@ void dropPiece()
void movePiece(enum OPR opr) void movePiece(enum OPR opr)
{ {
char i, j; char i, j;
for(i = 0; i < 8; i++) for(i = 0; i < MAX_X; i++)
for(j = 0; j < 8; j++) for(j = 0; j < MAX_Y; j++)
if(base[i][j] == 2) if(base[i][j] == 2)
{ {

View file

@ -6,6 +6,12 @@
#include <stdlib.h> #include <stdlib.h>
#include "block.h" #include "block.h"
//便于调试的预编译命令
#define DEBUG_MODE
#ifdef DEBUG_MODE
#define M_DEBUG M_BLOCK
#endif
Menu M_MAINMENU;//主菜单 Menu M_MAINMENU;//主菜单
Menu M_BLOCK; //俄罗斯方块 Menu M_BLOCK; //俄罗斯方块
@ -125,6 +131,9 @@ void menuInit()
M_MAINMENU.f = m_mainmenu; M_MAINMENU.f = m_mainmenu;
M_BLOCK.f = m_block; M_BLOCK.f = m_block;
#ifdef DEBUG_MODE
NOW = &M_DEBUG;
#else
NOW = &M_STARTUP; NOW = &M_STARTUP;
#endif
} }