1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
| #include <SDL.h> #include <fxcg_syscalls.h> #include <fxcg/display.h> #include <stdlib.h> #include <string.h>
static unsigned long next = 1; /* RAND_MAX assumed to be 32767 */ int sys_rand(void) { next = next * 1103515245 + 12345; return((unsigned)(next/65536) % 32768); }
void sys_srand(unsigned seed) { next = seed; }
int main() { SDL_Surface *screen; int i, j, k, width, height, bpp, done=0, printCase=0, win=1; SDL_Event event; SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER); width = 384; height = 216; bpp = 8; SDL_Color palette[5]; palette[0].r=255; palette[1].g=0; palette[1].r=0; palette[1].r=0; palette[2].g=255; palette[2].b=0; palette[2].r=0; palette[3].g=0; palette[3].b=255; palette[3].r=255; palette[0].g=255; palette[0].b=255; palette[4].r=0; palette[4].g=0; palette[4].b=0; screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE); SDL_SetColors(screen, palette, 0, 4); if (screen == NULL) return -1; SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRect(screen, 0, 0, 0, 0); PrintXY(1, 1, "XXPress AC/ON to start", 0x20, TEXT_COLOR_WHITE); PrintXY(1, 2, "XXPress Esc to Exit", 0x20, TEXT_COLOR_WHITE); PrintXY(1, 3, "XXPress 1 for help", 0x20, TEXT_COLOR_WHITE); Bdisp_PutDisp_DD(); while (!done) { while(SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_ESCAPE: return 0; case SDLK_POWER: done = 1; break; case SDLK_1: printCase = 1; done = 1; break; default: break; } } } if (SDL_GetTicks() > 10000) return 0; } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255)); SDL_UpdateRect(screen, 0, 0, 0, 0); unsigned char set[25]; unsigned char choice[25]; sys_srand(SDL_GetTicks()); for ( i=0; i<25; i++) { set[i] = sys_rand() % 4; } for (i=0; i<25; i++) { for (j=0; j<i; j++) { memset(screen->pixels, set[j], width*height); SDL_UpdateRect(screen, 0, 0, 0, 0); if (set[j] > 3) return -1; if (printCase) { switch (set[j]) { case 0: PrintXY(18, 7, "XXUP", 0, TEXT_COLOR_BLACK); break; case 1: PrintXY(16, 7, "XXRIGHT", 0, TEXT_COLOR_BLACK); break; case 2: PrintXY(16, 7, "XXDOWN", 0, TEXT_COLOR_BLACK); break; case 3: PrintXY(16, 7, "XXLEFT", 0, TEXT_COLOR_BLACK); break; } Bdisp_PutDisp_DD(); } SDL_Delay(750); } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0)); SDL_UpdateRect(screen, 0,0,0,0); k=0; while (k<i) { while(SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN) { switch (event.key.keysym.sym) { case SDLK_UP: choice[k]=0; memset(screen->pixels, 0, width*height); SDL_UpdateRect(screen, 0, 0, 0, 0); k+=1; break; case SDLK_RIGHT: choice[k]=1; memset(screen->pixels, 1, width*height); SDL_UpdateRect(screen, 0, 0, 0, 0); k+=1; break; case SDLK_DOWN: choice[k]=2; memset(screen->pixels, 2, width*height); SDL_UpdateRect(screen, 0, 0, 0, 0); k+=1; break; case SDLK_LEFT: choice[k]=3; memset(screen->pixels, 3, width*height); SDL_UpdateRect(screen, 0, 0, 0, 0); k+=1; break; case SDLK_ESCAPE: win=0; i=100; k=105; break; default: break; } } } } for (j=0; j<i; j++) { if (set[j] != choice[j]) { win=0; i=100; } } } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_UpdateRect(screen, 0, 0, 0, 0); if (win == 0) PrintXY(1, 1, "XXSorry You have lost", 0x20, TEXT_COLOR_WHITE); else PrintXY(1, 1, "XXYou have won the game!", 0x20, TEXT_COLOR_WHITE); Bdisp_PutDisp_DD(); SDL_Delay(2000); return 0; }
|