Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************/
- /* Minesweeper (15.06.12- . . ) */
- /* [GeekBros]Siapran */
- /* tristan.robin@hotmail.fr */
- /**********************************************/
- #include "fxlib.h"
- #include "ECode.h"
- #include "MonochromeLib.h"
- #include "syscall.h"
- //sprites of the game (I lost it)
- //open 8*8
- const unsigned char open[] = {1,1,1,1,1,1,1,255};
- //closed 8*8
- const unsigned char closed[] = {1,127,87,107,87,107,127,255};
- //flag 8*8
- const unsigned char flag[] = {1,127,71,71,119,67,127,255};
- //mine 8*8
- const unsigned char mine[] = {1,91,45,95,127,61,91,255};
- //wrong 8*8
- const unsigned char wrong[] = {1,127,93,107,119,107,93,255};
- //boom 8*8
- const unsigned char boom[] = {1,37,67,1,1,67,37,255};
- //gui 32*64
- const unsigned char gui[] = {0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,127,255,1,0,0,0,1,0,0,0,1,0,234,46,1,0,75,104,1,0,74,172,1,0,74,40,1,0,74,46,1,0,0,0,1,0,0,0,1,1,220,119,65,1,85,85,65,1,84,85,65,1,85,85,65,1,220,119,65,0,0,0,65,1,255,255,193,0,0,0,1,0,0,0,1,2,42,92,193,3,107,81,1,2,170,216,129,2,42,80,65,2,42,93,129,0,0,0,1,0,0,0,1,0,14,224,65,0,10,160,65,0,10,160,65,0,10,160,65,0,14,224,65,0,0,0,65,1,255,255,193,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,127,255,255,255};
- //face1 16*16
- const unsigned char face1[] = {0,0,0,1,7,225,12,49,16,9,50,77,34,69,32,5,32,5,36,37,51,205,16,9,12,49,7,225,0,1,127,255};
- //face2 16*16
- const unsigned char face2[] = {0,0,0,1,7,225,12,49,16,9,50,77,34,69,32,5,32,5,33,133,51,205,17,137,12,49,7,225,0,1,127,255};
- //face3 16*16
- const unsigned char face3[] = {0,0,0,1,7,225,12,49,16,9,62,125,63,253,62,125,32,5,36,5,51,205,16,9,12,49,7,225,0,1,127,255};
- //face4 16*16
- const unsigned char face4[] = {0,0,0,1,7,225,12,49,16,9,50,77,34,69,36,37,40,21,35,197,52,45,16,9,12,49,7,225,0,1,127,255};
- //char1 3*5
- const unsigned char char1[] = {64,192,64,64,224};
- //char2 3*5
- const unsigned char char2[] = {224,32,224,128,224};
- //char3 3*5
- const unsigned char char3[] = {224,32,224,32,224};
- //char4 3*5
- const unsigned char char4[] = {160,160,224,32,32};
- //char5 3*5
- const unsigned char char5[] = {224,128,224,32,224};
- //char6 3*5
- const unsigned char char6[] = {224,128,224,160,224};
- //char7 3*5
- const unsigned char char7[] = {224,32,32,32,32};
- //char8 3*5
- const unsigned char char8[] = {224,160,224,160,224};
- //char9 3*5
- const unsigned char char9[] = {224,160,224,32,224};
- //char0 3*5
- const unsigned char char0[] = {224,160,160,160,224};
- //cursor 12*12 monochrome alpha
- const unsigned char cursor[] = {255,240,128,16,128,16,128,16,128,16,128,16,128,16,128,16,128,16,128,16,128,16,255,240};
- const unsigned char cursor_alpha[] = {0,0,0,0,63,192,63,192,63,192,63,192,63,192,63,192,63,192,63,192,0,0,0,0};
- void replaceAwithBinGrid(unsigned char grid[], char a, char b) //replaces a with b in the grid
- {
- int i;
- for(i=0;i<(14*10+1);i++) //explore the whole grid
- {
- if(grid[i]==a) {grid[i] = b;} //replace a with b
- }
- }
- void creategrid(unsigned char grid[]) //creates a new grid
- {
- unsigned char x=0;
- unsigned char y=0;
- unsigned char i;
- unsigned char ok=0;
- unsigned char mcount=0; //mine count
- unsigned char a=0;
- unsigned char b=0;
- replaceAwithBinGrid(grid, 0, 42); //fill w/ 42
- for(i=0;i<16;i++) //16=nb of mines
- {
- ok = 0;
- while(!ok) //tries untill finds empty spot
- {
- x = 1+rand()%12;
- y = 1+rand()%8;
- if(grid[x+14*y]==42) {ok = 1;}
- }
- grid[x+14*y] = 9; //puts mine
- }
- for(x=0;x<13;x++) //create indicators
- {
- for(y=0;y<9;y++)
- {
- if(grid[(x+1)+14*(y+1)]=42)
- {
- mcount=0;
- for(a=0;a<3;a++)
- {
- for(b=0;b<3;b++)
- {
- if(grid[(x+a)+14*(y+b)]=9) {mcount++;} //if mine near
- }
- }
- grid[(x+1)+14*(y+1)]=mcount;
- }
- }
- }
- }
- void drawtilefromgrid(unsigned char grid[], char x, char y) //draws tile grid indicates at pos x,y
- {
- char value = grid[x+14*y];
- if(value<10) //if spot closed
- {
- ML_bmp_8_or(closed, (x-1)*8, (y-1)*8);
- }
- else if(value>19&&value<30) //flag
- {
- ML_bmp_8_or(flag, (x-1)*8, (y-1)*8);
- }
- else
- {
- if(value>9&&value<19)
- {
- ML_bmp_8_or(open, (x-1)*8, (y-1)*8);
- }
- switch(value) //other situations
- {
- case 10: //empty open
- break;
- case 11:
- ML_bmp_or(char1, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 12:
- ML_bmp_or(char2, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 13:
- ML_bmp_or(char3, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 14:
- ML_bmp_or(char4, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 15:
- ML_bmp_or(char5, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 16:
- ML_bmp_or(char6, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 17:
- ML_bmp_or(char7, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 18:
- ML_bmp_or(char8, 1+(x-1)*8, (y-1)*8, 3, 5);
- break;
- case 19: //opened mine (boom)
- ML_bmp_8_or(boom, (x-1)*8, (y-1)*8);
- break;
- case 30: //mine defused
- ML_bmp_8_or(mine, (x-1)*8, (y-1)*8);
- break;
- case 31: //wrong flag location
- ML_bmp_8_or(wrong, (x-1)*8, (y-1)*8);
- break;
- }
- }
- }
- void refreshscreen(unsigned char grid[])
- {
- }
- void openspot(unsigned char grid[], char x, char y) //opens a spot
- {
- grid[x+14*y] += 10;
- drawtilefromgrid(grid, x, y);
- }
- void openblanckspace(unsigned char grid[], char x, char y) //explores a blank space
- {
- char list_x[96]; //cordinate lists
- char list_y[96];
- char a = 0; //list position a
- char b = 1; //list position b
- char c;
- char d;
- char e;
- char f;
- char value;
- list_x[1] = x-1;
- list_y[1] = y-1;
- while(a!=b)
- {
- a++;
- e = list_x[a];
- f = list_y[a];
- for(c=0;c<3;c++)
- {
- for(d=0;d<3;d++)
- {
- value = grid[(e+c)+14*(f+d)];
- if(!value)
- {
- b++;
- list_x[b] = e+c;
- list_y[b] = f+d;
- }
- if(value!=42)
- {
- drawtilefromgrid(grid, e+c, f+d);
- }
- }
- }
- }
- }
- void clickspot(unsigned char grid[], char x, char y)
- {
- }
- void toggleflag(unsigned char grid[], char x, char y)
- {
- }
- //===================================//
- int AddIn_main(int isAppli, unsigned short OptionNum)
- {
- //actual int main() lol
- char i;
- char j;
- unsigned char grid[14*10];
- srand(RTC_GetTicks());
- creategrid(grid);
- ML_clear_vram();
- for(i=1;i<13;i++)
- {
- for(j=1;j<9;j++)
- {
- openspot(grid, i, j);
- }
- }
- ML_display_vram();
- while(1) {}
- return 1;
- }
- //========================================================================//
- #pragma section R_Size
- unsigned long BR_Size;
- #pragma section
- #pragma section _TOP
- int InitializeSystem(int isAppli, unsigned short OptionNum)
- {
- return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
- }
- #pragma section
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement