Example #1
0
    //Confusing Name; Takes in a piece that is intersecting a floor, edits it so that everything on that floor is removed and everything else is moved down according to gravity
    void removePieceFromFloor(PieceObject tempPiece, int floorVal)
    {
        var        tempList = tempPiece.getActualObjects();
        var        currNode = tempList.First;
        GameObject currObject;

        //Debug.Log(tempList.Count);
        while (currNode != null)
        {
            //Debug.Log("one Node");
            currObject = currNode.Value;
            currNode   = currNode.Next;
            //Debug.Log(currNode);
            if (currObject.transform.position.y == floorVal)
            {
                //Debug.Log("0 y value");
                tempPiece.removeObjectFromActualObjects(currObject);
                Destroy(currObject);
            }
            else
            {
                if (currObject.transform.position.y > floorVal)
                {
                    currObject.transform.Translate(new Vector3(0, -1, 0), Space.World);
                }
            }
        }
    }
Example #2
0
    public void ClickDown(PieceObject piece)
    {
        if (finished)
        {
            return;
        }

        // Ignore if managed by AI or is not your turn
        if (piece.piece.side != currentSide || (ai1 && !currentSide) || (ai2 && currentSide))
        {
            return;
        }

        List <Position> positions = model.GetMovements(piece.piece);

        markersPool.ClearAll();
        if (piece.Equals(selectedPiece))
        {
            selectedPiece = null;
            return;
        }
        selectedPiece   = piece;
        selectedUIPiece = null;
        for (int i = 0; i < positions.Count; i++)
        {
            Marker marker = markersPool.GetInstance <Marker>(true);
            marker.Initialize(ClickDownMarker);
            marker.SetHexPosition(positions[i]);
        }
    }
Example #3
0
    void removePieceFromWallZ(PieceObject tempPiece, int zVal)
    {
        var        tempList = tempPiece.getActualObjects();
        var        currNode = tempList.First;
        GameObject currObject;

        //bool tempBool;
        //tempBool = false;
        Debug.Log(tempList.Count);

        while (currNode != null)
        {
            Debug.Log("recursion tick2");
            //Debug.Log("one Node");
            currObject = currNode.Value;
            currNode   = currNode.Next;
            //Debug.Log(currNode);

            if (currObject.transform.position.y <= sizeDim + yOffset - 4 && currObject.transform.position.z == zVal)
            {
                Debug.Log("gameobject is part of wall and not above");
                //Debug.Log("0 y value");
                tempPiece.removeObjectFromActualObjects(currObject);
                Destroy(currObject);
            }
        }
    }
Example #4
0
    //===================================================
    /*!
       	@brief		ピースの移動&入れ替え

        @param		MouseData	マウスのデータ
       	@date		2013/01/20
       	@author		Daichi Horio
      */
    //===================================================
    public bool MoveUpdate(MouseData mouseData)
    {
        GameObject obj = TouchUpdate(mouseData.pos);

        // 他のピースに触れたら選択しているピースと位置入れ替え
        if (obj != null)
        {
            PieceObject p = obj.GetComponent<PieceObject>();
            if (p.GetState() == 0)
            {
                ReplacePiece(mNowSelectPiece, p);
                mRouteQueue.Enqueue(p.PicecPosition);
            }
        }

        if (mouseData.up || mNowSelectPiece.transform.position.y > (PieceSize * Height))
        {
            mRouteQueue.Enqueue(mNowSelectPiece.PicecPosition);
            mNowSelectPiece.Relese();
            mNowSelectPiece = null;
            return true;
        }

        return false;
    }
Example #5
0
        /// <summary>
        /// 駒打ちの処理を開始します。
        /// </summary>
        private void BeginDropPiece(PieceObject pieceObject)
        {
            var piece = pieceObject.Piece;

            if (!CanBeginMove(piece.BWType))
            {
                return;
            }

            if (GetCapturedPieceCount(piece.PieceType, piece.BWType) <= 0)
            {
                return;
            }

            // 表示用の駒を追加します。
            this.movingPiece = new PieceObject(this, piece);
            AddPieceObject(this.movingPiece);

            if (EditMode != EditMode.Editing && EffectManager != null)
            {
                EffectManager.BeginMove(null, piece);
            }

            InManipulating = true;
        }
Example #6
0
    public void SelectPiece(Piece piece)
    {
        PieceObject pieceObject = pieces[piece.position.x, piece.position.y];

        pieceObject.SelectPiece();
        SelectTiles(piece.GetValidDestinations(GetChess().state));
    }
Example #7
0
    /// <summary>
    /// Helper method that instantiates pieces on the correct nodes as well as saves said pieces in a private array per player.
    /// </summary>
    /// <param name="players"> The current player that owns the pieces. </param>
    /// <param name="piecePrefab">A prefab reference to create said pieces. </param>
    private static void PlacePieces(IPlayer player, PieceObject piecePrefab)
    {
        if (player == null)
        {
            return;
        }
        if (player.CurrentTeam == null || player.CurrentTeam.Team == Team.Empty)
        {
            return;
        }
        List <Piece> playerPieces = new List <Piece> ();
        Transform    parent       = new GameObject($"{player}'s pieces").transform;

        foreach (var node in player.CurrentTeam.TeamBase)
        {
            if (node.BelongsTo == player.CurrentTeam.Team)
            {
                node.StoredPiece = new Piece(piecePrefab, TeamGenerator.SetColorBasedOnTeam(player.CurrentTeam.Team), node, player.CurrentTeam.Team, parent);
                //Piece.CreatePiece (piecePrefab, TeamGenerator.SetColorBasedOnTeam (player.CurrentTeam.Team), node, player.CurrentTeam.Team);
                playerPieces.Add(node.StoredPiece);
            }
        }

        player.CurrentTeam.TeamsPieces = playerPieces;
    }
Example #8
0
    public void SelectPiece(PieceObject pieceObject)
    {
        pieceObject.SelectPiece();
        Piece piece = GetPiece(pieceObject.position);

        SelectTiles(piece.GetValidDestinations(chess.state));
    }
Example #9
0
        /// <summary>
        /// 駒の移動を終了します。
        /// </summary>
        public void EndMove()
        {
            if (this.movingPiece == null)
            {
                return;
            }

            var square = this.movingPiece.Square;

            if (square != null)
            {
                // 移動中の駒の位置を元に戻します。
                this.movingPiece.Coord = SquareToPoint(square);
            }
            else
            {
                // 駒打ちの場合は、表示用オブジェクトを新規に作成しています。
                RemovePieceObject(this.movingPiece);
            }

            this.movingPiece = null;
            ClosePromoteDialog();

            if (EffectManager != null)
            {
                EffectManager.EndMove();
            }

            InManipulating = false;
        }
Example #10
0
    private void handlePieceClick(PieceObject clickedPiece)
    {
        Piece piece = chessGame.GetPiece(clickedPiece.position);

        if (selectedPiece == null)
        {
            if (piece.team == chessGame.GetChess().currentTeam)
            {
                SelectPiece(clickedPiece);
            }
        }
        else
        {
            if (selectedPiece == clickedPiece)
            {
                DeselectPiece();
            }
            if (piece.team != chessGame.GetChess().currentTeam)
            {
                if (chessGame.GetChess().IsMoveValid(selectedPiece.position, clickedPiece.position))
                {
                    chessGame.MakeMove(selectedPiece.position, clickedPiece.position);
                }
                ;
            }
        }
    }
Example #11
0
    public void ClickDownMarker(Marker marker)
    {
        if (selectedPiece != null)
        {
            model.MovePiece(selectedPiece.piece, (marker.x, marker.y, marker.z));
            audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
            Position newPos = model.GetPiecePosition(selectedPiece.piece);
            selectedPiece.SetHexPosition(newPos.x, newPos.y, newPos.z);
            selectedPiece = null;
        }
        else if (selectedUIPiece != null)
        {
            if (selectedUIPiece.piece.side)
            {
                panels[1].RemovePiece(selectedUIPiece);
            }
            else
            {
                panels[0].RemovePiece(selectedUIPiece);
            }
            model.MovePiece(selectedUIPiece.piece, (marker.x, marker.y, marker.z));
            audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
            Position   newPos   = model.GetPiecePosition(selectedUIPiece.piece);
            GameObject instance = piecesPool.GetInstance(true);
            instance.GetComponent <PieceObject>().Initialize(selectedUIPiece.piece, ClickDown);
            instance.GetComponent <PieceObject>().SetHexPosition(model.GetPiecePosition(selectedUIPiece.piece));
            selectedUIPiece = null;
        }

        NextTurn();
    }
Example #12
0
    private void PlacePiece(ushort PieceIndex, Piece Piece)
    {
        GameObject newPiece = Instantiate(_piecePrefab, Piece.Position, Quaternion.identity);

        newPiece.transform.parent = _piecesContainer.transform;
        Piece.Name = Piece.Name + "_" + PieceIndex.ToString();
        newPiece.transform.name = Piece.Name;

        SpriteRenderer spriteRenderer = newPiece.GetComponent <SpriteRenderer>();

        spriteRenderer.sprite = Piece.GetSprite();

        if (Piece.GetColor() == PieceColor.White)
        {
            spriteRenderer.color = Globals.WhitePieceColor;
        }
        else
        {
            spriteRenderer.color = Globals.BlackPieceColor;
        }

        PieceObject pieceObject = newPiece.AddComponent <PieceObject>();

        pieceObject.SetInfo(PieceIndex, this, Piece.Position);

        _pieces.Add(PieceIndex, Piece);
        _pieceIndex++;
    }
Example #13
0
    //Used to remove the oueline from the highlighted piece
    void removeOutline(PieceObject tempPiece, string tempString)
    {
        var tempSet = tempPiece.getActualObjects();

        removePiece(tempPiece);
        //allPieces.Remove(tempPiece);
        createPiece(getVector3Set(tempPiece.getActualObjects()), false, tempString);
    }
 private void EatPiece(PieceObject piece, PieceObject pieceToEat, int x, int y)
 {
     eatemPieces.Add(pieceToEat);
     pieceToEat.gameObject.SetActive(false);
     Debug.Log(piece.name + "(" + piece.GetX() + ", " + piece.GetY() + ") comeu " + pieceToEat.name + " (" + pieceToEat.GetX() + ", " + pieceToEat.GetY() + ")");
     SetPiecePosition(piece, x, y);
     DeselectPiece();
 }
 public void SetPiecePosition(PieceObject piece, int newX, int newY)
 {
     boardPieces[piece.GetX(), piece.GetY()] = null;
     piece.SetXY(newX, newY);
     boardPieces[newX, newY] = piece;
     piece.MovePiece(newX, newY);
     DeselectPiece();
 }
 public void SelectPiece(int x, int y)
 {
     selectedPiece = boardPieces[x, y];
     if (selectedPiece != null)
     {
         Debug.Log(selectedPiece.name + " foi selecionada");
     }
 }
Example #17
0
 public void Insert(PieceObject obj, Grid grid)
 {
     this.grid = grid;
     this.obj = obj;
     obj.gameObject.SetActive (false);
     obj.transform.parent = this.drop.transform;
     obj.transform.localPosition = Vector2.zero;
 }
Example #18
0
    /// <summary>
    /// Fake constructor that creates a view piece.
    /// </summary>
    /// <param name="prefab">A prefab reference.</param>
    /// <param name="worldPosition">Where the newrly created view piece will be spawned at.</param>
    /// <param name="team">Which team it lies in.</param>
    /// <param name="parent">A designated parent for sorting.</param>
    /// <param name="boardCoord">A reference to the globalPieceList item.</param>
    /// <returns>A view Piece.</returns>
    public static PieceObject CreatePieceObject(PieceObject prefab, Vector2 worldPosition, PieceColor team, Transform parent, Vector2Int boardCoord)
    {
        PieceObject newPiece = Instantiate(prefab, worldPosition, Quaternion.identity, parent);

        newPiece.SetTeamColor(team);
        newPiece.boardCoordinate = boardCoord;
        return(newPiece);
    }
Example #19
0
    //Given a set of points, create a pieceobject in that spot that will be put into the arrays and bookkeeping currectly
    PieceObject createPiece(LinkedList <Vector3> tempSet, bool outlineBool, string tempString)
    {
        currentPieces += 1;
        PieceObject newPiece = new PieceObject(createPieceGameObject(tempSet, outlineBool, tempString), tempString);

        addBlockPositions(newPiece);
        allPieces.Add(newPiece);
        return(newPiece);
    }
Example #20
0
 public Piece(PieceObject po)
 {
     type            = po.data.type;
     baseHealth      = po.data.baseHealth;
     baseDamage      = po.data.baseDamage;
     baseAttackSpeed = po.data.baseAttackSpeed;
     baseRange       = po.data.baseRange;
     cost            = po.data.cost;
 }
Example #21
0
 // Hide the panels removes the game
 public void Clear()
 {
     panels[0].transform.parent.GetComponent <Animator>().SetBool("show", false);
     piecesPool.ClearAll();
     markersPool.ClearAll();
     hourglass.gameObject.SetActive(false);
     selectedPiece   = null;
     selectedUIPiece = null;
 }
Example #22
0
        /// <summary>
        /// 指定の位置にある駒を削除します。
        /// </summary>
        private void RemovePieceObject(PieceObject piece)
        {
            if (piece == null)
            {
                return;
            }

            this.pieceContainer.Children.Remove(piece.ModelGroup);
            this.pieceObjectList.Remove(piece);
        }
Example #23
0
 //Takes in a piece object and completely removes from exists (including gameobjects and arrays etc)
 void removePiece(PieceObject tempPiece)
 {
     currentPieces -= 1;
     allPieces.Remove(tempPiece);
     removeBlockPositions(tempPiece);
     foreach (var tempObject in tempPiece.getActualObjects())
     {
         Destroy(tempObject);
     }
 }
Example #24
0
    void Awake()
    {
        PieceObject pieceData = constructablePiece.GetComponent <GameboardPiece>().piece;

        constructionImage.sprite  = pieceData.staticSprite;
        baseAttackDamageText.text = pieceData.data.baseDamage.ToString();
        baseAttackSpeedText.text  = pieceData.data.baseAttackSpeed.ToString();
        baseAttackRangeText.text  = pieceData.data.baseRange.ToString();
        costText.text             = pieceData.data.cost.ToString();
    }
Example #25
0
    //Used everywhere to take in a piece object and add it to the boolean arrays and piece object arrays
    void addBlockPositions(PieceObject tempObject)
    {
        var tempSet = tempObject.getActualObjects();

        foreach (var element in tempSet)
        {
            actualField[(int)Mathf.Round(element.transform.position.x), (int)Mathf.Round(element.transform.position.y), (int)Mathf.Round(element.transform.position.z)] = tempObject;
            boolField[(int)Mathf.Round(element.transform.position.x), (int)Mathf.Round(element.transform.position.y), (int)Mathf.Round(element.transform.position.z)]   = true;
        }
    }
Example #26
0
    //Function called when you want to hold a piece. Currently used a lot of functionality copied from spawnrandom
    void holdCurrentPiece()
    {
        var tempPiece = currentPiece;

        removeReflection();
        removePiece(currentPiece);

        LinkedList <Vector3> tempSet2 = new LinkedList <Vector3>();
        //string tempString;

        var tempString = holdScript.holdCurrentPieceAndReturnOldPiece(tempPiece.getPieceName());

        if (tempString == "nothingHere")
        {
            booleanSpawnSwap();
            return;
        }
        else if (tempString == "lPiece")
        {
            tempSet2 = lPieceSet();
        }
        else if (tempString == "zPiece")
        {
            tempSet2 = zPieceSet();
        }
        else if (tempString == "linePiece")
        {
            tempSet2 = linePieceSet();
        }
        else if (tempString == "tPiece")
        {
            tempSet2 = tPieceSet();
        }
        else if (tempString == "cubePiece")
        {
            tempSet2 = cubePieceSet();
        }
        else if (tempString == "cornerPiece")
        {
            tempSet2 = cornerPieceSet();
        }

        if (lossCheck(tempSet2))
        {
            Debug.Log("you dead mate");
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            return;
        }
        else
        {
            PieceObject newObject = createPiece(tempSet2, true, tempString);
            currentPiece = newObject;
            createReflectionPiece(tempSet2, currentPiece);
        }
    }
Example #27
0
    private void InstantiatePiece(PieceObject pieceObject, int x, int y, Team team)
    {
        GameObject go = GameObject.Instantiate(pieceObject.gameObject, Vector3.zero, Quaternion.identity, PieceParent.transform);

        go.name += " (" + team + ")";
        //float pieceHeight = go.GetComponent<BoxCollider>().bounds.max.y;
        go.transform.position = new Vector3(x, tileHeight, y);
        go.GetComponent <PieceObject> ().position = new Vector2Int(x, y);
        pieces[x, y] = go.GetComponent <PieceObject> ();
        go.GetComponentInChildren <Renderer> ().material = team == Team.White ? WhiteMaterial : BlackMaterial;
    }
Example #28
0
        /// <summary>
        /// 駒台上の駒の表示用オブジェクトを取得します。
        /// </summary>
        private PieceObject CreateCapturedPieceObject(PieceType pieceType, BWType bwType)
        {
            var piece = new BoardPiece(pieceType, false, bwType);
            var value = new PieceObject(this, piece)
            {
                Count           = GetCapturedPieceCount(pieceType, bwType),
                Coord           = CapturedPieceToPoint(pieceType, bwType),
                IsAlwaysVisible = false,
            };

            return(value);
        }
Example #29
0
    public void Initialize(Board board, Action <Winner> endCallback, bool side = false)
    {
        bg.Initialize(ClickDownBackground);
        this.model       = board;
        this.currentSide = side;
        this.endCallback = endCallback;
        this.finished    = false;
        Dictionary <(int, int, int), Piece> placedPieces = model.GetPlacedPieces();
        List <Piece> notPlacedPieces = model.GetNotPlacedPieces();

        turnsCounter = board.GetMaxTurns();
        if (turnsCounter > 0)
        {
            hourglass.gameObject.SetActive(true);
            hourglass.SetValue(turnsCounter, false);
        }
        else
        {
            turnsCounter = -1;
        }

        piecesPool.ClearAll();
        foreach (KeyValuePair <(int, int, int), Piece> pair in placedPieces)
        {
            GameObject instance = piecesPool.GetInstance(true);
            instance.GetComponent <PieceObject>().Initialize(pair.Value, ClickDown);
            instance.GetComponent <PieceObject>().x = pair.Key.Item1;
            instance.GetComponent <PieceObject>().y = pair.Key.Item2;
            instance.GetComponent <PieceObject>().z = pair.Key.Item3;
            if (pair.Value.blocked)
            {
                GameObject chainInstance = chainsPool.GetInstance(true);
                chainInstance.GetComponent <HexObject>().SetHexPosition(pair.Value.position);
            }
        }

        foreach (Position p in model.GetBlockedPositions())
        {
            GameObject instance = rocksPool.GetInstance(true);
            instance.GetComponent <HexObject>().SetHexPosition(p);
        }

        panels[0].Initialize(model, ClickPanelPiece);
        panels[1].Initialize(model, ClickPanelPiece);
        panels[0].transform.parent.GetComponent <Animator>().SetBool("show", true);

        audioSource = GetComponent <AudioSource>();

        markersPool.ClearAll();
        selectedPiece   = null;
        selectedUIPiece = null;
    }
Example #30
0
    /// <summary>
    /// Mainline method: Creates a new match
    /// </summary>
    /// <param name="players">The amount of players participating, this includes what team each player will be as well as if they are computers.</param>
    /// <param name="prefab">A reference to a view piece prefab for spawning each player's pieces.</param>
    /// <returns>A list of active players that are participating in a match.</returns>
    public static List <UserModel> StartNewGame(List <PlayerDefinition> players, PieceObject prefab)
    {
        ResetGame(0);
        amountOfPlayers = players.Count;
        if (players.Count == 2)
        {
            AdaptTheBoard();
        }
        List <UserModel> users = CreatePlayers(players);

        CreatePieces(users, prefab);
        return(users);
    }
Example #31
0
    private void Kill(PieceObject pieceObject)
    {
        Piece piece = GetPiece(pieceObject.position);

        movesWithoutKill = 0;
        OnKilled.Notify(piece);
        if (piece is King)
        {
            ShowGameOver(chess.currentTeam);
        }
        pieceObject.Kill(() => {
            Destroy(pieceObject);
        });
    }
Example #32
0
    public IEnumerator AIMove(bool side)
    {
        yield return(new WaitForSeconds(1));

        //DateTime inicio = DateTime.Now;
        // Find best move
        AI.AIResult ai = AI.FindBestMove(side, model, 0);
        //Debug.Log((DateTime.Now - inicio).Minutes + ":" + (DateTime.Now - inicio).Seconds + "." + (DateTime.Now - inicio).Milliseconds);
        //Debug.Log("Leaves: " + ai.leaves + ", Value: " + ai.bestValue);

        // Find piece to move in placed pieces
        foreach (PieceObject po in piecesPool.Next <PieceObject>())
        {
            if (po.piece.Equals(ai.move.piece) && po.gameObject.activeSelf)
            {
                model.MovePiece(ai.move.piece, ai.move.position);
                audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
                Position newPos = model.GetPiecePosition(po.piece);
                po.SetHexPosition(ai.move.position.x, ai.move.position.y, ai.move.position.z);
                selectedPiece   = null;
                selectedUIPiece = null;
                break;
            }
        }

        // Find piece to move in the panel
        foreach (PiecesPanel panel in panels)
        {
            foreach (PieceUI pui in panel.pieces)
            {
                if (pui.piece.Equals(ai.move.piece))
                {
                    model.MovePiece(ai.move.piece, ai.move.position);
                    audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
                    GameObject instance = piecesPool.GetInstance(true);
                    instance.GetComponent <PieceObject>().Initialize(ai.move.piece, ClickDown);
                    instance.GetComponent <PieceObject>().SetHexPosition(model.GetPiecePosition(ai.move.piece));
                    panel.RemovePiece(pui);
                    selectedPiece   = null;
                    selectedUIPiece = null;
                    break;
                }
            }
        }

        selectedPiece   = null;
        selectedUIPiece = null;
        NextTurn();
    }
Example #33
0
    void Start()
    {
        foreach(string whitePieceName in whitePieceNames) {
            GameObject piece = GameObject.Find(whitePieceName);
            PieceObject obj = new PieceObject();
            obj.gameObject = piece;

            if(whitePieceName.StartsWith("Chess_King")) {
                obj.pieceType = PieceType.WhiteKing;
                obj.row = 8;
                obj.col = 4;
            }
            else if(whitePieceName.StartsWith("Chess_Queen")) {
                obj.pieceType = PieceType.WhiteQueen;
                obj.row = 8;
                obj.col = 5;
            }
            else if(whitePieceName.StartsWith("Chess_Bishop")) {
                obj.pieceType = PieceType.WhiteBishop;

                obj.row = 8;
                if(whitePieceName.EndsWith("1"))
                    obj.col = 3;
                else
                    obj.col = 6;
            }
            else if(whitePieceName.StartsWith("Chess_Knight")) {
                obj.pieceType = PieceType.WhiteKnight;

                obj.row = 8;
                if(whitePieceName.EndsWith("1"))
                    obj.col = 2;
                else
                    obj.col = 7;
            }
            else if(whitePieceName.StartsWith("Chess_Rock")) {
                obj.pieceType = PieceType.WhiteRock;

                obj.row = 8;
                if(whitePieceName.EndsWith("1"))
                    obj.col = 1;
                else
                    obj.col = 8;
            }
            else if(whitePieceName.StartsWith("Chess_Pawn")) {
                obj.pieceType = PieceType.WhitePawn;

                obj.row = 7;
                obj.col = int.Parse(whitePieceName[12].ToString());
            }

            pieceObjects.Add(whitePieceName, obj);
        }

        foreach(string blackPieceName in blackPieceNames) {
            GameObject piece = GameObject.Find(blackPieceName);
            PieceObject obj = new PieceObject();
            obj.gameObject = piece;

            if(blackPieceName.StartsWith("Chess_King")) {
                obj.pieceType = PieceType.BlackKing;

                obj.row = 1;
                obj.col = 4;
            }
            else if(blackPieceName.StartsWith("Chess_Queen")) {
                obj.pieceType = PieceType.BlackQueen;

                obj.row = 1;
                obj.col = 5;
            }
            else if(blackPieceName.StartsWith("Chess_Bishop")) {
                obj.pieceType = PieceType.BlackBishop;

                obj.row = 1;
                if(blackPieceName.EndsWith("1"))
                    obj.col = 3;
                else
                    obj.col = 6;
            }
            else if(blackPieceName.StartsWith("Chess_Knight")) {
                obj.pieceType = PieceType.BlackKnight;

                obj.row = 1;
                if(blackPieceName.EndsWith("1"))
                    obj.col = 2;
                else
                    obj.col = 7;
            }
            else if(blackPieceName.StartsWith("Chess_Rock")) {
                obj.pieceType = PieceType.BlackRock;

                obj.row = 1;
                if(blackPieceName.EndsWith("1"))
                    obj.col = 1;
                else
                    obj.col = 8;
            }
            else if(blackPieceName.StartsWith("Chess_Pawn")) {
                obj.pieceType = PieceType.BlackPawn;

                obj.row = 2;
                obj.col = int.Parse(blackPieceName[12].ToString());
            }

            pieceObjects.Add(blackPieceName, obj);

        }

        foreach (string name in whitePieceNames) {
            GameObject piece = pieceObjects[name].gameObject;
            BoxCollider collider = piece.GetComponent<BoxCollider>();
            collider.enabled = (GameTurn.Black != this.turn);
        }

        foreach (string name in blackPieceNames) {
            GameObject piece = pieceObjects[name].gameObject;
            BoxCollider collider = piece.GetComponent<BoxCollider>();
            collider.enabled = (GameTurn.Black == this.turn);
        }
    }
Example #34
0
    private bool IsFront(PieceObject hit)
    {
        if (hit == null)
            return false;
        else if(hit.GetPieceType() != Piece.PieceType.Mirror)
            return true;
        else {
            var flipped = hit.GetComponent<Mirror>().IsFlipped();

            var front = false;
            var facing = this.lazerIn.GetFacing();

            if(facing.y != 0){
                front = facing.y > 0;
            } else {
                front = facing.x > 0;
                front = flipped ? !front : front;
            }
            return front;
        }
    }
        /// <summary>
        /// 駒オブジェクトなどを初期化します。
        /// </summary>
        protected override void InitializeImpl()
        {
            base.InitializeImpl();

            // 駒はマウスクリックを識別したいので、
            // ModelUIElement3Dクラスを使います。
            Element = new ModelUIElement3D()
            {
                Model = ModelGroup,
            };

            // 表示用の駒オブジェクトを追加します。
            var pieceObject = new PieceObject(
                this.shogi, new BoardPiece(BWType, PieceType));
            AddChild(pieceObject);

            this.numberText = new DecoratedText()
            {
                TextFormat = "×{0}",
                Foreground = Brushes.Black,
                FontWeight = FontWeights.ExtraBlack,
                Stroke = Brushes.White,
                StrokeThickness = 0.8,
            };

            // 駒数の表示用オブジェクトを追加します。
            var w = this.shogi.CellSize.Width;
            var h = this.shogi.CellSize.Height;

            var numberModel = new GeometryModel3D()
            {
                Geometry = CreateDefaultMesh(0.7, 0.4),
                Material = new DiffuseMaterial(new VisualBrush(this.numberText)),
                Transform = new Transform3DGroup()
                    .Apply(_ => _.Children.Add(new TranslateTransform3D(0.4, -0.4, 0.0)),
                           _ => _.Children.Add(new ScaleTransform3D(w, h, 1.0))),
            };
            ModelGroup.Children.Add(numberModel);

            UpdateElement();
        }
        /// <summary>
        /// 駒の移動を開始します。
        /// </summary>
        private void BeginMovePiece(PieceObject pieceObject)
        {
            if (!CanBeginMove(pieceObject.Piece.BWType))
            {
                return;
            }

            this.movingPiece = pieceObject;

            // 描画順を変えます。
            this.pieceContainer.Children.Remove(pieceObject.ModelGroup);
            this.pieceContainer.Children.Add(pieceObject.ModelGroup);

            if (EditMode != EditMode.Editing && EffectManager != null)
            {
                EffectManager.BeginMove(pieceObject.Square, pieceObject.Piece);
            }
        }
Example #37
0
    public void SelectPiece(Piece piece)
    {
        this.StopParticlesAnimation();

        foreach (Transform child in transform) {
            Behaviour otherHalo = child.gameObject.GetComponent("Halo") as Behaviour;
            if(otherHalo == null)
                continue;

            otherHalo.enabled = false;
        }

        Behaviour halo = piece.GetComponent("Halo") as Behaviour;
        halo.enabled = true;

        selectedObject = pieceObjects [piece.name];
        selectedPiece = piece;

        int[][] availablePositionList = selectedObject.GetAvailableListToGo ();

        for(int i = 0; i < availablePositionList.Length; i++){
            ParticleSystem pSystem = GameObject.Find ("light_" + availablePositionList[i][0] + "/" + availablePositionList[i][1])
                .GetComponentInChildren<ParticleSystem>();
            if(pSystem == null) continue;

            pSystem.Play();
        }
    }
Example #38
0
 public void SetLayerOrder(PieceObject hit, int layer)
 {
     SendTo (IsFront(hit), layer);
 }
        /// <summary>
        /// 駒打ちの処理を開始します。
        /// </summary>
        private void BeginDropPiece(PieceObject pieceObject)
        {
            var piece = pieceObject.Piece;

            if (!CanBeginMove(piece.BWType))
            {
                return;
            }

            if (GetCapturedPieceCount(piece.PieceType, piece.BWType) <= 0)
            {
                return;
            }

            // 表示用の駒を追加します。
            this.movingPiece = new PieceObject(this, piece);
            AddPieceObject(this.movingPiece);

            if (EditMode != EditMode.Editing && EffectManager != null)
            {
                EffectManager.BeginMove(null, piece);
            }
        }
Example #40
0
    public void DeselectPiece(Piece piece)
    {
        Behaviour halo = piece.GetComponent("Halo") as Behaviour;
        halo.enabled = false;

        selectedObject = null;
        selectedPiece = null;
        this.StopParticlesAnimation ();
    }
        /// <summary>
        /// 駒の移動を終了します。
        /// </summary>
        private void EndMove()
        {
            if (this.movingPiece == null)
            {
                return;
            }

            var square = this.movingPiece.Square;
            if (square != null)
            {
                // 移動中の駒の位置を元に戻します。
                this.movingPiece.Coord = SquareToPoint(square);
            }
            else
            {
                // 駒打ちの場合は、表示用オブジェクトを新規に作成しています。
                RemovePieceObject(this.movingPiece);
            }

            this.movingPiece = null;
            ClosePromoteDialog();

            if (EffectManager != null)
            {
                EffectManager.EndMove();
            }

            //ReleaseMouseCapture();
        }
Example #42
0
    void recieveMsg(string msg)
    {
        string[] androidMessage = msg.Split (',');

        if (androidMessage.Length != 4)
            return;

        Vector3 targetPosition = GameObject.Find ("Cube-" + androidMessage [2] + "-" + androidMessage [3]).transform.localPosition;

        string[] keys = (turn != GameTurn.Black) ? whitePieceNames : blackPieceNames;
        int row = int.Parse (androidMessage [0]);
        int col = int.Parse (androidMessage [1]);

        foreach(string key in keys) {
            if(pieceObjects[key].row == row && pieceObjects[key].col == col) {
                selectedObject = pieceObjects[key];
                selectedPiece = selectedObject.gameObject.GetComponent<Piece> ();
            }
        }

        this.Move (int.Parse(androidMessage [2]), int.Parse (androidMessage [3]), targetPosition.x, targetPosition.z, true);
    }
        /// <summary>
        /// 駒の表示用オブジェクトを取得します。
        /// </summary>
        private void AddPieceObject(PieceObject value)
        {
            if (value == null)
            {
                return;
            }

            // 駒をデフォルト位置まで移動させます。
            value.Coord =
                (value.Square != null
                ? SquareToPoint(value.Square)
                : CapturedPieceToPoint(value.Piece));

            this.pieceContainer.Children.Add(value.ModelGroup);
            this.pieceObjectList.Add(value);
        }
Example #44
0
    //===================================================
    /*!
       	@brief		ピースの入れ替え

       	@date		2013/01/20
       	@author		Daichi Horio
      */
    //===================================================
    private void ReplacePiece(PieceObject now, PieceObject any)
    {
        PiecePos pos1 = now.PicecPosition;
        PiecePos pos2 = any.PicecPosition;

        PieceObject obj = mRoot.PiecesList[pos2.x, pos2.y];
        mRoot.PiecesList[pos2.x, pos2.y] = now;
        mRoot.PiecesList[pos1.x, pos1.y] = obj;

        any.SetPosition(pos1, NormalMoveSpeed);
        now.PicecPosition = pos2;

        mRoot.ActivList = any;
    }
        /// <summary>
        /// 指定の位置にある駒を削除します。
        /// </summary>
        private void RemovePieceObject(PieceObject piece)
        {
            if (piece == null)
            {
                return;
            }

            this.pieceContainer.Children.Remove(piece.ModelGroup);
            this.pieceObjectList.Remove(piece);
        }
Example #46
0
    //===================================================
    /*!
       	@brief		移動させるピースの選択

        @param		MouseData	マウスの座標データ
       	@date		2013/01/20
       	@author		Daichi Horio
      */
    //===================================================
    public bool SelectUpdate(MouseData mouseData)
    {
        GameObject obj = null;

        if (mouseData.down)
        {
            obj = TouchUpdate(mouseData.pos);
        }

        if (obj == null)
            return false;

        mNowSelectPiece = obj.GetComponent<PieceObject>();
        mNowSelectPiece.Catch();

        mRoot.ActivList = mNowSelectPiece;

        return true;
    }
        /// <summary>
        /// 駒台上の駒の表示用オブジェクトを取得します。
        /// </summary>
        private PieceObject CreateCapturedPieceObject(PieceType pieceType, BWType bwType)
        {
            var piece = new BoardPiece(pieceType, false, bwType);
            var value = new PieceObject(this, piece)
            {
                Count = GetCapturedPieceCount(pieceType, bwType),
                Coord = CapturedPieceToPoint(pieceType, bwType),
                IsAlwaysVisible = false,
            };

            // 駒台に表示します。
            if (pieceType != PieceType.None)
            {
                this.capturedPieceContainer.Children.Add(value.ModelGroup);
            }

            return value;
        }