lundi 8 novembre 2021

qrand was not declared on this scope

I have an error with a game - "Snake".
Generator of pseudo random digits is not working.
It says "using undeclared identifier qrand" or "qrand was not declared on this scope"
Maybe i'm using wrong QT version - 5.0.2

#include<QEvent>
#include <QGraphicsScene>
#include <QKeyEvent>
#include <QMessageBox>
#include <QAction>
#include <iostream>

#include "gamecontroller.h"
#include "food.h"
#include "snake.h"
#include "mainwindow.h"

void GameController::addNewFood()
{
    int x, y;

    do {
        x = (int)(qrand() % 200) / 10 - 10;       //using undeclared identifier qrand
        y = (int)(qrand() % 200) / 10 - 10;       //using undeclared identifier qrand
        x *= 10;
        y *= 10;
    } while (snake->shape().contains(snake->mapFromScene(QPointF(x + 5, y + 5))));

    Food *food = new Food(x, y);
    scene.addItem(food);
}



Aucun commentaire:

Enregistrer un commentaire