Subversion Repositories HelenOS-historic

Rev

Rev 1584 | Rev 1653 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1584 Rev 1590
Line 156... Line 156...
156
 
156
 
157
    gettimeofday(&tv, NULL);
157
    gettimeofday(&tv, NULL);
158
    srandom(tv.tv_sec + tv.tv_usec / 100000);
158
    srandom(tv.tv_sec + tv.tv_usec / 100000);
159
}
159
}
160
 
160
 
-
 
161
static void tetris_scores(int firstgame)
-
 
162
{
-
 
163
}
-
 
164
 
-
 
165
static void tetris_menu_draw(int level)
-
 
166
{
-
 
167
        clear_screen();
-
 
168
        moveto(5,10);
-
 
169
        puts("Tetris\n\n");
-
 
170
           
-
 
171
        moveto(8,10);
-
 
172
        printf("Level = %d (press keys 1 - 9 to change)",level);
-
 
173
        moveto(9,10);
-
 
174
        printf("Preview is %s (press 'p' to change)", (showpreview?"on ":"off"));
-
 
175
        moveto(12,10);
-
 
176
        printf("Press 'h' to show hiscore table.");
-
 
177
        moveto(13,10);
-
 
178
        printf("Press 's' to start game.");
-
 
179
        moveto(14,10);
-
 
180
        printf("Press 'q' to quit game.");
-
 
181
        moveto(20,10);
-
 
182
        printf("In game controls:");
-
 
183
        moveto(21,0);
-
 
184
        puts(key_msg);
-
 
185
}
-
 
186
 
-
 
187
static int tetris_menu(int *level)
-
 
188
{
-
 
189
    static int firstgame = 1;
-
 
190
    int i;
-
 
191
/*  if (showpreview == 0)
-
 
192
        (void)printf("Your score:  %d point%s  x  level %d  =  %d\n",
-
 
193
            score, score == 1 ? "" : "s", level, score * level);
-
 
194
    else {
-
 
195
        (void)printf("Your score:  %d point%s x level %d x preview penalty %0.3f = %d\n",
-
 
196
            score, score == 1 ? "" : "s", level, (double)PRE_PENALTY,
-
 
197
            (int)(score * level * PRE_PENALTY));
-
 
198
        score = score * PRE_PENALTY;
-
 
199
    }
-
 
200
    savescore(level);
-
 
201
 
-
 
202
    showscores(level);
-
 
203
   
-
 
204
    printf("\nHit 's' to new game, 'q' to quit.\n");
-
 
205
*/
-
 
206
    tetris_menu_draw(*level);
-
 
207
    while (1) {
-
 
208
   
-
 
209
        i = getchar();
-
 
210
       
-
 
211
        switch(i) {
-
 
212
            case 'p':
-
 
213
                showpreview = !showpreview;
-
 
214
                moveto(9,21);
-
 
215
                if (showpreview)
-
 
216
                    printf("on ");
-
 
217
                else
-
 
218
                    printf("off");
-
 
219
                   
-
 
220
                break;
-
 
221
            case 'h':
-
 
222
                showscores(firstgame);
-
 
223
                tetris_menu_draw(*level);
-
 
224
                break;
-
 
225
            case 's':
-
 
226
                firstgame = 0;
-
 
227
                return 1;
-
 
228
            case 'q':
-
 
229
                return 0;
-
 
230
            case '1':
-
 
231
            case '2':
-
 
232
            case '3':
-
 
233
            case '4':
-
 
234
            case '5':
-
 
235
            case '6':      
-
 
236
            case '7':
-
 
237
            case '8':
-
 
238
            case '9':
-
 
239
                *level = i - '0';
-
 
240
                moveto(8,18);
-
 
241
                printf("%d", *level);
-
 
242
                break;
-
 
243
        }
-
 
244
    }
-
 
245
   
-
 
246
}
-
 
247
 
161
int
248
int
162
main(int argc, char *argv[])
249
main(int argc, char *argv[])
163
{
250
{
164
    int pos, c;
251
    int pos, c;
165
    char *keys;
252
    char *keys;
Line 172... Line 259...
172
 
259
 
173
//  gid = getgid();
260
//  gid = getgid();
174
//  egid = getegid();
261
//  egid = getegid();
175
//  setegid(gid);
262
//  setegid(gid);
176
 
263
 
-
 
264
    classic = 0;
177
    classic = showpreview = 0;
265
    showpreview = 1;
178
 
266
 
179
/*  while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */
267
/*  while ((ch = getopt(argc, argv, "ck:l:ps")) != -1) */
180
/*      switch(ch) { */
268
/*      switch(ch) { */
181
/*      case 'c': */
269
/*      case 'c': */
182
/*          /\* */
270
/*          /\* */
Line 230... Line 318...
230
 
318
 
231
    snprintf(key_msg, sizeof key_msg,
319
    snprintf(key_msg, sizeof key_msg,
232
"%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
320
"%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
233
        key_write[0], key_write[1], key_write[2], key_write[3],
321
        key_write[0], key_write[1], key_write[2], key_write[3],
234
        key_write[4], key_write[5]);
322
        key_write[4], key_write[5]);
235
newgame:
323
 
236
    scr_init();
324
    scr_init();
-
 
325
    initscores();
-
 
326
    while (tetris_menu(&level)) {
-
 
327
 
-
 
328
 
-
 
329
        scr_clear();
237
    setup_board();
330
        setup_board();
238
 
331
   
239
    srandomdev();
332
        srandomdev();
240
    scr_set();
333
        scr_set();
241
 
334
   
Line 336... Line 429...
336
            scr_msg(key_msg, 1);
429
                scr_msg(key_msg, 1);
337
        }
430
            }
338
    }
431
        }
339
 
432
       
340
    scr_clear();
433
        scr_clear();
341
    scr_end();
-
 
342
 
-
 
343
    if (showpreview == 0)
-
 
344
        (void)printf("Your score:  %d point%s  x  level %d  =  %d\n",
-
 
345
            score, score == 1 ? "" : "s", level, score * level);
-
 
346
    else {
-
 
347
/*      (void)printf("Your score:  %d point%s x level %d x preview penalty %0.3f = %d\n", */
-
 
348
/*          score, score == 1 ? "" : "s", level, (double)PRE_PENALTY, */
-
 
349
/*          (int)(score * level * PRE_PENALTY)); */
-
 
350
/*      score = score * PRE_PENALTY; */
-
 
351
    }
-
 
352
    savescore(level);
-
 
353
 
-
 
354
    showscores(level);
434
        insertscore(score, level);
355
   
-
 
356
    printf("\nHit 's' to new game, 'q' to quit.\n");
-
 
357
 
-
 
358
   
-
 
359
    while (i = getchar()) {
-
 
360
        if (i == 's')
-
 
361
            goto newgame;
-
 
362
        if (i == 'q')
-
 
363
            break;
-
 
364
    }
435
    }
365
   
436
   
366
    scr_clear();
437
    scr_clear();
367
    printf("\n\n\n\t\tGame over.\n");
438
    printf("\n\n\n\t\tGame over.\n");
368
/* 
439
/* 
369
    while ((i = getchar()) != '\n')
440
    while ((i = getchar()) != '\n')
370
        if (i == EOF)
441
        if (i == EOF)
371
            break
442
            break
372
*/
443
*/
-
 
444
    scr_end();
373
    exit(0);
445
    exit(0);
374
}
446
}
375
 
447
 
376
/* void */
448
/* void */
377
/* onintr(int signo) */
449
/* onintr(int signo) */