Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (!Input.mousePresent)
        {
            mouse = null;
        }
        else
        {
            HexPosition newMouse = getMouseHex();
            if (newMouse == null)
            {
                HexPosition.clearSelection("Cursor");
            }
            else
            {
                if (newMouse != mouse)
                {
                    if (mouse != null)
                    {
                        mouse.unselect("Cursor");
                    }

                    mouse = newMouse;
                    mouse.select("Cursor");
                }
            }
        }
    }
    void Update()
    {
        if (!isLocalPlayer || !myTurn || waiting)
        {
            return;
        }
        if (!Input.mousePresent)
        {
            mouse = null;
        }
        else
        {
            HexPosition newMouse = getMouseHex();
            if (newMouse == null)
            {
                HexPosition.clearSelection("Path");
                HexPosition.clearSelection("Attack");
                path = null;
            }
            else
            {
                if (newMouse != mouse)
                {
                    if (mouse != null)
                    {
                        mouse.unselect("Cursor");
                    }
                    if (newMouse.containsKey("Obstacle"))                               //The Obstacle tag is being used to make the tile unselectable.
                    {
                        if (mouse != null && turn == Turn.MOVE)
                        {
                            HexPosition.clearSelection("Path");
                            HexPosition.clearSelection("Attack");
                            path = null;
                        }
                        mouse = null;
                        return;
                    }
                    mouse = newMouse;
                    mouse.select("Cursor");
                    if (turn == Turn.MOVE)
                    {
                        Unit unit = selection.getUnit();
                        HexPosition.clearSelection("Path");
                        HexPosition.clearSelection("Attack");
                        path = AStar.search(selection, mouse, unit.SPEED);
                        HexPosition.select("Path", path);
                        selectAttackable(unit, mouse);
                    }
                }
                if (Input.GetButtonDown("Fire1"))
                {
                    switch (turn)
                    {
                    case Turn.SELECT:
                        select();
                        break;

                    case Turn.MOVE:
                        move();
                        break;

                    case Turn.ATTACK:
                        attack();
                        break;

                    default:
                        print("Error: Turn " + turn + " not implemented.");
                        break;
                    }
                    return;
                }
            }
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        if (waiting || gameOver || !modeSelected)
        {
            return;
        }
        if (player == 1 && computerPlayer)
        {
            if (ai.go())
            {
                endTurn();
            }
            checkGameOver();
            return;
        }

        /*if (timeout > 0) {
         *              --timeout;
         *              if(timeout == 0) {
         *                      print ("Warning: HexGrid.cs timed out.");
         *              }
         *              return;
         *      }*/
        if (!Input.mousePresent)
        {
            mouse = null;
        }
        else
        {
            Ray          ray  = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit[] hits = Physics.RaycastAll(ray);
            if (hits.Length == 0)
            {
                if (mouse != null && turn == Turn.MOVE)
                {
                    HexPosition.clearSelection("Path");
                    HexPosition.clearSelection("Attack");
                    path = null;
                }
                // No hits == null
                mouse = null;
            }
            else  // if hit(s)
            {
                // Find closest
                float minDist = float.PositiveInfinity;
                int   min     = 0;
                for (int i = 0; i < hits.Length; ++i)
                {
                    if (hits[i].distance < minDist)
                    {
                        minDist = hits[i].distance;
                        min     = i;
                    }
                }
                HexPosition newMouse = new HexPosition(hits[min].point);
                if (newMouse != mouse)
                {
                    if (mouse != null)
                    {
                        mouse.unselect("Cursor");
                    }
                    if (newMouse.containsKey("Obstacle"))
                    {   //The Obstacle tag is being used to make the tile unselectable.
                        if (mouse != null && turn == Turn.MOVE)
                        {
                            HexPosition.clearSelection("Path");
                            HexPosition.clearSelection("Attack");
                            path = null;
                        }
                        mouse = null;
                        return;
                    }
                    mouse = newMouse;
                    mouse.select("Cursor");
                    if (turn == Turn.MOVE)
                    {
                        Unit unit = (Unit)selection.getValue("Unit");
                        HexPosition.clearSelection("Path");
                        HexPosition.clearSelection("Attack");
                        path = AStar.search(selection, mouse, unit.SPEED);
                        HexPosition.select("Path", path);
                        selectAttackable(unit, mouse);
                    }
                }
                if (Input.GetButtonDown("Fire1"))
                {
                    switch (turn)
                    {
                    case Turn.SELECT:
                        select();
                        break;

                    case Turn.MOVE:
                        move();
                        break;

                    case Turn.ATTACK:
                        attack();
                        break;

                    default:
                        print("Error: Turn " + turn + " not implemented.");
                        break;
                    }
                    return;
                }
            }
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        if (waiting || gameOver || !modeSelected)
        {
            return;
        }
        if (player == 1 && computerPlayer)
        {
            if (ai.go())
            {
                endPhase();
            }
            checkGameOver();
            return;
        }
        if (!Input.mousePresent)
        {
            mouse = null;
        }
        else
        {
            HexPosition newMouse = getMouseHex();
            if (newMouse == null)
            {
                HexPosition.clearSelection("Path");
                HexPosition.clearSelection("Attack");
                path = null;
            }
            else
            {
                if (newMouse != mouse)
                {
                    if (mouse != null)
                    {
                        mouse.unselect("Cursor");
                    }
                    if (newMouse.containsKey("Obstacle"))                               //The Obstacle tag is being used to make the tile unselectable.
                    {
                        if (mouse != null && phase == Phase.MOVE)
                        {
                            HexPosition.clearSelection("Path");
                            HexPosition.clearSelection("Attack");
                            path = null;
                        }
                        mouse = null;
                        return;
                    }
                    mouse = newMouse;
                    //display where the cursor is pointing at
                    mouse.select("Cursor");
                    //if is in move phase, also display the route toward where the cursor is current at
                    if (phase == Phase.MOVE)
                    {
                        Unit unit = selection.getUnit();
                        HexPosition.clearSelection("Path");
                        HexPosition.clearSelection("Attack");
                        path = AStar.search(selection, mouse, unit.SPEED);
                        HexPosition.select("Path", path);
                    }
                }
                if (Input.GetMouseButtonDown(0))
                {
                    switch (phase)
                    {
                    case Phase.SELECT:
                        select();
                        break;

                    case Phase.MOVE:
                        move();
                        break;

                    case Phase.ATTACK:
                        attack();
                        break;

                    default:
                        print("Error: Turn " + phase + " not implemented.");
                        break;
                    }
                    return;
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    HexPosition.clearSelection("Path");
                    HexPosition.clearSelection("Attack");
                    HexPosition.clearSelection("Movable");
                    HexPosition.clearSelection("Selection");
                    phase = Phase.SELECT;
                    Unit unit = selection.getUnit();
                    unit.undoMovement(moveFromPos);
                    unit.setState(Unit.State.MOVE);
                    selectSelectable();
                }
            }
        }
    }