示例#1
0
    private void select()
    {
        if (mouse.isSelected("Selectable"))
        {
            HexPosition.clearSelection("Selectable");
            selection = mouse;
            mouse.select("Selection");
            Unit unit = mouse.getUnit();
            selectMovable(unit);
            moveFromPos = unit.Coordinates;
            switch (unit.Status)
            {
            case Unit.State.MOVE:
                phase = Phase.MOVE;
                break;

            case Unit.State.ATTACK:
                phase = Phase.ATTACK;
                break;

            default:
                print("Error: Action " + unit.Status + " not implemented.");
                break;
            }
        }
    }
    private void select()
    {
        if (mouse.isSelected("Selectable"))
        {
            HexPosition.clearSelection("Selectable");
            selection = mouse;
            mouse.select("Selection");
            Unit unit = mouse.getUnit();
            selectAttackable(unit);
            switch (unit.Status)
            {
            case Unit.State.MOVE:
                turn = Turn.MOVE;
                break;

            case Unit.State.ATTACK:
                turn = Turn.ATTACK;
                break;

            default:
                Debug.LogError("Error: Action " + unit.Status + " not implemented.");
                break;
            }
        }
    }
 private void move()
 {
     if (mouse.Equals(selection))
     {
         unselect();
     }
     else if (!mouse.containsKey("Unit"))
     {
         if (path.Length > 0)
         {
             waiting = true;
             HexPosition.clearSelection();
             selection = mouse;
             selection.select("Selection");
             CmdMoveUnit(HexPosition.pathToIntString(path));
         }
     }
     else
     {
         object enemy = null;
         if (mouse.tryGetValue("Unit", out enemy))
         {
             if (isAttackable(selection.getUnit(), (Unit)enemy))
             {
                 actuallyAttack();
             }
         }
     }
 }
示例#4
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");
                }
            }
        }
    }
示例#5
0
 private void move()
 {
     if (mouse.Equals(selection))
     {
         unselect();
     }
     else if (!mouse.containsKey("Unit"))
     {
         if (path.Length > 0)
         {
             Unit myUnit = selection.getUnit();
             myUnit.move(path);
             HexPosition.clearSelection();
             selection = mouse;
             selection.select("Selection");
             if (selectAttackable(myUnit))
             {
                 phase = Phase.ATTACK;
             }
             else
             {
                 myUnit.skipAttack();
                 unselect();
             }
         }
     }
 }
示例#6
0
    private bool selectMovable(Unit unit)
    {
        bool nonempty = false;

        for (int i = unit.Coordinates.U - unit.SPEED; i <= unit.Coordinates.U + unit.SPEED; i++)
        {
            for (int j = unit.Coordinates.V - unit.SPEED; j <= unit.Coordinates.V + unit.SPEED; j++)
            {
                HexPosition moveAbleHex = new HexPosition(i, j);
                if (isMovable(unit, moveAbleHex))
                {
                    moveAbleHex.select("Movable");
                }
            }
        }
        return(nonempty);
    }
示例#7
0
 private void move()
 {
     if (mouse.Equals(selection))
     {
         unselect();
     }
     else if (!mouse.containsKey("Unit"))
     {
         if (path.Length > 0)
         {
             Unit myUnit = ((Unit)selection.getValue("Unit"));
             myUnit.move(path);
             HexPosition.clearSelection();
             selection = mouse;
             selection.select("Selection");
             if (selectAttackable(myUnit))
             {
                 turn = Turn.ATTACK;
             }
             else
             {
                 myUnit.Status = Unit.State.WAIT;
                 unselect();
                 endTurn();
             }
         }
     }
     else
     {
         object enemy = null;
         if (mouse.tryGetValue("Unit", out enemy))
         {
             Unit myUnit = ((Unit)selection.getValue("Unit"));
             if (isAttackable(myUnit, (Unit)enemy))
             {
                 actuallyAttack();
             }
         }
     }
 }
示例#8
0
 private void move()
 {
     if (mouse.Equals(selection))
     {
         unselect();
     }
     else if (!mouse.containsKey("Unit"))
     {
         if (path.Length > 0)
         {
             Unit myUnit = selection.getUnit();
             myUnit.move(path);
             HexPosition.clearSelection();
             selection = mouse;
             selection.select("Selection");
             if (selectAttackable(myUnit))
             {
                 turn = Turn.ATTACK;
             }
             else
             {
                 myUnit.skipAttack();
                 unselect();
             }
         }
     }
     else
     {
         Unit enemy = mouse.getUnit();
         if (enemy != null)
         {
             Unit myUnit = selection.getUnit();
             if (isAttackable(myUnit, enemy))
             {
                 actuallyAttack();
             }
         }
     }
 }
    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;
                }
            }
        }
    }
示例#10
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;
                }
            }
        }
    }
示例#11
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;
             }
         }
     }
 }
示例#12
0
 private void move()
 {
     if (mouse.Equals(selection))
     {
         unselect();
     }
     else if (!mouse.containsKey("Unit"))
     {
         if (path.Length > 0)
         {
             Unit myUnit = ((Unit)selection.getValue("Unit"));
             myUnit.move(path);
             HexPosition.clearSelection();
             selection = mouse;
             selection.select("Selection");
             if (selectAttackable(myUnit))
             {
                 turn = Turn.ATTACK;
             }
             else
             {
                 myUnit.Status = Unit.State.WAIT;
                 unselect();
                 endTurn();
             }
         }
     }
     else
     {
         object enemy = null;
         if (mouse.tryGetValue("Unit", out enemy))
         {
             Unit myUnit = ((Unit)selection.getValue("Unit"));
             if (isAttackable(myUnit, (Unit)enemy))
             {
                 actuallyAttack();
             }
         }
     }
 }
示例#13
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();
                }
            }
        }
    }