// 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"); } } } }
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(); } } } }
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(); } } } }
public void endTurn() { foreach (Unit unit in units) { //I only need to do this with units on that team, but checking won't speed things up. I could also only do it when player overflows. if (unit.PLAYER == player) { unit.newTurn(); } if (unit.PLAYER != player) { if (unit.position.containsKey("Base")) { if (player == 0) { countdownR--; } else { countdownB--; } checkGameOver(); } } } HexPosition.clearSelection(); player = (player + 1) % PLAYERS; if (player == 0 || !computerPlayer) { selectSelectable(); } }
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; } } }
void OnGUI() { if (!isLocalPlayer) { return; } if (gameOver) { GUIStyle style = new GUIStyle(); style.fontSize = 72; style.alignment = TextAnchor.MiddleCenter; GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "Player " + (player + 1) + " Wins!", style); return; } if (!myTurn) { GUI.Box(new Rect(10, 10, 150, 20), "Waiting for your turn..."); return; } if (waiting) { return; } GUI.Box(new Rect(10, 10, 90, 20), "Player " + (player + 1)); switch (turn) { case Turn.SELECT: GUI.Box(new Rect(10, 40, 90, 20), "Select"); if (GUI.Button(new Rect(10, 70, 90, 20), "End Turn")) { endTurn(); } break; case Turn.MOVE: GUI.Box(new Rect(10, 40, 90, 20), "Move"); if (GUI.Button(new Rect(10, 70, 90, 20), "Cancel Move")) { unselect(); } break; case Turn.ATTACK: GUI.Box(new Rect(10, 40, 90, 20), "Attack"); if (GUI.Button(new Rect(10, 70, 90, 20), "Skip Attack")) { HexPosition.clearSelection(); selection = null; if (mouse != null) { mouse.select("Cursor"); } selectSelectable(); turn = Turn.SELECT; } break; } }
private void unselect() { HexPosition.clearSelection(); selection = null; mouse.select("Cursor"); if (!(selectSelectable() || gameOver)) { endTurn(); } turn = Turn.SELECT; }
public void endTurn() { HexPosition.clearSelection(); foreach (Unit unit in units) //I only need to do this with units on that team, but checking won't speed things up. I could also only do it when player overflows. { unit.newTurn(); } player = (player + 1) % PLAYERS; if (player == 0 || !computerPlayer) { selectSelectable(); } }
public void endPhase() { HexPosition.clearSelection(); foreach (Unit unit in units) { unit.newPhase(); } player = (player + 1) % PLAYERS; if (player == 0 || !computerPlayer) { selectSelectable(); } }
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(); } } } }
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 (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; } } } }
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; } } } }
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(); } } } }
private void endTurn() { HexPosition.clearSelection(); myTurn = false; CmdEndTurn(); }
void OnGUI() { if (!modeSelected) { if (GUI.Button(new Rect(10, 10, 90, 20), "1 Player")) { selectSelectable(); computerPlayer = true; modeSelected = true; ai = new AI(units, 1); return; } if (GUI.Button(new Rect(10, 40, 90, 20), "2 Player")) { selectSelectable(); computerPlayer = false; modeSelected = true; return; } return; } if (gameOver) { player = (player + 1) % PLAYERS; GUIStyle style = new GUIStyle(); style.fontSize = 72; style.alignment = TextAnchor.MiddleCenter; if (countdownR == 0) { player = 1; } if (countdownB == 0) { player = 0; } GUI.Box(new Rect(10, 10, Screen.width - 20, Screen.height - 20), "Player " + (player + 1) + " Wins!", style); return; } if (waiting || (player == 1 && computerPlayer)) { return; } GUI.Box(new Rect(10, 10, 90, 20), "Player " + (player + 1)); switch (turn) { case Turn.SELECT: GUI.Box(new Rect(10, 40, 90, 20), "Select"); if (GUI.Button(new Rect(10, 70, 90, 20), "End Turn")) { endTurn(); } break; case Turn.MOVE: GUI.Box(new Rect(10, 40, 90, 20), "Move"); if (GUI.Button(new Rect(10, 70, 90, 20), "Cancel Move")) { unselect(); } break; case Turn.ATTACK: GUI.Box(new Rect(10, 40, 90, 20), "Attack"); if (GUI.Button(new Rect(10, 70, 90, 20), "Skip Attack")) { HexPosition.clearSelection(); selection = null; if (mouse != null) { mouse.select("Cursor"); } selectSelectable(); turn = Turn.SELECT; endTurn(); } break; } }