public bool Loop() { Console.WriteLine("Requesting GetToken..."); EventWaitHandle doneEvent = new ManualResetEvent(false); var getTokenResult = GetToken(); if (getTokenResult) { _netService.EnterResponseState = EnterResponseState.NotYet; _netService.EnqueueCommand($"enter {_serverAddress} {_token} {GetDeviceId()}"); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Login Failed"); Console.ResetColor(); StateManagerService.SetState(MainStates.Idle); return(false); } for (var i = 0; i < 5; ++i) { Thread.Sleep(300); if (_netService.EnterResponseState != EnterResponseState.NotYet) { break; } } if (_netService.EnterResponseState == EnterResponseState.Succeed) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Login succeed"); Console.ResetColor(); } else if (_netService.EnterResponseState == EnterResponseState.Failed) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Login Failed"); Console.ResetColor(); } else if (_netService.EnterResponseState == EnterResponseState.NotYet) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Login Timeout"); Console.ResetColor(); } StateManagerService.SetState(MainStates.Idle); return(false); }
public bool Loop() { Console.WriteLine("AutoMoveState"); var rnd = new Random(Guid.NewGuid().GetHashCode()); for (var i = 0; i < 5; ++i) { var pos = SharedUtil.GetRandomPosition(rnd); _netService.EnqueueCommand($"move {pos.X} {pos.Y}"); Thread.Sleep(1000); } StateManagerService.SetState(MainStates.Idle); return(false); }