void ReplyFirmActiveChoiceRecording(string [] args) { TLClientF nextState = TLClientF.GotActiveChoiceRecording; int firstArg = int.Parse(args [0]); if (firstArg < 0) { TreatError(firstArg, args, nextState); } else { for (int i = 0; i < GameFeatures.nPositions; i++) { consumerChoicesActive [i] = int.Parse(args [1 + i]); } endGame = int.Parse(args [1 + GameFeatures.nPositions]); if (endGame == 0) { t++; } state = TLClientF.GotActiveChoiceRecording; LogState(); } }
void ReplyFirmPassiveOpponentChoice(string [] args) { TLClientF nextState = TLClientF.GotPassiveOpponentChoice; int firstArg = int.Parse(args [0]); if (firstArg < 0) { TreatError(firstArg, args, nextState); } else { opponentPosition = int.Parse(args [1]); opponentPrice = int.Parse(args [2]); for (int i = 0; i < GameFeatures.nPositions; i++) { consumerChoicesPassive [i] = int.Parse(args [3 + i]); } endGame = int.Parse(args [3 + GameFeatures.nPositions]); if (endGame == 0) { t++; } state = nextState; LogState(); } }
// ------------------- Treat errors -------------------------------------------- // public void TreatError(int firstArg, string[] args, TLClientF nextState) { error = firstArg; if (error == CodeErrorF.haveToWait) { if (nextState == TLClientF.GotInit) { t = firstArg; // Get progress of other player progressOtherPlayer = args [1]; Debug.Log("ClientF: Have to wait for init. Progress of other player: " + progressOtherPlayer); state = nextState; } else { Debug.Log("ClientF: Have to wait."); StartCoroutine(RetryDemand()); } } else if (error == CodeErrorF.timeSuperior) { Debug.Log("ClientF: Time is superior."); StartCoroutine(RetryDemand()); } else { fatalError = true; state = nextState; } }
public void AskFirmActiveChoiceRecording(int userPosition, int userPrice) { position = userPosition; price = userPrice; state = TLClientF.ActiveChoiceRecording; LogState(); }
// Use this for initialization void Start() { consumerChoicesActive = new int[GameFeatures.nPositions]; consumerChoicesPassive = new int[GameFeatures.nPositions]; request = new Dictionary <string, string> (); url = gameController.GetUrl(); timeBeforeRetryingDemand = gameController.GetTimeBeforeRetryingDemand(); playerId = gameController.GetPlayerId(); state = TLClientF.WaitCommand; }
void ReplyFirmInit(string [] args) { TLClientF nextState = TLClientF.GotInit; int firstArg = int.Parse(args [0]); if (firstArg < 0) { TreatError(firstArg, args, nextState); } else { t = firstArg; Debug.Log("ClientF: t is " + t + "."); stateOfPlay = args[1]; initialStateOfPlay = stateOfPlay; Debug.Log("ClientF: my initial state of play is " + stateOfPlay + "."); position = int.Parse(args [2]); Debug.Log("ClientF: my initial position is " + position + "."); price = int.Parse(args[3]); Debug.Log("ClientF: my initial price is " + price + "."); score = int.Parse(args [4]); Debug.Log("ClientF: initial score is " + score + "."); opponentPosition = int.Parse(args[5]); Debug.Log("ClientF: intial opponent position is " + opponentPosition + "."); opponentPrice = int.Parse(args [6]); Debug.Log("ClientF: initial opponent price is " + opponentPrice + "."); opponentScore = int.Parse(args [7]); Debug.Log("ClientF: initial opponent score is " + opponentScore + "."); endingT = int.Parse(args [8]); Debug.Log("ClientF: ending t is " + endingT + "."); state = nextState; } LogState(); }
public void SetState(TLClientF value) { state = value; }
// --------------------------------------- Public: Relating to game state ---------------------------------- // public bool IsState(TLClientF value) { return(state == value); }
public void ReplySubmitTutorialProgression() { state = TLClientF.GotSubmitTutorialProgression; }
public void SubmitTutorialProgression(float value) { progressOnTutorial = value; state = TLClientF.SubmitTutorialProgression; }
// --------------------- Firm communication ------------------------------------------ // public void AskFirmPassiveOpponentChoice() { state = TLClientF.PassiveOpponentChoice; LogState(); }
// --------------------- Init ------------------------------------------------------- // public void AskInit() { state = TLClientF.Init; LogState(); }
void ManageState() { switch (state) { case TLClientF.WaitCommand: break; case TLClientF.Init: request.Clear(); request [KeyF.playerId] = playerId; request [KeyF.demand] = DemandF.askFirmInit; StartCoroutine(AskServer(request)); state = TLClientF.InitWaitReply; LogState(); break; case TLClientF.PassiveOpponentChoice: request.Clear(); request [KeyF.playerId] = playerId; request [KeyF.t] = t.ToString(); request [KeyF.demand] = DemandF.askFirmPassiveOpponentChoice; StartCoroutine(AskServer(request)); state = TLClientF.PassiveOpponentChoiceWaitReply; LogState(); break; case TLClientF.ActiveChoiceRecording: request.Clear(); request [KeyF.playerId] = playerId; request [KeyF.t] = t.ToString(); request [KeyF.position] = position.ToString(); request [KeyF.price] = price.ToString(); request [KeyF.demand] = DemandF.askFirmActiveChoiceRecording; StartCoroutine(AskServer(request)); state = TLClientF.ActiveChoiceRecordingWaitReply; LogState(); break; case TLClientF.SubmitTutorialProgression: request [KeyF.playerId] = playerId; request [KeyF.demand] = DemandF.submitTutorialProgression; request [KeyF.progressOnTutorial] = progressOnTutorial.ToString(); StartCoroutine(AskServer(request)); state = TLClientF.SubmitTutorialProgressionWaitReply; LogState(); break; case TLClientF.GotInit: case TLClientF.GotActiveChoiceRecording: case TLClientF.GotPassiveOpponentChoice: case TLClientF.GotSubmitTutorialProgression: break; case TLClientF.InitWaitReply: case TLClientF.PassiveOpponentChoiceWaitReply: case TLClientF.ActiveChoiceRecordingWaitReply: case TLClientF.SubmitTutorialProgressionWaitReply: if (HasResponse()) { HandleServerResponse(); } break; default: throw new Exception("ClientF: The state '" + state + "' is not handled."); } }