Commit 653a4067a3a0421ed762562c4aad74e143bfc449
1 parent
eeff651b
Exists in
master
choice system is done
Showing
4 changed files
with
183 additions
and
54 deletions
Show diff stats
form_matrixgame.lfm
| 1 | object FormMatrixGame: TFormMatrixGame | 1 | object FormMatrixGame: TFormMatrixGame |
| 2 | - Left = 0 | ||
| 3 | - Height = 560 | ||
| 4 | - Top = 70 | ||
| 5 | - Width = 1278 | ||
| 6 | - HorzScrollBar.Page = 1278 | 2 | + Left = -621 |
| 3 | + Height = 565 | ||
| 4 | + Top = 124 | ||
| 5 | + Width = 1393 | ||
| 6 | + HorzScrollBar.Page = 1393 | ||
| 7 | VertScrollBar.Page = 542 | 7 | VertScrollBar.Page = 542 |
| 8 | AutoScroll = True | 8 | AutoScroll = True |
| 9 | Caption = 'FormMatrixGame' | 9 | Caption = 'FormMatrixGame' |
| 10 | - ClientHeight = 550 | ||
| 11 | - ClientWidth = 1278 | 10 | + ClientHeight = 555 |
| 11 | + ClientWidth = 1393 | ||
| 12 | Font.Name = 'Monospace' | 12 | Font.Name = 'Monospace' |
| 13 | OnActivate = FormActivate | 13 | OnActivate = FormActivate |
| 14 | LCLVersion = '1.6.2.0' | 14 | LCLVersion = '1.6.2.0' |
| @@ -184,7 +184,7 @@ object FormMatrixGame: TFormMatrixGame | @@ -184,7 +184,7 @@ object FormMatrixGame: TFormMatrixGame | ||
| 184 | AnchorSideBottom.Side = asrBottom | 184 | AnchorSideBottom.Side = asrBottom |
| 185 | Left = 0 | 185 | Left = 0 |
| 186 | Height = 17 | 186 | Height = 17 |
| 187 | - Top = 533 | 187 | + Top = 538 |
| 188 | Width = 1632 | 188 | Width = 1632 |
| 189 | Anchors = [akLeft, akRight, akBottom] | 189 | Anchors = [akLeft, akRight, akBottom] |
| 190 | AutoSize = True | 190 | AutoSize = True |
| @@ -275,15 +275,15 @@ object FormMatrixGame: TFormMatrixGame | @@ -275,15 +275,15 @@ object FormMatrixGame: TFormMatrixGame | ||
| 275 | Caption = 'NA' | 275 | Caption = 'NA' |
| 276 | ParentColor = False | 276 | ParentColor = False |
| 277 | end | 277 | end |
| 278 | - object LabelExpNxtPlayer: TLabel | 278 | + object LabelExpTurn: TLabel |
| 279 | Left = 10 | 279 | Left = 10 |
| 280 | Height = 15 | 280 | Height = 15 |
| 281 | Top = 95 | 281 | Top = 95 |
| 282 | Width = 128 | 282 | Width = 128 |
| 283 | - Caption = 'Prox. Jog.:' | 283 | + Caption = 'Turno:' |
| 284 | ParentColor = False | 284 | ParentColor = False |
| 285 | end | 285 | end |
| 286 | - object LabelExpCountNxtPlayer: TLabel | 286 | + object LabelExpCountTurn: TLabel |
| 287 | Left = 158 | 287 | Left = 158 |
| 288 | Height = 15 | 288 | Height = 15 |
| 289 | Top = 95 | 289 | Top = 95 |
| @@ -451,4 +451,22 @@ object FormMatrixGame: TFormMatrixGame | @@ -451,4 +451,22 @@ object FormMatrixGame: TFormMatrixGame | ||
| 451 | left = 24 | 451 | left = 24 |
| 452 | top = 360 | 452 | top = 360 |
| 453 | end | 453 | end |
| 454 | + object PopupNotifier: TPopupNotifier | ||
| 455 | + Color = clTeal | ||
| 456 | + Icon.Data = { | ||
| 457 | + 07544269746D617000000000 | ||
| 458 | + } | ||
| 459 | + Text = 'Text' | ||
| 460 | + Visible = False | ||
| 461 | + OnClose = PopupNotifierClose | ||
| 462 | + left = 112 | ||
| 463 | + top = 360 | ||
| 464 | + end | ||
| 465 | + object Timer: TTimer | ||
| 466 | + Enabled = False | ||
| 467 | + Interval = 8000 | ||
| 468 | + OnTimer = TimerTimer | ||
| 469 | + left = 200 | ||
| 470 | + top = 360 | ||
| 471 | + end | ||
| 454 | end | 472 | end |
form_matrixgame.pas
| @@ -15,7 +15,7 @@ interface | @@ -15,7 +15,7 @@ interface | ||
| 15 | 15 | ||
| 16 | uses | 16 | uses |
| 17 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids, | 17 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids, |
| 18 | - StdCtrls, DBGrids, ExtCtrls | 18 | + StdCtrls, DBGrids, ExtCtrls, PopupNotifier |
| 19 | 19 | ||
| 20 | , game_zmq_actors | 20 | , game_zmq_actors |
| 21 | , game_actors | 21 | , game_actors |
| @@ -46,8 +46,8 @@ type | @@ -46,8 +46,8 @@ type | ||
| 46 | LabelExpCountGeneration: TLabel; | 46 | LabelExpCountGeneration: TLabel; |
| 47 | LabelExpCycle: TLabel; | 47 | LabelExpCycle: TLabel; |
| 48 | LabelExpCountCycle: TLabel; | 48 | LabelExpCountCycle: TLabel; |
| 49 | - LabelExpNxtPlayer: TLabel; | ||
| 50 | - LabelExpCountNxtPlayer: TLabel; | 49 | + LabelExpTurn: TLabel; |
| 50 | + LabelExpCountTurn: TLabel; | ||
| 51 | LabelExpInterlocks: TLabel; | 51 | LabelExpInterlocks: TLabel; |
| 52 | LabelExpCountInterlocks: TLabel; | 52 | LabelExpCountInterlocks: TLabel; |
| 53 | LabelIndCount: TLabel; | 53 | LabelIndCount: TLabel; |
| @@ -62,7 +62,9 @@ type | @@ -62,7 +62,9 @@ type | ||
| 62 | ChatPanel: TPanel; | 62 | ChatPanel: TPanel; |
| 63 | ChatSplitter: TSplitter; | 63 | ChatSplitter: TSplitter; |
| 64 | OpenDialog: TOpenDialog; | 64 | OpenDialog: TOpenDialog; |
| 65 | + PopupNotifier: TPopupNotifier; | ||
| 65 | StringGridMatrix: TStringGrid; | 66 | StringGridMatrix: TStringGrid; |
| 67 | + Timer: TTimer; | ||
| 66 | procedure btnConfirmRowClick(Sender: TObject); | 68 | procedure btnConfirmRowClick(Sender: TObject); |
| 67 | procedure Button3Click(Sender: TObject); | 69 | procedure Button3Click(Sender: TObject); |
| 68 | procedure ButtonExpCancelClick(Sender: TObject); | 70 | procedure ButtonExpCancelClick(Sender: TObject); |
| @@ -70,9 +72,12 @@ type | @@ -70,9 +72,12 @@ type | ||
| 70 | procedure ButtonExpStartClick(Sender: TObject); | 72 | procedure ButtonExpStartClick(Sender: TObject); |
| 71 | procedure ChatMemoSendKeyPress(Sender: TObject; var Key: char); | 73 | procedure ChatMemoSendKeyPress(Sender: TObject; var Key: char); |
| 72 | procedure FormActivate(Sender: TObject); | 74 | procedure FormActivate(Sender: TObject); |
| 75 | + procedure PopupNotifierClose(Sender: TObject; var CloseAction: TCloseAction | ||
| 76 | + ); | ||
| 73 | procedure StringGridMatrixClick(Sender: TObject); | 77 | procedure StringGridMatrixClick(Sender: TObject); |
| 74 | procedure StringGridMatrixDrawCell(Sender: TObject; aCol, aRow: integer; | 78 | procedure StringGridMatrixDrawCell(Sender: TObject; aCol, aRow: integer; |
| 75 | aRect: TRect; aState: TGridDrawState); | 79 | aRect: TRect; aState: TGridDrawState); |
| 80 | + procedure TimerTimer(Sender: TObject); | ||
| 76 | private | 81 | private |
| 77 | FGameControl : TGameControl; | 82 | FGameControl : TGameControl; |
| 78 | FID: string; | 83 | FID: string; |
| @@ -212,6 +217,12 @@ begin | @@ -212,6 +217,12 @@ begin | ||
| 212 | end; | 217 | end; |
| 213 | end; | 218 | end; |
| 214 | 219 | ||
| 220 | +procedure TFormMatrixGame.TimerTimer(Sender: TObject); | ||
| 221 | +begin | ||
| 222 | + PopupNotifier.Visible:=False; | ||
| 223 | + Timer.Enabled := False; | ||
| 224 | +end; | ||
| 225 | + | ||
| 215 | procedure TFormMatrixGame.SetGameActor(AValue: TGameActor); | 226 | procedure TFormMatrixGame.SetGameActor(AValue: TGameActor); |
| 216 | 227 | ||
| 217 | procedure SetZMQAdmin; | 228 | procedure SetZMQAdmin; |
| @@ -223,7 +234,7 @@ procedure TFormMatrixGame.SetGameActor(AValue: TGameActor); | @@ -223,7 +234,7 @@ procedure TFormMatrixGame.SetGameActor(AValue: TGameActor); | ||
| 223 | procedure SetZMQPlayer; | 234 | procedure SetZMQPlayer; |
| 224 | begin | 235 | begin |
| 225 | FGameControl := TGameControl.Create(TZMQPlayer.Create(Self,FID)); | 236 | FGameControl := TGameControl.Create(TZMQPlayer.Create(Self,FID)); |
| 226 | - StringGridMatrix.Enabled := True; | 237 | + //StringGridMatrix.Enabled := True; |
| 227 | end; | 238 | end; |
| 228 | 239 | ||
| 229 | procedure SetZMQWatcher; | 240 | procedure SetZMQWatcher; |
| @@ -267,6 +278,12 @@ begin | @@ -267,6 +278,12 @@ begin | ||
| 267 | end; | 278 | end; |
| 268 | end; | 279 | end; |
| 269 | 280 | ||
| 281 | +procedure TFormMatrixGame.PopupNotifierClose(Sender: TObject; | ||
| 282 | + var CloseAction: TCloseAction); | ||
| 283 | +begin | ||
| 284 | + // do nothing for now | ||
| 285 | +end; | ||
| 286 | + | ||
| 270 | procedure TFormMatrixGame.StringGridMatrixClick(Sender: TObject); | 287 | procedure TFormMatrixGame.StringGridMatrixClick(Sender: TObject); |
| 271 | begin | 288 | begin |
| 272 | if goRowSelect in StringGridMatrix.Options then Exit; | 289 | if goRowSelect in StringGridMatrix.Options then Exit; |
| @@ -292,9 +309,6 @@ end; | @@ -292,9 +309,6 @@ end; | ||
| 292 | 309 | ||
| 293 | procedure TFormMatrixGame.btnConfirmRowClick(Sender: TObject); | 310 | procedure TFormMatrixGame.btnConfirmRowClick(Sender: TObject); |
| 294 | begin | 311 | begin |
| 295 | - StringGridMatrix.Enabled:= False; | ||
| 296 | - btnConfirmRow.Enabled:=False; | ||
| 297 | - btnConfirmRow.Caption:='OK'; | ||
| 298 | FGameControl.SendMessage(K_CHOICE); | 312 | FGameControl.SendMessage(K_CHOICE); |
| 299 | end; | 313 | end; |
| 300 | 314 |
units/game_control.pas
| @@ -43,13 +43,14 @@ type | @@ -43,13 +43,14 @@ type | ||
| 43 | procedure SetMustDrawDotsClear(AValue: Boolean); | 43 | procedure SetMustDrawDotsClear(AValue: Boolean); |
| 44 | procedure SetRowBase(AValue: integer); | 44 | procedure SetRowBase(AValue: integer); |
| 45 | private | 45 | private |
| 46 | - function CanStartExperiment : Boolean; | 46 | + function ShouldStartExperiment : Boolean; |
| 47 | procedure KickPlayer(AID:string); | 47 | procedure KickPlayer(AID:string); |
| 48 | procedure NextTurn(Sender: TObject); | 48 | procedure NextTurn(Sender: TObject); |
| 49 | procedure NextCycle(Sender: TObject); | 49 | procedure NextCycle(Sender: TObject); |
| 50 | procedure NextLineage(Sender: TObject); | 50 | procedure NextLineage(Sender: TObject); |
| 51 | procedure NextCondition(Sender: TObject); | 51 | procedure NextCondition(Sender: TObject); |
| 52 | procedure EndExperiment(Sender: TObject); | 52 | procedure EndExperiment(Sender: TObject); |
| 53 | + procedure StartExperiment; | ||
| 53 | public | 54 | public |
| 54 | constructor Create(AOwner : TComponent);override; | 55 | constructor Create(AOwner : TComponent);override; |
| 55 | destructor Destroy; override; | 56 | destructor Destroy; override; |
| @@ -76,6 +77,7 @@ const | @@ -76,6 +77,7 @@ const | ||
| 76 | K_REFUSED = '.Refused'; | 77 | K_REFUSED = '.Refused'; |
| 77 | K_CHAT_M = '.ChatM'; | 78 | K_CHAT_M = '.ChatM'; |
| 78 | K_CHOICE = '.Choice'; | 79 | K_CHOICE = '.Choice'; |
| 80 | + K_START = '.Start'; | ||
| 79 | K_LEFT = '.Left'; | 81 | K_LEFT = '.Left'; |
| 80 | K_RESUME = '.Resume'; | 82 | K_RESUME = '.Resume'; |
| 81 | K_DATA_A = '.Data'; | 83 | K_DATA_A = '.Data'; |
| @@ -115,7 +117,7 @@ end; | @@ -115,7 +117,7 @@ end; | ||
| 115 | 117 | ||
| 116 | { TGameControl } | 118 | { TGameControl } |
| 117 | 119 | ||
| 118 | -function TGameControl.CanStartExperiment: Boolean; | 120 | +function TGameControl.ShouldStartExperiment: Boolean; |
| 119 | begin | 121 | begin |
| 120 | Result := FExperiment.PlayersCount = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value; | 122 | Result := FExperiment.PlayersCount = FExperiment.Condition[FExperiment.CurrentCondition].Turn.Value; |
| 121 | end; | 123 | end; |
| @@ -127,21 +129,29 @@ end; | @@ -127,21 +129,29 @@ end; | ||
| 127 | 129 | ||
| 128 | procedure TGameControl.NextTurn(Sender: TObject); | 130 | procedure TGameControl.NextTurn(Sender: TObject); |
| 129 | begin | 131 | begin |
| 132 | + // update admin view | ||
| 133 | + FormMatrixGame.LabelExpCountTurn.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Turn.Count); | ||
| 134 | + | ||
| 130 | // inform players | 135 | // inform players |
| 136 | + | ||
| 131 | end; | 137 | end; |
| 132 | 138 | ||
| 133 | procedure TGameControl.NextCycle(Sender: TObject); | 139 | procedure TGameControl.NextCycle(Sender: TObject); |
| 134 | begin | 140 | begin |
| 135 | // prompt question to all players | 141 | // prompt question to all players |
| 142 | + FormMatrixGame.LabelExpCountCycle.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Count); | ||
| 136 | end; | 143 | end; |
| 137 | 144 | ||
| 138 | procedure TGameControl.NextLineage(Sender: TObject); | 145 | procedure TGameControl.NextLineage(Sender: TObject); |
| 139 | begin | 146 | begin |
| 140 | - | 147 | + // pause, kick older player, wait for new player, resume |
| 148 | + FormMatrixGame.LabelExpCountGeneration.Caption:=IntToStr(FExperiment.Condition[FExperiment.CurrentCondition].Cycles.Generation); | ||
| 141 | end; | 149 | end; |
| 142 | 150 | ||
| 143 | procedure TGameControl.NextCondition(Sender: TObject); | 151 | procedure TGameControl.NextCondition(Sender: TObject); |
| 144 | begin | 152 | begin |
| 153 | + FormMatrixGame.LabelExpCountCondition.Caption:= FExperiment.Condition[FExperiment.CurrentCondition].ConditionName; | ||
| 154 | + | ||
| 145 | // append OnStart data | 155 | // append OnStart data |
| 146 | //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.A; | 156 | //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.A; |
| 147 | //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.B; | 157 | //FExperiment.Condition[FExperiment.CurrentCondition].Points.OnStart.B; |
| @@ -155,10 +165,23 @@ begin | @@ -155,10 +165,23 @@ begin | ||
| 155 | 165 | ||
| 156 | end; | 166 | end; |
| 157 | 167 | ||
| 168 | +procedure TGameControl.StartExperiment; | ||
| 169 | +begin | ||
| 170 | + // all players arrived, lets begin | ||
| 171 | + FExperiment.State:=xsRunning; | ||
| 172 | + | ||
| 173 | + // wait some time, we just sent a message earlier | ||
| 174 | + Sleep(5); | ||
| 175 | + | ||
| 176 | + // enable matrix grid for the first player | ||
| 177 | + FZMQActor.SendMessage([K_START]); | ||
| 178 | +end; | ||
| 179 | + | ||
| 158 | procedure TGameControl.Start; | 180 | procedure TGameControl.Start; |
| 159 | begin | 181 | begin |
| 160 | // basic data/csv setup | 182 | // basic data/csv setup |
| 161 | // wait for players | 183 | // wait for players |
| 184 | + | ||
| 162 | end; | 185 | end; |
| 163 | 186 | ||
| 164 | procedure TGameControl.Pause; | 187 | procedure TGameControl.Pause; |
| @@ -303,14 +326,6 @@ begin | @@ -303,14 +326,6 @@ begin | ||
| 303 | FRowBase:=AValue; | 326 | FRowBase:=AValue; |
| 304 | end; | 327 | end; |
| 305 | 328 | ||
| 306 | -procedure TGameControl.StartTurn; | ||
| 307 | -begin | ||
| 308 | - FormMatrixGame.btnConfirmRow.Enabled:=True; | ||
| 309 | - FormMatrixGame.StringGridMatrix.Options := FormMatrixGame.StringGridMatrix.Options-[goRowSelect]; | ||
| 310 | - FormMatrixGame.btnConfirmRow.Caption:='Confirmar'; | ||
| 311 | - FormMatrixGame.btnConfirmRow.Visible := False; | ||
| 312 | -end; | ||
| 313 | - | ||
| 314 | constructor TGameControl.Create(AOwner: TComponent); | 329 | constructor TGameControl.Create(AOwner: TComponent); |
| 315 | begin | 330 | begin |
| 316 | FZMQActor := TZMQActor(AOwner); | 331 | FZMQActor := TZMQActor(AOwner); |
| @@ -333,12 +348,18 @@ begin | @@ -333,12 +348,18 @@ begin | ||
| 333 | MustDrawDotsClear:=False; | 348 | MustDrawDotsClear:=False; |
| 334 | 349 | ||
| 335 | FExperiment := TExperiment.Create(FZMQActor.Owner); | 350 | FExperiment := TExperiment.Create(FZMQActor.Owner); |
| 351 | + FExperiment.State:=xsWaiting; | ||
| 336 | FExperiment.OnEndTurn := @NextTurn; | 352 | FExperiment.OnEndTurn := @NextTurn; |
| 337 | FExperiment.OnEndCycle := @NextCycle; | 353 | FExperiment.OnEndCycle := @NextCycle; |
| 338 | FExperiment.OnEndGeneration:=@NextLineage; | 354 | FExperiment.OnEndGeneration:=@NextLineage; |
| 339 | FExperiment.OnEndCondition:= @NextCondition; | 355 | FExperiment.OnEndCondition:= @NextCondition; |
| 340 | FExperiment.OnEndExperiment:= @EndExperiment; | 356 | FExperiment.OnEndExperiment:= @EndExperiment; |
| 341 | 357 | ||
| 358 | + NextTurn(Self); | ||
| 359 | + NextCycle(Self); | ||
| 360 | + NextLineage(Self); | ||
| 361 | + NextCondition(Self); | ||
| 362 | + | ||
| 342 | SendRequest(K_LOGIN); | 363 | SendRequest(K_LOGIN); |
| 343 | end; | 364 | end; |
| 344 | 365 | ||
| @@ -453,10 +474,10 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | @@ -453,10 +474,10 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | ||
| 453 | gaPlayer: | 474 | gaPlayer: |
| 454 | begin | 475 | begin |
| 455 | P := FExperiment.PlayerFromString[AMessage[1]]; | 476 | P := FExperiment.PlayerFromString[AMessage[1]]; |
| 477 | + FExperiment.AppendPlayer(P); | ||
| 456 | if Self.ID = P.ID then | 478 | if Self.ID = P.ID then |
| 457 | begin | 479 | begin |
| 458 | - FExperiment.AppendPlayer(P); | ||
| 459 | - CreatePlayerBox(P, True); | 480 | + CreatePlayerBox(P, True) |
| 460 | end | 481 | end |
| 461 | else | 482 | else |
| 462 | CreatePlayerBox(P,False); | 483 | CreatePlayerBox(P,False); |
| @@ -465,27 +486,76 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | @@ -465,27 +486,76 @@ procedure TGameControl.ReceiveMessage(AMessage: TStringList); | ||
| 465 | 486 | ||
| 466 | end; | 487 | end; |
| 467 | 488 | ||
| 489 | + procedure EnableMatrix(ATurn:integer); | ||
| 490 | + begin | ||
| 491 | + if FExperiment.PlayerFromID[Self.ID].Turn = ATurn then | ||
| 492 | + begin | ||
| 493 | + FormMatrixGame.StringGridMatrix.Enabled:=True; | ||
| 494 | + FormMatrixGame.StringGridMatrix.Options := FormMatrixGame.StringGridMatrix.Options-[goRowSelect]; | ||
| 495 | + FormMatrixGame.btnConfirmRow.Enabled:=True; | ||
| 496 | + FormMatrixGame.btnConfirmRow.Caption:='Confirmar'; | ||
| 497 | + FormMatrixGame.btnConfirmRow.Visible := False; | ||
| 498 | + end; | ||
| 499 | + end; | ||
| 500 | + | ||
| 468 | procedure ReceiveChoice; | 501 | procedure ReceiveChoice; |
| 502 | + var P : TPlayer; | ||
| 469 | begin | 503 | begin |
| 470 | - with GetPlayerBox(AMessage[1]) do | 504 | + P := FExperiment.PlayerFromID[AMessage[1]]; |
| 505 | + | ||
| 506 | + // add last responses to player box | ||
| 507 | + with GetPlayerBox(P.ID) do | ||
| 471 | begin | 508 | begin |
| 472 | - LabelLastRowCount.Caption := Format('%-*.*d', [1,2,StrToInt(AMessage[2])]); | 509 | + LabelLastRowCount.Caption := AMessage[2]; |
| 473 | PanelLastColor.Color := GetRowColorFromString(AMessage[3]); | 510 | PanelLastColor.Color := GetRowColorFromString(AMessage[3]); |
| 474 | - FormMatrixGame.Caption:=''; | 511 | + PanelLastColor.Caption:=''; |
| 475 | end; | 512 | end; |
| 476 | 513 | ||
| 477 | case FActor of | 514 | case FActor of |
| 478 | gaPlayer:begin | 515 | gaPlayer:begin |
| 479 | - | 516 | + if Self.ID = P.ID then |
| 517 | + begin | ||
| 518 | + FormMatrixGame.StringGridMatrix.Enabled:= False; | ||
| 519 | + FormMatrixGame.btnConfirmRow.Enabled:=False; | ||
| 520 | + FormMatrixGame.btnConfirmRow.Caption:='OK'; | ||
| 521 | + end | ||
| 522 | + else | ||
| 523 | + EnableMatrix(P.Turn+1); | ||
| 480 | end; | 524 | end; |
| 481 | 525 | ||
| 482 | gaAdmin:begin | 526 | gaAdmin:begin |
| 483 | - // if last choice in cycle then end cycle | ||
| 484 | FExperiment.NextTurn; | 527 | FExperiment.NextTurn; |
| 485 | end; | 528 | end; |
| 486 | end; | 529 | end; |
| 487 | end; | 530 | end; |
| 488 | 531 | ||
| 532 | + procedure NotifyPlayers; | ||
| 533 | + var PopUpPos : TPoint; | ||
| 534 | + begin | ||
| 535 | + case FActor of | ||
| 536 | + gaPlayer: | ||
| 537 | + begin | ||
| 538 | + PopUpPos.X := FormMatrixGame.StringGridMatrix.Left+FormMatrixGame.StringGridMatrix.Width; | ||
| 539 | + PopUpPos.Y := FormMatrixGame.StringGridMatrix.Top; | ||
| 540 | + PopUpPos := FormMatrixGame.StringGridMatrix.ClientToScreen(PopUpPos); | ||
| 541 | + if FExperiment.PlayerFromID[Self.ID].Turn = 0 then | ||
| 542 | + begin | ||
| 543 | + PopUpPos.X := FormMatrixGame.StringGridMatrix.Left+FormMatrixGame.StringGridMatrix.Width; | ||
| 544 | + PopUpPos.Y := FormMatrixGame.StringGridMatrix.Top; | ||
| 545 | + EnableMatrix(0); | ||
| 546 | + FormMatrixGame.PopupNotifier.Text:='É sua vez! Clique sobre uma linha da matrix e confirme sua escolha.'; | ||
| 547 | + FormMatrixGame.PopupNotifier.ShowAtPos(PopUpPos.X,PopUpPos.Y); | ||
| 548 | + end | ||
| 549 | + else | ||
| 550 | + begin | ||
| 551 | + FormMatrixGame.PopupNotifier.Text:='Começou! Aguarde sua vez.'; | ||
| 552 | + FormMatrixGame.PopupNotifier.ShowAtPos(PopUpPos.X,PopUpPos.Y); | ||
| 553 | + end; | ||
| 554 | + FormMatrixGame.Timer.Enabled:=True; | ||
| 555 | + end; | ||
| 556 | + end; | ||
| 557 | + end; | ||
| 558 | + | ||
| 489 | procedure ReceiveChat; | 559 | procedure ReceiveChat; |
| 490 | begin | 560 | begin |
| 491 | FormMatrixGame.ChatMemoRecv.Lines.Append(('['+AMessage[1]+']: ')+AMessage[2]); | 561 | FormMatrixGame.ChatMemoRecv.Lines.Append(('['+AMessage[1]+']: ')+AMessage[2]); |
| @@ -551,6 +621,7 @@ begin | @@ -551,6 +621,7 @@ begin | ||
| 551 | if MHas(K_CHAT_M) then ReceiveChat; | 621 | if MHas(K_CHAT_M) then ReceiveChat; |
| 552 | if MHas(K_CHOICE) then ReceiveChoice; | 622 | if MHas(K_CHOICE) then ReceiveChoice; |
| 553 | if MHas(K_KICK) then SayGoodBye; | 623 | if MHas(K_KICK) then SayGoodBye; |
| 624 | + if MHas(K_START) then NotifyPlayers; | ||
| 554 | end; | 625 | end; |
| 555 | 626 | ||
| 556 | // Here FActor is garanted to be a TZMQAdmin | 627 | // Here FActor is garanted to be a TZMQAdmin |
| @@ -585,10 +656,9 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -585,10 +656,9 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 585 | end | 656 | end |
| 586 | else | 657 | else |
| 587 | begin | 658 | begin |
| 588 | - // if not generate and save p data | 659 | + // if not then generate and save p data |
| 589 | i := FExperiment.AppendPlayer; | 660 | i := FExperiment.AppendPlayer; |
| 590 | P.Nicname := GenResourceName(i); | 661 | P.Nicname := GenResourceName(i); |
| 591 | - P.Turn := FExperiment.NextTurn; | ||
| 592 | P.Points.A:=0; | 662 | P.Points.A:=0; |
| 593 | P.Points.B:=0; | 663 | P.Points.B:=0; |
| 594 | P.Status:=gpsPlaying; | 664 | P.Status:=gpsPlaying; |
| @@ -596,8 +666,8 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -596,8 +666,8 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 596 | P.Choice.Current.Row:=grNone; | 666 | P.Choice.Current.Row:=grNone; |
| 597 | P.Choice.Last.Color:=gcNone; | 667 | P.Choice.Last.Color:=gcNone; |
| 598 | P.Choice.Last.Row:=grNone; | 668 | P.Choice.Last.Row:=grNone; |
| 599 | - // turns by entrance order | ||
| 600 | - P.Turn := FExperiment.PlayersCount; | 669 | + // turns by entrance order or by random order |
| 670 | + P.Turn := FExperiment.NextTurn; | ||
| 601 | FExperiment.Player[i] := P; | 671 | FExperiment.Player[i] := P; |
| 602 | end; | 672 | end; |
| 603 | 673 | ||
| @@ -631,7 +701,7 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | @@ -631,7 +701,7 @@ procedure TGameControl.ReceiveRequest(var ARequest: TStringList); | ||
| 631 | FZMQActor.SendMessage([K_ARRIVED,PS]); | 701 | FZMQActor.SendMessage([K_ARRIVED,PS]); |
| 632 | 702 | ||
| 633 | // start Experiment if allowed | 703 | // start Experiment if allowed |
| 634 | - if CanStartExperiment then | 704 | + if ShouldStartExperiment then |
| 635 | StartExperiment; | 705 | StartExperiment; |
| 636 | 706 | ||
| 637 | end | 707 | end |
| @@ -671,6 +741,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); | @@ -671,6 +741,7 @@ procedure TGameControl.ReceiveReply(AReply: TStringList); | ||
| 671 | for i:= 3 to AReply.Count -2 do | 741 | for i:= 3 to AReply.Count -2 do |
| 672 | begin | 742 | begin |
| 673 | P := FExperiment.PlayerFromString[AReply[i]]; | 743 | P := FExperiment.PlayerFromString[AReply[i]]; |
| 744 | + FExperiment.AppendPlayer(P); | ||
| 674 | CreatePlayerBox(P, False); | 745 | CreatePlayerBox(P, False); |
| 675 | end; | 746 | end; |
| 676 | 747 |
units/game_experiment.pas
| @@ -40,6 +40,7 @@ type | @@ -40,6 +40,7 @@ type | ||
| 40 | FSendChatHistoryForNewPlayers: Boolean; | 40 | FSendChatHistoryForNewPlayers: Boolean; |
| 41 | FShowChat: Boolean; | 41 | FShowChat: Boolean; |
| 42 | FState: TExperimentState; | 42 | FState: TExperimentState; |
| 43 | + FTurnsRandom : TStringList; | ||
| 43 | function GetCondition(I : Integer): TCondition; | 44 | function GetCondition(I : Integer): TCondition; |
| 44 | function GetConditionsCount: integer; | 45 | function GetConditionsCount: integer; |
| 45 | function GetContingency(ACondition, I : integer): TContingency; | 46 | function GetContingency(ACondition, I : integer): TContingency; |
| @@ -146,12 +147,14 @@ end; | @@ -146,12 +147,14 @@ end; | ||
| 146 | 147 | ||
| 147 | function TExperiment.GetNextTurn: integer; // used during player arriving | 148 | function TExperiment.GetNextTurn: integer; // used during player arriving |
| 148 | begin | 149 | begin |
| 149 | - Result := FConditions[CurrentCondition].Turn.Count; | 150 | + if FConditions[CurrentCondition].Turn.Random then |
| 151 | + Result := StrToInt(FTurnsRandom.Names[FConditions[CurrentCondition].Turn.Count]) | ||
| 152 | + else | ||
| 153 | + Result := FConditions[CurrentCondition].Turn.Count; | ||
| 154 | + if Assigned(FOnEndTurn) then FOnEndTurn(Self); | ||
| 155 | + | ||
| 150 | if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then | 156 | if FConditions[CurrentCondition].Turn.Count < FConditions[CurrentCondition].Turn.Value then |
| 151 | - begin | ||
| 152 | - Inc(FConditions[CurrentCondition].Turn.Count); | ||
| 153 | - if Assigned(FOnEndTurn) then FOnEndTurn(Self); | ||
| 154 | - end | 157 | + Inc(FConditions[CurrentCondition].Turn.Count) |
| 155 | else | 158 | else |
| 156 | begin | 159 | begin |
| 157 | FConditions[CurrentCondition].Turn.Count := 0; | 160 | FConditions[CurrentCondition].Turn.Count := 0; |
| @@ -174,8 +177,11 @@ begin | @@ -174,8 +177,11 @@ begin | ||
| 174 | else | 177 | else |
| 175 | begin | 178 | begin |
| 176 | FConditions[CurrentCondition].Cycles.Count := 0; | 179 | FConditions[CurrentCondition].Cycles.Count := 0; |
| 177 | - if Assigned(FOnEndGeneration) then FOnEndGeneration(Self); | ||
| 178 | - NextCondition; | 180 | + if State = xsRunning then |
| 181 | + begin | ||
| 182 | + if Assigned(FOnEndGeneration) then FOnEndGeneration(Self); | ||
| 183 | + NextCondition; | ||
| 184 | + end; | ||
| 179 | end; | 185 | end; |
| 180 | end; | 186 | end; |
| 181 | 187 | ||
| @@ -186,7 +192,7 @@ var | @@ -186,7 +192,7 @@ var | ||
| 186 | 192 | ||
| 187 | procedure EndCondition; | 193 | procedure EndCondition; |
| 188 | begin | 194 | begin |
| 189 | - Inc(CurrentCondition); | 195 | + Inc(FCurrentCondition); |
| 190 | if Assigned(FOnEndCondition) then FOnEndCondition(Self); | 196 | if Assigned(FOnEndCondition) then FOnEndCondition(Self); |
| 191 | end; | 197 | end; |
| 192 | 198 | ||
| @@ -197,7 +203,7 @@ begin | @@ -197,7 +203,7 @@ begin | ||
| 197 | FConditions[CurrentCondition].Cycles.Generation) + FConditions[CurrentCondition].Cycles.Count; | 203 | FConditions[CurrentCondition].Cycles.Generation) + FConditions[CurrentCondition].Cycles.Count; |
| 198 | 204 | ||
| 199 | // interlockings in last x cycles | 205 | // interlockings in last x cycles |
| 200 | - LInterlocks := InterlockingsIn(FConditions[CurrentCondition].EndCriterium.LastCycles); | 206 | + LInterlocks := InterlockingsIn[FConditions[CurrentCondition].EndCriterium.LastCycles]; |
| 201 | case FConditions[CurrentCondition].EndCriterium.Value of | 207 | case FConditions[CurrentCondition].EndCriterium.Value of |
| 202 | gecWhichComeFirst: | 208 | gecWhichComeFirst: |
| 203 | begin | 209 | begin |
| @@ -260,8 +266,8 @@ var | @@ -260,8 +266,8 @@ var | ||
| 260 | begin | 266 | begin |
| 261 | case AStatus of | 267 | case AStatus of |
| 262 | gpsWaiting: Result := '0'; | 268 | gpsWaiting: Result := '0'; |
| 263 | - gpsPlayed: Result := '1'; | ||
| 264 | - gpsPlaying: Result := '2'; | 269 | + gpsPlaying: Result := '1'; |
| 270 | + gpsPlayed: Result := '2'; | ||
| 265 | end; | 271 | end; |
| 266 | end; | 272 | end; |
| 267 | 273 | ||
| @@ -308,6 +314,7 @@ begin | @@ -308,6 +314,7 @@ begin | ||
| 308 | , GetStatusString(P.Status) | 314 | , GetStatusString(P.Status) |
| 309 | , GetChoiceString(P.Choice.Current) | 315 | , GetChoiceString(P.Choice.Current) |
| 310 | , GetChoiceString(P.Choice.Last) | 316 | , GetChoiceString(P.Choice.Last) |
| 317 | + , IntToStr(P.Turn) | ||
| 311 | ]); | 318 | ]); |
| 312 | for i := 0 to Length(M)-1 do | 319 | for i := 0 to Length(M)-1 do |
| 313 | Result += M[i] + '|'; | 320 | Result += M[i] + '|'; |
| @@ -360,8 +367,8 @@ function TExperiment.GetPlayerFromString(s: UTF8string): TPlayer; | @@ -360,8 +367,8 @@ function TExperiment.GetPlayerFromString(s: UTF8string): TPlayer; | ||
| 360 | begin | 367 | begin |
| 361 | case S of | 368 | case S of |
| 362 | '0': Result := gpsWaiting; | 369 | '0': Result := gpsWaiting; |
| 363 | - '1': Result := gpsPlayed; | ||
| 364 | - '2': Result := gpsPlaying; | 370 | + '1': Result := gpsPlaying; |
| 371 | + '2': Result := gpsPlayed; | ||
| 365 | end; | 372 | end; |
| 366 | end; | 373 | end; |
| 367 | begin | 374 | begin |
| @@ -379,6 +386,7 @@ begin | @@ -379,6 +386,7 @@ begin | ||
| 379 | Result.Status := GetStatusFromString(ExtractDelimited(4,s,['|'])); | 386 | Result.Status := GetStatusFromString(ExtractDelimited(4,s,['|'])); |
| 380 | Result.Choice.Current := GetChoiceFromString(ExtractDelimited(5,s,['|'])); | 387 | Result.Choice.Current := GetChoiceFromString(ExtractDelimited(5,s,['|'])); |
| 381 | Result.Choice.Last := GetChoiceFromString(ExtractDelimited(6,s,['|'])); | 388 | Result.Choice.Last := GetChoiceFromString(ExtractDelimited(6,s,['|'])); |
| 389 | + Result.Turn:=StrToInt(ExtractDelimited(7,s,['|'])); | ||
| 382 | end; | 390 | end; |
| 383 | 391 | ||
| 384 | function TExperiment.GetPlayerIndexFromID(AID: UTF8string): integer; | 392 | function TExperiment.GetPlayerIndexFromID(AID: UTF8string): integer; |
| @@ -511,13 +519,31 @@ begin | @@ -511,13 +519,31 @@ begin | ||
| 511 | end; | 519 | end; |
| 512 | 520 | ||
| 513 | constructor TExperiment.Create(AFilename: string;AOwner:TComponent); | 521 | constructor TExperiment.Create(AFilename: string;AOwner:TComponent); |
| 522 | +var c , | ||
| 523 | + i, | ||
| 524 | + r : integer; | ||
| 514 | begin | 525 | begin |
| 515 | inherited Create(AOwner); | 526 | inherited Create(AOwner); |
| 527 | + FTurnsRandom := TStringList.Create; | ||
| 516 | LoadExperimentFromFile(Self,AFilename); | 528 | LoadExperimentFromFile(Self,AFilename); |
| 529 | + if Condition[CurrentCondition].Turn.Random then | ||
| 530 | + begin | ||
| 531 | + for i:= 0 to Condition[CurrentCondition].Turn.Value-1 do | ||
| 532 | + FTurnsRandom.Add(IntToStr(i)); | ||
| 533 | + | ||
| 534 | + c := FTurnsRandom.Count - 1; | ||
| 535 | + for i := 0 to c do | ||
| 536 | + begin | ||
| 537 | + r := Random(c); | ||
| 538 | + while r = i do r := Random(c); | ||
| 539 | + FTurnsRandom.Exchange(r,i); | ||
| 540 | + end; | ||
| 541 | + end; | ||
| 517 | end; | 542 | end; |
| 518 | 543 | ||
| 519 | destructor TExperiment.Destroy; | 544 | destructor TExperiment.Destroy; |
| 520 | begin | 545 | begin |
| 546 | + FTurnsRandom.Free; | ||
| 521 | inherited Destroy; | 547 | inherited Destroy; |
| 522 | end; | 548 | end; |
| 523 | 549 |