2022-06-04 14:15:13 +00:00
|
|
|
|
#include "block.h"
|
2022-06-05 15:35:53 +00:00
|
|
|
|
#include "draw.h"
|
2022-06-06 05:41:14 +00:00
|
|
|
|
#include "button.h"
|
2022-06-06 05:55:35 +00:00
|
|
|
|
#include <reg52.h>
|
2022-06-06 12:06:14 +00:00
|
|
|
|
#include "delay.h"
|
2022-06-07 06:25:11 +00:00
|
|
|
|
#include "eeprom.h"
|
2022-06-07 16:26:36 +00:00
|
|
|
|
#include <stdlib.h>
|
2022-06-04 14:15:13 +00:00
|
|
|
|
|
2022-06-07 13:45:23 +00:00
|
|
|
|
extern unsigned int bestScore[];
|
2022-06-09 04:52:41 +00:00
|
|
|
|
char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ<30><CEAA> 1Ϊ<31><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2Ϊ<32><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3Ϊ<33><CEAA>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
|
|
|
|
|
char mask[MAX_X][MAX_Y] = {0}; //<2F><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-06 12:52:06 +00:00
|
|
|
|
extern unsigned int score;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
extern enum OPR opr;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
enum GS blockGameStatus = __idle;
|
2022-06-06 09:33:02 +00:00
|
|
|
|
|
2022-06-04 14:15:13 +00:00
|
|
|
|
void blockInit()
|
|
|
|
|
{
|
2022-06-07 13:45:23 +00:00
|
|
|
|
score = 0;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
srand((unsigned)TL0);
|
2022-06-06 11:05:34 +00:00
|
|
|
|
blockGameStatus = start;
|
2022-06-04 14:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
void blockDestroy()
|
2022-06-04 14:15:13 +00:00
|
|
|
|
{
|
2022-06-07 15:51:01 +00:00
|
|
|
|
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD>
|
|
|
|
|
if(addBest(score))
|
|
|
|
|
{
|
|
|
|
|
IapEraseSector(IAP_ADDRESS);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 0, bestScore[0] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 1, bestScore[0] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 2, bestScore[1] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 3, bestScore[1] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 4, bestScore[2] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 5, bestScore[2] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 6, bestScore[3] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 7, bestScore[3] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 8, bestScore[4] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 9, bestScore[4] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 10, bestScore[5] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 11, bestScore[5] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 12, bestScore[6] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 13, bestScore[6] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 14, bestScore[7] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 15, bestScore[7] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 16, bestScore[8] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 17, bestScore[8] % 256);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 18, bestScore[9] >> 8);
|
|
|
|
|
IapProgramByte(IAP_ADDRESS + 19, bestScore[9] % 256);
|
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
memset(base, 0, sizeof(base));
|
2022-06-06 11:05:34 +00:00
|
|
|
|
blockGameStatus = over;
|
2022-06-04 14:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
void genPiece()
|
2022-06-04 14:15:13 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
char i, j;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
//<2F><>Ҫһ<D2AA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-07 16:26:36 +00:00
|
|
|
|
int random = rand() % 100;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
|
2022-06-06 06:48:59 +00:00
|
|
|
|
|
2022-06-06 11:05:34 +00:00
|
|
|
|
if(blockGameStatus == over)
|
|
|
|
|
return;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
|
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵķ<C9B5><C4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-09 04:52:41 +00:00
|
|
|
|
if(base[i][j] >= 2)
|
2022-06-06 05:55:35 +00:00
|
|
|
|
return;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
|
2022-06-06 06:48:59 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-07 16:26:36 +00:00
|
|
|
|
if(random >= 0 && random <= 6)
|
2022-06-06 06:48:59 +00:00
|
|
|
|
{
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[4][9] = 2;
|
2022-06-06 06:48:59 +00:00
|
|
|
|
}
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-07 16:26:36 +00:00
|
|
|
|
if(random >= 7 && random <= 15)
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][9] = 3; //
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[4][10] = 2; //
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if(random >= 16 && random <= 22)
|
2022-06-06 06:48:59 +00:00
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[3][9] = 3; ////
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[4][9] = 2;
|
2022-06-06 06:48:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-05 15:35:53 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if(random >= 23 && random <= 32)
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 06:48:59 +00:00
|
|
|
|
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[4][11] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-06 06:48:59 +00:00
|
|
|
|
base[4][9] = 2;
|
|
|
|
|
}
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if(random >= 32 && random <= 38)
|
2022-06-06 06:48:59 +00:00
|
|
|
|
{
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[3][9] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][9] = 3;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[5][9] = 2;
|
2022-06-06 06:48:59 +00:00
|
|
|
|
}
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if(random >= 39 && random <= 47)
|
2022-06-06 06:48:59 +00:00
|
|
|
|
{
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[3][9] = 3;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[4][9] = 2;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if (random >= 48 && random <= 55)
|
2022-06-06 06:48:59 +00:00
|
|
|
|
{
|
2022-06-07 16:00:27 +00:00
|
|
|
|
base[4][10] = 2;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[3][9] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][9] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if (random >= 56 && random <= 63)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[4][9] = 2;
|
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if (random >= 64 && random <= 69)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[3][9] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[3][10] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
base[4][10] = 2;
|
2022-06-06 06:48:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-07 16:26:36 +00:00
|
|
|
|
else if(random >= 70 && random <= 79)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[3][10] = 2;
|
|
|
|
|
base[4][10] = 2;
|
|
|
|
|
base[3][9] = 2;
|
|
|
|
|
base[4][9] = 2;
|
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if(random >= 80 && random <= 84)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
base[3][9] = 2;
|
|
|
|
|
base[4][11] = 2;
|
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if(random >= 85 && random <= 89)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
base[3][11] = 2;
|
|
|
|
|
base[4][9] = 2;
|
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if(random >= 90 && random <= 94)
|
2022-06-07 16:00:27 +00:00
|
|
|
|
{
|
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-07 16:00:27 +00:00
|
|
|
|
base[4][9] = 2;
|
|
|
|
|
base[5][9] = 2;
|
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
else if(random >= 95 && random <= 99)
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 11:05:34 +00:00
|
|
|
|
base[3][10] = 2;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[4][10] = 3;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
base[3][9] = 2;
|
|
|
|
|
base[4][9] = 2;
|
2022-06-06 05:41:14 +00:00
|
|
|
|
}
|
2022-06-06 01:40:49 +00:00
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB>
|
|
|
|
|
unsigned char isIegal(char i, char j)
|
2022-06-06 01:40:49 +00:00
|
|
|
|
{
|
2022-06-06 09:10:00 +00:00
|
|
|
|
if(i >= 0 && i < MAX_X && j >= 0 && j < MAX_Y && base[i][j] != 1)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void drawBlock()
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 05:41:14 +00:00
|
|
|
|
char i, j;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
for(i = 0; i < 8; i++)
|
|
|
|
|
for(j = 0; j < 8; j++)
|
|
|
|
|
if(base[i][j] != 0)
|
|
|
|
|
placeIMG_BLOCK(i, j);
|
|
|
|
|
else
|
2022-06-06 06:48:59 +00:00
|
|
|
|
placeVOID_BLOCK(i, j);
|
2022-06-05 15:35:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD>
|
|
|
|
|
void dropPiece()
|
|
|
|
|
{
|
|
|
|
|
char i, j, flag = 0;
|
2022-06-05 15:35:53 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<C7B7>
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
|
|
|
|
if(flag == 1)
|
|
|
|
|
break;
|
2022-06-09 04:52:41 +00:00
|
|
|
|
if(base[i][j] >= 2)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(flag == 0 && (base[i][j - 1] == 1 || j == 0))
|
|
|
|
|
{
|
|
|
|
|
flag = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(flag == 1)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//ת<><D7AA>Ƕ<EFBFBD><C7B6>
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
if(base[i][j] >= 2)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-06 06:27:04 +00:00
|
|
|
|
//<2F>ޱ<EFBFBD><DEB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-06 05:41:14 +00:00
|
|
|
|
if(flag == 0 && isIegal(i, j - 1))
|
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[i][j - 1] = base[i][j];
|
2022-06-06 05:41:14 +00:00
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
}
|
2022-06-06 06:27:04 +00:00
|
|
|
|
//<2F>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
|
2022-06-06 05:41:14 +00:00
|
|
|
|
else if(flag == 1)
|
2022-06-07 13:45:23 +00:00
|
|
|
|
{
|
|
|
|
|
score++;
|
|
|
|
|
base[i][j] = 1;
|
|
|
|
|
}
|
2022-06-06 05:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>
|
2022-06-06 06:27:04 +00:00
|
|
|
|
void moveLeftPiece()
|
2022-06-05 15:35:53 +00:00
|
|
|
|
{
|
2022-06-06 06:27:04 +00:00
|
|
|
|
|
2022-06-06 05:41:14 +00:00
|
|
|
|
char i, j;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
if(blockGameStatus == over)
|
|
|
|
|
return;
|
2022-06-06 05:55:35 +00:00
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-06 09:01:36 +00:00
|
|
|
|
if(base[i][j] == 2 && !isIegal(i - 1, j))
|
2022-06-06 09:03:03 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
2022-06-09 04:52:41 +00:00
|
|
|
|
if(base[i][j] >= 2)
|
2022-06-06 05:41:14 +00:00
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[i - 1][j] = base[i][j];
|
2022-06-06 06:27:04 +00:00
|
|
|
|
base[i][j] = 0;
|
2022-06-06 05:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-06 06:27:04 +00:00
|
|
|
|
void moveRightPiece()
|
|
|
|
|
{
|
|
|
|
|
char i, j;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
if(blockGameStatus == over)
|
|
|
|
|
return;
|
2022-06-06 06:27:04 +00:00
|
|
|
|
for(i = MAX_X - 1; i >= 0; i--)
|
|
|
|
|
for(j = MAX_Y - 1; j >= 0; j--)
|
2022-06-06 09:03:03 +00:00
|
|
|
|
if(base[i][j] == 2 && !isIegal(i + 1, j))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for(i = MAX_X - 1; i >= 0; i--)
|
|
|
|
|
for(j = MAX_Y - 1; j >= 0; j--)
|
2022-06-09 04:52:41 +00:00
|
|
|
|
if(base[i][j] >= 2 )
|
2022-06-06 06:27:04 +00:00
|
|
|
|
{
|
2022-06-09 04:52:41 +00:00
|
|
|
|
base[i + 1][j] = base[i][j];
|
2022-06-06 06:27:04 +00:00
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
}
|
2022-06-06 07:55:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 06:25:11 +00:00
|
|
|
|
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2022-06-06 07:55:51 +00:00
|
|
|
|
void judgeBlock()
|
|
|
|
|
{
|
|
|
|
|
char i, j, k, h, count;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
if(blockGameStatus == over)
|
|
|
|
|
return;
|
2022-06-06 07:55:51 +00:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8>
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
{
|
|
|
|
|
count = 0;
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(base[i][j] == 1)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(count == 8)
|
2022-06-06 09:03:03 +00:00
|
|
|
|
{
|
2022-06-07 13:45:23 +00:00
|
|
|
|
score = score + 10;
|
2022-06-06 11:05:34 +00:00
|
|
|
|
blockGameStatus = good;
|
2022-06-06 09:03:03 +00:00
|
|
|
|
for(k = 0; k < MAX_X; k++)
|
|
|
|
|
for(h = j ; h < MAX_Y - 1; h++)
|
|
|
|
|
base[k][h] = base[k][h + 1];
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 07:55:51 +00:00
|
|
|
|
}
|
2022-06-06 11:05:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 06:25:11 +00:00
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
2022-06-06 11:05:34 +00:00
|
|
|
|
void blockGameOver()
|
|
|
|
|
{
|
2022-06-07 13:45:23 +00:00
|
|
|
|
char j, i;
|
|
|
|
|
if(blockGameStatus == over)
|
2022-06-06 11:05:34 +00:00
|
|
|
|
return;
|
|
|
|
|
for(j = 0; j < MAX_X; j++)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD>
|
|
|
|
|
if(base[j][7] == 1)
|
|
|
|
|
{
|
|
|
|
|
blockGameStatus = over;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(blockGameStatus == over)
|
|
|
|
|
{
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
2022-06-07 13:45:23 +00:00
|
|
|
|
{
|
|
|
|
|
//<2F>˴<EFBFBD><CBB4><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>Ч<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2>Ч<EFBFBD><D0A7>
|
|
|
|
|
delayms(10);
|
|
|
|
|
base[i][j] = 1;
|
|
|
|
|
placeIMG_BLOCK(i, j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 04:52:41 +00:00
|
|
|
|
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>߷<EFBFBD>
|
2022-06-07 13:45:23 +00:00
|
|
|
|
unsigned int addBest(unsigned int s)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
for(i = 0; i < 10; i++)
|
|
|
|
|
if(bestScore[i] < s)
|
|
|
|
|
{
|
|
|
|
|
for(j = 9; j > i; j--)
|
|
|
|
|
bestScore[j] = bestScore[j - 1];
|
|
|
|
|
|
|
|
|
|
bestScore[i] = s;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2022-06-09 04:52:41 +00:00
|
|
|
|
|
|
|
|
|
unsigned int rotateBlock(enum OPR opr)
|
|
|
|
|
{
|
|
|
|
|
char i, j, cy, cx, flag = 0;
|
|
|
|
|
//Ѱ<><D1B0><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ĵ<EFBFBD>
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
{
|
|
|
|
|
if(base[i][j] == 3)
|
|
|
|
|
{
|
|
|
|
|
flag = 1;
|
|
|
|
|
cx = i;
|
|
|
|
|
cy = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!flag)
|
|
|
|
|
return 0; //û<>ҵ<EFBFBD><D2B5><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD>
|
|
|
|
|
if(opr == right)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD> <20><><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>ת
|
|
|
|
|
for(i = - 1; i <= 1; i++)
|
|
|
|
|
for(j = - 1; j <= 1; j++)
|
|
|
|
|
if(base[cx + i][cy + j] == 2)
|
|
|
|
|
if(isIegal(j + cx, -i + cy))
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
mask[j + cx][-i + cy] = base[cx + i][cy + j];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
if(base[i][j] == 2)
|
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>㸲<EFBFBD><E3B8B2>
|
|
|
|
|
for(i = -1; i <= 1; i++)
|
|
|
|
|
for(j = -1; j <= 1; j++)
|
|
|
|
|
if(mask[cx + i][cy + j] == 2)
|
|
|
|
|
base[cx + i][cy + j] = mask[cx + i][cy + j];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(opr == left)
|
|
|
|
|
{
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD> <20><><EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD><EFBFBD><EFBFBD>ת
|
|
|
|
|
for(i = - 1; i <= 1; i++)
|
|
|
|
|
for(j = - 1; j <= 1; j++)
|
|
|
|
|
if(base[cx + i][cy + j] == 2)
|
|
|
|
|
if(isIegal(-j + cx, i + cy))
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
mask[-j + cx][i + cy] = base[cx + i][cy + j];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>
|
|
|
|
|
for(i = 0; i < MAX_X; i++)
|
|
|
|
|
for(j = 0; j < MAX_Y; j++)
|
|
|
|
|
if(base[i][j] == 2)
|
|
|
|
|
base[i][j] = 0;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>㸲<EFBFBD><E3B8B2>
|
|
|
|
|
for(i = -1; i <= 1; i++)
|
|
|
|
|
for(j = -1; j <= 1; j++)
|
|
|
|
|
if(mask[cx + i][cy + j] == 2)
|
|
|
|
|
base[cx + i][cy + j] = mask[cx + i][cy + j];
|
|
|
|
|
}
|
|
|
|
|
memset(mask, 0, sizeof(mask));
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|