打字母游戏

1.第一阶段——一个字母

#include"stdafx.h"
#include<stdio.h>
#include<iostream>
#include<time.h>
#include<conio.h>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
using namespace std;
#define ROW 4
#define LIST 30
#define SIZE 1
typedef char G_Array[ROW][LIST + 1];
typedef struct {
	char  ch;
	int row;
	int list;
}GX;
void Init_G(G_Array ga){
	for (int i = 0; i < ROW; i++){
		memset(ga[i], '#', sizeof(char)*LIST);
		ga[i][LIST] = '\0';
	}
}
void Show_G(G_Array ga ,GX *gx,int n){
	assert(gx != NULL);
	system("cls");
	Init_G(ga); 
	for (int i = 0; i < n; i++){
		ga[gx[i].row ][gx[i].list] = gx[i].ch;
	}
	for (int i = 0; i <ROW; i++){
		cout << ga[i] << endl;
	}
}
void Arondoms(G_Array ga, GX *gx, int n){
	assert(gx != NULL);
	srand(time(NULL));
	for (int i = 0; i < n; i++){
		gx[i].ch = rand() % 26 + 'a';
		gx[i].row = 0;
		gx[i].list = rand() %LIST;
	}
}
int main(){
	G_Array ga;
	GX gx[SIZE] = {0};
	char ch;
	Arondoms(ga, gx, SIZE);
	while (1){
		Show_G(ga, gx, SIZE);
		Sleep(1000);
		if (_kbhit()){
			ch = _getch();
			if (ch == gx[0].ch){
				gx[0].ch = rand() % 26 + 'a';
				gx[0].list = rand() % LIST;
				gx[0].row = -1;
			}
		}
		gx[0].row += 1;
		if (gx[0].row >= ROW){
			cout << "游戏结束!" << endl;
			cout << "时光作渡,眉目成书,从此我们的深情,不被辜负!" << endl;
			break;
		}

	}


}

 2.

#include"stdafx.h"
#include<stdio.h>
#include<iostream>
#include<time.h>
#include<conio.h>
#include<Windows.h>
#include<string.h>
#include<stdlib.h>
#include<assert.h>
using namespace std;
#define ROW 30
#define LIST 5
#define SIZE 10
typedef char G_Array[ROW][LIST + 1];
typedef struct {
	char  ch;
	int row;
	int list;
}GX;
void Init_G(G_Array ga){
	for (int i = 0; i < ROW; i++){
		memset(ga[i], ' ', sizeof(char)*LIST);
		ga[i][LIST] = '\0';
	}
}
void Show_G(G_Array ga ,GX *gx,int n){
	assert(gx != NULL);
	system("cls");
	Init_G(ga); 
	for (int i = 0; i < n; i++){
		ga[gx[i].row ][gx[i].list] = gx[i].ch;
	}
	for (int i = 0; i <ROW; i++){
		cout << ga[i] << endl;
	}
}
void Arondoms(G_Array ga, GX *gx, int n){
	assert(gx != NULL);
	srand(time_t(NULL));
	for (int i = 0; i < n; i++){
		gx[i].ch = rand() % 26 + 'a';
		gx[i].row = 0;
		gx[i].list = rand() %LIST;
	}
}
int main(){
	G_Array ga;
	GX gx[SIZE] = {0};
	char ch;
	Arondoms(ga, gx, SIZE);
	while (1)
	{
		Show_G(ga, gx, SIZE);
		Sleep(1000);
		if (_kbhit())
		{
			ch = _getch();
			for (int i = 0; i < SIZE; i++)
			{
				if (ch == gx[i].ch)
				{
					gx[i].ch = rand() % 26 + 'a';
					gx[i].list = rand() % LIST;
					gx[i].row = -1;
				}
			}
		}
		for (int i = 0; i < SIZE; i++)
		{
			gx[i].row += 1;
			if (gx[i].row >= ROW)
			{
				cout << "游戏结束!" << endl;
				cout << "时光作渡,眉目成书,从此我们的深情,不被辜负!" << endl;
				return 0;
			}

		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值