238 lines
5.1 KiB
C
238 lines
5.1 KiB
C
#include "menu.h"
|
|
#include "display.h"
|
|
#include "delay.h"
|
|
#include "draw.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "block.h"
|
|
|
|
//便于调试的预编译命令
|
|
//#define DEBUG_MODE
|
|
|
|
#ifdef DEBUG_MODE
|
|
#define M_DEBUG M_BLOCK
|
|
#endif
|
|
|
|
Menu M_MAINMENU;//主菜单
|
|
Menu M_BLOCK; //俄罗斯方块
|
|
Menu M_BEST; //弹球
|
|
Menu M_ABOUT; //关于
|
|
|
|
Menu* NOW; //当前菜单指针
|
|
Menu* LAST = NULL; //上一个状态的菜单
|
|
|
|
enum OPR opr = idle;
|
|
static unsigned char local[2] = {0};
|
|
unsigned int score;
|
|
unsigned int bestScore[10];
|
|
extern enum GS blockGameStatus;
|
|
|
|
|
|
//主菜单
|
|
void m_mainmenu(struct _menu* this)
|
|
{
|
|
if(LAST != &M_MAINMENU)
|
|
{
|
|
LAST = &M_MAINMENU;
|
|
drawMAINMENU(local[0]);
|
|
}
|
|
|
|
if(opr == right)
|
|
{
|
|
local[0]++;
|
|
if(local[0] > 3)
|
|
local[0] = 3;
|
|
|
|
opr = idle;
|
|
drawMAINMENU(local[0]);
|
|
}
|
|
if(opr == left)
|
|
{
|
|
if(local[0] != 0)
|
|
local[0]--;
|
|
|
|
opr = idle;
|
|
drawMAINMENU(local[0]);
|
|
}
|
|
if(opr == confirm)
|
|
{
|
|
|
|
switch(local[0])
|
|
{
|
|
case 0:
|
|
return;
|
|
case 1:
|
|
NOW = &M_BLOCK; //转向下一菜单
|
|
break;
|
|
case 2:
|
|
NOW = &M_BEST; //转向下一菜单
|
|
break;
|
|
case 3:
|
|
NOW = &M_ABOUT; //转向下一菜单
|
|
break;
|
|
}
|
|
|
|
local[0] = 0;
|
|
clear();
|
|
opr = idle;
|
|
}
|
|
}
|
|
|
|
|
|
//方块游戏
|
|
void m_block(struct _menu* this)
|
|
{
|
|
if(LAST != &M_BLOCK)
|
|
{
|
|
LAST = &M_BLOCK;
|
|
drawVerticalDottedLine(64);
|
|
drawBLOCKSCORE();
|
|
blockInit();
|
|
}
|
|
//重置
|
|
if(opr == confirm)
|
|
{
|
|
opr = idle;
|
|
blockDestroy();
|
|
NOW = &M_MAINMENU;
|
|
clear();
|
|
return;
|
|
}
|
|
if(opr == left)
|
|
{
|
|
opr = idle;
|
|
moveLeftPiece();
|
|
drawBlock();
|
|
return;
|
|
}
|
|
if(opr == right)
|
|
{
|
|
opr = idle;
|
|
moveRightPiece();
|
|
drawBlock();
|
|
return;
|
|
}
|
|
switch(blockGameStatus)
|
|
{
|
|
case good:
|
|
drawGOOD(70, 4);
|
|
blockGameStatus = start;
|
|
break;
|
|
case over:
|
|
drawGAME(70, 4);
|
|
drawOVER(70, 6);
|
|
break;
|
|
default:
|
|
drawVOID8(70, 4, 40);
|
|
drawVOID8(70, 6, 32);
|
|
}
|
|
drawSUPNUM(70, 2, score / 10000); //绘制分数
|
|
drawSUPNUM(79, 2, (score % 10000) / 1000);
|
|
drawSUPNUM(88, 2, (score % 1000) / 100);
|
|
drawSUPNUM(97, 2, (score % 100) / 10);
|
|
drawSUPNUM(106, 2, score % 10);
|
|
blockGameOver(); //检查是否游戏结束
|
|
genPiece(); //若有需要,生成新块
|
|
dropPiece(); //若有需要,块下落
|
|
judgeBlock(); //若有需要,清除一行
|
|
drawBlock(); //绘制界面
|
|
delayms(400);
|
|
|
|
}
|
|
|
|
//关于页
|
|
void m_about(struct _menu* this)
|
|
{
|
|
|
|
|
|
if(LAST != &M_ABOUT)
|
|
{
|
|
LAST = &M_ABOUT;
|
|
delayms(2000);
|
|
drawNAME(); //绘制名字
|
|
delayms(2000);
|
|
drawNUMBER(); //绘制学号
|
|
}
|
|
|
|
if(opr == confirm)
|
|
{
|
|
opr = idle;
|
|
NOW = &M_MAINMENU; //转向下一菜单
|
|
clear();
|
|
}
|
|
}
|
|
|
|
//记录页
|
|
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()
|
|
{
|
|
|
|
M_MAINMENU.f = m_mainmenu;
|
|
M_BLOCK.f = m_block;
|
|
M_ABOUT.f = m_about;
|
|
M_BEST.f = m_best;
|
|
|
|
#ifdef DEBUG_MODE
|
|
NOW = &M_DEBUG;
|
|
#else
|
|
NOW = &M_MAINMENU;
|
|
#endif
|
|
}
|