blob: c0828f1e2b0d183ea168fc6d9a6be9a8c67b2d57 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
#include "mp_simple_board.h"
#include "mp_simple_board.moc"
void MPSimpleBoard::init(bool AI, bool multiplayers, bool server, bool first,
const TQString &name)
{
state = BS_Init;
_init(AI, multiplayers, server, first, name);
}
void MPSimpleBoard::dataIn(TQDataStream &s)
{
if ( s.atEnd() ) return; // no data
IO_Flag f;
s >> f;
switch ( f.value() ) {
case IO_Flag::Init: initFlag(s); break;
case IO_Flag::Play: playFlag(s); break;
case IO_Flag::Pause: pauseFlag(); break;
case IO_Flag::GameOver: gameOverFlag(); break;
case IO_Flag::Stop: stopFlag(); break;
}
}
void MPSimpleBoard::initFlag(TQDataStream &s)
{
state = BS_Play;
emit enableKeys(true);
_initFlag(s);
}
void MPSimpleBoard::playFlag(TQDataStream &s)
{
Q_ASSERT( state==BS_Play );
_playFlag(s);
}
void MPSimpleBoard::pauseFlag()
{
Q_ASSERT( state==BS_Play || state==BS_Pause );
bool p = ( state==BS_Pause );
state = (p ? BS_Play : BS_Pause);
emit enableKeys(p);
_pauseFlag(!p);
}
void MPSimpleBoard::gameOverFlag()
{
Q_ASSERT( BS_Play );
_stop(TRUE);
state = BS_Stop;
}
void MPSimpleBoard::stopFlag()
{
_stop(FALSE);
state = BS_Standby;
}
void MPSimpleBoard::_stop(bool gameover)
{
if ( state==BS_Pause ) _pauseFlag(FALSE);
emit enableKeys(false);
_stopFlag(gameover);
}
void MPSimpleBoard::dataOut(TQDataStream &s)
{
switch (state) {
case BS_Init:
_initDataOut(s);
state = BS_Standby;
return;
case BS_Play: _dataOut(s); return;
case BS_Stop:
_gameOverDataOut(s);
state = BS_Standby;
return;
case BS_Pause: return;
case BS_Standby: return;
}
}
|