コード例 #1
0
        protected async Task CheckAnswer(AnswerData answer)
        {
            bool isCorrect;

            if (answer.Answer == DisplayCard.Answer)
            {
                answer.IsCorrect   = true;
                answer.IsIncorrect = false;
                answer.CssClass    = "correct";
                correctTotal++;
                isCorrect = true;
            }
            else
            {
                answer.IsCorrect   = false;
                answer.IsIncorrect = true;
                answer.CssClass    = "wrong";
                wrongTotal++;
                isCorrect = false;
            }
            await DeckState.UpdateStats(isCorrect);

            var stats = DeckState.DeckStats;

            StateHasChanged();
        }
コード例 #2
0
ファイル: Deck.cs プロジェクト: ObeA/intersection-simulator
    // Start is called before the first frame update
    private async void Start()
    {
        _newState = _state;
        _animator = GetComponentInParent <Animator>();

        Debug.Log($"Subscribing to {Topic}");
        await EnsureSubscribeRegisteredAsync();
    }
コード例 #3
0
        protected async Task ShowDeckCards(Deck deck)
        {
            deckEdit     = deck;
            DisplayCards = await DeckState.GetDeckCards(deck);

            showCards = true;
            StateHasChanged();
        }
コード例 #4
0
        protected async Task UpdateCard()
        {
            cardEdit.Answer   = answer;
            cardEdit.Question = question;
            await DeckState.UpdateDeckCard(deckEdit, cardEdit);

            showEdit = false;
            StateHasChanged();
        }
コード例 #5
0
        protected async Task SelectDeck()
        {
            SelectedDeck = UserDecks.Find(x => x.Name == deckName);
            await DeckState.UpdateSelectedDeckAsync(SelectedDeck);

            isAddCard = true;
            DeckCards = DeckState.SelectedDeck?.Cards;

            isSelectDeck = true;
            StateHasChanged();
        }
コード例 #6
0
        protected async Task AddDeck()
        {
            UserDecks ??= new List <Deck>();
            UserDecks.Add(newDeck);
            SelectedDeck = newDeck;
            deckName     = newDeck.Name;
            await DeckState.UpdateSelectedDeckAsync(SelectedDeck, true);

            isAddCard    = true;
            isSelectDeck = true;
        }
コード例 #7
0
ファイル: HandState.cs プロジェクト: SiniK88/ClashRoyaleCopy
    public HandState(DeckState _deckState)
    {
        deckState = _deckState;
        cards     = new List <Card>();

        for (int i = 0; i < CARDS_INITIALLY; i++)
        {
            Card card = deckState.NextCardFromDeck();
            card.state = Card.State.IN_HAND;
            cards.Add(card);
        }
    }
コード例 #8
0
ファイル: Deck.cs プロジェクト: ObeA/intersection-simulator
    // Update is called once per frame
    private async void Update()
    {
        await EnsureSubscribeRegisteredAsync();

        if (_state == _newState)
        {
            return;
        }

        _state = _newState;
        _animator.SetBool(Open, _state == DeckState.Open);
    }
コード例 #9
0
ファイル: Deck.cs プロジェクト: ObeA/intersection-simulator
    private async Task EnsureSubscribeRegisteredAsync()
    {
        if (_isSubscribed || !communicationsManager.IsInitialized || topic == null)
        {
            return;
        }

        await communicationsManager.Client.SubscribeAsync(Topic,
                                                          state =>
        {
            Debug.Log($"Received state {state} for {Topic}");
            _newState = (DeckState)int.Parse(state);
        });

        _isSubscribed = true;
    }
コード例 #10
0
        internal void OscMessage(string[] address, List <object> arguments)
        {
            if (address.Length >= 3 && arguments.Count == 1)
            {
                switch (address[2])
                {
                case "tc":
                    Tc?.Invoke(this, new TcEventArgs(arguments[0].ToString()));
                    break;

                case "control":
                    DeckControl control;
                    if (Enum.TryParse(arguments[0].ToString(), out control))
                    {
                        DeckControl?.Invoke(this, new DeckControlEventArgs(control));
                    }
                    break;

                case "state":
                    DeckState state;
                    if (Enum.TryParse(arguments[0].ToString(), out state))
                    {
                        DeckState?.Invoke(this, new DeckStateEventArgs(state));
                    }
                    break;

                case "connected":
                    bool isConnected;
                    if (bool.TryParse(arguments[0].ToString(), out isConnected))
                    {
                        IsConnected = isConnected;
                    }
                    break;

                case "frames_left":
                    if (arguments[0] is long)
                    {
                        FramesLeft?.Invoke(this, new FramesLeftEventArgs((long)arguments[0]));
                    }
                    break;

                default:
                    Debug.WriteLine($"Unrecognized message: {string.Join("/", address)}:{string.Join(",", arguments)}");
                    break;
                }
            }
        }
コード例 #11
0
        protected async Task AddCardToDeck()
        {
            SelectedDeck.Cards ??= new List <Card>();
            var newCard = new Card()
            {
                Question = question, Answer = answer
            };

            SelectedDeck.Cards.Add(newCard);
            await DeckState.AddCardToDeck(newCard, SelectedDeck);

            question  = null;
            answer    = null;
            DeckCards = SelectedDeck.Cards;
            await DeckState.UpdateDeckCards(SelectedDeck, DeckCards);

            StateHasChanged();
        }
コード例 #12
0
    private void SetDeckState(LaneTypes lanetype, int groupID, int componentID, DeckState newState)
    {
        //Finds all decks with id
        List <Bridge> bridgeList = bridges.FindAll(b => b.laneType == lanetype && b.GroupId == groupID && b.ComponentID == componentID);

        //No barrier found
        if (bridgeList == null)
        {
            Debug.LogError($"ERROR: Bridge with groupID: {groupID} and componentID: {componentID} not found");
            return;
        }

        foreach (var bridge in bridgeList)
        {
            if (newState != bridge.state)
            {
                bridge.state = newState;
            }
        }
    }
コード例 #13
0
        protected async Task DeleteCard(Card card)
        {
            if (card.IsDeleteConfirm)
            {
                await DeckState.RemoveCardFromDeck(card);

                SelectedDeck.Cards.Remove(card);
                await DeckState.UpdateDeckCards(SelectedDeck, SelectedDeck.Cards);

                card.ConfirmDelete   = "";
                card.CssConfirmClass = "";
            }
            else
            {
                card.ConfirmDelete   = "Delete forever?";
                card.CssConfirmClass = "wrong";
            }
            card.IsDeleteConfirm = !card.IsDeleteConfirm;
            StateHasChanged();
        }
コード例 #14
0
        protected async Task DeleteDeck(Deck deck)
        {
            if (deck.IsDeleteConfirm)
            {
                var cards = await DeckState.GetDeckCards(deck);

                await DeckState.RemoveDeck(deck, cards);

                UserDecks.Remove(deck);
                deck.ConfirmDelete   = "";
                deck.CssConfirmClass = "";
            }
            else
            {
                deck.ConfirmDelete   = "Delete this deck and all card contents, forever?";
                deck.CssConfirmClass = "deckDelete zoom";
            }
            deck.IsDeleteConfirm = !deck.IsDeleteConfirm;
            deckDeleteMessage    = deck.ConfirmDelete;
        }
コード例 #15
0
 public DeckStateEventArgs(DeckState state)
 {
     State = state;
 }
コード例 #16
0
    //Handles MQTT messages when they are received
    public void HandleMessage(string topic, string message)
    {
        //Parse and store topic information
        TopicInformation info = ParseTopic(topic);

        switch (info.componentType)
        {
        case ComponentTypes.traffic_light:
            //Handle traffic lights
            //Try setting new traffic light state
            try
            {
                TrafficLightState newState = (TrafficLightState)System.Enum.Parse(typeof(TrafficLightState), message);
                SetTrafficLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid traffic light state: '{message}' for traffic light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.warning_light:
            //Handle warning lights
            //Try setting new warning light state
            try
            {
                WarningLightState newState = (WarningLightState)System.Enum.Parse(typeof(WarningLightState), message);
                SetWarningLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid warning light state: '{message}' for warning light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.boat_light:
            //Handle boat lights
            //Try setting new boat light state
            try
            {
                BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message);
                SetBoatLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid boat light state: '{message}' for boat light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.sensor:     //Don't have to handle sensor data
            break;

        case ComponentTypes.barrier:
            //Handle barriers
            //Try setting new barrier state
            try
            {
                BarrierState newState = (BarrierState)System.Enum.Parse(typeof(BarrierState), message);
                SetBarrierState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid barrier state: '{message}' for barrier with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.deck:
            //Handle deck(bridge)
            //Try setting new deck(bridge) state
            try
            {
                DeckState newState = (DeckState)System.Enum.Parse(typeof(DeckState), message);
                SetDeckState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid deck(bridge) state: '{message}' for deck with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;

        case ComponentTypes.train_light:
            //Handle train_light
            //Try setting new train_light state
            try
            {
                BoatAndTrainLightState newState = (BoatAndTrainLightState)System.Enum.Parse(typeof(BoatAndTrainLightState), message);
                SetTrainLightState(info.laneType, info.groupID, info.componentID, newState);
            }
            catch
            {
                Debug.LogError($"ERROR: Tried setting invalid train_light state: '{message}' for train_light with GroupID: {info.groupID} and ComponentID: {info.componentID}");
            }
            break;
        }
    }
コード例 #17
0
ファイル: Player.cs プロジェクト: SiniK88/ClashRoyaleCopy
 public Player(bool _isHuman, List <Card> deckCards)
 {
     isHuman   = _isHuman;
     deckState = new DeckState(deckCards);
     handState = new HandState(deckState);
 }