Changeset a35b458 in mainline for uspace/app/tetris/tetris.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tetris/tetris.c
r3061bc1 ra35b458 97 97 int i; 98 98 cell *p = board; 99 99 100 100 for (i = B_SIZE; i; i--) 101 101 *p++ = (i <= (2 * B_COLS) || (i % B_COLS) < 2) ? 0x0000ff : 0x000000; … … 112 112 int base; 113 113 cell *p; 114 114 115 115 for (i = A_FIRST; i < A_LAST; i++) { 116 116 base = i * B_COLS + 1; … … 121 121 rows++; 122 122 memset(&board[base], 0, sizeof(cell) * (B_COLS - 2)); 123 123 124 124 scr_update(); 125 125 tsleep(); 126 126 127 127 while (--base != 0) 128 128 board[base + B_COLS] = board[base]; 129 129 130 130 scr_update(); 131 131 tsleep(); 132 132 133 133 break; 134 134 } 135 135 } 136 136 } 137 137 138 138 switch (rows) { 139 139 case 1: … … 159 159 int i; 160 160 int j = rand() % 4; 161 161 162 162 for (i = 0; i < j; i++) 163 163 tmp = &shapes[classic ? tmp->rotc : tmp->rot]; 164 164 165 165 return (tmp); 166 166 } … … 169 169 { 170 170 struct timeval tv; 171 171 172 172 gettimeofday(&tv, NULL); 173 173 srand(tv.tv_sec + tv.tv_usec / 100000); … … 179 179 moveto(5, 10); 180 180 puts("Tetris\n\n"); 181 181 182 182 moveto(8, 10); 183 183 printf("Level = %d (press keys 1 - 9 to change)", level); … … 201 201 while (1) { 202 202 int i = getchar(); 203 203 204 204 switch(i) { 205 205 case 'p': … … 248 248 int j; 249 249 int ch; 250 250 251 251 console = console_init(stdin, stdout); 252 252 253 253 keys = "jkl pq"; 254 254 255 255 classic = 0; 256 256 showpreview = 1; 257 257 258 258 while ((ch = getopt(argc, argv, "ck:ps")) != -1) 259 259 switch(ch) { … … 279 279 usage(); 280 280 } 281 281 282 282 argc -= optind; 283 283 argv += optind; 284 284 285 285 if (argc) 286 286 usage(); 287 287 288 288 for (i = 0; i <= 5; i++) { 289 289 for (j = i + 1; j <= 5; j++) { … … 293 293 } 294 294 } 295 295 296 296 if (keys[i] == ' ') 297 297 str_cpy(key_write[i], sizeof(key_write[i]), "<space>"); … … 301 301 } 302 302 } 303 303 304 304 snprintf(key_msg, sizeof(key_msg), 305 305 "%s - left %s - rotate %s - right %s - drop %s - pause %s - quit", 306 306 key_write[0], key_write[1], key_write[2], key_write[3], 307 307 key_write[4], key_write[5]); 308 308 309 309 scr_init(); 310 310 if (loadscores() != EOK) … … 313 313 while (tetris_menu(&level)) { 314 314 fallrate = 1000000 / level; 315 315 316 316 scr_clear(); 317 317 setup_board(); 318 318 319 319 srandomdev(); 320 320 scr_set(); 321 321 322 322 pos = A_FIRST * B_COLS + (B_COLS / 2) - 1; 323 323 nextshape = randshape(); 324 324 curshape = randshape(); 325 325 326 326 scr_msg(key_msg, 1); 327 327 328 328 while (1) { 329 329 place(curshape, pos, 1); … … 339 339 continue; 340 340 } 341 341 342 342 /* 343 343 * Put up the current shape `permanently', … … 347 347 score++; 348 348 elide(); 349 349 350 350 /* 351 351 * Choose a new shape. If it does not fit, … … 355 355 nextshape = randshape(); 356 356 pos = A_FIRST * B_COLS + (B_COLS / 2) - 1; 357 357 358 358 if (!fits_in(curshape, pos)) 359 359 break; 360 361 continue; 362 } 363 360 361 continue; 362 } 363 364 364 /* 365 365 * Handle command keys. … … 369 369 break; 370 370 } 371 371 372 372 if (c == keys[4]) { 373 373 static char msg[] = 374 374 "paused - press RETURN to continue"; 375 375 376 376 place(curshape, pos, 1); 377 377 do { … … 381 381 console_flush(console); 382 382 } while (!twait()); 383 383 384 384 scr_msg(msg, 0); 385 385 scr_msg(key_msg, 1); … … 387 387 continue; 388 388 } 389 389 390 390 if (c == keys[0]) { 391 391 /* move left */ … … 394 394 continue; 395 395 } 396 396 397 397 if (c == keys[1]) { 398 398 /* turn */ 399 399 const struct shape *new = 400 400 &shapes[classic ? curshape->rotc : curshape->rot]; 401 401 402 402 if (fits_in(new, pos)) 403 403 curshape = new; 404 404 continue; 405 405 } 406 406 407 407 if (c == keys[2]) { 408 408 /* move right */ … … 411 411 continue; 412 412 } 413 413 414 414 if (c == keys[3]) { 415 415 /* move to bottom */ … … 420 420 continue; 421 421 } 422 422 423 423 if (c == '\f') { 424 424 scr_clear(); … … 426 426 } 427 427 } 428 428 429 429 scr_clear(); 430 430 loadscores(); … … 433 433 score = 0; 434 434 } 435 435 436 436 scr_clear(); 437 437 printf("\nGame over.\n"); 438 438 scr_end(); 439 439 440 440 return 0; 441 441 }
Note:
See TracChangeset
for help on using the changeset viewer.