#include<stdio.h> #include<string.h> #include<stdlib.h> #include<conio.h> #include<thread> #include<assert.h> #include<windows.h> #if 0 using namespace std; #define ROWSIZE 25 #define COLSIZE 40 #define LETSIZE 26 //26个英文字母的长度 #define LENSIZE 26 //对26个字母进行映射,防止开局出现重复字母 #define MAXSIZE 10 //游戏开局出现10个 //GridType类型即代表了具有行25和列40 的元素的字符数组 typedef char GridType[ROWSIZE][COLSIZE]; typedef enum { NULLLET = 0, UPLET = 1, LOWLET = 2 } LetType; struct LetterNode { LetType tag; //0表示空 1是大写字母 2是小写字母 int row; int col; }; //这是一个结构体类型的数组 //还是全局数组,用来表示26个字母 //用typedef简写成了LeTable,要定义它的时候直接上LeTable typedef struct LetterNode LeTable[LENSIZE]; void Init_Let(LeTable plet) { assert(plet!=nullptr); int num = 0; int table[COLSIZE] = { 0 };// 0~39 srand(time(nullptr)); while (num<MAXSIZE) { int tag = rand() % 2 + 1; //1 2 int pos = rand() % LETSIZE; if (plet[pos].tag==NULLLET) { plet[pos].tag = (tag == 1) ? UPLET : LOWLET; plet[pos].row = 0; while (1) { int col = rand() % (COLSIZE - 1); if (0==table[col]) { table[col] = 1; plet[pos].col = col; break; } } num++; } } } void Init_Grid(GridType grid) { for (int i=0;i<ROWSIZE;i++) { memset(grid[i],0x20,sizeof(char)*COLSIZE); grid[i][COLSIZE - 1] = '