示例#1
0
 private void Update()
 {
     LastUpdate = DateTime.Now;
     GameUpdated.SetResult(_values);
     GameUpdated   = new TaskCompletionSource <GameValues>();
     CorrelationId = Guid.NewGuid().ToString();
 }
示例#2
0
        public async Task DealCards()
        {
            GameStatus       = GameStatus.Playing;
            RiverPokers      = new List <Poker>();
            _openRiverPokers = new List <Poker>();
            int index = 0;

            foreach (var player in Players)
            {
                player.Poker1 = AllPokers[index++];
                player.Poker2 = AllPokers[index++];
                await Dealing?.Invoke(player);

                Thread.Sleep(500);
            }

            for (int i = 0; i < 5; i++)
            {
                RiverPokers.Add(_backPoker);
                _openRiverPokers.Add(AllPokers[index++]);
                Thread.Sleep(500);
                await GameUpdated?.Invoke(this);
            }
            Start();
        }
示例#3
0
        /// <summary>
        /// Where the grabber updates every x seconds and data is parsed
        /// </summary>
        private void Pulse(object sender, ElapsedEventArgs e)
        {
            gameGrabber.UpdateGames();
            List <Game> updates = new List <Game>();

            if (gameGrabber.Games.Length > 0)
            {
                if (gameUpdateTimes.Keys.Count > 0)
                {
                    foreach (int id in gameUpdateTimes.Keys)
                    {
                        Game game = IdMatch(id);
                        if (game != null)
                        {
                            if (game.LastUpdate != gameUpdateTimes[id] || game.LastUpdate > gameUpdateTimes[id] ||
                                game.BoxScore.LastUpdate > gameUpdateTimes[id])
                            {
                                updates.Add(game);
                            }
                        }
                    }
                }
            }
            foreach (Game game in updates)
            {
                gameUpdateTimes[game.Id] = game.BoxScore.LastUpdate;
                if (GameUpdated != null)
                {
                    GameUpdated.Invoke(game);
                }
            }
        }
示例#4
0
        private void ThreadAwake()
        {
            GameStatusUpdate gameStatusUpdate = _gameStatusRetriever.GetCurrentStatus();

            GameUpdated?.Invoke(gameStatusUpdate);

            ChangeDelay(gameStatusUpdate.GameStatus);
        }
示例#5
0
 public void TryRotate()
 {
     if (CanRotationBeMade())
     {
         ClearPreviousCurrentShapePosition();
         CurrentShape.Rotate();
         PlaceCurrentShape();
         GameUpdated?.Invoke(this, EventArgs.Empty);
     }
 }
示例#6
0
        public void GameCycle()
        {
            while (_running)
            {
                //Game loop

                GameUpdated?.Invoke(this, EventArgs.Empty);
                Thread.Sleep(50);
            }
        }
示例#7
0
 private void OnGameUpdated(List <GameUpdateEvent> updates)
 {
     if (!IsEventBufferEnabled)
     {
         GameUpdated?.Invoke(this, new GameUpdatedEventArgs(updates));
     }
     else
     {
         GameUpdatesEventBuffer.AddRange(updates);
     }
 }
示例#8
0
        public void Handle(GameUpdated @event)
        {
            var repository = _container.Resolve <IBonusRepository>();
            var game       = repository.Games.SingleOrDefault(g => g.Id == @event.Id);

            if (game == null)
            {
                throw new RegoException(string.Format(NoGameFormatter, @event.Id));
            }

            game.ProductId = @event.GameProviderId;
            repository.SaveChanges();
        }
示例#9
0
 private void CreateNewShape()
 {
     ClearPreviousCurrentShapePosition();
     CurrentShape = ShapeFactory.CreateRandomShape();
     //check if the position we want to place current shape is occupied by another item
     foreach (var item in CurrentShape)
     {
         if (GameArray[item.Row, item.Column] != null)
         {
             PlayerLost?.Invoke(this, EventArgs.Empty);
             return;
         }
     }
     PlaceCurrentShape();
     GameUpdated?.Invoke(this, EventArgs.Empty);
 }
示例#10
0
        public async Task Run()
        {
            while (true)
            {
                GameUpdated?.Invoke(this);

                List <Move> moves = GetPossibleMoves(Chips).Select(i => new Move(i)).ToList();

                Move selectedMove = (CurrentChip == Chip.Mouse ? await Controller1.Select(this, moves) : await Controller2.Select(this, moves));

                if (MoveAndCheckForWin(Chips, CurrentChip, WIN, selectedMove.ColumnIndex))
                {
                    GameUpdated?.Invoke(this);
                    Window.SetTimeout(() =>
                    {
                        Window.Alert($"{CurrentChip} wins!");
                    });

                    break;
                }

                CurrentChip = (CurrentChip == Chip.Mouse ? Chip.Cat : Chip.Mouse);
            }
        }
示例#11
0
 public static void InvokeGameUpdated(int timeLeft)
 {
     GameUpdated?.Invoke(timeLeft);
 }
 public void Consume(GameUpdated message)
 {
     _eventHandlers.Handle(message);
 }
示例#13
0
 public void Consume(GameUpdated message)
 {
     _gameSubscriber.Handle(message);
 }
示例#14
0
        /// <summary>
        /// Try and move the shape
        /// </summary>
        /// <param name="movement"></param>
        public void Move(Movement movement)
        {
            if (CurrentShape == null)
            {
                return;
            }

            //"sensitive" area
            lock (lockerObject)
            {
                //check if shape can be moved
                if (CanMovementCanBeMade(movement))
                {
                    //nullify its previous position in the array
                    ClearPreviousCurrentShapePosition();
                    //update all pieces' row or column information according to the movement requested
                    switch (movement)
                    {
                    case Movement.Left:
                        for (int i = 0; i < CurrentShape.Count; i++)
                        {
                            CurrentShape[i].Column--;
                        }
                        break;

                    case Movement.Bottom:
                        for (int i = 0; i < CurrentShape.Count; i++)
                        {
                            CurrentShape[i].Row++;
                        }
                        break;

                    case Movement.Right:
                        for (int i = 0; i < CurrentShape.Count; i++)
                        {
                            CurrentShape[i].Column++;
                        }
                        break;

                    default:
                        break;
                    }
                    //move the current shape in the array
                    PlaceCurrentShape();
                    GameUpdated?.Invoke(this, EventArgs.Empty);
                }
                else//movement cannot be made
                {
                    //item cannot be moved
                    //if the requested movement is bottom, this means that the shape cannot move even further
                    //so we need to 1. check if any row(s) are full of pieces, i.e. there exists a horizontal line
                    //2. remove these lines
                    //3. move all the rest lines towards the bottom of the array
                    //4. request another shape
                    if (movement == Movement.Bottom)
                    {
                        CurrentShape = null;
                        //check and clear lines
                        //move pieces below
                        ClearLinesAndMovePiecesBelow();
                        //create new shape
                        CreateNewShape();
                    }
                }
            }
        }
示例#15
0
 public void Handle(GameUpdated @event)
 {
     AddActivityLog(AdminActivityLogCategory.Game, @event);
 }