예제 #1
0
    public void OnMovementFinished()
    {
        if (IsPlayerWin())
        {
            Signals.Invoke(ESignalType.PlayerWin, currentPlayerIndex);

            if (players.Count == 1)
            {
                Signals.Invoke(ESignalType.PuzzleComplete, 3);
            }
            return;
        }
        else
        {
            bool anyTurning = false;
            bool allLegal   = true;
            foreach (Piece piece in CurrentPlayer.pieces)
            {
                anyTurning |= piece.IsRotating();
                allLegal   &= IsValidPosition(piece);
            }

            bool hasTurned = currentSelectedPiece != null && currentSelectedPiece.IsRotated();


            if (allLegal && !anyTurning && hasTurned)
            {
                NextPlayer();
            }
        }
    }
예제 #2
0
    public static void SelectGame(int?index = null)
    {
        currentGame?.End();


        if (HextwistStateMachine.GameType == HextwistStateMachine.EGameType.Puzzle)
        {
            currentGameIndex = index ?? ++currentGameIndex;

            currentGame = ObjectFactory.Game(Progression.Puzzles[currentGameIndex]);
        }
        else
        {
            currentGame = ObjectFactory.Game(Progression.PvPGamePrefab);
        }

        Signals.Invoke(ESignalType.CamPosition, currentGame.GetBoardBounds());
        Signals.Invoke(ESignalType.GameStart, currentGameIndex);
    }
예제 #3
0
    void SelectPiece(Piece piece)
    {
        if (currentSelectedPiece != null)
        {
            if (currentSelectedPiece.lockSelected)
            {
                return;
            }

            currentSelectedPiece.ResetRotation();
            lastSelectedPiece      = currentSelectedPiece;
            lastSelectedPiece.Mode = Piece.EMode.Inactive;
        }
        currentSelectedPiece = piece;
        if (piece)
        {
            piece.Mode = Piece.EMode.Selected;
        }
        Signals.Invoke(ESignalType.PieceSelected, piece);
    }
예제 #4
0
    void NextPlayer()
    {
        CurrentPlayer.SetActivePlayer(false);

        currentPlayerIndex = (currentPlayerIndex + 1) % numPlayers;

        CurrentPlayer.SetActivePlayer(true);

        currentBoard.HighlightPlayer(currentPlayerIndex + 1);
        Signals.Invoke(ESignalType.PlayerTurn, currentPlayerIndex);

        if (currentSelectedPiece != null)
        {
            currentSelectedPiece.LockRotation();
            if (numPlayers == 1)
            {
                lastSelectedPiece = currentSelectedPiece;
            }
            currentSelectedPiece = null;
        }
    }
예제 #5
0
 protected virtual void Click()
 {
     Signals.Invoke(signal);
 }
예제 #6
0
    void MakeNextPlacementPiece()
    {
        int numPieces = AllPieces.Count();


        //have all the pieces been placed?
        if (Mathf.FloorToInt(numPieces / numPlayers) == PieceDatas.Count)
        {
            //start with player 0
            currentPlayerIndex = players.Count - 1;
            Signals.Invoke(ESignalType.SetupComplete);
            NextPlayer();
            return;
        }

        //for two players go 01100110 etc.
        currentPlayerIndex = Mathf.Clamp(Mathf.FloorToInt(numPieces / numPlayers) % 2 == 0 ?
                                         numPieces % numPlayers :
                                         (numPlayers - 1) - numPieces % numPlayers, 0, (numPlayers - 1));

        int index = Mathf.FloorToInt(numPieces / 2);


        PieceData PieceData = PieceDatas[index];
        Piece     piece     = ObjectFactory.Piece(PieceData);

        piece.name = PieceData.piecePrefab.name + " " + CurrentPlayer.Name;

        CurrentPlayer.pieces.Add(piece);

        if (piece.lockPivotHex)
        {
            piece.SetPivotHex(PieceData.lockedPivotHex, true);
        }


        piece.OnPieceClicked.AddListener(OnPieceClickedSetup);
        piece.OnMovementFinished.AddListener(OnMovementFinished);
        piece.OuterInactive = PieceColourPallet.OuterInactive(currentPlayerIndex);
        piece.OuterPivot    = PieceColourPallet.OuterPivot(currentPlayerIndex);
        piece.OuterSelected = PieceColourPallet.OuterSelected(currentPlayerIndex);
        piece.InnerPivot    = PieceColourPallet.InnerPivot(currentPlayerIndex);
        piece.InnerActive   = PieceColourPallet.InnerActive(currentPlayerIndex);
        piece.InnerDisabled = PieceColourPallet.InnerDisabled(currentPlayerIndex);

        if (PieceData.useStartPosition)
        {
            PiecePlaced(piece);
        }
        else
        {
            SelectPiece(piece);
            currentBoard.HighlightPlayer(currentPlayerIndex);

            Signals.Invoke(ESignalType.PlayerTurn, currentPlayerIndex);
        }
        if (currentSelectedPiece)
        {
            SetPieceModeSetup(currentSelectedPiece);
        }
    }
예제 #7
0
 protected override void Click()
 {
     Signals.Invoke(signal, levelIndex);
 }