Ejemplo n.º 1
0
    IEnumerator MoveCard(GameObject card, PlayCard_script pc, Transform spawn)
    {
        card.transform.DOMove(spawn.position, MoveTime);
        yield return(new WaitForSeconds(MoveTime));

        pc.PlaceCard(spawn, false);
    }
Ejemplo n.º 2
0
    PlayCard_script CheckMaxValue() //find max
    {
        PlayCard_script tempCard = null;

        foreach (PlayCard_script card in _aiDeck.ActiveCards)
        {
            int totalValue = 0;
            if (card.Ability == "Normal")
            {
                totalValue = card.Value + AIBoard.ActiveValue;
            }
            else if (card.Ability == "PlusMinus")
            {
                if (card.Value < 0)
                {
                    card.ToggleValue();
                }
                totalValue = card.Value + AIBoard.ActiveValue;
            }
            else if (card.Ability == "Double")
            {
                PlayCard_script pc = AIBoard.GetLastCard();
                totalValue = (pc.Value * 2) + AIBoard.ActiveValue;
            }
            if (totalValue == _gameController.MaxValue)
            {
                tempCard = card;
                break;
            }
        }

        return(tempCard);
    }
Ejemplo n.º 3
0
 public void RemoveCard(PlayCard_script pc)
 {
     if (ActiveCards.Contains(pc))
     {
         ActiveCards.Remove(pc);
     }
 }
Ejemplo n.º 4
0
    PlayCard_script CheckOverMax()
    {
        PlayCard_script tempCard = null;

        foreach (PlayCard_script card in _aiDeck.ActiveCards)
        {
            int totalValue = 0;
            if (card.Ability == "Normal")
            {
                totalValue = AIBoard.ActiveValue + card.Value;
            }
            else if (card.Ability == "PlusMinus")
            {
                if (card.Value > 0) //toggle value if card is PlusMinus card
                {
                    card.ToggleValue();
                }
                totalValue = AIBoard.ActiveValue + card.Value;
            }
            if (totalValue <= _gameController.MaxValue)
            {
                tempCard = card;
                break;
            }
        }
        return(tempCard);
    }
Ejemplo n.º 5
0
 public void IncreaceValue(PlayCard_script pc, bool playerCard = true)
 {
     _playedCards.Add(pc);
     ActiveValue    += pc.Value;
     _valueText.text = ActiveValue.ToString("F0");
     if (ActiveValue == GameController.MaxValue)
     {
         _valueText.color = TextColors[1];
         SetPlayerDone();
         return;
         //auto end turn. at max
     }
     else if (ActiveValue > GameController.MaxValue)
     {
         _valueText.color = TextColors[2];
         //SetPlayerDone();
         //return;
         //Lost, over max
     }
     else if (ActiveValue < GameController.MaxValue)
     {
         _valueText.color = TextColors[0];
     }
     if (playerCard) //only allowed one card per turn
     {
         _cardPlayed = true;
         AllowMove   = false;
         //GameController.SwitchPlayer();
     }
     //next player
 }
Ejemplo n.º 6
0
    void CheckPlayerDone(out PlayCard_script tempCard, out PlayCard_script drawCard) //check higher if player done and for draw
    {
        tempCard = null;
        drawCard = null;

        int risk = Random.Range(0, 100);

        if (risk < AIStates.RiskValue || (AIBoard.ActiveValue + (10 - AIStates.EndOffset)) > _gameController.MaxValue) //will risk a random card
        {
            return;
        }

        foreach (PlayCard_script card in _aiDeck.ActiveCards)
        {
            if (PlayerBoard.PlayerDone)
            {
                int diffValue = (card.Value + AIBoard.ActiveValue) - PlayerBoard.ActiveValue;

                if (card.Ability == "Normal")
                {
                    diffValue = (card.Value + AIBoard.ActiveValue) - PlayerBoard.ActiveValue;
                }
                else if (card.Ability == "PlusMinus")
                {
                    if (card.Value < 0)
                    {
                        card.ToggleValue();
                    }
                    diffValue = (card.Value + AIBoard.ActiveValue) - PlayerBoard.ActiveValue;
                }
                else if (card.Ability == "Double")
                {
                    PlayCard_script pc = AIBoard.GetLastCard();
                    diffValue = ((pc.Value * 2) + AIBoard.ActiveValue) - PlayerBoard.ActiveValue;
                }
                if (diffValue <= 0) //avoid draw
                {
                    drawCard = card;
                    continue;
                }

                /*if (diffValue == 0)
                 * {
                 *  drawCard = card;
                 * }*/
                if (tempCard == null)
                {
                    tempCard = card;
                    continue;
                }
                //find closes to player
                int tempDiffValue = (tempCard.Value + AIBoard.ActiveValue) - PlayerBoard.ActiveValue;
                if (diffValue < tempDiffValue)
                {
                    tempCard = card;
                    continue;
                }
            }
        }
    }
    private void GenerateAllCards()
    {
        /*foreach (string cardInfo in PlayerInfo.DeckInventroy)
         * {
         *  Transform parent = GetCardPage();
         *  GameObject card = Instantiate(SelectCardPrefab, parent.position, Quaternion.identity,
         *      parent);
         *  PlayCardSelection_script pcs = card.GetComponentInChildren<PlayCardSelection_script>();
         *  PlayCard_script pc = card.GetComponentInChildren<PlayCard_script>();
         *  string[] cardString = cardInfo.Split(',');
         *  int cardAmount = int.Parse(cardString[0]);
         *  pc.Config(0, cardString[1], CardColors, GameController);
         *  pcs.ConfigDefaultCard(cardString[1], cardAmount, GameController);
         * }*/

        _allcards     = new List <PlayCard_script>();
        _allCardSlots = new List <PlayCardSelection_script>();
        _activePages  = 0;
        //Need to add check so only generation newly bought cards. currently clearing all and regenerating when new bought

        foreach (PlayerInfoManager_script.DeckInventroyClass cardInfo in PlayerInfo.PlayerDeck)
        {
            Transform  parent = GetCardPage();
            GameObject card   = Instantiate(SelectCardPrefab, parent.position, Quaternion.identity,
                                            parent);
            PlayCardSelection_script pcs = card.GetComponentInChildren <PlayCardSelection_script>();
            PlayCard_script          pc  = card.GetComponentInChildren <PlayCard_script>();

            pc.Config(0, cardInfo.CardInfo, CardColors, GameController);
            pcs.ConfigDefaultCard(cardInfo.CardInfo, cardInfo.CardAmount, GameController);

            _allcards.Add(pc);
            _allCardSlots.Add(pcs);
        }


        foreach (Transform c in _cardPages)
        {
            c.gameObject.SetActive(false);
            if (c.childCount > 0)
            {
                _activePages++;
            }
        }

        _activePages--; //reduce one to get array index
        _cardPages[0].gameObject.SetActive(true);

        if (_activePages <= 0) //one page? skip page setup
        {
            CardPageButtonHolder.SetActive(false);
            return;
        }

        _pageText.text = "1 / " + (_activePages + 1);

        _cardPageIndex = _cardPages.IndexOf(_cardPages[0]);
    }
Ejemplo n.º 8
0
    void Double()
    {
        //Double last played card
        PlayCard_script lastCard = _totalValueTracker.GetLastCard();

        _totalValueTracker.IncreaceValue(lastCard, _playerCard);
        lastCard.Value *= 2;
        lastCard.SetValueText();
    }
Ejemplo n.º 9
0
    public void GenereteShop()
    {
        if (!NewShop)
        {
            return;
        }
        _activeList = new List <string>(ShopMasterList);
        int r = Random.Range(MinAmount, MaxAmount);

        foreach (Transform card in _cardHolder)
        {
            Destroy(card.gameObject);
        }

        CurrentShop = new List <ShopCardInfo>();
        for (int i = 0; i < r; i++)
        {
            _activeList.Shuffle();
            string[]     cardInfo = _activeList[r].Split(',');
            ShopCardInfo shopCard = new ShopCardInfo();

            shopCard.CardPrice = int.Parse(cardInfo[0]);
            shopCard.CardInfo  = cardInfo[1];

            GameObject card = Instantiate(DefaultCard, _cardHolder);
            card.SetActive(true);

            PlayCardSelection_script pcs = card.GetComponentInChildren <PlayCardSelection_script>();
            PlayCard_script          pc  = card.GetComponentInChildren <PlayCard_script>();
            pc.Config(0, shopCard.CardInfo, CardColors, GameController);
            pcs.ConfigDefaultCard(shopCard.CardInfo, 1, GameController);

            shopCard.PlayCard = pc;

            Button buyButton = pcs.transform.GetChild(2).GetChild(1).GetComponent <Button>();
            int    index     = i;
            buyButton.onClick.AddListener(() => BuyCard(index));
            TextMeshProUGUI priceText = card.transform.GetChild(3).GetComponent <TextMeshProUGUI>();
            priceText.text = shopCard.CardPrice.ToString("F0") + "\nCredits";

            if (PlayerInfoManager.Credits < shopCard.CardPrice)
            {
                buyButton.interactable = false;
            }

            shopCard.BuyButton = buyButton;

            CurrentShop.Add(shopCard);
        }

        NewShop = false;

        _refreshButton.interactable = _activePrice < PlayerInfoManager.Credits;
    }
Ejemplo n.º 10
0
    /*IEnumerator DoDeterminPlay() //old, broken.
     * {
     *  debugTrack++;
     *  Debug.Log("AI Determin PLay - " + debugTrack);
     *  if (_gameController.ActivePlayer != AIBoard.PlayerID || _gameController.RoundDone || AIBoard.ActiveValue >= _gameController.MaxValue)
     *  {
     *      //not AI's turn or round over
     *      yield break;
     *  }
     *  //thinking animations
     *  float t = Random.Range(0.5f, 1f);
     *  yield return new WaitForSeconds(t);
     *  if ((AIBoard.ActiveValue > PlayerBoard.ActiveValue && AIBoard.ActiveValue < _gameController.MaxValue &&
     *       PlayerBoard.PlayerDone))
     *  {
     *      Debug.Log("More then player");
     *      AIBoard.SetPlayerDone();
     *      yield break;
     *      //StopCoroutine(_determin);
     *  }
     *  PlayCard_script[] pcs = AIBoard._handCardBoard.GetComponentsInChildren<PlayCard_script>();
     *  int playTotal;
     *  PlayCard_script pc = null;
     *  foreach (PlayCard_script fpc in pcs)
     *  {
     *      playTotal = AIBoard.ActiveValue + fpc.Value;
     *      if (playTotal > _gameController.MaxValue) //need minus
     *      {
     *          if (fpc.Value < 0)
     *          {
     *              pc = fpc;
     *              break;
     *          }
     *      }
     *      //check close to max
     *
     *      if (playTotal <= AIStates.EndOffset || (playTotal > PlayerBoard.ActiveValue && PlayerBoard.PlayerDone))
     *      {
     *          pc = fpc;
     *          break;
     *      }
     *  }
     *  if (pc != null)
     *  {
     *      _moveCard = StartCoroutine(MoveCard(pc));
     *      yield break;
     *  }
     *  else if (pc == null && AIBoard.ActiveValue > _gameController.MaxValue)
     *  {
     *      AIBoard.SetPlayerDone();
     *      yield break;
     *  }
     *  //no valid moves, skip
     *  Debug.Log("AI Switch Player");
     *  _gameController.SwitchPlayer();
     * }*/
    #endregion

    IEnumerator MoveCard(PlayCard_script pc) //look for valid slot and move card
    {
        Debug.Log("AIMananger_script: MoveCard: Start");
        if (_gameController.RoundDone)
        {
            //round over
            //StopCoroutine(_moveCard);
            yield break;
        }
        if (pc == null) //error skip turn
        {
            Debug.Log("AIMananger_script: MoveCard: null passed");
            _gameController.SwitchPlayer();
            yield break;
        }
        Transform slot = null;

        Debug.Log("AIMananger_script: MoveCard: find slot");
        foreach (Transform t in AIBoard._mainCardBoard)
        {
            if (t.childCount == 0)
            {
                slot = t;
                break;
            }
        }
        if (slot == null)
        {
            Debug.Log("AIMananger_script: MoveCard: no valid slot");
            //no valid slot left
            AIBoard.SetPlayerDone();
            // StopCoroutine(_moveCard);
            yield break;
        }
        Debug.Log("AIMananger_script: MoveCard: move card");
        pc.ToggleCardBack(false);
        pc.transform.DOMove(slot.position, MoveTime);
        _aiDeck.RemoveCard(pc);
        yield return(new WaitForSeconds(MoveTime));

        pc.PlaceCard(slot);

        /*if (AIBoard.ActiveValue == _gameController.MaxValue - EndOffset) //close to max, end player
         * {
         *  AIBoard.SetPlayerDone();
         *  StopCoroutine(_moveCard);
         * }*/
        //_gameController.SwitchPlayer();
        if (AIBoard.ActiveValue != _gameController.MaxValue)
        {
            AIBoard.SetPlayerDone();
        }
    }
Ejemplo n.º 11
0
    //Main game controls
    void GetCard()
    {
        if (_playCard != null)
        {
            return;
            //already holding card
        }
        if (_playCard == null)
        {
            m_PointerEventData          = new PointerEventData(m_EventSystem);
            m_PointerEventData.position = Input.mousePosition;
            List <RaycastResult> results = new List <RaycastResult>();
            m_Raycaster.Raycast(m_PointerEventData, results);
            //Debug.Log("InputControls_script: GetCard: hits - " +results.Count);

            foreach (RaycastResult hit in results)
            {
                if (hit.gameObject.GetComponent <Button>() != null)
                {
                    return;
                }
                _playCard = hit.gameObject.transform.parent.GetComponent <PlayCard_script>();
                if (_playCard != null)
                {
                    if (_gameController.GameStage == 1)
                    {
                        if (_playCard.PlayerID != _gameController.ActivePlayer || _playCard.Placed)
                        {
                            _playCard = null;
                            Debug.Log("InputControls_script: GetCard: wrong players card");
                            //wrong player
                            return;
                        }
                        if ((_gameController.ActivePlayer == 0 && !_gameController.LeftBoard.AllowMove) || (_gameController.ActivePlayer == 1 && !_gameController.RightBoard.AllowMove))
                        {
                            _playCard = null;
                            Debug.Log("InputControls_script: GetCard: already placed card");
                            return;
                        }
                    }
                    break;
                }
            }
            if (_playCard == null) //no card selected
            {
                return;
            }
            _playCard.transform.SetParent(MouseHolder, false);
        }
    }
Ejemplo n.º 12
0
 public void GenereateDeck()
 {
     _activeDeck = PlayerDeck;
     _activeDeck.Shuffle();
     foreach (Transform t in _cardSlots)
     {
         //int v = _activeDeck[0];
         string s = _activeDeck[0];
         _activeDeck.RemoveAt(0);
         GameObject      go = Instantiate(CardPrefab);
         PlayCard_script pc = go.GetComponent <PlayCard_script>();
         pc.PlaceCard(t, false, false);
         pc.Config(_totalValueTracker.PlayerID, s, CardColors, _totalValueTracker.GameController, isAI);
         ActiveCards.Add(pc);
     }
 }
Ejemplo n.º 13
0
    public bool CheckValible(PlayCard_script pc)
    {
        if (pc == null)
        {
            return(false);
        }
        if (pc.PlayerID != ID || _playCard != null) //wrong slot or slot occupide
        {
            return(false);
        }
        if (this.transform.childCount > 0)
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 14
0
    void PlaceCard()
    {
        if (_playCard == null)
        {
            //Debug.Log("InputControls_script: PlaceCard: play card empty");
            return;
            //no card held
        }
        m_PointerEventData          = new PointerEventData(m_EventSystem);
        m_PointerEventData.position = Input.mousePosition;
        List <RaycastResult> results = new List <RaycastResult>();

        m_Raycaster.Raycast(m_PointerEventData, results);
        //Debug.Log("InputControls_script: GetCard: hits - " + results.Count);
        MainCardHolder_script cardHolder = null;

        foreach (RaycastResult hit in results)
        {
            cardHolder = hit.gameObject.GetComponent <MainCardHolder_script>();
            if (cardHolder != null)
            {
                break;
            }
        }
        if (cardHolder == null || !cardHolder.CheckValible(_playCard))
        {
            Debug.Log("InputControls_script: PlaceCard: wrong placement");
            //error sound
            _playCard.BounceBack();
            _playCard = null;
            return;
        }
        else
        {
            //success sound
            Debug.Log("InputControls_script: PlaceCard: Correct placement");
            //_gameController.SwitchPlayer();
            _playCard.PlaceCard(cardHolder.transform);
            _playCard = null;
            if (_gameController.GameStage == 0)
            {
                CardSelection.SetPlayerDeck();
            }
        }
    }
Ejemplo n.º 15
0
    PlayCard_script CheckCloseMaxValue() //find closes to max
    {
        PlayCard_script tempCard = null;

        foreach (PlayCard_script card in _aiDeck.ActiveCards)
        {
            int totalValue = 0;
            int tempMax    = _gameController.MaxValue - AIStates.EndOffset;
            if (card.Ability == "Normal")
            {
                totalValue = card.Value + AIBoard.ActiveValue;
            }
            else if (card.Ability == "PlusMinus")
            {
                if (card.Value < 0)
                {
                    card.ToggleValue();
                }
                totalValue = card.Value + AIBoard.ActiveValue;
            }
            else if (card.Ability == "Double")
            {
                PlayCard_script pc = AIBoard.GetLastCard();
                totalValue = (pc.Value * 2) + AIBoard.ActiveValue;
            }
            if (totalValue >= tempMax && totalValue < _gameController.MaxValue && totalValue > PlayerBoard.ActiveValue)
            {
                if (tempCard == null)
                {
                    tempCard = card;
                    continue;
                }
                else if (card.Value > tempCard.Value)
                {
                    tempCard = card;
                    continue;
                }
            }
        }

        return(tempCard);
    }
Ejemplo n.º 16
0
    public void PlaceGlobalCard(int p)
    {
        //Debug.Log("GlobalDeckManager_script:PlaceGlobalCard: Start - Value " +_activeDeck[0]);
        Transform spawn = FindSpawnLoc(p);

        if (spawn == null)
        {
            return;
        }
        if (_activeDeck.Count <= 0) //recreates active deck if deck runs out
        {
            GenerateGlobalDeck();
        }
        GameObject      card = Instantiate(GlobalPlayCardPrefab, CardSpawnPoint.position, Quaternion.identity, CardSpawnPoint);
        PlayCard_script pc   = card.GetComponent <PlayCard_script>();
        //int i = _activeDeck[0];
        string s = _activeDeck[0];

        pc.Config(_gameController.ActivePlayer, s, CardColor, _gameController);
        //Debug.Log("GlobalDeck: Add card to - " + _gameController.ActivePlayer + "- card value" + pc.Value);
        //pc.PlaceCard(spawn, false);
        StartCoroutine(MoveCard(card, pc, spawn));
        _activeDeck.RemoveAt(0);
    }
Ejemplo n.º 17
0
    IEnumerator DoDeterminePlay() //check for play
    {
        //yield return new WaitForSeconds(_globalDeck.MoveTime); //added delay to player switch in game controller
        float rWait = Random.Range(0.5f, 1f);

        yield return(new WaitForSeconds(rWait));

        if (AIBoard.PlayerDone)
        {
            yield break;
        }
        PlayCard_script tempCard = null;
        PlayCard_script drawCard = null;

        if (PlayerBoard.ActiveValue > _gameController.MaxValue) //player over max, AI should expect to win
        {
            AIBoard.SetPlayerDone();
            yield break;
        }

        //Check if random card gets AI close
        if (AIBoard.ActiveValue >= (_gameController.MaxValue - AIStates.EndOffset) && AIBoard.ActiveValue < _gameController.MaxValue && !PlayerBoard.PlayerDone)
        {
            Debug.Log("AIMananger_script: DoDeterminePlay: random card close to max, end round");
            AIBoard.SetPlayerDone();
            yield break;
        }

        //Check if out of cards
        if (_aiDeck.ActiveCards.Count <= 0)
        {
            if (AIBoard.ActiveValue > _gameController.MaxValue)
            {
                AIBoard.SetPlayerDone();
                yield break;
            }
            Debug.Log("AIMananger_script: DoDeterminePlay: out of cards, skip");
            //Sound effect or something
            _gameController.SwitchPlayer();
            yield break;
        }

        if (AIBoard.ActiveValue > _gameController.MaxValue) //Active value over max, check for minus card
        {
            tempCard = CheckOverMax();
            if (tempCard == null) //No card to get lower the max
            {
                AIBoard.SetPlayerDone();
            }
            else //found card play it
            {
                Debug.Log("AIMananger_script: DoDeterminePlay: Play card");
                _moveCard = StartCoroutine(MoveCard(tempCard));
                yield break;
            }
        }

        //check able to get 20
        Debug.Log("AIMananger_script: DoDeterminePlay: check for max");
        tempCard = CheckMaxValue();

        if (tempCard != null)
        {
            Debug.Log("AIMananger_script: DoDeterminePlay: Play card");
            _moveCard = StartCoroutine(MoveCard(tempCard));
            yield break;
        }

        //check close to max
        Debug.Log("AIMananger_script: DoDeterminePlay: check close to max");
        tempCard = CheckCloseMaxValue();

        if (tempCard != null)
        {
            Debug.Log("AIMananger_script: DoDeterminePlay: Play card");
            _moveCard = StartCoroutine(MoveCard(tempCard));
            yield break;
        }

        if (PlayerBoard.PlayerDone && (drawCard != null || tempCard != null)) //not possible to win try for a draw
        {
            int risk = Random.Range(0, 100);
            if (risk > AIStates.RiskValue) //AI will not risk a new card, goes for draw
            {
                Debug.Log("AIMananger_script: DoDeterminePlay: Play card");
                _moveCard = StartCoroutine(MoveCard(tempCard));
                yield break;
            }
        }

        //need to check max

        Debug.Log("AIMananger_script: DoDeterminePlay: no valid card found, skip");
        //Sound effect or something
        _gameController.SwitchPlayer();
    }