コード例 #1
0
    // Use this for initialization
    void Start()
    {
        SelectionToggleObject = this.transform.GetChild(0).gameObject;
        CG = GameObject.Find("Deck").GetComponent <CoreGameplay>();
        GR = GameObject.FindGameObjectWithTag("Canvas").GetComponent <GraphicRaycaster>();
        if (this.transform.parent.tag == "Hand")
        {
            SelectionToggleObject.SetActive(true);
            this.GetComponent <Image>().sprite = Resources.Load <Sprite>(CG.LocalCards[0]);
            this.name = CG.LocalCards[0];
            CG.LocalCards.RemoveAt(0);
        }
        if (this.transform.parent.tag == "Table")
        {
            SelectionToggleObject.SetActive(false);
            this.transform.localScale          = new Vector3(2.5f, 1.25f, 1);
            this.GetComponent <Image>().sprite = Resources.Load <Sprite>(CG.TableCards[(CG.TableCards.Count - 1)]);
            this.name = CG.TableCards[CG.TableCards.Count - 1];
            //CG.TableCards.RemoveAt(0);
            this.GetComponent <Image>().raycastTarget = false;
        }
        if (this.transform.parent.tag == "Stih")
        {
            SelectionToggleObject.SetActive(false);
            this.transform.localScale          = new Vector3(1, 1, 1);
            this.GetComponent <Image>().sprite = Resources.Load <Sprite>(CG.allSelectedCards[(CG.allSelectedCards.Count - 1)].gameObject.name.ToString());
            this.name = CG.allSelectedCards[(CG.allSelectedCards.Count - 1)].gameObject.name.ToString();
            CG.allSelectedCards.RemoveAt((CG.allSelectedCards.Count - 1));
            this.GetComponent <Image>().raycastTarget = false;
        }
        if (this.transform.parent.tag == "iStih")
        {
            SelectionToggleObject.SetActive(false);
            this.transform.localScale          = new Vector3(1, 1, 1);
            this.GetComponent <Image>().sprite = Resources.Load <Sprite>(CG.iStihCards[0]);
            this.name = CG.iStihCards[0].ToString();
            CG.iStihCards.RemoveAt(0);
            this.GetComponent <Image>().raycastTarget = false;
        }

        string cardname = this.GetComponent <Image>().sprite.name;

        GetCardSign(cardname);
        GetCardValue(cardname);
        IsCardAJoker(cardname);

        GR = GameObject.FindGameObjectWithTag("Canvas").GetComponent <GraphicRaycaster>();
    }
コード例 #2
0
ファイル: AI.cs プロジェクト: ashton-summers/Hexplode
    /// <summary>
    /// Selects a move to make from the board.
    /// Implements the interface this way we can add different AI later if needed/wanted.
    /// </summary>
    public IEnumerator SelectMove()
    {
        System.Random r            = new System.Random();
        BoardManager  boardManager = GameObject.FindGameObjectWithTag("board").GetComponent <BoardManager>();
        CoreGameplay  coreGameplay = GameObject.FindGameObjectWithTag("coreGame").GetComponent <CoreGameplay>();
        Hexagon       hex          = null;

        int   numHexesOnBoard = boardManager.Hexagons.Count;
        int   randNum = r.Next(0, numHexesOnBoard);
        bool  aiHasFoundSpot = false;
        float x, y;

        turnIsOver = false;

        while (!aiHasFoundSpot)
        {
            // If the hex is not yet occupied or the player name is set to player 2. AI will ALWAYS be second player
            if (boardManager.Hexagons[randNum].HexOwner == null || boardManager.Hexagons[randNum].HexOwner.PlayerName == "player2")
            {
                // Add logic here to change mouse position using the selected hex and then notify subscribers
                hex            = boardManager.Hexagons[randNum];
                aiHasFoundSpot = true;
            }
            else
            {
                randNum = r.Next(0, numHexesOnBoard);
            }
        }

        yield return(new WaitForSeconds(3.0f));

        x = boardManager.Hexagons[randNum].x;
        y = boardManager.Hexagons[randNum].y;
        coreGameplay.AIChangeMousePos(x, y);
        NotifyPropertyChanged(this, "Mouse Clicked"); // AI has 'clicked' on a hexagon, tell the board manager
        turnIsOver = true;
    }