Ejemplo n.º 1
0
        public void AddToHand(TileView tile)
        {
            // Add the tile to the internal state tracking for the hand.
            _tiles.Add(tile);
            tile.Clicked += OnTileClicked;

            // Make the tile object a child of the root object for the tiles in the
            // player's hand.
            tile.transform.SetParent(_handRoot, worldPositionStays: false);

            // Re-layout the updated set of tiles in the player's hand.
            var leftSide = _tiles.Count * -TileWidth * 0.5f;

            foreach (var(index, tileObj) in _tiles.Enumerate())
            {
                tileObj.transform.localPosition = new Vector3(
                    leftSide + TileWidth * index,
                    0f,
                    0f);
            }
        }
Ejemplo n.º 2
0
        public void MoveToDiscard(TileId id)
        {
            TileView discarded;

            // Get the `TileView` object for the selected tile, either from the tiles
            // in the player's hand or from the current draw.
            var discardIndex = _tiles.FindIndex(tile => tile.Model.Id.Element0 == id.Element0);

            if (discardIndex >= 0)
            {
                discarded = _tiles[discardIndex];
                _tiles.RemoveAt(discardIndex);
            }
            else if (_currentDraw != null && _currentDraw.Model.Id.Element0 == id.Element0)
            {
                discarded    = _currentDraw;
                _currentDraw = null;
            }
            else
            {
                throw new ArgumentException($"Tile {id} is not in {Seat} player's hand");
            }

            // Add the discarded tile to the list of discards.
            _discards.Add(discarded);

            // Make the discarded tile a child of the root object for the discard pile,
            // but keep its world position so that we can animate it from its current
            // position to its target position int the discard pile.
            discarded.transform.SetParent(_discardRoot, worldPositionStays: true);

            // TODO: Actually do a tween. For now we'll immediately display the tile in
            // the player's discards.

            // Layout the discarded tiles in rows of 6 tiles.
            var leftSide = TileWidth * -6 * 0.5f;

            foreach (var(index, tile) in _discards.Enumerate())
            {
                int row = index / 6;
                int col = index % 6;
                tile.transform.localPosition = new Vector3(
                    leftSide + col * TileWidth,
                    0f,
                    -row * TileLength);

                tile.transform.localRotation = Quaternion.identity;
            }

            // Remove the click handler so that we don't get click events from discarded
            // tiles.
            discarded.Clicked -= OnTileClicked;

            // If we didn't discard the drawn tile, merge the drawn tile into the
            // player's hand.
            if (_currentDraw != null)
            {
                AddToHand(_currentDraw);
                _currentDraw = null;
            }
        }
Ejemplo n.º 3
0
 private void OnTileClicked(TileView clicked)
 {
     TileClicked?.Invoke(this, clicked.Model.Id);
 }