Ejemplo n.º 1
0
 public void Update()
 {
     // see if we're mouseOver a valid move
     TinySpot spot = driver.GetHovered();
     if(spot == null) {
         renderer.enabled = false;
     } else {
         if(driver.IsValidMove(spot)) {
             renderer.enabled = true;
             transform.position = spot.transform.position;
             if(currentTex != driver.CurrentTurn) {
                 UpdateTexture();
             }
             if(currentSpot != spot) {
                 currentSpot = spot;
                 AudioSource.PlayClipAtPoint(hoverSound,
                     Camera.main.transform.position);
             }
         } else {
             renderer.enabled = false;
             currentSpot = null;
         }
     }
 }
Ejemplo n.º 2
0
    public void MakeMove(TinySpot spot)
    {
        spot.MakeMark(currentTurn);
        spot.Board.MadeMove(spot);

        // check if this ends the game
        bigBoard.CheckWinner();
        if(bigBoard.Winner != SpotValue.None) {
            switch(bigBoard.Winner) {
                case SpotValue.X:
                    Debug.Log("Game Over, X won!"); break;
                case SpotValue.O:
                    Debug.Log("Game Over, O won!"); break;
                case SpotValue.Tie:
                    Debug.Log("Game Over, TIED!"); break;
            }
            isPlaying = false;
        } else {
            // find the next forced board
            int index = spot.Board.GetIndex(spot);
            TinyBoard targetBoard = bigBoard.GetSpot(index) as TinyBoard;
            forcedBoard = targetBoard;
            // but don't force it if it's already completed
            if(targetBoard.Winner != SpotValue.None) {
                forcedBoard = null;
            }
            highlight.Highlight(currentTurn, spot, targetBoard,
                targetBoard == forcedBoard);
            // next turn is opposite player's
            if(currentTurn == SpotValue.X) {
                currentTurn = SpotValue.O;
            } else {
                currentTurn = SpotValue.X;
            }
        }
    }
Ejemplo n.º 3
0
 public bool IsValidMove(TinySpot spot)
 {
     // nothing's valid if we're not playing!
     if(!isPlaying) {
         return false;
     }
     // don't change if this spot has a value
     if(spot.GetValue() != SpotValue.None) {
         return false;
     }
     // don't change if the spot's board isn't the current forced one
     if(forcedBoard != null && forcedBoard != spot.Board) {
         return false;
     }
     //don't change if the board already has a winner
     if(spot.Board.Winner != SpotValue.None) {
         return false;
     }
     return true;
 }