问题标题: 酷町堂:简单的打字小游戏

1
1
王梓澳
王梓澳
中级光能
中级光能

打字小游戏,不用多说了吧

里面什么字母打什么,重复的会一次消失,只有20次机会

就这样吧

以后会完善程序呀

王梓澳在2021-06-13 21:56:20追加了内容
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int PlayerLife=20;
int PlayerScore=0;
int enSleep=0;
struct en {
	int x,y;
	int startSleep;
	int Start;
	char c;
}fen[1001];
void color(int a) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a) {
    HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(out,a);
}
void SetPos(int i, int j) {
    COORD pos={i,j};
    SetPos(pos);
}
void hit() {
	for (int i=1;i<=20;i++) {
		if (KEY_DOWN(fen[i].c)) {
			PlayerScore++;
			SetPos(fen[i].y-1,fen[i].x);
			cout<<"   ";
			SetPos(fen[i].y-1,fen[i].x-1);
			cout<<"   ";
			SetPos(fen[i].y-1,fen[i].x+1);
			cout<<"   ";
			fen[i].x=3;
			fen[i].c=char(rand()%26+65);	
            fen[i].y=rand()%39;
            PlayerScore++;
		}
	}
}
void en_move () {
	if (enSleep==4) {
        for (int i=1;i<=20;i++) {
        	if (fen[i].startSleep==fen[i].Start) {
	            if (fen[i].x+1<=41)
	                fen[i].x++;
	            if (fen[i].x==41) {
	            	PlayerLife--;
	            	if (PlayerLife==0) {
	            		system("cls");
	            		cout<<"你一共获得了"<<PlayerScore<<"分,下次看看能不能超越自我!";
	            		exit(0);
					}
					SetPos(fen[i].y,fen[i].x-1);
					cout<<" ";
	                fen[i].x=3;
	                fen[i].c=char(rand()%26+65);
	                fen[i].y=rand()%39;
	            }
        	}
    	}
        enSleep=0;
    }
}
void print() {
	cout<<"_____________________________________________\n";
	for (int i=1;i<=42;i++)
		cout<<"                                             |\n";
	cout<<"_____________________________________________";
}
int main () {
	print();
	for (int i=1;i<=20;i++) {
		fen[i].x=3;
		fen[i].startSleep=rand()%20;
		fen[i].c=char(rand()%26+65);
		fen[i].y=rand()%39;
	}
//	SetPos(1,1);
//	cout<<"_";
	while (true) {
		hit();
		en_move();
		for (int i=1;i<=20;i++) {
			if (fen[i].startSleep==fen[i].Start) {
				if (fen[i].y!=1) {
					SetPos(fen[i].y,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y-1,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y+1,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y-1,fen[i].x-2);
					cout<<"   ";
					SetPos(fen[i].y-1,fen[i].x-1);
					cout<<"   ";
					SetPos(fen[i].y-1,fen[i].x);color(6);
					cout<<"|";
					SetPos(fen[i].y+1,fen[i].x);color(6);
					cout<<"|";
					SetPos(fen[i].y-1,fen[i].x-1);color(6);
					cout<<"---";
					SetPos(fen[i].y-1,fen[i].x+1);color(6);
					cout<<"---";
					SetPos(fen[i].y,fen[i].x);color(14);
					cout<<fen[i].c;
				}
			}
			if (fen[i].Start<fen[i].startSleep)fen[i].Start++;
		}
		color(7);
		SetPos(1,44);
		cout<<"你还剩下"<<PlayerLife<<"次机会";
		SetPos(1,45);
		cout<<"你获得了"<<PlayerScore<<"分";
		enSleep++;
		Sleep(100);
	}
	return 0;
}

忘记贴代码了。。。。

王梓澳在2021-07-01 20:00:57追加了内容
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int PlayerLife=20;
int PlayerScore=0;
int enSleep=0;
struct en {
	int x,y;
	int startSleep;
	int Start;
	char c;
}fen[1001];
void color(int a) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a) {
    HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(out,a);
}
void SetPos(int i, int j) {
    COORD pos={i,j};
    SetPos(pos);
}
//void choose() {
//	
//}
void rule() {
	system("cls");
	color(7);
	cout<<"规则:\n";
	cout<<"打字游戏\n上面会掉下来一个个小方块,里面有着一个字母,按下这个字母,即可消除方块,获取得分\n";
	cout<<"按下k继续";
	while (!KEY_DOWN('K'));
	system("cls");
}
void news() {
	system("cls");
	color(7);
	cout<<"1.0~1.1  更新游戏界面";
	while (!KEY_DOWN('K'));
	system("cls");
}
void start() {
	int i=1;
	while (true) {
		if (i==1) {
			color(14);
			if (KEY_DOWN('Z')) {
//				choose();
				return ;
			}
		}SetPos(2,2);cout<<"开始游戏";color(7);
		if (i==2) {
			color(14);
			if (KEY_DOWN('Z')) rule();
		}SetPos(2,3);cout<<"查看规则";color(7);
		if (i==3) {
			color(14);
			if (KEY_DOWN('Z')) news();
		}SetPos(2,4);cout<<"更新内容";color(7);
		if (i==4) {
			color(14);
			if (KEY_DOWN('Z')) 
		}SetPos(2,5);cout<<"游戏设置";
		if (KEY_DOWN('S')&&i+1<=4) i++;
		if (KEY_DOWN('W')&&i-1>=1) i--;
		Sleep(100);
	}
}
void hit() {
	for (int i=1;i<=20;i++) {
		if (KEY_DOWN(fen[i].c)) {
			PlayerScore++;
			SetPos(fen[i].y-1,fen[i].x);
			cout<<"   ";
			SetPos(fen[i].y-1,fen[i].x-1);
			cout<<"   ";
			SetPos(fen[i].y-1,fen[i].x+1);
			cout<<"   ";
			fen[i].x=3;
			fen[i].c=char(rand()%26+65);	
            fen[i].y=rand()%39;
            PlayerScore++;
		}
	}
}
void en_move () {
	if (enSleep==4) {
        for (int i=1;i<=20;i++) {
        	if (fen[i].startSleep==fen[i].Start) {
	            if (fen[i].x+1<=41)
	                fen[i].x++;
	            if (fen[i].x==41) {
	            	PlayerLife--;
	            	if (PlayerLife==0) {
	            		system("cls");
	            		cout<<"你一共获得了"<<PlayerScore<<"分,下次看看能不能超越自我!";
	            		exit(0);
					}
					SetPos(fen[i].y,fen[i].x-1);
					cout<<" ";
	                fen[i].x=3;
	                fen[i].c=char(rand()%26+65);
	                fen[i].y=rand()%39;
	            }
        	}
    	}
        enSleep=0;
    }
}
void print() {
	SetPos(0,0);
	cout<<"_____________________________________________\n";
	for (int i=1;i<=42;i++)
		cout<<"                                             |\n";
	cout<<"_____________________________________________";
}
int main () {
	start();
	print();
	for (int i=1;i<=20;i++) {
		fen[i].x=3;
		fen[i].startSleep=rand()%20;
		fen[i].c=char(rand()%26+65);
		fen[i].y=rand()%39;
	}
//	SetPos(1,1);
//	cout<<"_";
	while (true) {
		hit();
		en_move();
		for (int i=1;i<=20;i++) {
			if (fen[i].startSleep==fen[i].Start) {
				if (fen[i].y!=1) {
					SetPos(fen[i].y,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y-1,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y+1,fen[i].x-1);
					cout<<" ";
					SetPos(fen[i].y-1,fen[i].x-2);
					cout<<"   ";
					SetPos(fen[i].y-1,fen[i].x-1);
					cout<<"   ";
					SetPos(fen[i].y-1,fen[i].x);color(6);
					cout<<"|";
					SetPos(fen[i].y+1,fen[i].x);color(6);
					cout<<"|";
					SetPos(fen[i].y-1,fen[i].x-1);color(6);
					cout<<"---";
					SetPos(fen[i].y-1,fen[i].x+1);color(6);
					cout<<"---";
					SetPos(fen[i].y,fen[i].x);color(14);
					cout<<fen[i].c;
				}
			}
			if (fen[i].Start<fen[i].startSleep)fen[i].Start++;
		}
		color(7);
		SetPos(1,44);
		cout<<"你还剩下"<<PlayerLife<<"次机会";
		SetPos(1,45);
		cout<<"你获得了"<<PlayerScore<<"分";
		enSleep++;
		Sleep(100);
	}
	return 0;
}

作者做了一个界面,看看大家适不适应,考虑继续不继续

(中间断了作者期末,暑假了,作者开心!)

王梓澳在2021-08-09 13:01:22追加了内容

集体回复一下,窗口闪烁的问题

由于是SetPos的覆盖,所以光标会上下移动,如果屏幕太小那么会上下来回切换,就会很闪,解决方案作者在回答里面发过了,自己看一下


0
0
0
0
0
0
0
0
汪恺恒
汪恺恒
中级启示者
中级启示者

闪的太快了,根本看不清……

0
0
王梓澳
王梓澳
中级光能
中级光能

这里这个可能会闪

原因:运用SetPos在不同位置输出,光标会上下来回输出,就会不停上下闪

解决方案:

右击它,然后点属性(作者截屏截不出来了。。。)

将窗口大小和位置做一个调整,窗口变大就不卡了

0
0
0
0
0
0
0
王子逸
王子逸
新手天翼
新手天翼
#include <bits/stdc++.h>
#include <windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int PlayerLife=20;
int PlayerScore=0;
int enSleep=0;
struct en {
    int x,y;
    int startSleep;
    int Start;
    char c;
}fen[1001];
void color(int a) {
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void SetPos(COORD a) {
    HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(out,a);
}
void SetPos(int i, int j) {
    COORD pos={i,j};
    SetPos(pos);
}
void hit() {
    for (int i=1;i<=20;i++) {
        if (KEY_DOWN(fen[i].c)) {
            PlayerScore++;
            SetPos(fen[i].y-1,fen[i].x);
            cout<<"   ";
            SetPos(fen[i].y-1,fen[i].x-1);
            cout<<"   ";
            SetPos(fen[i].y-1,fen[i].x+1);
            cout<<"   ";
            fen[i].x=3;
            fen[i].c=char(rand()%26+65);    
            fen[i].y=rand()%39;
            PlayerScore++;
        }
    }
}
void HideCursor(){
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO CursorInfo;
    GetConsoleCursorInfo(handle, &CursorInfo);//获取控制台光标信息
    CursorInfo.bVisible = false; //隐藏控制台光标
    SetConsoleCursorInfo(handle, &CursorInfo);//设置控制台光标状态
}
void en_move () {
    if (enSleep==4) {
        for (int i=1;i<=20;i++) {
            if (fen[i].startSleep==fen[i].Start) {
                if (fen[i].x+1<=41)
                    fen[i].x++;
                if (fen[i].x==41) {
                    PlayerLife--;
                    if (PlayerLife==0) {
                        system("cls");
                        cout<<"你一共获得了"<<PlayerScore<<"分,下次看看能不能超越自我!";
                        exit(0);
                    }
                    SetPos(fen[i].y,fen[i].x-1);
                    cout<<" ";
                    fen[i].x=3;
                    fen[i].c=char(rand()%26+65);
                    fen[i].y=rand()%39;
                }
            }
        }
        enSleep=0;
    }
}
void print() {
    cout<<"_____________________________________________\n";
    for (int i=1;i<=42;i++)
        cout<<"                                             |\n";
    cout<<"_____________________________________________";
}
int main () {
     HideCursor(); 
    print();
    for (int i=1;i<=20;i++) {
        fen[i].x=3;
        fen[i].startSleep=rand()%20;
        fen[i].c=char(rand()%26+65);
        fen[i].y=rand()%39;
    }
//  SetPos(1,1);
//  cout<<"_";
    while (true) {
        hit();
        en_move();
        for (int i=1;i<=20;i++) {
            if (fen[i].startSleep==fen[i].Start) {
                if (fen[i].y!=1) {
                    SetPos(fen[i].y,fen[i].x-1);
                    cout<<" ";
                    SetPos(fen[i].y-1,fen[i].x-1);
                    cout<<" ";
                    SetPos(fen[i].y+1,fen[i].x-1);
                    cout<<" ";
                    SetPos(fen[i].y-1,fen[i].x-2);
                    cout<<"   ";
                    SetPos(fen[i].y-1,fen[i].x-1);
                    cout<<"   ";
                    SetPos(fen[i].y-1,fen[i].x);color(6);
                    cout<<"|";
                    SetPos(fen[i].y+1,fen[i].x);color(6);
                    cout<<"|";
                    SetPos(fen[i].y-1,fen[i].x-1);color(6);
                    cout<<"---";
                    SetPos(fen[i].y-1,fen[i].x+1);color(6);
                    cout<<"---";
                    SetPos(fen[i].y,fen[i].x);color(14);
                    cout<<fen[i].c;
                }
            }
            if (fen[i].Start<fen[i].startSleep)fen[i].Start++;
        }
        color(7);
        SetPos(1,44);
        cout<<"你还剩下"<<PlayerLife<<"次机会";
        SetPos(1,45);
        cout<<"你获得了"<<PlayerScore<<"分";
        enSleep++;
        Sleep(100);
    }
    return 0;
}

这样窗口是不是流畅多了?

0
0
0
0
0
0
我要回答