【发布时间】:2016-11-19 23:32:35
【问题描述】:
我目前正在使用 Visual Studio 在 C++ 中编写我的第一个游戏(Snake),我试图在屏幕上的随机区域设置你吃的块但是当我使用 rand() 函数时它说它是未定义的,确实有谁知道我为什么会出现这个错误?
#include <iostream>
using namespace std;
bool gameOver;
const int WIDTH = 20;
const int HEIGHT = 20;
int x, y, foodX, foodY, score;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN};
eDirection dir;
void Setup(){
gameOver = false;
dir = STOP;
x = WIDTH /2;
y = HEIGHT /2;
//rand function below is not defined??
//I thought the function was built in
foodX = rand() % WIDTH;
foodY = rand() % HEIGHT;
}
void Draw() {
}
void Input() {
}
void Logic() {
}
int main()
{
Setup();
while (!gameOver)
{
Draw();
Input();
Logic();
}
return 0;
}
【问题讨论】: