void UpdateBattleState(Whose whoseTurn, bool firing, Whose loser) { this.whoseTurn = whoseTurn; this.firing = firing; this.loser = loser; UpdateWaitingForOpponent(); }
public void Launch(Whose atWhose, Position targetPosition, PosRot start, PosRot end, float flightTime, Action callback) { this.callback = callback; this.atWhose = atWhose; this.targetPosition = targetPosition; this.rocketFlightTime = flightTime; t0 = Time.time; float distance = Vector3.Distance(start.position, end.position); bezier.t0.position = start.position; bezier.t0.rotation = start.rotation; bezier.t3.position = end.position; bezier.t3.rotation = end.rotation; bezier.t1.position = start.position + .3f * distance * bezier.t0.forward + Deviation(bezier.t0); bezier.t1.rotation = start.rotation; bezier.t2.position = end.position - .3f * distance * bezier.t3.forward; bezier.t2.rotation = end.rotation; transform.position = start.position; transform.rotation = start.rotation; }
void AnnounceStrike(Whose whose, Boat boat, Position position, StrikeResult result) { if (OnStrikeOccurred != null) { OnStrikeOccurred(whose, boat, position, result); } }
void BattleStateUpdated(Whose whoseTurn, bool firing, Whose loser) { this.whoseTurn = whoseTurn; this.firing = firing; this.loser = loser; UpdateAimGazeReticles(); }
public void LaunchRocket(Whose atWhose, Position targetPosition) { // gav4.LogEvent (CATEGORY, "LaunchRocket", atWhose.ToString (), 0); RocketController rocketController = GetGridController(atWhose).MakeRocket(); Vector3 localTargetPos = targetPosition.AsGridLocalPosition(Marker.Aim); PosRot start = new PosRot(rocketController.transform); Transform targetGridTransform = GetGridController(atWhose).transform; Vector3 pos = targetGridTransform.position + (targetGridTransform.rotation * localTargetPos); pos += targetGridTransform.right * .5f + targetGridTransform.up * .5f; PosRot end = new PosRot(pos, targetGridTransform.rotation); firing++; rocketFlightTime = Mathf.Max(1f, .95f * rocketFlightTime); rocketController.Launch(atWhose, targetPosition, start, end, rocketFlightTime, delegate { firing--; }); rocketsLaunched++; if (atWhose == Whose.Ours && rocketsLaunched < 7) { float duration = .7f * rocketFlightTime; float delay = rocketFlightTime - duration; centerPanelController.IssueWarning(delay, duration); } }
void UpdateSelf(Whose whoseTurn, bool firing, Whose loser) { text.enabled = gridController.grid != null; if (text.enabled) { text.text = GetText(gridController.grid); } }
public void AimAt(Whose whose, Position position) { GetGridController(whose).SetAimPosition(position); if (OnReticleAim != null) { OnReticleAim(whose, position); } }
public StrikeResult Strike(Whose whose, Position position) { StrikeResult result = _Strike(whose, position); // gav4.LogEvent (CATEGORY, "Strike", null, 0); // gav4.LogEvent (CATEGORY, "Strike-" + whose.ToString () + "-" + result.ToString (), null, 1); Whose nextTurn = CheckAllBoatsSunk(whose); StartCoroutine(SetTurn(nextTurn)); return(result); }
public void SetBoatsTheirs(string playerUniqueId, Boat[] boats) { gav4.LogEvent(CATEGORY, "BoatPositions-Theirs", null, 0); Whose whoseStarts = playerUniqueId.Equals(Utils.AI_PLAYER_ID) || playerUniqueId.CompareTo(SystemInfo.deviceUniqueIdentifier) > 0 ? Whose.Ours : Whose.Theirs; // Debug.Log ("***FIRST TURN: " + whoseStarts + " playerUniqueId=" + playerUniqueId + " deviceUniqueIdentifier=" + SystemInfo.deviceUniqueIdentifier); StartCoroutine(SetTurn(whoseStarts)); gridTheirsController.SetBoats(playerUniqueId, boats); AnnounceBattleState(); }
void UpdateBattleState(Whose whoseTurn, bool firing, Whose loser) { // Debug.Log ("UpdateBattleState(whoseTurn=" + whoseTurn + ", firing=" + firing + ", loser=" + loser + ")"); this.whoseTurn = whoseTurn; this.firing = firing; this.loser = loser; if (firing) { fireCount++; } UpdateText(); }
public void Deserialize(BinaryReader reader) { whose = (Whose)reader.ReadInt32(); playerUniqueId = reader.ReadString(); boats = new Boat[fleet.Length]; for (int i = 0; i < fleet.Length; i++) { boats [i] = new Boat(); boats [i].Deserialize(reader); } }
public StrikeResult _Strike(Whose whose, Position position) { Boat boat; StrikeResult result = GetGridController(whose).Strike(position, out boat); if (!Application.isEditor) { Debug.Log("***Strike(" + position + ") -> " + result); } AnnounceStrike(whose, boat, position, result); return(result); }
void UpdateSelf(Whose whoseTurn, bool firing, Whose loser) { Boat[] boats = gridController.grid.boats; if (boats != null) { for (int i = 0; i < boats.Length; i++) { var hits = boats [i].HitCount(); var size = boats [i].Size(); ships [i].transform.GetComponentInChildren <ShipController> ().SetDamage(hits, size); } } }
public static Boat RandomBoat(Whose whose, int boatConfigurationIndex) { Boat boat = new Boat(); boat.boatConfigurationIndex = boatConfigurationIndex; boat.config = Grid.fleet [boatConfigurationIndex]; boat.horizontal = boat.config.size > Utils.GRID_SIZE.y || Random.value > .5f; int u = Random.Range(0, (boat.horizontal ? Utils.GRID_SIZE.x : Utils.GRID_SIZE.y) - boat.config.size + 1); int v = Random.Range(0, boat.horizontal ? Utils.GRID_SIZE.y : Utils.GRID_SIZE.x); boat.positions = MakeBoatPositions(u, v, boat.config.size, boat.horizontal); boat.hits = new int[boat.config.size]; return(boat); }
IEnumerator SetTurn(Whose whose) { whoseTurn = whose; if (whose != Whose.Nobody) { yield return(new WaitForSeconds(1.5f)); } whoseTurnAnimator.SetInteger("WhoseTurnInt", (int)whose); if (OnWhoseTurn != null) { OnWhoseTurn(whose); } AnnounceBattleState(); }
void SetStrikeData(Whose whose, Boat boat, StrikeResult result) { StrikeData newStrikeData = new StrikeData(whose, boat, result); this.strikeData = newStrikeData; UpdateText(); SceneMaster.instance.Async(delegate { if (this.strikeData == newStrikeData) { this.strikeData = null; UpdateText(); } }, GetTimeout(result)); }
void OnEnable() { strikeData = null; whoseTurn = Whose.Nobody; firing = false; loser = Whose.Nobody; reticleAimingAtGrid = false; fireCount = 0; Game.instance.OnGameStateChange += UpdateGameState; BattleController.instance.OnBattleState += UpdateBattleState; BattleController.instance.OnReticleAim += UpdateAimAtGrid; BattleController.instance.OnStrikeOccurred += UpdateStrikeOccurred; UpdateText(); }
public void Deserialize(BinaryReader reader) { whose = (Whose)reader.ReadInt32(); boatConfigurationIndex = reader.ReadInt32(); config = Grid.fleet [boatConfigurationIndex]; hits = new int[config.size]; horizontal = reader.ReadBoolean(); Position position = new Position(); position.Deserialize(reader); positions = MakeBoatPositions(horizontal ? position.x : position.y, horizontal ? position.y : position.x, config.size, horizontal); }
public void Init() { // gav4.LogEvent (CATEGORY, "Init", null, 0); Debug.Log("***" + typeof(BattleController) + ".Init()"); whoseTurn = Whose.Nobody; loser = Whose.Nobody; _firing = 0; rocketFlightTime = 3f; rocketsLaunched = 0; // reset grids gameStartTime = Time.unscaledTime; boatPositionsSent = false; gridOursController.Init(SystemInfo.deviceUniqueIdentifier); gridTheirsController.Init(null); // tell everyone to reset state AnnounceBattleState(); }
Whose CheckAllBoatsSunk(Whose whose) { if (loser != Whose.Nobody) { return(Whose.Nobody); } if (GetGridController(whose).grid.AllBoatsSunk()) { loser = whose; gav4.LogEvent(CATEGORY, "AnnounceLoser", "Loser-" + loser.ToString(), 0); AnnounceBattleState(); SceneMaster.instance.Async(delegate { Game.instance.QuitGame("AnnounceLoser"); }, Utils.RESTART_DELAY); return(Whose.Nobody); } return(whose); }
Boat[] MakeRandomizedBoats(Whose whose) { boats = new Boat[fleet.Length]; for (int i = 0; i < fleet.Length; i++) { bool conflict = true; while (conflict) { Boat boat = Boat.RandomBoat(whose, i); conflict = false; for (int j = 0; j < boat.positions.Length && !conflict; j++) { Position pos = boat.positions [j]; Boat otherBoat; StrikeResult result = FireAt(pos, out otherBoat, testOnly: true); switch (result) { case StrikeResult.MISS: case StrikeResult.IGNORED_ALREADY_MISSED: continue; case StrikeResult.IGNORED_ALREADY_HIT: case StrikeResult.HIT_NOT_SUNK: case StrikeResult.HIT_AND_SUNK: conflict = true; break; default: throw new System.NotImplementedException(); } } if (!conflict) { boats [i] = boat; } } } return(boats); }
public void SetBoats(Whose whose, Boat[] boats) { this.whose = whose; // Debug.Log ("Grid(" + whose + ") misses = new int[" + Utils.GRID_SIZE + "," + Utils.GRID_SIZE + "]"); misses = new int[Utils.GRID_SIZE.x, Utils.GRID_SIZE.y]; if (boats == null) { MakeRandomizedBoats(whose); } else { for (int i = 0; i < fleet.Length; i++) { boats [i].whose = whose; } this.boats = boats; } if (OnGridSetup != null) { OnGridSetup(); } }
void NoteStrikeResult(Whose whose, Boat boat, Position position, StrikeResult result) { if (whose == Whose.Theirs) { return; } lock (_lock) { switch (result) { case StrikeResult.MISS: _identifiedMiss.Add(position); break; case StrikeResult.HIT_NOT_SUNK: _unidentifiedHits.Add(position); break; case StrikeResult.HIT_AND_SUNK: for (int i = 0; i < boat.positions.Length; i++) { Position pos = boat.GetPosition(i); if (!pos.Equals(position)) { Assert.IsTrue(_unidentifiedHits.Remove(pos)); } _identifiedHits.Add(pos); } break; case StrikeResult.IGNORED_ALREADY_MISSED: case StrikeResult.IGNORED_ALREADY_HIT: default: throw new System.NotImplementedException(); } // Debug.Log (TextGrid ()); } }
void UpdateWhoseTurn(Whose whoseTurn) { this.whoseTurn = whoseTurn; UpdateWaitingForOpponent(); }
GridController GetGridController(Whose whose) { return(whose == Whose.Theirs ? gridTheirsController : gridOursController); }
void UpdateBattleState(Whose whoseTurn, bool firing, Whose loser) { // this.whoseTurn = whoseTurn; // this.firing = firing; this.loser = loser; }
void UpdateAimAtGrid(Whose whose, Position position) { this.reticleAimingAtGrid = position != null; UpdateText(); }
void UpdateStrikeOccurred(Whose whose, Boat boat, Position position, StrikeResult result) { SetStrikeData(whose, boat, result); }
public StrikeData(Whose whose, Boat boat, StrikeResult result) { this.whose = whose; this.boat = boat; this.result = result; }