我不明白这个错误它在教程中编写的完全相同,但我的错误会产生错误。
#include "drawEngine.h"
#include <Windows.h>
#include <iostream>
using namespace std;
DrawEngine::DrawEngine(int xSize, int ySize)
{
screenWidth = xSize;
screenHeight = ySize;
//set cursor visibility to false
map = 0;
cursorVisibility(false);
}
DrawEngine::~DrawEngine()
{
//set cursor visibility to true
cursorVisibility(true);
}
int DrawEngine::createSprite(int index, char c)
{
if (index >= 0 && index < 16)
{
spriteImage[index] = c;
return index;
}
return -1;
}
void DrawEngine::deleteSprite(int index)
{
//in this implementation we don't need it
}
void DrawEngine::drawSprite(int index, int posx, int posy)
{
//go to the correct location
gotoxy(posx, posy);
//draw the image with cout
cout << spriteImage[index];
}
void DrawEngine::eraseSprite(int posx, int posy)
{
gotoxy(posx, posy);
cout << ' ';
}
void DrawEngine::setMap(char **data)
{
map = data;
}
void DrawEngine::createBackgroundTile(int index, char c)
{
if (index >= 0 && index < 16)
{
tileImage[index] = c;
}
}
void DrawEngine::drawBackground(void)
{
if (map)
{
for (int y = 0; y < screenHeight; y++)
{
goto(0, y); // This generates the error
for (int x = 0; x < screenWidth; x++)
{
cout << tileImage[map[x][y]];
}
}
}
}
void DrawEngine::gotoxy(int x, int y)
{
HANDLE output_handle;
COORD pos;
pos.X = x;
pos.Y = y;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(output_handle, pos);
}
void DrawEngine::cursorVisibility(bool visibility)
{
HANDLE output_handle;
CONSOLE_CURSOR_INFO cciInfo;
cciInfo.dwSize = sizeof(CONSOLE_CURSOR_INFO);
cciInfo.bVisible = visibility;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(output_handle, &cciInfo);
}
答案 0 :(得分:7)
我认为你打算写gotoxy(0, y)
而不是goto(0, y)
。
goto
是一个跳转到标签的C ++关键字,例如:
home:
goto home; // Loops forever
不要使用它,但是创建意大利面条代码太容易了。
答案 1 :(得分:0)
goto(0, y)
应该是gotoxy(0, y)
。 goto
是C中的保留关键字,不能用作函数名称。
答案 2 :(得分:0)
我认为你的意思是gotoxy
。 goto
完全是另一回事。