diff --git a/MCU/MCU_REAL_FINAL/block.c b/MCU/MCU_REAL_FINAL/block.c index eab30c2..334dfd3 100644 --- a/MCU/MCU_REAL_FINAL/block.c +++ b/MCU/MCU_REAL_FINAL/block.c @@ -4,6 +4,7 @@ #include #include "delay.h" #include "eeprom.h" +#include extern unsigned int bestScore[]; char base[MAX_X][MAX_Y] = {0}; //x*y //0为空 1为下落完成 2为正在下落 @@ -14,6 +15,7 @@ enum GS blockGameStatus = __idle; void blockInit() { score = 0; + srand((unsigned)TL0); blockGameStatus = start; } @@ -53,7 +55,7 @@ void genPiece() char i, j; //需要一点随机性 - int random = TH0 % 16; + int random = rand() % 100; if(blockGameStatus == over) @@ -67,56 +69,56 @@ void genPiece() return; //当两个方块的情况 - if(random == 0) + if(random >= 0 && random <= 6) { base[4][9] = 2; } //当两个方块的情况 - if(random == 1 || random == 2) + if(random >= 7 && random <= 15) { base[4][9] = 2; // base[4][10] = 2; // } - else if(random == 3) + else if(random >= 16 && random <= 22) { base[3][9] = 2; //// base[4][9] = 2; } //当三个方块的情况 - else if(random == 4 || random == 5) + else if(random >= 23 && random <= 32) { base[4][11] = 2; base[4][10] = 2; base[4][9] = 2; } - else if(random == 6) + else if(random >= 32 && random <= 38) { base[3][9] = 2; base[4][9] = 2; base[5][9] = 2; } - else if(random == 7) + else if(random >= 39 && random <= 47) { base[3][10] = 2; base[3][9] = 2; base[4][9] = 2; } - else if (random == 8) + else if (random >= 48 && random <= 55) { base[4][10] = 2; base[3][9] = 2; base[4][9] = 2; } - else if (random == 9) + else if (random >= 56 && random <= 63) { base[4][9] = 2; base[3][10] = 2; base[4][10] = 2; } - else if (random == 10) + else if (random >= 64 && random <= 69) { base[3][9] = 2; base[3][10] = 2; @@ -124,35 +126,35 @@ void genPiece() } //当四个方块的情况 - else if(random == 11) + else if(random >= 70 && random <= 79) { base[3][10] = 2; base[4][10] = 2; base[3][9] = 2; base[4][9] = 2; } - else if(random == 12) + else if(random >= 80 && random <= 84) { base[3][10] = 2; base[4][10] = 2; base[3][9] = 2; base[4][11] = 2; } - else if(random == 13) + else if(random >= 85 && random <= 89) { base[3][10] = 2; base[4][10] = 2; base[3][11] = 2; base[4][9] = 2; } - else if(random == 14) + else if(random >= 90 && random <= 94) { base[3][10] = 2; base[4][10] = 2; base[4][9] = 2; base[5][9] = 2; } - else if(random == 15) + else if(random >= 95 && random <= 99) { base[3][10] = 2; base[4][10] = 2; diff --git a/MCU/MCU_REAL_FINAL/main.c b/MCU/MCU_REAL_FINAL/main.c index 58f8b29..95d2270 100644 --- a/MCU/MCU_REAL_FINAL/main.c +++ b/MCU/MCU_REAL_FINAL/main.c @@ -3,7 +3,7 @@ //#define WIPE_BEST -#define RELOAD (65535-9216) //定时器填充值(1ms) +#define RELOAD (65535-8535) //定时器填充值(1ms) unsigned char TH, TL; extern Menu *NOW; //菜单指针