예제 #1
0
        public void StartEvent(object sender, StartRoundEventArgs args)
        {
            try
            {
                if (args != null && args.TaskPool != null)
                {
                    args.TaskPool.Add(Task.Factory.StartNew(() =>
                    {
                        lock (_SyncLock)
                        {
                            if (args.Token != null && !args.Token.IsCancellationRequested)
                            {
                                RPS firstPlayerRes  = FirstPlayer.Play();
                                RPS secondPlayerRes = SecondPlayer.Play();

                                FirstPlayer.Status  = CheckWin((Int32)firstPlayerRes, (Int32)secondPlayerRes);
                                SecondPlayer.Status = CheckWin((Int32)secondPlayerRes, (Int32)firstPlayerRes);

                                switch (FirstPlayer.Status)
                                {
                                case BET.Win: FirstPlayer.Team.Count++; break;

                                case BET.Lose: SecondPlayer.Team.Count++; break;
                                }

                                //Console.WriteLine("{0} : {1} --- {2} : {3}", FirstPlayer.Name, firstPlayerRes, SecondPlayer.Name, secondPlayerRes);
                            }

                            if (args.CancelTokenSource != null && (FirstPlayer.Team.Count >= args.WinLength || SecondPlayer.Team.Count >= args.WinLength))
                            {
                                args.CancelTokenSource.Cancel();
                            }
                        }
                    }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error playing in couple", ex.InnerException);
            }
        }
예제 #2
0
 public RPS Play()
 {
     _Result = (RPS)RandomNumber(1, 4);
     return(_Result);
 }