fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4. #include<windows.h>
  5. #define HEI 23
  6. #define WID 12
  7. void CreatigneTetrimono(int);
  8. void draw(int);
  9. void sec_counter(int);
  10. int locate(int y,int x);
  11. int gamescore[13];
  12. int stat[50];
  13. int field[HEI][WID];//ゲームエリア
  14. int next[4][2];//Nextエリア
  15. ///////////////////////////////
  16. int main(void){
  17. int state[6];
  18. int tetrimino,tetriminoS;
  19. int timer=0;
  20. int y,x;//エリア制御
  21. ///////////////////////////////
  22. for(y=0;y<HEI;y++)
  23. for(x=0;x<WID;++x)
  24. field[y][x]= x<=0||WID-1<=x||HEI-1<=y
  25. ?2: y<=1?3 :0;
  26. printf("テトリス!!!\n"
  27. "Enterキーの入力でゲームがスタートします");
  28. while(getchar()!='\n'){}//EnterKeyWait
  29. printf("Game Start! ");
  30. Sleep(1000);//カウントダウン3sec
  31. for(y=3;y>=0;--y)sec_counter(y);
  32. system("cls");
  33. srand((unsigned)time(NULL));// 乱数のシードを与える
  34. stat[0]=tetriminoS=0;//テトリミノステータス変数初期化
  35. //////////////////////////////
  36. while(1){//ゲームループ開始
  37. do tetrimino=rand()%7+1;//乱数1-7//1I/2O/3S/4Z/5J/6L/7T
  38. while(tetriminoS==tetrimino);//同一種類の連発禁止
  39. CreatigneTetrimono(tetrimino);
  40. stat[0]++;
  41. locate(0,0); //ゲームエリアの描画
  42. for(y=0;y<HEI;printf("\n",++y)){
  43. for(x=0;x<WID;x++)
  44. draw(field[y][x]);
  45. if(y<=4+1)printf("__");
  46. if(!y)printf("<***NEXT___%d,%d",tetrimino,stat[0]);
  47. if(1<=y&&y<=4) for(x=0;x<2;++x)
  48. draw(next[y-1][x]);
  49. if(y==4+1)printf("stat=%d teto=%d",tetriminoS,tetrimino);
  50. }
  51. Sleep(500);
  52. timer+=500;
  53. if(timer==15000)break;
  54. tetriminoS=tetrimino;
  55. }//ゲームループ終了
  56. //system("cls");
  57. printf("[DM]処理を終了しました");
  58. return 0;
  59. }
  60. void CreatigneTetrimono(int tetrimino){
  61. int y,x,nxt[7][4][2]={
  62. {{0,1},{0,1},{0,1},{0,1}},//I
  63. {{0,0},{0,0},{1,1},{1,1}},//O
  64. {{0,0},{0,1},{1,1},{1,0}},//S
  65. {{0,0},{1,0},{1,1},{0,1}},//Z
  66. {{0,0},{0,1},{0,1},{1,1}},//J
  67. {{0,0},{1,0},{1,0},{1,1}},//L
  68. {{0,0},{0,1},{1,1},{0,1}} //T
  69. };
  70. if(1<=tetrimino&&tetrimino<=7)
  71. for(y=0;y<4;++y)
  72. for(x=0;x<2;++x)
  73. next[y][x]=nxt[tetrimino-1][y][x];
  74. }
  75. void draw(int n){
  76. char*cp[]={"ee","□","■","◆","〇"};
  77. printf(0<=n&&n<=3?cp[1+n]:*cp);}
  78. void sec_counter(int n){
  79. if(1<=n&&n<=10){
  80. printf("%d ",n); Sleep(1000);
  81. }
  82. }
  83. int locate(int y,int x){COORD cor;
  84. static HANDLE hso=INVALID_HANDLE_VALUE;
  85. cor.Y=y; cor.X=x;
  86. if(hso==INVALID_HANDLE_VALUE)
  87. hso=GetStdHandle(STD_OUTPUT_HANDLE);
  88. return hso==INVALID_HANDLE_VALUE ? 0 :
  89. SetConsoleCursorPosition(hso, cor);
  90. }
  91.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty