Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tetris/tetris.c

    ra35b458 r1b20da0  
    9797        int i;
    9898        cell *p = board;
    99 
     99       
    100100        for (i = B_SIZE; i; i--)
    101101                *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000;
     
    112112        int base;
    113113        cell *p;
    114 
     114       
    115115        for (i = A_FIRST; i < A_LAST; i++) {
    116116                base = i * B_COLS + 1;
     
    121121                                rows++;
    122122                                memset(&board[base], 0, sizeof(cell) * (B_COLS - 2));
    123 
     123                               
    124124                                scr_update();
    125125                                tsleep();
    126 
     126                               
    127127                                while (--base != 0)
    128128                                        board[base + B_COLS] = board[base];
    129 
     129                               
    130130                                scr_update();
    131131                                tsleep();
    132 
     132                               
    133133                                break;
    134134                        }
    135135                }
    136136        }
    137 
     137       
    138138        switch (rows) {
    139139        case 1:
     
    159159        int i;
    160160        int j = rand() % 4;
    161 
     161       
    162162        for (i = 0; i < j; i++)
    163163                tmp = &shapes[classic ? tmp->rotc : tmp->rot];
    164 
     164       
    165165        return (tmp);
    166166}
     
    169169{
    170170        struct timeval tv;
    171 
     171       
    172172        gettimeofday(&tv, NULL);
    173173        srand(tv.tv_sec + tv.tv_usec / 100000);
     
    179179        moveto(5, 10);
    180180        puts("Tetris\n\n");
    181 
     181       
    182182        moveto(8, 10);
    183183        printf("Level = %d (press keys 1 - 9 to change)", level);
     
    201201        while (1) {
    202202                int i = getchar();
    203 
     203               
    204204                switch(i) {
    205205                        case 'p':
     
    248248        int j;
    249249        int ch;
    250 
     250       
    251251        console = console_init(stdin, stdout);
    252 
     252       
    253253        keys = "jkl pq";
    254 
     254       
    255255        classic = 0;
    256256        showpreview = 1;
    257 
     257       
    258258        while ((ch = getopt(argc, argv, "ck:ps")) != -1)
    259259                switch(ch) {
     
    279279                        usage();
    280280                }
    281 
     281       
    282282        argc -= optind;
    283283        argv += optind;
    284 
     284       
    285285        if (argc)
    286286                usage();
    287 
     287       
    288288        for (i = 0; i <= 5; i++) {
    289289                for (j = i + 1; j <= 5; j++) {
     
    293293                        }
    294294                }
    295 
     295               
    296296                if (keys[i] == ' ')
    297297                        str_cpy(key_write[i], sizeof(key_write[i]), "<space>");
     
    301301                }
    302302        }
    303 
     303       
    304304        snprintf(key_msg, sizeof(key_msg),
    305305            "%s - left   %s - rotate   %s - right   %s - drop   %s - pause   %s - quit",
    306306            key_write[0], key_write[1], key_write[2], key_write[3],
    307307            key_write[4], key_write[5]);
    308 
     308       
    309309        scr_init();
    310310        if (loadscores() != EOK)
     
    313313        while (tetris_menu(&level)) {
    314314                fallrate = 1000000 / level;
    315 
     315               
    316316                scr_clear();
    317317                setup_board();
    318 
     318               
    319319                srandomdev();
    320320                scr_set();
    321 
     321               
    322322                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    323323                nextshape = randshape();
    324324                curshape = randshape();
    325 
     325               
    326326                scr_msg(key_msg, 1);
    327 
     327               
    328328                while (1) {
    329329                        place(curshape, pos, 1);
     
    339339                                        continue;
    340340                                }
    341 
     341                               
    342342                                /*
    343343                                 * Put up the current shape `permanently',
     
    347347                                score++;
    348348                                elide();
    349 
     349                               
    350350                                /*
    351351                                 * Choose a new shape.  If it does not fit,
     
    355355                                nextshape = randshape();
    356356                                pos = A_FIRST * B_COLS + (B_COLS / 2) - 1;
    357 
     357                               
    358358                                if (!fits_in(curshape, pos))
    359359                                        break;
    360 
    361                                 continue;
    362                         }
    363 
     360                               
     361                                continue;
     362                        }
     363                       
    364364                        /*
    365365                         * Handle command keys.
     
    369369                                break;
    370370                        }
    371 
     371                       
    372372                        if (c == keys[4]) {
    373373                                static char msg[] =
    374374                                    "paused - press RETURN to continue";
    375 
     375                               
    376376                                place(curshape, pos, 1);
    377377                                do {
     
    381381                                        console_flush(console);
    382382                                } while (!twait());
    383 
     383                               
    384384                                scr_msg(msg, 0);
    385385                                scr_msg(key_msg, 1);
     
    387387                                continue;
    388388                        }
    389 
     389                       
    390390                        if (c == keys[0]) {
    391391                                /* move left */
     
    394394                                continue;
    395395                        }
    396 
     396                       
    397397                        if (c == keys[1]) {
    398398                                /* turn */
    399399                                const struct shape *new =
    400400                                    &shapes[classic ? curshape->rotc : curshape->rot];
    401 
     401                               
    402402                                if (fits_in(new, pos))
    403403                                        curshape = new;
    404404                                continue;
    405405                        }
    406 
     406                       
    407407                        if (c == keys[2]) {
    408408                                /* move right */
     
    411411                                continue;
    412412                        }
    413 
     413                       
    414414                        if (c == keys[3]) {
    415415                                /* move to bottom */
     
    420420                                continue;
    421421                        }
    422 
     422                       
    423423                        if (c == '\f') {
    424424                                scr_clear();
     
    426426                        }
    427427                }
    428 
     428               
    429429                scr_clear();
    430430                loadscores();
     
    433433                score = 0;
    434434        }
    435 
     435       
    436436        scr_clear();
    437437        printf("\nGame over.\n");
    438438        scr_end();
    439 
     439       
    440440        return 0;
    441441}
Note: See TracChangeset for help on using the changeset viewer.