C++自制打印正方形小游戏

自制制作了一个打印正方形的互动小游戏,制作难度不高,想尝试一下的可以复制代码到VS上试试看,可以试试错误的选项,应该会有点意思。

#include<iostream>
using namespace std;
int main() {
	cout << "欢迎来到我的小游戏" << endl;
	cout << "按0键和回车键继续" << endl;
	char ch;
	cin >> ch;
	if (ch == '0') {
		cout << "游戏说明:我们需要打印出一个正确的正方形" << endl;
		cout << "我们会根据你输入的n值来确定你所需要生成的正方形长度" << endl;
		cout << "接下来" << endl;
		cout << "让我们开始吧" << endl;
		cout << "请选择你所输入的正方形的长度" << endl;
		int n;
		cin >> n;
		cout << "你选择的正方形长度是:" << n << endl;
		cout << "你所认为的正方形应该是什么形状的" << endl;
		int k1,k2;
		cout << "1 四个角是直角且四边相等" << endl;
		cout << "2 四个角是直角且四边不相等" << endl;
		A: cout << "请输入你的选择:1 or 2" << endl;
		cin >> k1;
		if (k1 == 1)
		{
			cout << "恭喜你,你的选择是正确的!" << endl;
			cout << "接下来请看下一个选相" << endl;
			B:cout << "你想打印什么类型的正方形" << endl;
			cout << "1 实心的" << endl;
			cout << "2 空心的" << endl;
			cout << "3 空间型的" << endl;
			cin >> k2;
			if (k2 == 1) {
				cout << "开始打印" << endl;
				for (int i = 1; i <= n; i++) {
					for (int i = 1; i <= n; i++) {
						cout << "* ";
					}
					cout << endl;
				}
				cout << "游戏结束,请收好你的正方形" << endl;
			}
			else if (k2 == 2) {
				cout << "好家伙!!!" << endl;
				cout << "居然敢选空心的" << endl;
				cout << "但是难不倒我,哼哼哼" << endl;
				for (int i = 1; i <= n; i++)
				{
					cout << "* ";
				}
				cout << endl;
				for (int i = 1; i <= n-2; i++) {
					cout << "* ";
					for (int i = 1; i <= n-2; i++) {
						cout << "  ";
					}
					cout << "* ";
					cout << endl;
				}
				for (int i = 1; i <= n; i++)
				{
					cout << "* ";
				}
				cout << endl;

			}
			else if (k2 == 3) {
				cout << "寄!!!!!" << endl;
				for (int i = 1; i <= 4; i++) {
					cout << "\a";
				}
				for (int i = 1; i <= 4; i++) {
					cout << "\a";
				}for (int i = 1; i <= 4; i++) {
					cout << "\a";
				}
				for (int i = 1; i <= 100; i++) {
					for (int i = 1; i <= 100; i++)
						cout << "寄" << "####";
				}
				cout << "抱歉哦亲" << endl;
				cout << "目前我还不能满足找个要求" << endl;
				cout << "我就是打出来装装逼" << endl;
				cout << "重新选择吧,嘻嘻嘻" << endl;
				goto B;
			}

		}
		else if (k1 == 2)
		{
			for (int i = 1; i <= 4; i++) {
				cout << "\a";
			}
			for (int i = 1; i <= 1000; i++) {
				cout << "####" << "错了错了";
			}
			cout << "请重新选择" << endl;
			goto A;
		}
	}
	
	return 0;
}

运行展示:

 

 


版权声明:本文为weixin_62304027原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。