28
28
connection::$debug = false;
29
29
error_reporting(E_ERROR);
32
define("GS_CREATED", 0); // newborn baby
33
define("GS_TRANSFER_SETTINGS", 7);
34
define("GS_CREATE_GRID", 10);
35
define("GS_CREATE_OBJECTS", 20);
36
define("GS_TRANSFER_OBJECTS", 30);
37
define("GS_CAMERA", 35);
38
define("GS_SYNCING", 40);
39
define("GS_SYNCING2", 41);
40
define("GS_SYNCING3", 42);
41
define("GS_PLAY", 50);
42
define("GS_DELETE_OBJECTS", 60);
43
define("GS_DELETE_GRID", 70);
44
define("GS_STATE_MAX", 80);
52
function __construct()
55
$this->state = GS_CREATED;
56
$this->stateNext = GS_TRANSFER_SETTINGS;
59
function SetState($act,$next)
64
function StateUpdate()
66
if($this->state == GS_CREATED)
67
$this->stateNext = GS_PLAY;
68
while($this->state != $this->stateNext)
73
print("Deleting grid...\n");
74
exit_game_objects(grid);
75
$this->SetState(GS_CREATE_GRID,GS_CREATE_OBJECTS);
80
print("Creating grid...\n");
81
$this->SetState(GS_CREATE_OBJECTS,GS_TRANSFER_OBJECTS);
84
case GS_TRANSFER_OBJECTS:
85
$this->SetState(GS_CAMERA,GS_SYNCING);
89
$this->SetState(GS_SYNCING,GS_PLAY);
93
//print("New Round\n");
94
$this->SetState(GS_PLAY,GS_PLAY);
99
$this->SetState(GS_DELETE_OBJECTS,GS_DELETE_GRID);
102
case GS_CREATE_OBJECTS:
103
//print("Creating objects...\n");
104
$this->SetState(GS_TRANSFER_OBJECTS,GS_CAMERA);
108
$this->SetState(GS_DELETE_OBJECTS,GS_DELETE_GRID);
111
case GS_DELETE_OBJECTS:
112
print("Deleting objects...\n");
113
$this->SetState(GS_DELETE_GRID,GS_CREATE_GRID);
121
function WriteSync($connection=null)
123
if($connection == null) $connection = $this->connection;
125
$msg = nMessage::makeMsg(311);
126
$msg->writeshort($this->state);
127
$connection->send($msg);
31
131
class Client extends connection
33
133
function send($msg)
233
334
#print_r($thing);
336
function handleGame($msg)
338
$msgstate = $msg->readshort();
340
if(!isset($this->game))
342
$this->game = new gGame();
343
$this->game->connection = $this;
344
$this->game->WriteSync();
346
// Eh, this is good enough for now...
347
while($this->game->state != GS_PLAY)
349
$this->game->StateUpdate();
235
354
function onFreeID($ids)
237
356
foreach($ids as $id)