File indexing completed on 2024-04-21 04:02:08
0001 /*************************************************************************** 0002 * KBlocks, a falling blocks game by KDE * 0003 * SPDX-FileCopyrightText: 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> * 0004 * * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 ***************************************************************************/ 0007 #include "KBlocksPieceGenerator.h" 0008 0009 #include <QRandomGenerator> 0010 #include <stdio.h> 0011 0012 #include "KBlocksPiece.h" 0013 0014 KBlocksPieceGenerator::KBlocksPieceGenerator(int size) 0015 { 0016 maxCapacity = size; 0017 pieceIndex = 0; 0018 maPieceList = new int[maxCapacity]; 0019 } 0020 0021 KBlocksPieceGenerator::~KBlocksPieceGenerator() 0022 { 0023 delete [] maPieceList; 0024 } 0025 0026 void KBlocksPieceGenerator::genList(int seed) 0027 { 0028 QRandomGenerator randomGenerator(seed); 0029 for (int i = 0; i < maxCapacity; i++) { 0030 maPieceList[i] = randomGenerator.bounded(PieceType_Detail_Max_Count); 0031 } 0032 0033 pieceIndex = 0; 0034 } 0035 0036 int KBlocksPieceGenerator::getPiece() 0037 { 0038 pieceIndex++; 0039 0040 if (pieceIndex > maxCapacity) { 0041 pieceIndex = 0; 0042 genList(maPieceList[0]); 0043 } 0044 0045 return maPieceList[pieceIndex]; 0046 } 0047 0048 int KBlocksPieceGenerator::getIndex() 0049 { 0050 return pieceIndex; 0051 } 0052