Ejemplo n.º 1
0
    public ChessUnit UnitAt(int x, int y)
    {
        Debug.Assert(x >= 0 && x < _CurrentConfig.Width && y >= 0 && y < _CurrentConfig.Height);
        ChessUnit u = null;

        if (x >= 0 && x < _CurrentConfig.Width && y >= 0 && y < _CurrentConfig.Height)
        {
            u = _checkUnits [x, y];
        }

        return(u);
    }
Ejemplo n.º 2
0
//	// Update is called once per frame
//	public override void Update () {
//
//	}


    public override void HandleInput()
    {
        if (Input.GetMouseButtonUp(0))
        {
            var mouseScreenPosition = Input.mousePosition;

            var ray  = Camera.main.ScreenPointToRay(mouseScreenPosition);
            var hits = Physics.RaycastAll(ray, 100, LayerMask.GetMask(new string[] { "ChessBoard" }));
            if (hits != null && hits.Length > 0)
            {
                var       hit = hits [0];
                ChessUnit u   = hit.collider.GetComponent <ChessUnit> ();
                if (u != null)
                {
                    Debug.LogFormat("Click on unit: {0}", u);

                    GamePlayOperation op = new GamePlayOperation();

                    op.Op       = GamePlayOperation.OpEnum.PLACE;
                    op.X        = u.X;
                    op.Y        = u.Y;
                    op.PlayerId = this.PlayerId;

                    if (CurrentReferee.IsValidMove(op))
                    {
                        CurrentReferee.PlayMove(op);

                        EndTurn(CurrentReferee);
//						CurrentReferee.EndPlayerTurn (this);
                    }
                }
                else
                {
                    Debug.Log("Click on invalid unit");
                }
            }
            else
            {
                Debug.LogFormat("Click ({0}) hit nothing", mouseScreenPosition);
            }
        }
    }
Ejemplo n.º 3
0
    private ChessUnit initUnit(Vector2 origin, int x, int y, float unitSize, float spacing)
    {
        var unitObject = Instantiate(_ChessUnitPrefab);

        Vector2 pos = new Vector2();

        pos.x = origin.x + unitSize * (x + 0.5f) + spacing * (x + 1);
        pos.y = origin.y + unitSize * (y + 0.5f) + spacing * (y + 1);

        unitObject.transform.localPosition = pos;
        unitObject.transform.localScale    = Vector2.one * unitSize;

        ChessUnit unit = unitObject.GetComponent <ChessUnit> ();

        unit.X       = x;
        unit.Y       = y;
        unit.OwnerId = GameUnit.OWNER_NONE;

        return(unit);
    }
Ejemplo n.º 4
0
    public IChessUnit New()
    {
        IChessUnit chessUnit;

        if (IdleChesses.Count > 1)
        {
            chessUnit = IdleChesses.Dequeue();
        }
        else
        {
            chessUnit        = new ChessUnit();
            chessUnit.Layout = Object.Instantiate(mPrefab, mIdleRoot);
        }

        // init data
        chessUnit.ChessType = ChessType.Black;
        chessUnit.Index     = -1;

        // 丟進工作中的池內
        ActiveChesses.Add(chessUnit);

        return(chessUnit);
    }