为了账号安全,请及时绑定邮箱和手机立即绑定

帮忙 写一下注释不多,很急 谢谢 要求在下面的文件里面

帮忙 写一下注释不多,很急 谢谢 要求在下面的文件里面

C
慕粉1401006384 2016-12-08 16:44:42
#include <windows.h>         //1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、#include <stdio.h>          //1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、#include <time.h>          //1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、#include <conio.h>        //1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、#include <stdlib.h>      //1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、/*** 俄罗斯方块结构体*///1、这段是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、具体是如何运行的?、struct Tetris { int _pool[16][32];  // int(*pool)[32];    // 指向_pool的指针数组 int tmap[8][4][16]; // int x;  // X坐标 int y;  // Y坐标 int s;  // int st; // int t;  //};// 定义输出字符串   1、运用到了什么算法(或类型)?、char gcText[] = " #######";// 定义俄罗斯方块程序对象     1、运用到了什么算法(或类型)?、struct Tetris tetris;// 声明所有方法               1、有没有关联(和其他代码)?2、运用到了什么算法(或类型)?、3、具体是如何运行的?、void runInit();int process(int box[], int x, int y, int c);int runScene();int main() { // 初始化随机数生成器             1、有没有关联(和其他代码)?2、运用到了什么算法(或类型)?、 srand((unsigned)time(NULL)); // 初始化界面、并运行俄罗斯方块场景            1、有没有关联(和其他代码)?2、运用到了什么算法(或类型)?、 for (runInit(); runScene(); ); return 0;}/*** 初始化方法*/void runInit() { // 初始化俄罗斯方块的七个标准方块             1、这一段有没有关联(和其他代码)?2、运用到了什么算法(或类型)?、3、具体是如何运行的?、 int box[8][4] = { { 15,4369,15,4369 }, { 23,785,116,547 }, { 71,275,113,802 }, { 39,305,114,562 }, { 54,561,54,561 }, { 99,306,99,306 }, { 51,51,51,51 }, { -1 } }; int i;          //1、这一大段表示什么意思?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、具体是如何运行的?、 int j; int k; tetris.pool = &tetris._pool[4]; for (j = 0; j < 7; ++j) { for (i = 0; i < 4; ++i) { for (k = 0; k < 16; ++k) { tetris.tmap[j + 1][i][k] = (box[j][i] & 1) * (j + 1); box[j][i] >>= 1; } } } // 将_pool数组里的元素全部置为-1               1、有没有关联(和其他代码)?2、运用到了什么算法(或类型)?、3、具体是如何运行的?、 memset(tetris._pool, -1, sizeof(tetris._pool)); for (i = 0; i < 10; ++i) { memset(&tetris.pool[i], 0, sizeof(int[21])); } return;}/*** 方块处理方法:c为0,判断左移、右移、变换形态等操作是否可执行;c为1,方块位置确定,添入已堆积方块中;*/int process(int box[], int x, int y, int c) {           //1、这一大段1、这一大段表示什么意思?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、具体是如何运行的?、 int i; int cx; int cy; for (i = 0; i < 16; ++i) { if (box[i]) { cx = x + (i & 3); cy = y + (i >> 2); if (tetris.pool[cx][cy]) { if (c == 2) { tetris.pool[cx][cy] = 0; } else { return 0; } } // 方块位置固定,将方块添入已堆积方块 if (c == 1) { tetris.pool[cx][cy] = box[i]; } } } return 1;}/*** 场景运行               //1、这一段表示什么意思?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、具体是如何运行的?、*/int runScene() { int x = 0; int y = 0; COORD pos = { 0 }; tetris.s = rand() % 7 + 1; tetris.t = 0; tetris.st = tetris.t; tetris.x = 3; tetris.y = 0; // 方块定时下降,,每下降一次休眠1毫米          1、运用到了什么算法(或类型) for (--tetris.t; ; Sleep(1), --tetris.t) { int k = 0; // 监听键盘按键           1、运用到了什么算法(或类型) while (_kbhit()) { // 获取按键值           1、运用到了什么算法(或类型) k = _getch(); if (k == 27) return 0; if (k == 'A' || k == 'a') { // 左移,X坐标值减1,如果方块已到最左边,则不执行左移            1、运用到了什么算法(或类型) if (process(tetris.tmap[tetris.s][tetris.st], tetris.x - 1, tetris.y, 0)) { --tetris.x; } } else if (k == 'D' || k == 'd') { // 右移,X坐标值加1,如果方块已到最右边,则不执行右移            1、运用到了什么算法(或类型) if (process(tetris.tmap[tetris.s][tetris.st], tetris.x + 1, tetris.y, 0)) { ++tetris.x; } } else if (k == 'W' || k == 'w') { // 变换形态,如果方块变形后超出左右边边界,或与已堆积方块重叠,则不执行变形操作         1、运用到了什么算法(或类型) if (process(tetris.tmap[tetris.s][(tetris.st + 1) % 4], tetris.x, tetris.y, 0)) { tetris.st = (tetris.st + 1) % 4; } } } // 方块下降或者加速下降            1、运用到了什么算法(或类型) if (k == 'S' || k == 's' || tetris.t < 0) { // 下降,如果方块下降后不与已堆积方块重叠,则下降;否则,执行消行逻辑判断                1、运用到了什么算法(或类型) if (process(tetris.tmap[tetris.s][tetris.st], tetris.x, tetris.y + 1, 0)) { ++tetris.y; tetris.t = 50; } else { // 方块位置确定,添入已堆积方块中            1、运用到了什么算法(或类型) process(tetris.tmap[tetris.s][tetris.st], tetris.x, tetris.y, 1); // 消行判断              1、运用到了什么算法(或类型)、2、具体是怎么运行的?、 for (--y; y > 0; --y) { for (x = 0; tetris.pool[x][y] > 0; ++x); if (tetris.pool[x][y] < 0) { for (k = y++; k > 0; --k) { for (x = 0; tetris.pool[x][0] >= 0; ++x) { tetris.pool[x][k] = tetris.pool[x][k - 1]; } } } } return 1; } } // 方块位置确定,添入已堆积方块中            1、运用到了什么算法(或类型)、 process(tetris.tmap[tetris.s][tetris.st], tetris.x, tetris.y, 1); // 重新设置光标的位置              1、运用到了什么算法(或类型)、 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); // 地图打印          1、运用到了什么算法(或类型)、2、具体是怎么运行的?、 for (y = 1; tetris.pool[0][y] >= 0; ++y, putchar(10)) { for (x = 0; tetris.pool[x][0] >= 0; ++x) { putchar(gcText[tetris.pool[x][y]]); } } process(tetris.tmap[tetris.s][tetris.st], tetris.x, tetris.y, 2);//1、这行是用用来干嘛的?、2、有没有关联(和其他代码)?3、运用到了什么算法(或类型)?、4、有什么意思在里面?、 }}
查看完整描述

1 回答

?
rookie2maven

TA贡献278条经验 获得超76个赞

#include是包含头文件(header),里面封装好了一些系统自带的类和方法,俄罗斯方块并没有用到什么算法,就是简单的位置移动,关联的话,当然是代码里调用什么方法就关联什么呗,我觉得你需要C语言的API文档


查看完整回答
反对 回复 2016-12-08
  • 1 回答
  • 0 关注
  • 1061 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信