git repos / blockattack-game

blame: source/code/BlockGame.hpp

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
7ac8aa4b sago007 2016-02-22 19:25 20
http://www.blockattack.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
c53e6443 sago007 2012-04-17 11:04 22
*/
89c4a3a6 sago007 2008-08-29 14:32 23
17916a2e sago007 2010-11-07 11:26 24
#ifndef BLOCKGAME_HPP
17916a2e sago007 2010-11-07 11:26 25
#define BLOCKGAME_HPP 1
17916a2e sago007 2010-11-07 11:26 26
32c9b349 sago007 2008-11-20 18:14 27
#include "stats.h"
32c9b349 sago007 2008-11-20 18:14 28
#include "common.h"
4a6d425b sago007 2016-06-05 16:23 29
#include <deque>
4a6d425b sago007 2016-06-05 16:23 30
#include "cereal/cereal.hpp"
4a6d425b sago007 2016-06-05 16:23 31
#include "cereal/types/deque.hpp"
4a6d425b sago007 2016-06-05 16:23 32
#include "cereal/types/string.hpp"
17916a2e sago007 2010-11-07 11:26 33
17916a2e sago007 2010-11-07 11:26 34
#define NUMBEROFCHAINS 100
69862ef6 sago007 2015-08-22 17:24 35
#define BLOCKWAIT 100000
69862ef6 sago007 2015-08-22 17:24 36
#define BLOCKHANG 1000
32c9b349 sago007 2008-11-20 18:14 37
a1072daf sago007 2016-02-20 12:47 38
enum stageButton {SBdontShow, SBstageClear, SBpuzzleMode};
a1072daf sago007 2016-02-20 12:47 39
a1072daf sago007 2016-02-20 12:47 40
extern stageButton stageButtonStatus;
a1072daf sago007 2016-02-20 12:47 41
a1072daf sago007 2016-02-20 12:47 42
//This is the size of the blocks. They are always 50. The internal logic calculates it that way
a1072daf sago007 2016-02-20 12:47 43
const int bsize = 50;
a1072daf sago007 2016-02-20 12:47 44
5159dd90 sago007 2016-02-21 15:50 45
/**
5159dd90 sago007 2016-02-21 15:50 46
 * This struct defines the start conditions of the game
5159dd90 sago007 2016-02-21 15:50 47
 */
5159dd90 sago007 2016-02-21 15:50 48
struct BlockGameStartInfo {
5159dd90 sago007 2016-02-21 15:50 49
	unsigned int ticks = 0;
5159dd90 sago007 2016-02-21 15:50 50
	bool timeTrial = false;
b256fda5 sago007 2016-02-21 16:21 51
	///True means a stage clear game will be started. level must be set too.
b1fe2ae5 sago007 2016-02-21 16:01 52
	bool stageClear = false;
b256fda5 sago007 2016-02-21 16:21 53
	///True if puzzle mode. level must be set too.
b256fda5 sago007 2016-02-21 16:21 54
	bool puzzleMode = false;
83e4f8fe sago007 2016-02-22 19:22 55
	///Single puzzle is used for the editor only.
83e4f8fe sago007 2016-02-22 19:22 56
	bool singlePuzzle = false;
b1fe2ae5 sago007 2016-02-21 16:01 57
	int level = 0;
1e5aff60 sago007 2016-02-21 18:23 58
	bool AI = false;
ae5fb2bb sago007 2016-03-22 18:00 59
	/**
ae5fb2bb sago007 2016-03-22 18:00 60
	 * True means that stats will be recorded.
66e1a55c Poul Sander 2018-12-23 16:25 61
	 * If AI is true then this will be overruled to false
ae5fb2bb sago007 2016-03-22 18:00 62
	 */
50cf6485 sago007 2016-03-21 19:11 63
	bool recordStats = true;
1e5aff60 sago007 2016-02-21 18:23 64
	bool vsMode = false;
ae5fb2bb sago007 2016-03-22 18:00 65
	/**
ae5fb2bb sago007 2016-03-22 18:00 66
	 * Set to true if we are fighting an AI. level should be the AI level we are fighting
ae5fb2bb sago007 2016-03-22 18:00 67
	 */
ae5fb2bb sago007 2016-03-22 18:00 68
	bool vsAI = false;
917dac61 sago007 2016-02-21 20:01 69
	int startBlocks = -1;
3e7b8813 sago007 2016-02-22 19:45 70
	int handicap = 0;
3e7b8813 sago007 2016-02-22 19:45 71
	int gameSpeed = 0;
b76e0075 Poul Sander 2024-03-31 20:09 72
	int basicBlockVariants = 6;
4a6d425b sago007 2016-06-05 16:23 73
	template <class Archive>
5d601060 Poul Sander 2023-10-26 21:00 74
	void serialize( Archive& ar ) {
66e1a55c Poul Sander 2018-12-23 16:25 75
		ar( CEREAL_NVP(ticks), CEREAL_NVP(timeTrial), CEREAL_NVP(stageClear), CEREAL_NVP(puzzleMode), CEREAL_NVP(singlePuzzle),
5d601060 Poul Sander 2023-10-26 21:00 76
		    CEREAL_NVP(level), CEREAL_NVP(AI), CEREAL_NVP(recordStats), CEREAL_NVP(vsMode), CEREAL_NVP(vsAI),
b76e0075 Poul Sander 2024-03-31 20:09 77
		    CEREAL_NVP(startBlocks), CEREAL_NVP(handicap), CEREAL_NVP(gameSpeed), CEREAL_NVP(basicBlockVariants) );
4a6d425b sago007 2016-06-05 16:23 78
	}
1e5aff60 sago007 2016-02-21 18:23 79
};
1e5aff60 sago007 2016-02-21 18:23 80
1e5aff60 sago007 2016-02-21 18:23 81
struct GarbageStruct {
1e5aff60 sago007 2016-02-21 18:23 82
	bool greyGarbage = false;
3d12f4a8 sago007 2016-03-21 18:40 83
	int width = 0;
3d12f4a8 sago007 2016-03-21 18:40 84
	int height = 0;
3d12f4a8 sago007 2016-03-21 18:40 85
	void setGarbage(int w, int h, bool g = false) {
3d12f4a8 sago007 2016-03-21 18:40 86
		greyGarbage = g;
3d12f4a8 sago007 2016-03-21 18:40 87
		width = w;
3d12f4a8 sago007 2016-03-21 18:40 88
		height = h;
3d12f4a8 sago007 2016-03-21 18:40 89
	}
4a6d425b sago007 2016-06-05 16:23 90
	template <class Archive>
5d601060 Poul Sander 2023-10-26 21:00 91
	void serialize( Archive& ar ) {
4a6d425b sago007 2016-06-05 16:23 92
		ar( CEREAL_NVP(greyGarbage), CEREAL_NVP(width), CEREAL_NVP(height) );
4a6d425b sago007 2016-06-05 16:23 93
	}
5159dd90 sago007 2016-02-21 15:50 94
};
5159dd90 sago007 2016-02-21 15:50 95
4fb2e351 sago007 2016-05-19 19:27 96
struct BlockGameAction {
167c2a1d sago007 2016-06-05 12:45 97
	enum class Action {NONE, UPDATE, SET_DRAW, SET_WON, SET_GAME_OVER, MOVE, SWITCH, PUSH, PUSH_GARBAGE, MOUSE_DOWN, MOUSE_UP, MOUSE_MOVE};
62b3f619 sago007 2016-05-20 07:01 98
	Action action = Action::NONE;
e5a23912 sago007 2016-06-04 10:52 99
	unsigned int tick = 0;  //< Used for update
e5a23912 sago007 2016-06-04 10:52 100
	char way = '\0';  //< The direction to move the cursor: 'N', 'E', 'S' or 'W'
167c2a1d sago007 2016-06-05 12:45 101
	int x = 0;
167c2a1d sago007 2016-06-05 12:45 102
	int y = 0;
8d5e5953 sago007 2016-06-04 13:15 103
	std::vector<GarbageStruct> garbage;
4a6d425b sago007 2016-06-05 16:23 104
	template <class Archive>
5d601060 Poul Sander 2023-10-26 21:00 105
	void serialize( Archive& ar ) {
4a6d425b sago007 2016-06-05 16:23 106
		ar( CEREAL_NVP(action), CEREAL_NVP(tick), CEREAL_NVP(way), CEREAL_NVP(x), CEREAL_NVP(y), CEREAL_NVP(garbage) );
4a6d425b sago007 2016-06-05 16:23 107
	}
4a6d425b sago007 2016-06-05 16:23 108
};
4a6d425b sago007 2016-06-05 16:23 109
1fd8156c sago007 2016-06-07 16:41 110
struct BlockGameInfoExtra {
1fd8156c sago007 2016-06-07 16:41 111
	std::string name;
1fd8156c sago007 2016-06-07 16:41 112
	int score = 0;
1fd8156c sago007 2016-06-07 16:41 113
	int seconds = 0;
1fd8156c sago007 2016-06-07 16:41 114
	template <class Archive>
5d601060 Poul Sander 2023-10-26 21:00 115
	void serialize( Archive& ar ) {
1fd8156c sago007 2016-06-07 16:41 116
		ar( CEREAL_NVP(name), CEREAL_NVP(score), CEREAL_NVP(seconds) );
1fd8156c sago007 2016-06-07 16:41 117
	}
1fd8156c sago007 2016-06-07 16:41 118
};
1fd8156c sago007 2016-06-07 16:41 119
4a6d425b sago007 2016-06-05 16:23 120
struct BlockGameInfo {
4a6d425b sago007 2016-06-05 16:23 121
	BlockGameStartInfo startInfo;
4a6d425b sago007 2016-06-05 16:23 122
	std::deque<BlockGameAction> actions;
1fd8156c sago007 2016-06-07 16:41 123
	BlockGameInfoExtra extra;
4a6d425b sago007 2016-06-05 16:23 124
	template <class Archive>
5d601060 Poul Sander 2023-10-26 21:00 125
	void serialize( Archive& ar ) {
1fd8156c sago007 2016-06-07 16:41 126
		ar( CEREAL_NVP(startInfo), CEREAL_NVP(actions), CEREAL_NVP(extra) );
4a6d425b sago007 2016-06-05 16:23 127
	}
4fb2e351 sago007 2016-05-19 19:27 128
};
4fb2e351 sago007 2016-05-19 19:27 129
89c4a3a6 sago007 2008-08-29 14:32 130
////////////////////////////////////////////////////////////////////////////////
89c4a3a6 sago007 2008-08-29 14:32 131
//The BloackGame class represents a board, score, time etc. for a single player/
89c4a3a6 sago007 2008-08-29 14:32 132
////////////////////////////////////////////////////////////////////////////////
5d601060 Poul Sander 2023-10-26 21:00 133
class BlockGame {
89c4a3a6 sago007 2008-08-29 14:32 134
private:
87a0a1db sago007 2016-04-16 13:11 135
	int prevTowerHeight = 0;
87a0a1db sago007 2016-04-16 13:11 136
	bool bGarbageFallLeft = false;
a1072daf sago007 2016-02-20 12:47 137
	bool singlePuzzle = false;
89c4a3a6 sago007 2008-08-29 14:32 138
87a0a1db sago007 2016-04-16 13:11 139
	int nextGarbageNumber = 0;
87a0a1db sago007 2016-04-16 13:11 140
	int pushedPixelAt = 0;
87a0a1db sago007 2016-04-16 13:11 141
	int nrPushedPixel = 0;
87a0a1db sago007 2016-04-16 13:11 142
	int nrFellDown = 0;
87a0a1db sago007 2016-04-16 13:11 143
	unsigned int nrStops = 0;
7013ad1a sago007 2018-03-25 09:55 144
	bool garbageToBeCleared[7][30] = {};
87a0a1db sago007 2016-04-16 13:11 145
	unsigned int lastAImove = 0;
89c4a3a6 sago007 2008-08-29 14:32 146
87a0a1db sago007 2016-04-16 13:11 147
	int AI_LineOffset = 0; //how many lines have changed since command
87a0a1db sago007 2016-04-16 13:11 148
	int hangTicks = 0;    //How many times have hang been decreased?
c53e6443 sago007 2012-04-17 11:04 149
	//int the two following index 0 may NOT be used (what the fuck did I meen?)
5d601060 Poul Sander 2023-10-26 21:00 150
	int chainSize[NUMBEROFCHAINS] {}; //Contains the chains
5d601060 Poul Sander 2023-10-26 21:00 151
	bool chainUsed[NUMBEROFCHAINS] {};  //True if the chain is used
89c4a3a6 sago007 2008-08-29 14:32 152
87a0a1db sago007 2016-04-16 13:11 153
	unsigned int nextRandomNumber = 0;
87a0a1db sago007 2016-04-16 13:11 154
	int Level = 0; //Only used in stageClear and puzzle (not implemented)
89c4a3a6 sago007 2008-08-29 14:32 155
4a6d425b sago007 2016-06-05 16:23 156
	BlockGameInfo replayInfo;
66e1a55c Poul Sander 2018-12-23 16:25 157
63c773dd sago007 2016-01-24 11:47 158
	int rand2();
c53e6443 sago007 2012-04-17 11:04 159
	int firstUnusedChain();
89c4a3a6 sago007 2008-08-29 14:32 160
6b1dc7a6 sago007 2010-11-08 21:03 161
protected:
c98e567e sago007 2016-03-25 09:39 162
	int lastCounter = 0;
63c773dd sago007 2016-01-24 11:47 163
	std::string strHolder;
c98e567e sago007 2016-03-25 09:39 164
	bool bDraw = false;
c98e567e sago007 2016-03-25 09:39 165
	unsigned int ticks = 0;
c98e567e sago007 2016-03-25 09:39 166
	unsigned int gameStartedAt = 0;
5d601060 Poul Sander 2023-10-26 21:00 167
	unsigned int gameEndedAfter = 0;        //How long did the game last?
c98e567e sago007 2016-03-25 09:39 168
	int linesCleared = 0;
c98e567e sago007 2016-03-25 09:39 169
	int TowerHeight = 0;
63c773dd sago007 2016-01-24 11:47 170
	int board[7][30];
c98e567e sago007 2016-03-25 09:39 171
	int stop = 0;
c98e567e sago007 2016-03-25 09:39 172
	int speedLevel = 0;
c98e567e sago007 2016-03-25 09:39 173
	int pixels = 0;
c98e567e sago007 2016-03-25 09:39 174
	int MovesLeft = 0;
c98e567e sago007 2016-03-25 09:39 175
	bool timetrial = false;
c98e567e sago007 2016-03-25 09:39 176
	bool stageClear = false;
c98e567e sago007 2016-03-25 09:39 177
	bool vsMode = false;
c98e567e sago007 2016-03-25 09:39 178
	bool puzzleMode = false;
c98e567e sago007 2016-03-25 09:39 179
	int stageClearLimit = 0; //stores number of lines user must clear to win
c98e567e sago007 2016-03-25 09:39 180
	int combo = 0;
c98e567e sago007 2016-03-25 09:39 181
	int chain = 0;
87a0a1db sago007 2016-04-16 13:11 182
	int cursorx = 2; //stores cursor position
87a0a1db sago007 2016-04-16 13:11 183
	int cursory = 3; // -||-
d0c62e33 sago007 2016-04-02 15:18 184
	int mouse_cursorx = -1;  //Stores the mouse hold cursor. -1 if nothing is selected.
d0c62e33 sago007 2016-04-02 15:18 185
	int mouse_cursory = -1;
c98e567e sago007 2016-03-25 09:39 186
	double speed = 0.0;
c98e567e sago007 2016-03-25 09:39 187
	double baseSpeed = 0.0; //factor for speed. Lower value = faster gameplay
c98e567e sago007 2016-03-25 09:39 188
	int score = 0;
c98e567e sago007 2016-03-25 09:39 189
	bool bGameOver = false;
c98e567e sago007 2016-03-25 09:39 190
	bool hasWonTheGame = false;
c98e567e sago007 2016-03-25 09:39 191
	int AI_MoveSpeed = 0;   //How often will the computer move? milliseconds
c98e567e sago007 2016-03-25 09:39 192
	bool AI_Enabled = false;
50cf6485 sago007 2016-03-21 19:11 193
	bool recordStats = true;
ae5fb2bb sago007 2016-03-22 18:00 194
	bool vsAI = false;  //Set to true for single player vs
c53e6443 sago007 2012-04-17 11:04 195
c98e567e sago007 2016-03-25 09:39 196
	int handicap = 0;
66e1a55c Poul Sander 2018-12-23 16:25 197
4ce4646e Poul Sander 2024-03-27 17:45 198
	// Number of different basic blocks. Default is 6. Easy mde is limited t 5.
4ce4646e Poul Sander 2024-03-27 17:45 199
	int basicBlockVariants = 6;
4ce4646e Poul Sander 2024-03-27 17:45 200
3d12f4a8 sago007 2016-03-21 18:40 201
	std::vector<GarbageStruct> garbageSendQueue;
c53e6443 sago007 2012-04-17 11:04 202
c98e567e sago007 2016-03-25 09:39 203
	int AIlineToClear = 0;
c53e6443 sago007 2012-04-17 11:04 204
c98e567e sago007 2016-03-25 09:39 205
	short AIstatus = 0;   //Status flags:
c53e6443 sago007 2012-04-17 11:04 206
	//0: nothing, 2: clear tower, 3: clear horisontal, 4: clear vertical
c53e6443 sago007 2012-04-17 11:04 207
	//1: make more lines, 5: make 2 lines, 6: make 1 line
6b1dc7a6 sago007 2010-11-08 21:03 208
e1290bdf sago007 2010-10-25 19:56 209
public:
c53e6443 sago007 2012-04-17 11:04 210
8f632c05 sago007 2015-08-22 16:21 211
	std::string name;
c53e6443 sago007 2012-04-17 11:04 212
0f031889 sago007 2012-05-01 19:57 213
public:
c53e6443 sago007 2012-04-17 11:04 214
	BlockGame();
87ac12e9 sago007 2016-04-09 18:47 215
	virtual ~BlockGame() = default;
c53e6443 sago007 2012-04-17 11:04 216
63c773dd sago007 2016-01-24 11:47 217
	int getAIlevel()  const;
66e1a55c Poul Sander 2018-12-23 16:25 218
3f3ff0b6 sago007 2018-03-30 12:59 219
	virtual void AddText(int, int, unsigned int, int) const  {}
f7c1a51d Poul Sander 2016-09-07 21:12 220
	virtual void AddBall(int, int, bool, int) const  {}
f7c1a51d Poul Sander 2016-09-07 21:12 221
	virtual void AddExplosion(int, int) const  {}
313ecd1b sago007 2015-08-22 20:38 222
	virtual void PlayerWonEvent() const  {}
027b5cfd sago007 2015-08-23 14:27 223
	virtual void DrawEvent() const {}
313ecd1b sago007 2015-08-22 20:38 224
	virtual void BlockPopEvent() const  {}
313ecd1b sago007 2015-08-22 20:38 225
	virtual void LongChainDoneEvent() const  {}
313ecd1b sago007 2015-08-22 20:38 226
	virtual void TimeTrialEndEvent() const  {}
313ecd1b sago007 2015-08-22 20:38 227
	virtual void EndlessHighscoreEvent() const  {}
66e1a55c Poul Sander 2018-12-23 16:25 228
5d601060 Poul Sander 2023-10-26 21:00 229
	void NewGame(const BlockGameStartInfo& s);
4fb2e351 sago007 2016-05-19 19:27 230
	void DoAction (const BlockGameAction& action);
8d5e5953 sago007 2016-06-04 13:15 231
	/**
8d5e5953 sago007 2016-06-04 13:15 232
	 * This function returns all the garbage.
8d5e5953 sago007 2016-06-04 13:15 233
	 * This is actual const in the way that it does not change the games state
8d5e5953 sago007 2016-06-04 13:15 234
	 * Technically it is not const because it empties the queue that are stored inside the object even if not part of the game state.
8d5e5953 sago007 2016-06-04 13:15 235
	 * @param poppedData
8d5e5953 sago007 2016-06-04 13:15 236
	 */
8d5e5953 sago007 2016-06-04 13:15 237
	void PopSendGarbage(std::vector<GarbageStruct>& poppedData);
66e1a55c Poul Sander 2018-12-23 16:25 238
027b5cfd sago007 2015-08-23 14:27 239
	int GetScore() const;
027b5cfd sago007 2015-08-23 14:27 240
	int GetHandicap() const;
027b5cfd sago007 2015-08-23 14:27 241
	bool isGameOver() const;
63c773dd sago007 2016-01-24 11:47 242
	int GetGameStartedAt() const;
63c773dd sago007 2016-01-24 11:47 243
	int GetGameEndedAt() const;
027b5cfd sago007 2015-08-23 14:27 244
	bool isTimeTrial() const;
027b5cfd sago007 2015-08-23 14:27 245
	bool isStageClear() const;
027b5cfd sago007 2015-08-23 14:27 246
	bool isVsMode() const;
027b5cfd sago007 2015-08-23 14:27 247
	bool isPuzzleMode() const;
027b5cfd sago007 2015-08-23 14:27 248
	int GetLinesCleared() const;
027b5cfd sago007 2015-08-23 14:27 249
	int GetStageClearLimit() const;
027b5cfd sago007 2015-08-23 14:27 250
	int GetChains() const;
027b5cfd sago007 2015-08-23 14:27 251
	int GetPixels() const;
027b5cfd sago007 2015-08-23 14:27 252
	int GetSpeedLevel() const;
027b5cfd sago007 2015-08-23 14:27 253
	int GetTowerHeight() const;
027b5cfd sago007 2015-08-23 14:27 254
	int GetCursorX() const;
027b5cfd sago007 2015-08-23 14:27 255
	int GetCursorY() const;
5d601060 Poul Sander 2023-10-26 21:00 256
	void GetMouseCursor(bool& pressed, int& x, int& y) const;
027b5cfd sago007 2015-08-23 14:27 257
	bool GetIsWinner() const;
47fef8e8 sago007 2016-11-24 21:37 258
	bool isSinglePuzzle() const;
47fef8e8 sago007 2016-11-24 21:37 259
	int getLevel() const;
3e7b8813 sago007 2016-02-22 19:45 260
	bool GetAIenabled() const;
3e7b8813 sago007 2016-02-22 19:45 261
	bool IsNearDeath() const;
5d601060 Poul Sander 2023-10-26 21:00 262
	double GetBaseSpeed() const {
5d601060 Poul Sander 2023-10-26 21:00 263
		return baseSpeed;
5d601060 Poul Sander 2023-10-26 21:00 264
	}
4ce4646e Poul Sander 2024-03-27 17:45 265
	int GetBasicBlockVariants() const {
4ce4646e Poul Sander 2024-03-27 17:45 266
		return basicBlockVariants;
4ce4646e Poul Sander 2024-03-27 17:45 267
	}
4a6d425b sago007 2016-06-05 16:23 268
	const BlockGameInfo& GetBlockGameInfo() {
4a6d425b sago007 2016-06-05 16:23 269
		return replayInfo;
4a6d425b sago007 2016-06-05 16:23 270
	}
10a4aa95 Poul Sander 2023-10-31 20:39 271
	void putSampleBlocks();
e1290bdf sago007 2010-10-25 19:56 272
private:
4379ec19 Poul Sander 2019-01-30 18:27 273
	void NewGameInternal(unsigned int ticks);
c53e6443 sago007 2012-04-17 11:04 274
	//Test if LineNr is an empty line, returns false otherwise.
ca486238 sago007 2015-08-23 15:12 275
	bool LineEmpty(int lineNr) const;
c53e6443 sago007 2012-04-17 11:04 276
	//Test if the entire board is empty (used for Puzzles)
ca486238 sago007 2015-08-23 15:12 277
	bool BoardEmpty() const;
c53e6443 sago007 2012-04-17 11:04 278
	//Anything that the user can't move? In that case Game Over cannot occur
ca486238 sago007 2015-08-23 15:12 279
	bool hasStaticContent() const;
c53e6443 sago007 2012-04-17 11:04 280
	void putStartBlocks();
917dac61 sago007 2016-02-21 20:01 281
	void putStartBlocks(int n);
c53e6443 sago007 2012-04-17 11:04 282
	//decreases hang for all hanging blocks and wait for waiting blocks
c53e6443 sago007 2012-04-17 11:04 283
	void ReduceStuff();
3e7b8813 sago007 2016-02-22 19:45 284
	void setGameSpeed(int globalSpeedLevel);
3e7b8813 sago007 2016-02-22 19:45 285
	void setHandicap(int globalHandicap);
c53e6443 sago007 2012-04-17 11:04 286
	//Clears garbage, must take one the lower left corner!
c53e6443 sago007 2012-04-17 11:04 287
	int GarbageClearer(int x, int y, int number, bool aLineToClear, int chain);
c53e6443 sago007 2012-04-17 11:04 288
	//Marks garbage that must be cleared
c53e6443 sago007 2012-04-17 11:04 289
	int GarbageMarker(int x, int y);
c53e6443 sago007 2012-04-17 11:04 290
	int FirstGarbageMarker(int x, int y);
c53e6443 sago007 2012-04-17 11:04 291
	//Clear Blocks if 3 or more is alligned (naive implemented)
c53e6443 sago007 2012-04-17 11:04 292
	void ClearBlocks();
c53e6443 sago007 2012-04-17 11:04 293
	//Moves all peaces a spot down if possible
c53e6443 sago007 2012-04-17 11:04 294
	int FallBlock(int x, int y, int number);
c53e6443 sago007 2012-04-17 11:04 295
	//Makes all Garbage fall one spot
c53e6443 sago007 2012-04-17 11:04 296
	void GarbageFall();
c53e6443 sago007 2012-04-17 11:04 297
	//Makes the blocks fall (it doesn't test time, this must be done before hand)
c53e6443 sago007 2012-04-17 11:04 298
	void FallDown();
c53e6443 sago007 2012-04-17 11:04 299
	//Pushes a single pixel, so it appears to scrool
c53e6443 sago007 2012-04-17 11:04 300
	void PushPixels();
c53e6443 sago007 2012-04-17 11:04 301
	//See how high the tower is, saved in integer TowerHeight
c53e6443 sago007 2012-04-17 11:04 302
	void FindTowerHeight();
c9226e8d sago007 2016-06-04 10:17 303
	//Generates a new line and moves the field one block up (restart puzzle mode)
c9226e8d sago007 2016-06-04 10:17 304
	void PushLine();
b58caa17 sago007 2016-06-04 10:32 305
	//prints "Game Over" and ends game
b58caa17 sago007 2016-06-04 10:32 306
	void SetGameOver();
b58caa17 sago007 2016-06-04 10:32 307
	//Moves the cursor, receaves N,S,E or W as a char an moves as desired
b58caa17 sago007 2016-06-04 10:32 308
	void MoveCursor(char way);
b58caa17 sago007 2016-06-04 10:32 309
	//switches the two blocks at the cursor position, unless game over
b58caa17 sago007 2016-06-04 10:32 310
	void SwitchAtCursor();
8d5e5953 sago007 2016-06-04 13:15 311
	//Creates garbage using a given wide and height
8d5e5953 sago007 2016-06-04 13:15 312
	bool CreateGarbage(int wide, int height);
8d5e5953 sago007 2016-06-04 13:15 313
	//Creates garbage using a given wide and height
8d5e5953 sago007 2016-06-04 13:15 314
	bool CreateGreyGarbage();
66e1a55c Poul Sander 2018-12-23 16:25 315
	void MouseDown(int x, int y);  //Send then the mouse is pressed
167c2a1d sago007 2016-06-05 12:45 316
	void MouseMove(int x);  //Send then the mouse moves
167c2a1d sago007 2016-06-05 12:45 317
	void MouseUp();  //Send then the mouse goes up
2488b1f5 sago007 2016-06-05 13:38 318
	void MoveCursorTo(int x, int y);
1fd8156c sago007 2016-06-07 16:41 319
	void FinalizeBlockGameInfo();
89c4a3a6 sago007 2008-08-29 14:32 320
///////////////////////////////////////////////////////////////////////////
89c4a3a6 sago007 2008-08-29 14:32 321
/////////////////////////// AI starts here! ///////////////////////////////
89c4a3a6 sago007 2008-08-29 14:32 322
///////////////////////////////////////////////////////////////////////////
c53e6443 sago007 2012-04-17 11:04 323
	//First the helpet functions:
c53e6443 sago007 2012-04-17 11:04 324
	int nrOfType(int line, int type);
ca31a27a sago007 2016-04-16 21:29 325
	int AIcolorToClear = 0;
c53e6443 sago007 2012-04-17 11:04 326
	//See if a combo can be made in this line
c53e6443 sago007 2012-04-17 11:04 327
	int horiInLine(int line);
c53e6443 sago007 2012-04-17 11:04 328
	bool horiClearPossible();
c53e6443 sago007 2012-04-17 11:04 329
	//the Line Has Unmoveable Objects witch might stall the AI
c53e6443 sago007 2012-04-17 11:04 330
	bool lineHasGarbage(int line);
c53e6443 sago007 2012-04-17 11:04 331
	//Types 0..6 in line
c53e6443 sago007 2012-04-17 11:04 332
	int nrOfRealTypes(int line);
c53e6443 sago007 2012-04-17 11:04 333
	//See if there is a tower
c53e6443 sago007 2012-04-17 11:04 334
	bool ThereIsATower();
c53e6443 sago007 2012-04-17 11:04 335
	double firstInLine1(int line);
c53e6443 sago007 2012-04-17 11:04 336
	//returns the first coordinate of the block of type
c53e6443 sago007 2012-04-17 11:04 337
	double firstInLine(int line, int type);
c53e6443 sago007 2012-04-17 11:04 338
	//There in the line shall we move
c53e6443 sago007 2012-04-17 11:04 339
	int closestTo(int line, int place);
c53e6443 sago007 2012-04-17 11:04 340
	//The AI will remove a tower
c53e6443 sago007 2012-04-17 11:04 341
	void AI_ClearTower();
c53e6443 sago007 2012-04-17 11:04 342
	//The AI will try to clear block horisontally
c53e6443 sago007 2012-04-17 11:04 343
	void AI_ClearHori();
c53e6443 sago007 2012-04-17 11:04 344
	//Test if vertical clear is possible
c53e6443 sago007 2012-04-17 11:04 345
	bool veriClearPossible();
c53e6443 sago007 2012-04-17 11:04 346
	//There in the line shall we move
c53e6443 sago007 2012-04-17 11:04 347
	int closestTo(int line, int type, int place);
c53e6443 sago007 2012-04-17 11:04 348
	//The AI will try to clear blocks vertically
c53e6443 sago007 2012-04-17 11:04 349
	void AI_ClearVertical();
ca31a27a sago007 2016-04-16 21:29 350
	bool firstLineCreated = 0;
c53e6443 sago007 2012-04-17 11:04 351
	void AI_Move();
52d3ef2e sago007 2016-03-22 19:30 352
//////////////////////////////////////////////////////////////////
52d3ef2e sago007 2016-03-22 19:30 353
///////////////////////////// AI ends here! //////////////////////
a1072daf sago007 2016-02-20 12:47 354
//////////////////////////////////////////////////////////////////
6d6b2788 sago007 2016-02-21 18:51 355
	//Set the move speed of the AI based on the aiLevel parameter
6d6b2788 sago007 2016-02-21 18:51 356
	void setAIlevel(int aiLevel);
79d3c1d3 sago007 2012-05-05 15:54 357
	void PushLineInternal();
07f5b3f3 sago007 2016-05-19 19:37 358
	//Prints "winner" and ends game
07f5b3f3 sago007 2016-05-19 19:37 359
	void setPlayerWon();
07f5b3f3 sago007 2016-05-19 19:37 360
	//Prints "draw" and ends the game
07f5b3f3 sago007 2016-05-19 19:37 361
	void setDraw();
c53e6443 sago007 2012-04-17 11:04 362
	//Updates evrything, if not called nothing happends
c53e6443 sago007 2012-04-17 11:04 363
	void Update();
80b830cd sago007 2012-08-19 17:51 364
	void UpdateInternal(unsigned int newtick);
17916a2e sago007 2010-11-07 11:26 365
};
fde1f2dd sago007 2016-02-21 15:24 366
c1785ec5 sago007 2016-02-21 16:07 367
//Play the next level
c1785ec5 sago007 2016-02-21 16:07 368
void nextLevel(BlockGame& g, unsigned int ticks);
fde1f2dd sago007 2016-02-21 15:24 369
//Replay the current level
fde1f2dd sago007 2016-02-21 15:24 370
void retryLevel(BlockGame& g, unsigned int ticks);
17916a2e sago007 2010-11-07 11:26 371
17916a2e sago007 2010-11-07 11:26 372
#endif
1970-01-01 00:00 373