diff --git a/MCU/MCU_REAL_FINAL/IMG/方块.psd b/MCU/MCU_REAL_FINAL/IMG/方块.psd index 742434f..5c18c42 100644 Binary files a/MCU/MCU_REAL_FINAL/IMG/方块.psd and b/MCU/MCU_REAL_FINAL/IMG/方块.psd differ diff --git a/MCU/MCU_REAL_FINAL/IMG/箭头.bmp b/MCU/MCU_REAL_FINAL/IMG/箭头.bmp new file mode 100644 index 0000000..fbac6e9 Binary files /dev/null and b/MCU/MCU_REAL_FINAL/IMG/箭头.bmp differ diff --git a/MCU/MCU_REAL_FINAL/block.c b/MCU/MCU_REAL_FINAL/block.c index 334dfd3..432ddcd 100644 --- a/MCU/MCU_REAL_FINAL/block.c +++ b/MCU/MCU_REAL_FINAL/block.c @@ -7,7 +7,8 @@ #include extern unsigned int bestScore[]; -char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ 1Ϊ 2Ϊ +char base[MAX_X][MAX_Y] = {0}; //x*y //0Ϊ 1Ϊ 2Ϊ 3Ϊתĵ +char mask[MAX_X][MAX_Y] = {0}; //ת extern unsigned int score; extern enum OPR opr; enum GS blockGameStatus = __idle; @@ -15,7 +16,7 @@ enum GS blockGameStatus = __idle; void blockInit() { score = 0; - srand((unsigned)TL0); + srand((unsigned)TL0); blockGameStatus = start; } @@ -65,7 +66,7 @@ void genPiece() //δɵķ for(i = 0; i < MAX_X; i++) for(j = 0; j < MAX_Y; j++) - if(base[i][j] == 2) + if(base[i][j] >= 2) return; // @@ -77,12 +78,12 @@ void genPiece() // if(random >= 7 && random <= 15) { - base[4][9] = 2; // + base[4][9] = 3; // base[4][10] = 2; // } else if(random >= 16 && random <= 22) { - base[3][9] = 2; //// + base[3][9] = 3; //// base[4][9] = 2; } @@ -91,37 +92,37 @@ void genPiece() { base[4][11] = 2; - base[4][10] = 2; + base[4][10] = 3; base[4][9] = 2; } else if(random >= 32 && random <= 38) { base[3][9] = 2; - base[4][9] = 2; + base[4][9] = 3; base[5][9] = 2; } else if(random >= 39 && random <= 47) { base[3][10] = 2; - base[3][9] = 2; + base[3][9] = 3; base[4][9] = 2; } else if (random >= 48 && random <= 55) { base[4][10] = 2; base[3][9] = 2; - base[4][9] = 2; + base[4][9] = 3; } - else if (random >= 56 && random <= 63) + else if (random >= 56 && random <= 63) { base[4][9] = 2; base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; } - else if (random >= 64 && random <= 69) + else if (random >= 64 && random <= 69) { base[3][9] = 2; - base[3][10] = 2; + base[3][10] = 3; base[4][10] = 2; } @@ -133,31 +134,31 @@ void genPiece() base[3][9] = 2; base[4][9] = 2; } - else if(random >= 80 && random <= 84) + else if(random >= 80 && random <= 84) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][9] = 2; base[4][11] = 2; } - else if(random >= 85 && random <= 89) + else if(random >= 85 && random <= 89) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][11] = 2; base[4][9] = 2; } - else if(random >= 90 && random <= 94) + else if(random >= 90 && random <= 94) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[4][9] = 2; base[5][9] = 2; } - else if(random >= 95 && random <= 99) + else if(random >= 95 && random <= 99) { base[3][10] = 2; - base[4][10] = 2; + base[4][10] = 3; base[3][9] = 2; base[4][9] = 2; } @@ -196,7 +197,7 @@ void dropPiece() { if(flag == 1) break; - if(base[i][j] == 2) + if(base[i][j] >= 2) { //, if(flag == 0 && (base[i][j - 1] == 1 || j == 0)) @@ -215,12 +216,12 @@ void dropPiece() { for(j = 0; j < MAX_Y; j++) { - if(base[i][j] == 2) + if(base[i][j] >= 2) { //ޱ if(flag == 0 && isIegal(i, j - 1)) { - base[i][j - 1] = 2; + base[i][j - 1] = base[i][j]; base[i][j] = 0; } //бת @@ -250,14 +251,13 @@ void moveLeftPiece() } for(i = 0; i < MAX_X; i++) for(j = 0; j < MAX_Y; j++) - if(base[i][j] == 2) + if(base[i][j] >= 2) { - base[i - 1][j] = 2; + base[i - 1][j] = base[i][j]; base[i][j] = 0; } } void moveRightPiece() - { char i, j; if(blockGameStatus == over) @@ -270,9 +270,9 @@ void moveRightPiece() } for(i = MAX_X - 1; i >= 0; i--) for(j = MAX_Y - 1; j >= 0; j--) - if(base[i][j] == 2 ) + if(base[i][j] >= 2 ) { - base[i + 1][j] = 2; + base[i + 1][j] = base[i][j]; base[i][j] = 0; } } @@ -337,6 +337,7 @@ void blockGameOver() } } +//ж߷ unsigned int addBest(unsigned int s) { int i, j; @@ -351,3 +352,83 @@ unsigned int addBest(unsigned int s) } return 0; } + +unsigned int rotateBlock(enum OPR opr) +{ + char i, j, cy, cx, flag = 0; + //Ѱתĵ + 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; //ûҵֱӷ + if(opr == right) + { + //жǷϷ Ϸת + 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)) + { + //ɻ + mask[j + cx][-i + cy] = base[cx + i][cy + j]; + } + else + { + memset(mask, 0, sizeof(mask)); + return 0; + } + //в + for(i = 0; i < MAX_X; i++) + for(j = 0; j < MAX_Y; j++) + if(base[i][j] == 2) + base[i][j] = 0; + + //㸲 + 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) + { + //жǷϷ Ϸת + 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)) + { + //ɻ + mask[-j + cx][i + cy] = base[cx + i][cy + j]; + } + else + { + memset(mask, 0, sizeof(mask)); + return 0; + } + //в + for(i = 0; i < MAX_X; i++) + for(j = 0; j < MAX_Y; j++) + if(base[i][j] == 2) + base[i][j] = 0; + + //㸲 + 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; +} + diff --git a/MCU/MCU_REAL_FINAL/block.h b/MCU/MCU_REAL_FINAL/block.h index 7b3da10..dbef21c 100644 --- a/MCU/MCU_REAL_FINAL/block.h +++ b/MCU/MCU_REAL_FINAL/block.h @@ -23,4 +23,5 @@ void blockGameOver(); void saveBest(); void readBest(); unsigned int addBest(unsigned int s); +unsigned int rotateBlock(enum OPR opr); #endif \ No newline at end of file diff --git a/MCU/MCU_REAL_FINAL/img.h b/MCU/MCU_REAL_FINAL/img.h index c760358..3dfb29c 100644 --- a/MCU/MCU_REAL_FINAL/img.h +++ b/MCU/MCU_REAL_FINAL/img.h @@ -92,6 +92,10 @@ code unsigned char SUPER_NUM1[]={ code unsigned char IMG_BLOCK[]={ 0x81,0x7E,0x7E,0x7E,0x7A,0x72,0x7E,0x81, }; +//תͷ +code unsigned char IMG_ROTATE[]={ +0x7F,0x1F,0x07,0x0B,0x13,0x21,0x41,0x80, +}; //÷ code unsigned char FONT_SCORE0[]={ 0x00,0x10,0x88,0xC4,0x33,0x00,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x80,0x00,0x00, diff --git a/MCU/MCU_REAL_FINAL/main.c b/MCU/MCU_REAL_FINAL/main.c index 9b5302f..2fd9069 100644 --- a/MCU/MCU_REAL_FINAL/main.c +++ b/MCU/MCU_REAL_FINAL/main.c @@ -40,7 +40,7 @@ void time() interrupt 1 // if(PIN_4 == 0) { - delayms(15); + delayms(9); if(PIN_4 == 0) { opr = confirm; diff --git a/MCU/MCU_REAL_FINAL/menu.c b/MCU/MCU_REAL_FINAL/menu.c index 2a42860..c1744f7 100644 --- a/MCU/MCU_REAL_FINAL/menu.c +++ b/MCU/MCU_REAL_FINAL/menu.c @@ -27,7 +27,7 @@ Menu* LAST = NULL; // code unsigned int ver _at_ 0x7ffe; enum OPR opr = idle; -static unsigned int local[5] = {0}; +static unsigned int local[5] = {0}; //˵ʹ0,1๫ unsigned int score; unsigned int bestScore[10]; unsigned int mBestScore[10]; @@ -106,30 +106,47 @@ void m_block(struct _menu* this) if(LAST != &M_BLOCK) { LAST = &M_BLOCK; - drawVerticalDottedLine(64); - drawBLOCKSCORE(); blockInit(); + local[2] = 0; //Ŀǰ״̬ 0ƽ 1ת } // if(opr == confirm) { opr = idle; - clear(); - blockDestroy(); - NOW = &M_MAINMENU; + if(blockGameStatus == over) + { + clear(); + local[2] = 0; + blockDestroy(); + NOW = &M_MAINMENU; + return; + } + local[2] = ~local[2]; return; } if(opr == left) { + if(local[2]) + { + rotateBlock(opr); + local[2] = 0; + } + else + moveLeftPiece(); opr = idle; - moveLeftPiece(); drawBlock(); return; } if(opr == right) { + if(local[2]) + { + rotateBlock(opr); + local[2] = 0; + } + else + moveRightPiece(); opr = idle; - moveRightPiece(); drawBlock(); return; } @@ -147,17 +164,25 @@ void m_block(struct _menu* this) drawVOID8(70, 4, 40); drawVOID8(70, 6, 32); } + drawVerticalDottedLine(64); + drawBLOCKSCORE(); 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); +// if(local[2]) +// placeIMG_ROTATE(115, 6); +// else +// placeRIMG_BLOCK(115, 6); + + blockGameOver(); //ǷϷ genPiece(); //Ҫ¿ dropPiece(); //Ҫ judgeBlock(); //Ҫһ drawBlock(); //ƽ - delayms(400); + delayms(1500); }