A字母并没有被显示出来,不明白哪里出了问题

0

A字母并没有被显示出来,不明白哪里出了问题

#include<stdio.h>
#include<windows.h>

int width = 20;
int high = 50;
int y = 10;
int x = 20;

void show()
{
	system("cls");
	int i, j;
	for (i = 0; i <= high; i++)
	{
		for (j = 0; j <= width; j++)
		{
			if ((i == x) && (j == y))
				printf(" ");
			printf("A\n");
		}
	}
	printf("\n");

}
void control()
{
	char ch;
	getchar();

	if ((x <= high) && (y <= width))
	{
		switch (ch)
		{
		case 'a':
			y--;
			break;
		case 'd':
			y++;
			break;
		case 'w':
			x--;
			break;
		case 's':
			x++;
			break;
		}
	}
}


int main()
{
	while (1)
	{
		void show();
		void control();
	}
	return 0;
}

已经解决。正确代码如下:

#include <stdio.h>
#include <windows.h>
#include <conio.h>

int width;
int high;
int y;
int x;

void init()
{
	high = 100;
	width = 50;
	y = 5;
	x = 10;
}

void show()
{
	system("cls");
	Sleep(1000);
	int i, j;
	for (i = 0; i <= high; i++)
	{
		for (j = 0; j <= width; j++)
		{
			if ((i == x) && (j == y))
				printf("A");
			else
				printf(" ");
		}
	}
	printf("\n");
}

void control()
{
	char ch;
	if (kbhit())
	{
		ch = getch();
		switch (ch)
		{
			case 'a': y--; break;
			case 'd': y++; break;
			case 'w': x--; break;
			case 's': x++; break;
		}
	}
}

int main()
{
	init();
	while (1)
	{
		show();
		control();
	}
	return 0;
}
ava
没烦恼

2020-11-24

已经解决 -  没烦恼  2020-11-24
0

:)

ava
慢羊羊

2020-11-24

技术讨论社区