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 "KBlocksPlayManager.h"
0008 
0009 KBlocksPlayManager::KBlocksPlayManager(GameLogicInterface *p, int capacity)
0010 {
0011     mpGameLogic = p;
0012 
0013     mPlayerCount = 0;
0014     mMaxCapacity = capacity;
0015 
0016     maPlayerList = new KBlocksSinglePlayer*[mMaxCapacity];
0017 }
0018 
0019 KBlocksPlayManager::~KBlocksPlayManager()
0020 {
0021     delete [] maPlayerList;
0022 }
0023 
0024 bool KBlocksPlayManager::addGamePlayer(GamePlayerInterface *p, int thinkInterval, int processInterval)
0025 {
0026     if (mPlayerCount == mMaxCapacity) {
0027         return false;
0028     }
0029     maPlayerList[mPlayerCount] = new KBlocksSinglePlayer(p, thinkInterval, processInterval);
0030     mPlayerCount++;
0031     return true;
0032 }
0033 
0034 void KBlocksPlayManager::clearGamePlayer()
0035 {
0036     for (int i = 0; i < mPlayerCount; i++) {
0037         delete maPlayerList[i];
0038         maPlayerList[i] = nullptr;
0039     }
0040     mPlayerCount = 0;
0041 }
0042 
0043 void KBlocksPlayManager::startGame()
0044 {
0045     for (int i = 0; i < mPlayerCount; i++) {
0046         maPlayerList[i]->startGame(mpGameLogic->getSingleGame(i));
0047     }
0048 }
0049 
0050 void KBlocksPlayManager::stopGame()
0051 {
0052     for (int i = 0; i < mPlayerCount; i++) {
0053         maPlayerList[i]->stopGame();
0054     }
0055 }
0056 
0057 void KBlocksPlayManager::pauseGame(bool flag)
0058 {
0059     for (int i = 0; i < mPlayerCount; i++) {
0060         maPlayerList[i]->pauseGame(flag);
0061     }
0062 }