Ejemplo n.º 1
0
    public string GetStateDelta()
    {
        // Just return the location/rotation of the players and the cards information
        List <string> cardStringArray = new List <string>();

        for (int i = 0; i < propPlacement.cards.Length; i++)
        {
            if (propPlacement.cards[i] != null)
            {
                var    outline       = propPlacement.cards[i].GetComponent <cakeslice.Outline>();
                bool   notSelected   = outline.eraseRenderer;
                string selectionInfo = notSelected ? "unselected" : "selected";

                cardStringArray.Add("\"" + selectionInfo + " " + CardProperties.Stringify(propPlacement.cards[i]) + "\"");
            }
        }

        var cardString = String.Join(", ", cardStringArray.ToArray());

        var leaderPosV3   = propPlacement.props[propPlacement.props.Count - 2].transform.position.ToString("f3");
        var leaderRotV3   = propPlacement.props[propPlacement.props.Count - 2].transform.rotation.eulerAngles.ToString("f3");
        var followerPosV3 = propPlacement.props[propPlacement.props.Count - 1].transform.position.ToString("f3");
        var followerRotV3 = propPlacement.props[propPlacement.props.Count - 1].transform.rotation.eulerAngles.ToString("f3");

        string finalString = "";

        finalString += "{\"leader\": {\"position\": \"" + leaderPosV3 + "\", \"rotation\": \"" + leaderRotV3 + "\"},";
        finalString += "\"follower\": {\"position\": \"" + followerPosV3 + "\", \"rotation\": \"" + followerRotV3 + "\"},";
        finalString += "\"cards\": [" + cardString + "]}";

        return(finalString);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// adds newly selected card to active cards list and if 3 checks if selection is a set
    /// </summary>
    /// <param name="card"></param>
    private void AddCard(GameObject card)
    {
        webSocketManager.SendLog("selected " + CardProperties.Stringify(card));
        if (!cardsToRemove.Contains(card) && card.activeSelf && !activeCards.Contains(card))
        {
            webSocketManager.SendLog("not about to remove card from board, so will add it to active cards");
            activeCards.Add(card);

            StartCoroutine("CheckSet");

            Dictionary <string, string> strData = new Dictionary <string, string>()
            {
                { "card", CardProperties.Stringify(card) },
                { "result", "ACTIVATED" }
            };
            webSocketManager.Send("result", strData, null);
        }
        else
        {
            webSocketManager.SendLog("about to remove card from board, not adding to active cards");
        }
    }
Ejemplo n.º 3
0
    public void AddMoreCards()
    {
        List <int> newCards = new List <int>();

        // 3 cards in a set.
        List <GameObject> cardsToDelete = new List <GameObject>();

        for (int i = 0; i < propPlacement.cards.Length; i++)
        {
            if (!propPlacement.cards[i].activeSelf)
            {
                cardsToDelete.Add(propPlacement.cards[i]);
                webSocketManager.SendLog("marking card " + CardProperties.Stringify(propPlacement.cards[i]) + " to delete");

                // If not in a reset state, generate a card to put in this spot instead.
                if (!reset)
                {
                    propPlacement.cards[i] = cardGenerator.GenCard();
                    newCards.Add(i);
                }
                else
                {
                    propPlacement.cards[i] = null;
                }
            }
        }

        if (!reset)
        {
            while (!SetsExist(propPlacement.cards))
            {
                foreach (int i in newCards)
                {
                    Destroy(propPlacement.cards[i]);
                    propPlacement.cards[i] = cardGenerator.GenCard();
                }
            }
            foreach (int i in newCards)
            {
                var rndGoodCell = hexgrid.GetRandomGrassOrPathCell();
                while (propPlacement.propLocs.Contains(rndGoodCell))
                {
                    rndGoodCell = hexgrid.GetRandomGrassOrPathCell();
                }

                propPlacement.cards[i].transform.position = rndGoodCell.transform.position;
                propPlacement.propLocs.Add(rndGoodCell);
                propPlacement.walkableLocs.Add(rndGoodCell);
            }
        }

        // Then you delete the cards.
        foreach (var card in cardsToDelete)
        {
            if (card != null)
            {
                webSocketManager.SendLog("about to destroy card " + CardProperties.Stringify(card));
                Destroy(card);
            }
        }

        cardsToDelete.Clear();
        webSocketManager.SendLog("successfully destroyed all previous cards");

        Debug.Log("Reset: " + reset);
        Debug.Log("Cards:");
        for (int i = 0; i < propPlacement.cards.Length; i++)
        {
            Debug.Log(propPlacement.cards[i]);
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Checks if the current active cards are a set
    /// If they are removes them and updates score'
    /// if not it removes them from the active set forcing player to start over selection
    /// </summary>
    /// <returns></returns>
    public IEnumerator CheckSet()
    {
        yield return(null);

        var materialHashSet = new HashSet <Material>();
        var countHashSet    = new HashSet <int>();
        var shapeHashSet    = new HashSet <GameObject>();

        foreach (var card in activeCards)
        {
            var cardProperties = card.GetComponent <CardProperties>();
            materialHashSet.Add(cardProperties.color);
            countHashSet.Add(cardProperties.count);
            shapeHashSet.Add(cardProperties.shape);
        }

        //if all 3 card components are different score
        if (activeCards.Count == 3 &&
            materialHashSet.Count == 3 &&
            countHashSet.Count == 3 &&
            shapeHashSet.Count == 3)
        {
            // IMMEDIATELY need to remove cards from the active set.
            webSocketManager.SendLog("found a valid set, including:");
            cardsToRemove = new List <GameObject>();
            for (int i = 0; i < 3; i++)
            {
                cardsToRemove.Add(activeCards[i]);
                webSocketManager.SendLog("active card: " + CardProperties.Stringify(activeCards[i]));
            }

            // Clearing this now means that no moveement will modify the set of
            // active cards while the set is processing
            activeCards.Clear();

            ChangeCardColors(1, cardsToRemove);
            webSocketManager.SendLog("successfully changed the card colors");

            #if !SIMULATING
            yield return(new WaitForSeconds(.25f));
            #endif
            #if SIMULATING
            yield return(null);
            #endif

            for (int i = 0; i < 3; i++)
            {
                cardsToRemove[i].SetActive(false);
                webSocketManager.SendLog("successfully marked card " + CardProperties.Stringify(cardsToRemove[i]) + " as inactive");
            }
            cardsToRemove.Clear();
            webSocketManager.SendLog("emptied list of cards to remove");
            yield return(null);

            #if !SIMULATING
            yield return(new WaitForSeconds(.25f));
            #endif
            scorekeeper.ScoredSet();
            turnController.AddMovesOnSet(scorekeeper.score);
            webSocketManager.SendLog("added a set and extra turns");
            AddMoreCards();
            webSocketManager.SendLog("added new cards");

            #if !SIMULATING
            List <string> cardStringArray = new List <string>();
            for (int i = 0; i < propPlacement.cards.Length; i++)
            {
                cardStringArray.Add(CardProperties.Stringify(propPlacement.cards[i]));
            }

            string cardsString = String.Join(", ", cardStringArray.ToArray());

            Dictionary <string, string> strData = new Dictionary <string, string>()
            {
                { "formed", "YES" },
                { "score", (scorekeeper.score).ToString() },
                { "cards", cardsString }
            };

            webSocketManager.Send("set", strData, null);
            #endif
        }
        else if (activeCards.Count >= 3 ||
                 (materialHashSet.Count < activeCards.Count ||
                  countHashSet.Count < activeCards.Count ||
                  shapeHashSet.Count < activeCards.Count))
        {
            ChangeCardColors(2, activeCards);
        }
        else
        {
            ChangeCardColors(0, activeCards);
        }

        // I believe this is only relevant if you are simulating

        #if !SIMULATING
        yield return(null);
        #endif
        #if SIMULATING
        MainControl mainControl = FindObjectOfType <MainControl>();
        yield return(null);

        mainControl.updating_cards = false;
        #endif

        yield break;
    }