176 lines
2.9 KiB
C
176 lines
2.9 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[10] = {0};
|
|
unsigned int score = 0;
|
|
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(78, 2, score/1000);
|
|
drawSUPNUM(86, 2, score/100);
|
|
drawSUPNUM(94, 2, score/10);
|
|
drawSUPNUM(102, 2, score%10);
|
|
blockGameOver(); //检查是否游戏结束
|
|
genPiece(); //若有需要,生成新块
|
|
dropPiece(); //若有需要,块下落
|
|
judgeBlock(); //若有需要,清除一行
|
|
drawBlock(); //绘制界面
|
|
delayms(400);
|
|
|
|
}
|
|
|
|
//关于页
|
|
void m_about(struct _menu* this)
|
|
{
|
|
|
|
|
|
if(LAST != &M_ABOUT)
|
|
{
|
|
LAST = &M_ABOUT;
|
|
|
|
drawNAME(); //绘制名字
|
|
delayms(2000);
|
|
drawNUMBER(); //绘制学号
|
|
}
|
|
|
|
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;
|
|
|
|
#ifdef DEBUG_MODE
|
|
NOW = &M_DEBUG;
|
|
#else
|
|
NOW = &M_MAINMENU;
|
|
#endif
|
|
}
|