Schrieffer.zsy 2021-03-27 16:34 采纳率: 93.8%
浏览 100
已采纳

(C++::俄罗斯方块)大佬帮我看看问题在哪?

#include<iostream>
#include<string>
#include<ctime>
#include<conio.h>
#include<Windows.h>
#include<cstdlib>
using namespace std;

#define Ht 20
#define Wh 10
string Map[Ht][Wh];

void Print_map()
{
	for (int i = 0; i < Ht; i++) {
		for (int j = 0; j < Wh; j++) {
			cout << Map[i][j];
		}
		cout << endl;
	}
}

class Coord
{
public:
	int m_X;
	int m_Y;
	Coord(int x,int y) {
		m_X = x;
		m_Y = y;
	}
	bool operator==(Coord C) {
		return C.m_X == m_X && C.m_Y == m_Y;
	}
};
class Assets
{
public:
	int m_X[4];
	int m_Y[4];
	Assets(){}
	Assets(int* s1) {
		srand((unsigned int)time(NULL));
		for (int i = 0; i < 4; i++) {
			m_X[i] = s1[i];
		}
		m_Y[0] = 5;
	}
};
Assets Choice[6];

//废弃不用的决策号
int a0_x[4] = { 0,0,0,0 };
Assets a0(a0_x);
/////////////
//     ■  //
//     ■  //
//   ■■  //
//         //
/////////////
int a1_x[4] = { 0,1,2,2 };
Assets a1(a1_x);

/////////////
//     ■  //
//     ■  //
//     ■  //
//     ■  //
/////////////
int a2_x[4] = { 0,1,2,3 };
Assets a2(a2_x);

/////////////
//     ■  //
//   ■■  //
//     ■  //
//         //
/////////////
int a3_x[4] = { 0,1,1,2 };
Assets a3(a3_x);

/////////////
//   ■■  //
//   ■■  //
//         //
//         //
/////////////
int a4_x[4] = { 0,0,1,1 };
Assets a4(a4_x);

/////////////
//   ■■  //
// ■■    //
//         //
//         //
/////////////
int a5_x[4] = { 0,0,1,1 };
Assets a5(a5_x);

//////////////////////////////////////////////////////////////////////////////////////
//输入一个Assets块将其添加到Map中(在打印层面上)
void assign_ast(Assets A) 
{
	for (int i = 0; i < 4; i++) {
		Map[A.m_X[i]][A.m_Y[i]] = "□";
	}
	Sleep(100);
}
//输入一个Assets块将其从Map中删除(在打印层面上)
void delete_ast(Assets A)
{
	for (int i = 0; i < 4; i++) {
		Map[A.m_X[i]][A.m_Y[i]] = "  ";
	}
}
//////////////////////////////////////////////////////////////////////////////////////
void create_ast() 
{
	srand((unsigned int)time(NULL));
	int judge = rand() % 5 + 1;
	assign_ast(Choice[3]);
}












//禁止触碰的位点(在触碰之后需要更新)
Coord Pbt_area[Wh - 2] = { {18,1},{18, 2},{18, 3},{18, 4},{18, 5},{18, 6},{18, 7},{18, 8} };
//检查是否被触碰(若位点被赋值"□",那么函数将返回是)ps:这里只输入当前正在操控的temp
bool check_if(Assets temp) 
{
	bool exit = 0;
	Coord coord_0(temp.m_X[0], temp.m_Y[0]);
	Coord coord_1(temp.m_X[1], temp.m_Y[1]);
	Coord coord_2(temp.m_X[2], temp.m_Y[2]);
	Coord coord_3(temp.m_X[3], temp.m_Y[3]);
	Coord ALL[4] = { coord_0 ,coord_1 ,coord_2 ,coord_3 };
	
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 8; j++) {
			exit = exit || (ALL[i] == Pbt_area[j]);
		}
	}

	return exit;
}


int main()
{
	srand((unsigned int)time(NULL));
	// 画面的初始化 && 添加边框
	for (int i = 0; i < Ht; i++) {
		for (int j = 0; j < Wh; j++) {
			Map[i][j] = "  ";
		}
	}
	for (int i = 0; i < Ht; i++) {
		for (int j = 0; j < Wh; j++) {
			if (j == 0 || j == Wh - 1 || i == 19) {
				Map[i][j] = "■";
			}
		}
	}
	//////////////////////////////////////////////////////////////////////////////////////
	//Assets块的设计

	a1.m_Y[1] = a1.m_Y[0];
	a1.m_Y[2] = a1.m_Y[0];
	a1.m_Y[3] = a1.m_Y[0] - 1;

	a2.m_Y[1] = a2.m_Y[0];
	a2.m_Y[2] = a2.m_Y[0];
	a2.m_Y[3] = a2.m_Y[0];

	a3.m_Y[1] = a3.m_Y[0];
	a3.m_Y[2] = a3.m_Y[0] - 1;
	a3.m_Y[3] = a3.m_Y[0];

	a4.m_Y[1] = a4.m_Y[0] - 1;
	a4.m_Y[2] = a4.m_Y[0] - 1;
	a4.m_Y[3] = a4.m_Y[0];

	a5.m_Y[1] = a5.m_Y[0] - 1;
	a5.m_Y[2] = a5.m_Y[0] - 1;
	a5.m_Y[3] = a5.m_Y[0] - 2;

	Assets Choice[6] = { a0,a1,a2,a3,a4,a5, };
	Assets temp;
	int judge;

	//游戏进行循环
	while (true)
	{
		//随机创建一个Assets块
		judge = rand() % 5 + 1;
		assign_ast(Choice[judge]);
		temp = Choice[judge];
		while (true)
		{
			Print_map();
			if (_kbhit()) {
				int key = _getch();
				switch (key)
				{
				//输入a(代表顺时针旋转)
				case 97:

					break;
				//输入d(代表逆时针旋转)
				case 100:

					break;
				default:
					break;
				}
			}

			//刷新正在操控的Assets块,使其向下
			delete_ast(temp);
			for (int i = 0; i < 4; i++) {
				temp.m_X[i]++;
			}
			assign_ast(temp); 

			//程序的出口(若正在操控的Assets块触碰到了违法位点,函数将输出1)
			if (check_if(temp)) {
				for (int i = 0; i <= 18; i++) {
					for (int j = 1; j <= 8; j++) {
						if (Map[i][j] == "□") {
							Map[i][j] = "■";
						}
					}
				}

				system("cls");
				break;
			}

			//违法位点的更新
			
			int i;
			for (int j = 1; j <= 8; j++) {
				i = 0;
				while (Map[i][j] != "■"){
					i++;
				}
				Pbt_area[j].m_X = i - 1;
				Pbt_area[j].m_Y = j;
			}
			system("cls");
		}
		//检查是否有行被填满
		for (int i = 18; i >= 0; i--) {
			for (int j = 18; j >= 0; j--) {


			}

		}


	}

	system("pause");
	return 0;
}
  • 写回答

7条回答 默认 最新

  • ProfSnail 2021-03-27 20:41
    关注

    感觉代码暂时没什么问题,我运行起来也没有发现游戏框右移的情况。你可以自己的命令行字体是不是出现了一些问题。

    或者注释掉第264行,并把263行的j换成j-1。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效