feat(MCU课设): 增加历史排行榜功能,但还有bug
This commit is contained in:
parent
cc9a66ef00
commit
4a01b42afe
7 changed files with 124 additions and 20 deletions
|
@ -3,6 +3,7 @@
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include <reg52.h>
|
#include <reg52.h>
|
||||||
#include "delay.h"
|
#include "delay.h"
|
||||||
|
#include "eeprom.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为正在下落
|
||||||
extern unsigned int score;
|
extern unsigned int score;
|
||||||
|
@ -208,7 +209,7 @@ void moveRightPiece()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断是否游戏结束/分数增加
|
//判断消除整行
|
||||||
void judgeBlock()
|
void judgeBlock()
|
||||||
{
|
{
|
||||||
char i, j, k, h, count;
|
char i, j, k, h, count;
|
||||||
|
@ -239,6 +240,7 @@ void judgeBlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断是否游戏结束
|
||||||
void blockGameOver()
|
void blockGameOver()
|
||||||
{
|
{
|
||||||
char j,i;
|
char j,i;
|
||||||
|
@ -256,6 +258,8 @@ void blockGameOver()
|
||||||
//结束则填满
|
//结束则填满
|
||||||
if(blockGameStatus == over)
|
if(blockGameStatus == over)
|
||||||
{
|
{
|
||||||
|
addBest(score);
|
||||||
|
saveBest();
|
||||||
for(j = 0; j < MAX_Y; j++)
|
for(j = 0; j < MAX_Y; j++)
|
||||||
for(i = 0; i < MAX_X; i++)
|
for(i = 0; i < MAX_X; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -588,7 +588,7 @@ void drawBEST(unsigned char x, unsigned char y)
|
||||||
CSA = 0;
|
CSA = 0;
|
||||||
CSB = 1;
|
CSB = 1;
|
||||||
}
|
}
|
||||||
for(j = 0; j < 40; j++)
|
for(j = 0; j < 32; j++)
|
||||||
{
|
{
|
||||||
RS = 0;
|
RS = 0;
|
||||||
RW = 0;
|
RW = 0;
|
||||||
|
|
|
@ -14,6 +14,11 @@ void drawGOOD(unsigned char x, unsigned char y);
|
||||||
void drawGAME(unsigned char x, unsigned char y);
|
void drawGAME(unsigned char x, unsigned char y);
|
||||||
void drawOVER(unsigned char x, unsigned char y);
|
void drawOVER(unsigned char x, unsigned char y);
|
||||||
void drawBLOCKSCORE();
|
void drawBLOCKSCORE();
|
||||||
|
|
||||||
|
////=================== ¼Ç¼ ==================
|
||||||
|
void drawRECORD(unsigned char x, unsigned char y);
|
||||||
|
void drawBEST(unsigned char x, unsigned char y);
|
||||||
|
|
||||||
////=================== ¼¸ºÎ ==================
|
////=================== ¼¸ºÎ ==================
|
||||||
void drawVerticalDottedLine(char x);
|
void drawVerticalDottedLine(char x);
|
||||||
#endif
|
#endif
|
|
@ -13,7 +13,9 @@
|
||||||
#include "reg51.h"
|
#include "reg51.h"
|
||||||
#include "intrins.h"
|
#include "intrins.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
#include "delay.h"
|
||||||
|
|
||||||
|
extern unsigned int bestScore[10];
|
||||||
|
|
||||||
/*----------------------------
|
/*----------------------------
|
||||||
Disable ISP/IAP/EEPROM function
|
Disable ISP/IAP/EEPROM function
|
||||||
|
@ -86,3 +88,29 @@ void IapEraseSector(WORD addr)
|
||||||
IapIdle();
|
IapIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addBest(unsigned int s)
|
||||||
|
{
|
||||||
|
bestScore[2]=s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveBest()
|
||||||
|
{
|
||||||
|
char i;
|
||||||
|
IapEraseSector(IAP_ADDRESS);
|
||||||
|
delayms(20);
|
||||||
|
for(i=0;i++;i<10)
|
||||||
|
{
|
||||||
|
IapProgramByte(IAP_ADDRESS+2*i, bestScore[i]/256);
|
||||||
|
|
||||||
|
IapProgramByte(IAP_ADDRESS+2*i+1, bestScore[i]%256);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void readBest()
|
||||||
|
{
|
||||||
|
char i;
|
||||||
|
for(i=0;i++;i<10)
|
||||||
|
{
|
||||||
|
bestScore[i]=(unsigned int)IapReadByte(IAP_ADDRESS+2*i)*256 +(unsigned int)IapReadByte(IAP_ADDRESS+2*i+1);
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,4 +33,8 @@ BYTE IapReadByte(WORD addr);
|
||||||
void IapProgramByte(WORD addr, BYTE dat);
|
void IapProgramByte(WORD addr, BYTE dat);
|
||||||
void IapEraseSector(WORD addr);
|
void IapEraseSector(WORD addr);
|
||||||
|
|
||||||
|
void saveBest();
|
||||||
|
void readBest();
|
||||||
|
void addBest(unsigned int s);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -1,4 +1,5 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "eeprom.h"
|
||||||
|
|
||||||
#define RELOAD (65535-9216) //定时器填充值(1ms)
|
#define RELOAD (65535-9216) //定时器填充值(1ms)
|
||||||
unsigned char TH, TL;
|
unsigned char TH, TL;
|
||||||
|
@ -64,8 +65,8 @@ int main()
|
||||||
|
|
||||||
displayInit(); //屏幕初始化
|
displayInit(); //屏幕初始化
|
||||||
clear();
|
clear();
|
||||||
menuInit(); //꽉데섟페儉놓迦뺏
|
menuInit(); //꽉데놓迦뺏
|
||||||
|
readBest();
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,9 @@ Menu* NOW; //
|
||||||
Menu* LAST = NULL; //上一个状态的菜单
|
Menu* LAST = NULL; //上一个状态的菜单
|
||||||
|
|
||||||
enum OPR opr = idle;
|
enum OPR opr = idle;
|
||||||
static unsigned char local[10] = {0};
|
static unsigned char local[2] = {0};
|
||||||
unsigned int score;
|
unsigned int score;
|
||||||
|
unsigned int bestScore[10];
|
||||||
extern enum GS blockGameStatus;
|
extern enum GS blockGameStatus;
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,29 +94,29 @@ void m_block(struct _menu* this)
|
||||||
{
|
{
|
||||||
opr = idle;
|
opr = idle;
|
||||||
blockDestroy();
|
blockDestroy();
|
||||||
NOW=&M_MAINMENU;
|
NOW = &M_MAINMENU;
|
||||||
clear();
|
clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(opr == left)
|
if(opr == left)
|
||||||
{
|
{
|
||||||
opr = idle;
|
opr = idle;
|
||||||
moveLeftPiece();
|
moveLeftPiece();
|
||||||
drawBlock();
|
drawBlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(opr == right)
|
if(opr == right)
|
||||||
{
|
{
|
||||||
opr = idle;
|
opr = idle;
|
||||||
moveRightPiece();
|
moveRightPiece();
|
||||||
drawBlock();
|
drawBlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch(blockGameStatus)
|
switch(blockGameStatus)
|
||||||
{
|
{
|
||||||
case good:
|
case good:
|
||||||
drawGOOD(70, 4);
|
drawGOOD(70, 4);
|
||||||
blockGameStatus=start;
|
blockGameStatus = start;
|
||||||
break;
|
break;
|
||||||
case over:
|
case over:
|
||||||
drawGAME(70, 4);
|
drawGAME(70, 4);
|
||||||
|
@ -125,12 +126,12 @@ void m_block(struct _menu* this)
|
||||||
drawVOID8(70, 4, 40);
|
drawVOID8(70, 4, 40);
|
||||||
drawVOID8(70, 6, 32);
|
drawVOID8(70, 6, 32);
|
||||||
}
|
}
|
||||||
drawSUPNUM(70, 2, score/10000); //绘制分数
|
drawSUPNUM(70, 2, score / 10000); //绘制分数
|
||||||
drawSUPNUM(79, 2, (score%10000)/1000);
|
drawSUPNUM(79, 2, (score % 10000) / 1000);
|
||||||
drawSUPNUM(88, 2, (score%1000)/100);
|
drawSUPNUM(88, 2, (score % 1000) / 100);
|
||||||
drawSUPNUM(97, 2, (score%100)/10);
|
drawSUPNUM(97, 2, (score % 100) / 10);
|
||||||
drawSUPNUM(106, 2, score%10);
|
drawSUPNUM(106, 2, score % 10);
|
||||||
blockGameOver(); //检查是否游戏结束
|
blockGameOver(); //检查是否游戏结束
|
||||||
genPiece(); //若有需要,生成新块
|
genPiece(); //若有需要,生成新块
|
||||||
dropPiece(); //若有需要,块下落
|
dropPiece(); //若有需要,块下落
|
||||||
judgeBlock(); //若有需要,清除一行
|
judgeBlock(); //若有需要,清除一行
|
||||||
|
@ -147,7 +148,7 @@ void m_about(struct _menu* this)
|
||||||
if(LAST != &M_ABOUT)
|
if(LAST != &M_ABOUT)
|
||||||
{
|
{
|
||||||
LAST = &M_ABOUT;
|
LAST = &M_ABOUT;
|
||||||
delayms(2000);
|
delayms(2000);
|
||||||
drawNAME(); //绘制名字
|
drawNAME(); //绘制名字
|
||||||
delayms(2000);
|
delayms(2000);
|
||||||
drawNUMBER(); //绘制学号
|
drawNUMBER(); //绘制学号
|
||||||
|
@ -161,12 +162,73 @@ void m_about(struct _menu* this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//记录页
|
||||||
|
void m_best(struct _menu* this)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if(LAST != &M_BEST)
|
||||||
|
{
|
||||||
|
LAST = &M_BEST;
|
||||||
|
drawBEST(2, 0);
|
||||||
|
drawSUPNUM(2, 2, bestScore[0] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(11, 2, (bestScore[0] % 10000) / 1000);
|
||||||
|
drawSUPNUM(20, 2, (bestScore[0] % 1000) / 100);
|
||||||
|
drawSUPNUM(29, 2, (bestScore[0] % 100) / 10);
|
||||||
|
drawSUPNUM(38, 2, bestScore[0] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(2, 4, bestScore[1] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(11, 4, (bestScore[1] % 10000) / 1000);
|
||||||
|
drawSUPNUM(20, 4, (bestScore[1] % 1000) / 100);
|
||||||
|
drawSUPNUM(29, 4, (bestScore[1] % 100) / 10);
|
||||||
|
drawSUPNUM(38, 4, bestScore[1] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(2, 6, bestScore[2] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(11, 6, (bestScore[2] % 10000) / 1000);
|
||||||
|
drawSUPNUM(20, 6, (bestScore[2] % 1000) / 100);
|
||||||
|
drawSUPNUM(29, 6, (bestScore[2] % 100) / 10);
|
||||||
|
drawSUPNUM(38, 6, bestScore[2] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(72, 0, bestScore[3] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(81, 0, (bestScore[3] % 10000) / 1000);
|
||||||
|
drawSUPNUM(90, 0, (bestScore[3] % 1000) / 100);
|
||||||
|
drawSUPNUM(99, 0, (bestScore[3] % 100) / 10);
|
||||||
|
drawSUPNUM(108, 0, bestScore[3] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(72, 2, bestScore[4] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(81, 2, (bestScore[4] % 10000) / 1000);
|
||||||
|
drawSUPNUM(90, 2, (bestScore[4] % 1000) / 100);
|
||||||
|
drawSUPNUM(99, 2, (bestScore[4] % 100) / 10);
|
||||||
|
drawSUPNUM(108, 2, bestScore[4] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(72, 4, bestScore[5] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(81, 4, (bestScore[5] % 10000) / 1000);
|
||||||
|
drawSUPNUM(90, 4, (bestScore[5] % 1000) / 100);
|
||||||
|
drawSUPNUM(99, 4, (bestScore[5] % 100) / 10);
|
||||||
|
drawSUPNUM(108, 4, bestScore[5] % 10);
|
||||||
|
|
||||||
|
drawSUPNUM(72, 6, bestScore[6] / 10000); //绘制分数
|
||||||
|
drawSUPNUM(81, 6, (bestScore[6] % 10000) / 1000);
|
||||||
|
drawSUPNUM(90, 6, (bestScore[6] % 1000) / 100);
|
||||||
|
drawSUPNUM(99, 6, (bestScore[6] % 100) / 10);
|
||||||
|
drawSUPNUM(108, 6, bestScore[6] % 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(opr == confirm)
|
||||||
|
{
|
||||||
|
opr = idle;
|
||||||
|
NOW = &M_MAINMENU; //转向下一菜单
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void menuInit()
|
void menuInit()
|
||||||
{
|
{
|
||||||
|
|
||||||
M_MAINMENU.f = m_mainmenu;
|
M_MAINMENU.f = m_mainmenu;
|
||||||
M_BLOCK.f = m_block;
|
M_BLOCK.f = m_block;
|
||||||
M_ABOUT.f = m_about;
|
M_ABOUT.f = m_about;
|
||||||
|
M_BEST.f = m_best;
|
||||||
|
|
||||||
#ifdef DEBUG_MODE
|
#ifdef DEBUG_MODE
|
||||||
NOW = &M_DEBUG;
|
NOW = &M_DEBUG;
|
||||||
|
|
Reference in a new issue