1 | /*************************************************************************** |
---|---|
2 | * KBlocks, a falling blocks game for KDE * |
3 | * Copyright (C) 2010 Zhongjie Cai <squall.leonhart.cai@gmail.com> * |
4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * |
7 | * the Free Software Foundation; either version 2 of the License, or * |
8 | * (at your option) any later version. * |
9 | ***************************************************************************/ |
10 | #include "KBlocksPlayManager.h" |
11 | |
12 | KBlocksPlayManager::KBlocksPlayManager(GameLogicInterface * p, int capacity) |
13 | { |
14 | mpGameLogic = p; |
15 | |
16 | mPlayerCount = 0; |
17 | mMaxCapacity = capacity; |
18 | |
19 | maPlayerList = new KBlocksSinglePlayer*[mMaxCapacity]; |
20 | } |
21 | |
22 | KBlocksPlayManager::~KBlocksPlayManager() |
23 | { |
24 | delete [] maPlayerList; |
25 | } |
26 | |
27 | bool KBlocksPlayManager::addGamePlayer(GamePlayerInterface * p, int thinkInterval, int processInterval) |
28 | { |
29 | if (mPlayerCount == mMaxCapacity) |
30 | { |
31 | return false; |
32 | } |
33 | maPlayerList[mPlayerCount] = new KBlocksSinglePlayer(p, thinkInterval, processInterval); |
34 | mPlayerCount++; |
35 | return true; |
36 | } |
37 | |
38 | void KBlocksPlayManager::clearGamePlayer() |
39 | { |
40 | for(int i = 0; i < mPlayerCount; i++) |
41 | { |
42 | delete maPlayerList[i]; |
43 | maPlayerList[i] = 0; |
44 | } |
45 | mPlayerCount = 0; |
46 | } |
47 | |
48 | void KBlocksPlayManager::startGame() |
49 | { |
50 | for(int i = 0; i < mPlayerCount; i++) |
51 | { |
52 | maPlayerList[i]->startGame(mpGameLogic->getSingleGame(i)); |
53 | } |
54 | } |
55 | |
56 | void KBlocksPlayManager::stopGame() |
57 | { |
58 | for(int i = 0; i < mPlayerCount; i++) |
59 | { |
60 | maPlayerList[i]->stopGame(); |
61 | } |
62 | } |
63 | |
64 | void KBlocksPlayManager::pauseGame(bool flag) |
65 | { |
66 | for(int i = 0; i < mPlayerCount; i++) |
67 | { |
68 | maPlayerList[i]->pauseGame(flag); |
69 | } |
70 | } |
71 |