Commit bbda47c2 authored by Julian Helfferich's avatar Julian Helfferich

Use qrand() and qsrand() instead of rand() and srand()

The Qt versions are guaranteed to be portible. This fixes 11 Krazy
issues.
parent 638a9830
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "KBlocksDummyAI.h" #include "KBlocksDummyAI.h"
#include <stdlib.h> #include <QtGlobal>
KBlocksDummyAI::KBlocksDummyAI() KBlocksDummyAI::KBlocksDummyAI()
{ {
...@@ -49,8 +49,8 @@ void KBlocksDummyAI::think(GamePlayer_ActionList *actionList) ...@@ -49,8 +49,8 @@ void KBlocksDummyAI::think(GamePlayer_ActionList *actionList)
return; return;
} }
int rotation = rand() % (mRotateCount + 1) - mRotateCount / 2; int rotation = qrand() % (mRotateCount + 1) - mRotateCount / 2;
int motionx = rand() % (mFieldWidth + 1) - mFieldWidth / 2; int motionx = qrand() % (mFieldWidth + 1) - mFieldWidth / 2;
if (rotation > 0) { if (rotation > 0) {
for (int i = 0; i < rotation; i++) { for (int i = 0; i < rotation; i++) {
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
***************************************************************************/ ***************************************************************************/
#include "KBlocksGameLogic.h" #include "KBlocksGameLogic.h"
#include <QtGlobal>
KBlocksGameLogic::KBlocksGameLogic(int capacity, bool record) KBlocksGameLogic::KBlocksGameLogic(int capacity, bool record)
{ {
mGameCount = 0; mGameCount = 0;
...@@ -170,7 +172,7 @@ int KBlocksGameLogic::updateGame(int *lineList) ...@@ -170,7 +172,7 @@ int KBlocksGameLogic::updateGame(int *lineList)
lineList[i] = tmpTotal; lineList[i] = tmpTotal;
if ((mPunishFlag) && (tmpPunishCount > 0)) { if ((mPunishFlag) && (tmpPunishCount > 0)) {
int punishSeed = rand() % 256; int punishSeed = qrand() % 256;
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
maGameList[j]->punishGame(tmpPunishCount, punishSeed); maGameList[j]->punishGame(tmpPunishCount, punishSeed);
} }
...@@ -276,9 +278,9 @@ void KBlocksGameLogic::createSingleGames(int gameCount) ...@@ -276,9 +278,9 @@ void KBlocksGameLogic::createSingleGames(int gameCount)
int *seedList = new int[mGameCount]; int *seedList = new int[mGameCount];
if (mGameSeed < 0) { if (mGameSeed < 0) {
mGameSeed = -mGameSeed; mGameSeed = -mGameSeed;
srand(mGameSeed); qsrand(mGameSeed);
for (int i = 0; i < mGameCount; i++) { for (int i = 0; i < mGameCount; i++) {
seedList[i] = rand() % 256; seedList[i] = qrand() % 256;
} }
} else { } else {
for (int i = 0; i < mGameCount; i++) { for (int i = 0; i < mGameCount; i++) {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
***************************************************************************/ ***************************************************************************/
#include "KBlocksPieceGenerator.h" #include "KBlocksPieceGenerator.h"
#include <stdlib.h> #include <QtGlobal>
#include <stdio.h> #include <stdio.h>
#include "KBlocksPiece.h" #include "KBlocksPiece.h"
...@@ -28,10 +28,10 @@ KBlocksPieceGenerator::~KBlocksPieceGenerator() ...@@ -28,10 +28,10 @@ KBlocksPieceGenerator::~KBlocksPieceGenerator()
void KBlocksPieceGenerator::genList(int seed) void KBlocksPieceGenerator::genList(int seed)
{ {
srand(seed); qsrand(seed);
for (int i = 0; i < maxCapacity; i++) { for (int i = 0; i < maxCapacity; i++) {
maPieceList[i] = rand() % PieceType_Detail_Max_Count; maPieceList[i] = qrand() % PieceType_Detail_Max_Count;
} }
pieceIndex = 0; pieceIndex = 0;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "KBlocksField.h" #include "KBlocksField.h"
#include "KBlocksPiece.h" #include "KBlocksPiece.h"
#include <stdlib.h> #include <QtGlobal>
KBlocksSingleGame::KBlocksSingleGame(int gameIndex, int fieldWidth, int fieldHeight, int showPieceCount, int messagePoolSize) KBlocksSingleGame::KBlocksSingleGame(int gameIndex, int fieldWidth, int fieldHeight, int showPieceCount, int messagePoolSize)
{ {
...@@ -125,11 +125,11 @@ int KBlocksSingleGame::punishGame(int lineCount, int punishSeed) ...@@ -125,11 +125,11 @@ int KBlocksSingleGame::punishGame(int lineCount, int punishSeed)
mpGameRecorder->append(mGameIndex, RecordDataType_PunishLineSeed, punishSeed); mpGameRecorder->append(mGameIndex, RecordDataType_PunishLineSeed, punishSeed);
} }
srand(punishSeed); qsrand(punishSeed);
int punishIndex = 0; int punishIndex = 0;
for (int i = 0; i < lineCount; i++) { for (int i = 0; i < lineCount; i++) {
setCurrentPiece(0, -1, 0); setCurrentPiece(0, -1, 0);
punishIndex = rand() % width; punishIndex = qrand() % width;
mpField->addPunishLine(lineCount, punishIndex); mpField->addPunishLine(lineCount, punishIndex);
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "KBlocksWin.h" #include "KBlocksWin.h"
#include <limits.h> #include <limits.h>
#include <stdlib.h>
#include <KConfigDialog> #include <KConfigDialog>
#include <kstandardgameaction.h> #include <kstandardgameaction.h>
...@@ -24,6 +23,7 @@ ...@@ -24,6 +23,7 @@
#include <QStatusBar> #include <QStatusBar>
#include <KgDifficulty> #include <KgDifficulty>
#include <QtGlobal>
#include <QPixmapCache> #include <QPixmapCache>
#include <QPointer> #include <QPointer>
#include <QLabel> #include <QLabel>
...@@ -103,8 +103,8 @@ void KBlocksWin::addScore(int gameIndex, int lineCount) ...@@ -103,8 +103,8 @@ void KBlocksWin::addScore(int gameIndex, int lineCount)
void KBlocksWin::startGame() void KBlocksWin::startGame()
{ {
srand(time(0)); qsrand(time(0));
mpGameLogic->setGameSeed(rand()); mpGameLogic->setGameSeed(qrand());
if (mpGameLogic->startGame(mGameCount)) { if (mpGameLogic->startGame(mGameCount)) {
mpPlayManager->startGame(); mpPlayManager->startGame();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment