示例#1
0
    void MoveActivePlayer( List<TileCoord> path )
    {
        audio.clip = PlacePieceSound;
        audio.Play();

        var playerPiece = _playerPieces[ _activePlayerIndex ];
        if( path != null )
        {
            var lastPos = path[ path.Count - 1 ];

            // Just jump to target coord.
            var transformOnTile = GetTransformOnTile( lastPos.x, lastPos.y, lastPos.edge );
            if( transformOnTile != null )
            {
                var boardPiece = _boardPieceField[lastPos.x][lastPos.y];
                playerPiece.transform.parent = boardPiece.transform;
                var objectMover = playerPiece.gameObject.GetComponent< ObjectMover >();
                objectMover.Move( transformOnTile.position, Quaternion.identity, 2.0f, null );
                playerPiece.CurrCoord = lastPos;
                _playAreaState = PlayAreaState.NextTurn;
                _timer = 0.25f;

                if( boardPiece.EventPiece != null )
                {
                    if( _eventCardActive.CheckEvent( boardPiece.EventPiece.EventId ) )
                    {
                        // Increment score.
                        _playerPieces[ _activePlayerIndex ].Score += boardPiece.ScoreValue;

                        var particleSystem = _playerScoreBoard[ _activePlayerIndex ].GetComponentInChildren< ParticleSystem >();
                        if( particleSystem != null )
                        {
                            particleSystem.Emit(25);
                        }

                        _needNewEventCard = true;
                    }
                }

            }
        }
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        var playerPiece = _playerPieces[ _activePlayerIndex ];

        _timer -= Time.deltaTime;

        switch( _playAreaState )
        {
        case PlayAreaState.BeginTurn:
        {
            // Activate.
            _playerScoreBoard[ _activePlayerIndex ].SetActive();

            _playAreaState = PlayAreaState.PlaceNewTile;

            ClearPathfinding();
            SetupPathGlow();

            for(int i = 0; i < _boardPiecePlayLocations.Count; ++i)
            {
                var glower = _boardPiecePlayLocations[i].GetComponentInChildren<Glower> ();
                glower.GlowTarget = 2.0f;
            }

            if( _needNewEventCard )
            {
                _playAreaState = PlayAreaState.ShowNewEventCard;
            }

            if( playerPiece.isAI )
            {
                _timer = 1.0f;
            }

            audio.clip = NextPlayerSound;
            audio.Play();
        }
        break;

        case PlayAreaState.ShowNewEventCard:
        {
            _playAreaState = PlayAreaState.WaitNewEventCard;
            _needNewEventCard = false;
            RevealEventCard();
        }
        break;

        case PlayAreaState.WaitNewEventCard:
        {
            if(_timer < 0.0f )
            {
                if( _eventCardActive )
                {
                    var objectMover = _eventCardActive.GetComponent< ObjectMover >();
                    objectMover.Move( EventCardRevealPosition.position, EventCardRevealPosition.rotation, MoveHeightForReturnTile, null );
                    _playAreaState = PlayAreaState.PlaceNewTile;
                }
            }
        }
        break;

        case PlayAreaState.PlaceNewTile:
        {
            BoardPiecePlayLocation boardPiece = null;

            if( playerPiece.isAI == false )
            {
                /////////////////////////////////////////////// HUMAN
                if( Input.GetMouseButtonDown( 0 ) )
                {
                    var ray = Camera.main.ScreenPointToRay( Input.mousePosition );
                    var rayHits = Physics.RaycastAll( ray, Mathf.Infinity, 1 << Layers.PiecePlayLocation );
                    if( rayHits.Length > 0 )
                    {
                        var rayHit = rayHits[0];
                        boardPiece = rayHit.collider.gameObject.GetComponent< BoardPiecePlayLocation >();
                    }
                }
            }
            else
            {
                if( _timer < 0.0f )
                {
                    /////////////////////////////////////////////// AI
                    var randomIdx = Random.Range( 0, _boardPiecePlayLocations.Count );
                    boardPiece = _boardPiecePlayLocations[randomIdx];

                    _timer = 1.0f;
                }
            }

            // Do move.
            if( boardPiece != null )
            {
                PlayPiece( boardPiece.X, boardPiece.Y, null );

                // Check that we can make a move.
                bool canMove = false;
                var fromCoord = _playerPieces[ _activePlayerIndex ].CurrCoord;
                for( int i = 0; i < 4; ++i )
                {
                    if( IsValidMoveSingleStep( fromCoord, i, false ) != null )
                    {
                        canMove = true;
                    }
                }

                if(canMove)
                {
                    _playAreaState = PlayAreaState.MovePlayer;

                    // Touch all valid move bits.
                    fromCoord = _playerPieces[ _activePlayerIndex ].CurrCoord;
                    CalulatePath( fromCoord, null );

                    SetupPathGlow();

                }
                else
                {
                    _playAreaState = PlayAreaState.NextTurn;
                    _timer = 0.25f;
                }

                for(int i = 0; i < _boardPiecePlayLocations.Count; ++i)
                {
                    var glower = _boardPiecePlayLocations[i].GetComponentInChildren<Glower> ();
                    glower.GlowTarget = 0.0f;
                }

            }
        }
        break;

        case PlayAreaState.MovePlayer:
        {
            if( playerPiece.isAI == false )
            {
                /////////////////////////////////////////////// HUMAN
                if( Input.GetMouseButtonDown( 0 ) )
                {
                    var ray = Camera.main.ScreenPointToRay( Input.mousePosition );
                    var rayHits = Physics.RaycastAll( ray, Mathf.Infinity, 1 << Layers.MoveLocation );
                    if( rayHits.Length > 0 )
                    {
                        var rayHit = rayHits[0];

                        var fromBoardPiece = _playerPieces[ _activePlayerIndex ].transform.parent.GetComponent< BoardPiece >();
                        var movePosition = rayHit.collider.gameObject.GetComponent< PieceMovePosition >();
                        var targetBoardPiece = movePosition.transform.parent.GetComponent< BoardPiece >();
                        if( targetBoardPiece != null )
                        {
                            var newCoord = targetBoardPiece.Coord;

                            if( newCoord != null )
                            {
                                for( int i = 0; i < 4; ++i )
                                {
                                    if( targetBoardPiece.GetEdgePieceTransform( i ) == movePosition.transform )
                                    {
                                        newCoord = new TileCoord( newCoord.x, newCoord.y, i );
                                        break;
                                    }
                                }

                                var path = CalulatePath( playerPiece.CurrCoord, newCoord );

                                MoveActivePlayer(path);
                            }
                        }
                    }
                }
            }
            else
            {
                if( _timer < 0.0f )
                {
                    /////////////////////////////////////////////// AI!

                    // Path outwards from the player to mark cells.
                    var path = CalulatePath( playerPiece.CurrCoord, null );

                    // Build list of movable board pieces.
                    List<BoardPiece> movableBoardPieces = new List<BoardPiece>();
                    for( int y = 0; y < Size; ++y )
                    {
                        for( int x = 0; x < Size; ++x )
                        {
                            var boardPiece = _boardPieceField[x][y];

                            if( boardPiece.HasVisited() )
                            {
                                boardPiece.AIScoreValue = Random.Range( 0, 8 );

                                // Event piece? Bump that score up.
                                if( boardPiece.EventPiece != null )
                                {
                                    for( int i = 0; i < 3; ++i )
                                    {
                                        var eventScore = ( 3 - i ) * 10;
                                        var eventPiece = _eventCardActive.EventPieces[i];

                                        if( eventPiece.EventId == boardPiece.EventPiece.EventId )
                                        {
                                            boardPiece.AIScoreValue += eventScore;
                                        }
                                    }
                                }

                                movableBoardPieces.Add (boardPiece);
                            }
                        }
                    }

                    // Sort.
                    movableBoardPieces = movableBoardPieces.OrderBy( x => -x.AIScoreValue ).ToList ();

                    // Target coord.
                    var targetPiece = movableBoardPieces[0];
                    TileCoord targetCoord = targetPiece.Coord;
                    for( int i = 0; i < 4; ++i )
                    {
                        if( targetPiece.PathNodes[i].HasVisited )
                        {
                            targetCoord = new TileCoord( targetCoord.x, targetCoord.y, i );
                            break;
                        }
                    }

                    // Path
                    path = CalulatePath( playerPiece.CurrCoord, targetCoord );

                    MoveActivePlayer(path);
                }
            }
        }
        break;

        case PlayAreaState.NextTurn:
        {
            if( _timer < 0.0f )
            {
                ClearPathfinding();
                SetupPathGlow();

                _playAreaState = PlayAreaState.BeginTurn;

                //
                if( _playerPieces[ _activePlayerIndex ].Score >= 8 )
                {
                    _playAreaState = PlayAreaState.PlayerWon;

                    if( _activePlayerIndex == 0 )
                    {
                        ScoreScreenText.text = "You Win!";
                    }
                    else
                    {
                        if( _activePlayerIndex == 0 )
                        {
                            ScoreScreenText.text = string.Format ( "You Win!" );
                        }
                        else
                        {
                            ScoreScreenText.text = string.Format ( "Player {0} Wins!", _activePlayerIndex + 1 );
                        }
                    }

                    ScoreScreen.Move ( ScoreScreenScreenPosition.transform.position, ScoreScreenScreenPosition.transform.rotation, 2.0f, null );
                    break;
                }

                // Deactivate.
                _playerScoreBoard[ _activePlayerIndex ].SetInactive();

                // Player.
                _activePlayerIndex = ( _activePlayerIndex + 1 ) % 4;
            }
        }
        break;

        case PlayAreaState.PlayerWon:
        {

        }
        break;
        }
    }
示例#3
0
    public void RevealEventCard()
    {
        if( _eventCards.Count == 0)
        {
            _playAreaState = PlayAreaState.PlayerWon;

            ScoreScreenText.text = "You Lose!";

            ScoreScreen.Move ( ScoreScreenScreenPosition.transform.position, ScoreScreenScreenPosition.transform.rotation, 2.0f, null );
        }
        var newEventCard = _eventCards[0];
        _eventCards.RemoveAt(0);

        var objectMover = newEventCard.GetComponent< ObjectMover >();

        objectMover.Move( this.EventCardScreenPosition.position, EventCardScreenPosition.rotation, MoveHeightForNewTile, null );

        if( _eventCardActive )
        {
            objectMover = _eventCardActive.GetComponent< ObjectMover >();
            objectMover.Move( EventCardDiscardPosition.position, EventCardDiscardPosition.rotation, MoveHeightForReturnTile, null );
            //_eventCards.Add(_eventCardActive);
        }

        _eventCardActive = newEventCard;

        _timer = 4.0f;
    }