请教一下
  • 板块学术版
  • 楼主logo_2022
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/8 20:34
  • 上次更新2024/7/8 22:08:59
查看原帖
请教一下
800412
logo_2022楼主2024/7/8 20:34

为什么下面这个代码刷新出来的方块置顶不了(方块并没有刷新在第二行)

#include<bits/stdc++.h>//俄罗斯方块 
#include<windows.h>
#define VK_W 87
#define VK_A 65
#define VK_S 83
#define VK_D 68
using namespace std;
int m[38][28],fa,max_h,l;//25*35
int f_x,f_y;
bool k=1;
void c_1()
{
	for(int i=1;i<=37;i++)
	{
		for(int j=1;j<=27;j++)
		{
			if(i==1||i==37||j==1||j==27)
			{
				m[i][j]=1;
				cout<<"="; 
			}else
			{
				cout<<" ";
			}
		}
		cout<<endl;
	}
}
void c_2(int x,int y)
{
	HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
	COORD coord={x,y};
	SetConsoleCursorPosition(hout,coord);
} 
void end()
{
	system("cls");
	cout<<"分数:"<<fa; 
}
int main()
{
	srand((unsigned)time(NULL));
	c_1();
	while(1)
	{
		if(max_h>=35)
		{
			break;
		}
		if(k)//刷新方块 
		{
			l=(rand() % (4-1+1))+1;//方块种类 
			f_x=13;
			f_y=1;
			k=0;
		}else
		{
			if(GetAsyncKeyState(VK_S)&&m[f_y+2][f_x]!=1&&m[f_y+1][f_x+1]!=2)
			{
				c_2(f_x,f_y);
				cout<<" ";
				f_y++;
				c_2(f_x,f_y);
				cout<<"#";
			}
			if(GetAsyncKeyState(VK_A)&&m[f_y][f_x]!=1&&m[f_y][f_x]!=2)
			{
				c_2(f_x,f_y);
				cout<<" ";
				f_x--;
				c_2(f_x,f_y);
				cout<<"#";
			}
			if(GetAsyncKeyState(VK_D)&&m[f_y][f_x+2]!=1&&m[f_y][f_x+2]!=2)
			{
				c_2(f_x,f_y);
				cout<<" ";
				f_x++;
				c_2(f_x,f_y);
				cout<<"#";
			}
		}
		if(m[f_y+2][f_x+1]!=1&&m[f_y+1]
		{
			c_2(f_x,f_y);
			cout<<" ";
			f_y++;
			c_2(f_x,f_y);
			cout<<"#";
		}else
		{
			k=1;
			m[f_y][f_x+1]=2;
		}
		Sleep(100);
	}
	end();
	return 0;
}

谢谢。

2024/7/8 20:34
加载中...