Exemplo n.º 1
0
        public INotify RegisterNotificationService(INotify n)
        {
            if (n == null)
            {
                throw new ArgumentNullException();
            }

            if (RegisteredAutomations.ContainsKey(n.Name))
            {
                throw new ArgumentException($"Canot register notification service '{n.Name}' of type '{n.GetType()}'. It's already registered.");
            }

            RegisteredNotificationServices.Add(n.Name, n);

            LOGGER.Info($"Registered automation '{n.Name}' of type '{n.GetType()}'");

            return(n);
        }
        public void fireStateChangedNotification(INotify notify)
        {
            LOG.Info("Received notification '" + notify.GetType() + "'");
            if (notify.GetType().Equals(typeof(PlayerReadyNotify)))
            {
                bool allReady = true;
                for (int i = 0; i < 2; i++)
                {
                    if (!this.players[i].getCurrentState().GetType().Equals(typeof(PlayerReadyState)))
                    {
                        allReady = false;
                        break;
                    }
                }
                if (allReady)
                {
                    LOG.Info("All players is ready");
                    for (int i = 0; i < 2; i++)
                    {
                        PlayerPlayEvent playerPlayEvent = new PlayerPlayEvent();
                        this.players[i].consumeEvent(playerPlayEvent);
                    }
                    int first = 1; // Hard code
                    this.players[1 - first].consumeEvent(new PlayerWaitEvent());

                    GameInitializedEvent _initializedEvent = new GameInitializedEvent();
                    this.consumeEvent(_initializedEvent);
                }
                else
                {
                    LOG.Info("All player not ready");
                }
            }
            else if (notify.GetType().Equals(typeof(BoardMovedNotify)))
            {
                for (int i = 0; i < 2; i++)
                {
                    if (this.players[i].getCurrentState().GetType().Equals(typeof(PlayerPlayingState)))
                    {
                        LOG.Info("Change player " + i + "  Playing to Waiting");
                        this.players[i].consumeEvent(new PlayerWaitEvent());
                    }
                    else if (this.players[i].getCurrentState().GetType().Equals(typeof(PlayerWaitingState)))
                    {
                        LOG.Info("Change player " + i +" Waiting to Turning");
                        this.players[i].consumeEvent(new PlayerTurnEvent());
                    }
                    else
                    {
                        LOG.Info("Current state: " + players[i].getCurrentState().GetType());
                    }
                }
            }
        }
        public void fireStateChangedNotification(INotify notify)
        {
            if (notify.GetType().Equals(typeof(InitializingNotify)))
            {
                LOG.Info("State changed: initializing");
            }
            else if (notify.GetType().Equals(typeof(ReadyNotify)))
            {
                LOG.Info("State changed: ready");
            }
            else if (notify.GetType().Equals(typeof(MovingNotify)))
            {
                LOG.Info("State changed: moving");
            }
            else if (notify.GetType().Equals(typeof(BoardMovedNotify)))
            {
                LOG.Info("State changed: moved");
            }
            else if (notify.GetType().Equals(typeof(RejectedNotify)))
            {
                LOG.Info("State changed: rejected");
            }

            _notifyListeners(notify);
        }