日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【打字母游戏_C语言实现】

發布時間:2023/12/14 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【打字母游戏_C语言实现】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

    • 1.項目需求:
    • 2.項目分析:
    • 3.項目設計:
      • 3.1設計字母結構體:
      • 3.2屏幕大小:
      • 3.3 添加二維數組空格函數 LnitGrid(GridArray ga)
      • 3.4 顯示網格 ShowGrid(GridArray ga, struct LetterNode* px, int n)
      • 3.5 產生隨機字母函數 RandLetter(struct LetterNode* px, int n)
      • 3.6 main函數
      • 3.7 調用的頭文件

1.項目需求:

隨機產生一個字母從屏幕下落,玩家輸入字母,如果和顯示字母相同,就消去字母;游戲會再隨機產生一個字母,繼續游戲,如果字母落出屏幕,玩家失敗,游戲結束;

2.項目分析:

項目由兩個模塊構成:
1.顯示模塊 : 顯示模塊由二維數組構成,把隨機產出的字母賦值到二維數組中。
2.處理模塊 : 處理模塊功能有:隨機產生字母 ,輸入字母比較,字母是否落出屏幕,字母下降功能;

3.項目設計:

3.1設計字母結構體:

struct LetterNode {char ch;int row;int col; };

3.2屏幕大小:

#define ROWSIZE 20 // 行 #define COLSIEE 70 // 列 typedef char GridArray[ROWSIZE][COLSIEE + 1]; //二維數組的 網格 #define LETSIZE 1 // 產生的字母數

3.3 添加二維數組空格函數 LnitGrid(GridArray ga)

void LnitGrid(GridArray ga) // {for (int i = 0; i < ROWSIZE; i++){memset(ga[i], ' ', sizeof(char) * COLSIEE);ga[i][COLSIEE] = '\0';} }

3.4 顯示網格 ShowGrid(GridArray ga, struct LetterNode* px, int n)

清屏函數:system(“cls”); 頭文件: #include <windows.h>

void ShowGrid(GridArray ga, struct LetterNode* px, int n) {assert(px != NULL);system("cls"); //清屏LnitGrid(ga);for (int i = 0; i < n; ++i){ga[px[i].row][px[i].col] = px[i].ch;}for (int i = 0; i < ROWSIZE; ++i){printf("%s \n", ga[i]);} }

3.5 產生隨機字母函數 RandLetter(struct LetterNode* px, int n)

void RandLetter(struct LetterNode* px, int n) {assert(px != NULL);srand((int)time(NULL));for (int i = 0; i < n; i++){px[i].ch = rand() % 26 + 'a';px[i].row = 0;px[i].col = rand() % COLSIEE;} }

3.6 main函數

_kbhit() : //鍵盤是否有輸入 頭文件:#include<conio.h>

int main() {GridArray ga;char ch;struct LetterNode x[LETSIZE] = { 0 };RandLetter(x, LETSIZE);while (1){ShowGrid(ga, x, LETSIZE);Sleep(1000); //1000毫秒 == 1 秒if (_kbhit()) //鍵盤是否有輸入{//ch = getchar();ch = _getch(); //無需等待回車輸入if (ch == x[0].ch){x[0].ch = rand() % 26 + 'a';x[0].row = -1;x[0].col = rand() % COLSIEE;}}x[0].row += 1;if (x[0].row >= ROWSIZE){printf("游戲結束 \n");break;}}return 0; }

3.7 調用的頭文件

#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<string.h> #include<stdbool.h> #include<assert.h> #include<Windows.h> #include<time.h> #include<conio.h> #include<ctype.h>

運行結果:

總結

以上是生活随笔為你收集整理的【打字母游戏_C语言实现】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。