Example #1
0
        // Update is called once per frame
        void Update()
        {
            // Detect mouse button click
            if (Input.GetMouseButtonDown(0))
            {
                var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.collider.tag == "DominoTile")
                    {
                        DominoTile dtile = hit.collider.GetComponent <DominoTile>();
                        Debug.Log("Mouse clicked domino tile: " + dtile.ToString());

                        if (nextTurnCards.Contains(dtile))
                        {
                            Debug.Log("DominoTile in nextTurnCards");
                            // Mark that this domino tile is the next for this player
                            int card_ind = nextTurnCards.IndexOf(dtile);

                            Debug.Log("Selected card index: " + card_ind.ToString());
                            Debug.Log("nextMoves Count = " + nextMoves.Count.ToString());
                            Debug.Log("isFirstTurn = " + isFirstTurn.ToString());
                            nextMoves[card_ind].playerColor = previousMoves[0].playerColor;

                            if (!isFirstTurn)
                            {
                                Debug.Log("Making a move");
                                previousMoves[0].rotationType = RotationType.Rot0;
                                previousMoves[0].position.Set(col: 1, row: 1, true);
                                MakeMove(previousMoves[0]);

                                // Add move to full moves list
                                moves.Add(previousMoves[0]);
                            }

                            // Remove the previous move
                            previousMoves.RemoveAt(0);

                            // Check if all players have selected their cards
                            if (previousMoves.Count == 0)
                            {
                                isTurnFinished = true;
                            }
                        }
                    }
                }
            }

            if (isTurnFinished)
            {
                // Remove the flag which indicates the first turn
                if (isFirstTurn)
                {
                    isFirstTurn = false;
                }
                AdvanceTurn();
            }
        }
Example #2
0
 public bool IsMoveValid(DominoTile domino_tile, int tile_ind)
 {
     for (int i = 0; i < properties.Count; i++)
     {
         Property group = properties[i];
     }
     // TODO
     return(false);
 }
Example #3
0
 private void Shuffle()
 {
     // Fisher-Yates shuffle
     for (int i = 0; i < domino_tiles.Count; i++)
     {
         DominoTile temp        = domino_tiles[i];
         int        randomIndex = Random.Range(i, domino_tiles.Count);
         domino_tiles[i]           = domino_tiles[randomIndex];
         domino_tiles[randomIndex] = temp;
     }
 }
Example #4
0
 public int CompareTo(DominoTile other)
 {
     if (this.sortIndex == other.sortIndex)
     {
         return(0);
     }
     else if (this.sortIndex < other.sortIndex)
     {
         return(-1);
     }
     else
     {
         return(1); // this.other > other.other
     }
 }
Example #5
0
        private void MakeMove(Move move)
        {
            // Find the DominoTile index in the previous cards list
            int prev_ind = previousTurnCards.FindIndex(p => p.sortIndex == move.dominoTileSortIndex);

            Debug.Log("prev_ind = " + prev_ind.ToString());

            // Find player index
            int player_ind = players.FindIndex(p => p.playerColor == move.playerColor);

            Debug.Log("player_ind = " + player_ind.ToString());

            // Move the domino tile GameObject to the relevant player
            DominoTile tile_obj = previousTurnCards[prev_ind];

            tile_obj.gameObject.transform.parent = players[player_ind].transform;
            tile_obj.rotationType = move.rotationType;

            // Update the Board object of the player - TODO !!

            // TODO - move tile graphics to place !!!
            tile_obj.gameObject.transform.localPosition = new Vector3(-1f, -1f, 0f);
        }