private async void DoSpin() { if (isWaitForUpdate) { return; } isWaitForUpdate = true; // Update this only for user to see, after taking info from server, we update it again view.SetSpinLeft(model.SpinsLeft - 1, model.MaxSpins); ToggleSpinAndWait(true); var result = await server.DoSpin(model.CurrentBet); model = JsonUtility.FromJson <SlotMachineModel>(result); // await Task.Run(() => server.DoSpin()); stopSlot1At = GetPageIndexBySlotIndex(slotScroll1, model.Slot1.WinningItemIndex); await Task.Delay(delayBetweenSlots); stopSlot2At = GetPageIndexBySlotIndex(slotScroll2, model.Slot2.WinningItemIndex); await Task.Delay(delayBetweenSlots); stopSlot3At = GetPageIndexBySlotIndex(slotScroll3, model.Slot3.WinningItemIndex); UpdateInterface(); isWaitForUpdate = false; }
private void Awake() { currentModel = new SlotMachineModel { Score = Score, MaxSpins = MaxSpins, SpinsLeft = SpinsLeft, CurrentBet = CurrentBet, SpinsRenewCount = SpinsRenewCount, SpinsRenewInTime = (int)SpinsRenewInTime }; }
public async Task <string> DoSpin(int bet) { await Task.Delay(2000); var test = TestData(bet); currentModel = test; return(JsonUtility.ToJson(test)); }
private async void UpdateCurrentStats() { if (isWaitForUpdate) { return; } isWaitForUpdate = true; var res = await server.GetCurrentStats(); model = JsonUtility.FromJson <SlotMachineModel>(res); isWaitForUpdate = false; UpdateInterface(); }
private SlotMachineModel TestData(int bet) { CurrentBet = bet; SpinsLeft = SpinsLeft - 1 < 0 ? 0 : SpinsLeft - 1; var model = new SlotMachineModel(); switch (SpinsLeft % 5) { case 4: model.Slot1 = new SlotModel { WinningItemIndex = 3 }; model.Slot2 = new SlotModel { WinningItemIndex = 2 }; model.Slot3 = new SlotModel { WinningItemIndex = 0 }; model.Score = Score -= bet; break; case 3: model.Slot1 = new SlotModel { WinningItemIndex = 1 }; model.Slot2 = new SlotModel { WinningItemIndex = 1 }; model.Slot3 = new SlotModel { WinningItemIndex = 3 }; model.Score = Score -= bet; break; case 2: model.Slot1 = new SlotModel { WinningItemIndex = 2 }; model.Slot2 = new SlotModel { WinningItemIndex = 3 }; model.Slot3 = new SlotModel { WinningItemIndex = 1 }; model.Score = Score -= bet; break; case 1: model.Slot1 = new SlotModel { WinningItemIndex = 4 }; model.Slot2 = new SlotModel { WinningItemIndex = 4 }; model.Slot3 = new SlotModel { WinningItemIndex = 4 }; model.Score = Score += bet; break; case 0: model.Slot1 = new SlotModel { WinningItemIndex = 2 }; model.Slot2 = new SlotModel { WinningItemIndex = 2 }; model.Slot3 = new SlotModel { WinningItemIndex = 2 }; model.Score = Score += bet; break; } model.MaxSpins = MaxSpins; model.SpinsLeft = SpinsLeft; model.CurrentBet = CurrentBet; model.SpinsRenewCount = SpinsRenewCount; model.SpinsRenewInTime = (int)SpinsRenewInTime; currentModel = model; return(model); }