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;
}
}
}
}