public void CanLaunchSingleSub() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.SetDrillerCount(10); outpost2.SetDrillerCount(10); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); }
/// <summary> /// Transfers ownership between outpost or specialists. /// </summary> /// <returns>If the event was successful</returns> public bool ForwardAction() { _originalOutpostOwner = _outpost.GetOwner(); _originalDrillerCount = _outpost.GetDrillerCount(); // Tie or sub won. if (_outpost.GetDrillerCount() < 0) { this.TransferOwnership(); } else { if (_outpost.GetDrillerCount() == 0) { // Was a tie. if (_sub.GetSpecialistManager().GetSpecialistCount() > _outpost.GetSpecialistManager().GetSpecialistCount()) { this.TransferOwnership(); } else { this.CaptureSub(); } } } this._eventSuccess = true; return(true); }
public void CanLaunchSubs() { List <Player> players = new List <Player>(); players.Add(new Player("1")); GameConfiguration config = new GameConfiguration(players, DateTime.Now, new MapConfiguration(players)); Game game = new Game(config); game.TimeMachine.GetState().GetOutposts().Add(_outpost); game.TimeMachine.GetState().GetOutposts().Add(_outpost2); int initialDrillers = _outpost.GetDrillerCount(); _outpost.LaunchSub(game.TimeMachine.GetState(), new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = _outpost.GetId(), DrillerCount = 10, SourceId = _outpost2.GetId(), }.ToByteString(), EventId = "123", EventType = EventType.LaunchEvent, OccursAtTick = 10, })); Assert.AreEqual(initialDrillers - 10, _outpost.GetDrillerCount()); Assert.AreEqual(1, game.TimeMachine.GetState().GetSubList().Count); }
public void CanRemoveDrillers() { Outpost outpost = new Outpost("0", new RftVector(_map, 0, 0), new Player("1"), OutpostType.Mine); int initialDrillers = outpost.GetDrillerCount(); outpost.RemoveDrillers(40); Assert.AreEqual(initialDrillers - 40, outpost.GetDrillerCount()); }
public void CanAddDrillers() { Outpost outpost = new Outpost(new RftVector(_map, 0, 0), new Player(1), OutpostType.Mine); int initialDrillers = outpost.GetDrillerCount(); outpost.AddDrillers(40); Assert.AreEqual(initialDrillers + 40, outpost.GetDrillerCount()); }
public void SubsArriveAfterLaunch() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.SetDrillerCount(10); outpost2.SetDrillerCount(5); outpost1.SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 10, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch1.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 10, outpost1.GetDrillerCount()); // Ensure a combat event has been added. int combatEvents = 0; GameEvent combat = null; foreach (GameEvent gameEvent in _game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combat = gameEvent; combatEvents++; } } Assert.AreEqual(1, combatEvents); // Go to the event and ensure the arrival is successful _game.TimeMachine.GoTo(combat); _game.TimeMachine.Advance(1); Assert.AreEqual(true, combat.WasEventSuccessful()); Assert.AreEqual(outpost1.GetOwner(), outpost2.GetOwner()); Assert.AreEqual(Math.Abs(outpostTwoInitial - outpostOneInitial), outpost2.GetDrillerCount()); }
public void CanLaunchSingleSub() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[1]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(true, launch.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); }
public void CanLaunchSubs() { List <Player> players = new List <Player>(); players.Add(new Player(1)); GameConfiguration config = new GameConfiguration(players); Game game = new Game(config); int initialDrillers = _outpost.GetDrillerCount(); _outpost.LaunchSub(10, new Outpost(new RftVector(_map, 0, 0), new Player(1), OutpostType.Mine)); Assert.AreEqual(initialDrillers - 10, _outpost.GetDrillerCount()); Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count); }
public void CannotLaunchFromNonGeneratedOutposts() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(false, launch.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); }
public void CanSetDrillerCount() { Outpost outpost = new Outpost(new RftVector(_map, 0, 0), new Player(1), OutpostType.Mine); outpost.SetDrillerCount(420); Assert.AreEqual(420, outpost.GetDrillerCount()); }
/// <summary> /// Validates an outpost /// </summary> /// <param name="outpost">The outpost to validate</param> /// <returns>If the outpost is valid</returns> public static bool ValidateOutpost(GameState state, Outpost outpost) { if (outpost == null) { return(false); } if (!state.OutpostExists(outpost)) { return(false); } if (outpost.GetDrillerCount() < 0) { return(false); } if (outpost.GetSpecialistManager() == null) { return(false); } if (outpost.GetSpecialistManager().GetSpecialistCount() < 0) { return(false); } if (outpost.GetSpecialistManager().GetSpecialistCount() > outpost.GetSpecialistManager().GetCapacity()) { return(false); } if (outpost.GetOwner() != null && !state.PlayerExists(outpost.GetOwner())) { return(false); } return(true); }
public void SubLaunchCreatesCombatEvents() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[2]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch1 = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); LaunchEvent launch2 = new LaunchEvent(new GameTick(), outpost2, 1, outpost1); Assert.AreEqual(true, launch1.ForwardAction()); Assert.AreEqual(true, launch2.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(2, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); Assert.AreEqual(outpostTwoInitial - 1, outpost2.GetDrillerCount()); // Ensure a combat event has been added that includes both subs. int subToSubBattles = 0; int subToOutpostBattles = 0; GameEvent arriveEvent = null; CombatEvent combatEvent = null; foreach (GameEvent gameEvent in Game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combatEvent = (CombatEvent)gameEvent; if (combatEvent.GetCombatants()[0] is Sub && combatEvent.GetCombatants()[1] is Sub) { subToSubBattles++; } else { subToOutpostBattles++; arriveEvent = gameEvent; } } } // There should be 3 combats, one on each outpost, one on both subs. Assert.AreEqual(1, subToSubBattles); Assert.AreEqual(2, subToOutpostBattles); }
void Update() { if (Input.GetMouseButtonDown(0)) { // Check if the pressed location was an outpost. If it was, the user is trying to launch a sub. RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null && hit.collider.gameObject.tag == "Outpost") { // Clicked object is an outpost, don't move the camera. launchOutpost = hit.collider.gameObject.GetComponent <OutpostManager>().outpost; return; } } // If the mouse button is released, apply velocity to the map to scroll if (Input.GetMouseButtonUp(0)) { // If the first click was on an outpost, check if the second is on another outpost for a launch. if (launchOutpost != null && showLaunchHud == false) { // Check if the pressed location was an outpost. If it was, the user is trying to launch a sub. RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null && hit.collider.gameObject.tag == "Outpost") { // Clicked object is an outpost, don't move the camera. destinationOutpost = hit.collider.gameObject.GetComponent <OutpostManager>().outpost; // only show the hud if the souce outpost is owned by the current player & the destination is not the source. if (launchOutpost != destinationOutpost && launchOutpost.GetOwner().GetId() == ApplicationState.player.GetId()) { SouceLaunchInformation sourcePanel = launchHud.GetComponentInChildren <SouceLaunchInformation>(); sourcePanel.source = launchOutpost; SubLaunchInformation informationPanel = launchHud.GetComponentInChildren <SubLaunchInformation>(); informationPanel.destination = destinationOutpost; informationPanel.sourceOutpost = launchOutpost; drillerSlider.maxValue = launchOutpost.GetDrillerCount(); this.SetLaunchHub(true); } else { launchOutpost = null; } } } else if (showLaunchHud) { // Determine if the click was in the panel if (EventSystem.current.IsPointerOverGameObject()) { return; } this.SetLaunchHub(false); } } }
// Update is called once per frame void Update() { Text text = gameObject.GetComponentInChildren <Text>(); text.text = "====Source Outpost====\n" + "Outpost Id: " + source.GetId() + "\n" + "Shields: " + source.GetShields() + "\n" + "Drillers: " + source.GetDrillerCount() + "\n" + "Specialists: " + source.GetSpecialistManager().GetSpecialistCount(); }
public void CannotLaunchFromNonGeneratedOutposts() { Outpost outpost1 = new Outpost(new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost(new RftVector(new Rft(300, 300), 0, 0)); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(false, launch.ForwardAction()); }
public void SubsArriveAfterLaunch() { Outpost outpost1 = Game.TimeMachine.GetState().GetOutposts()[0]; Outpost outpost2 = Game.TimeMachine.GetState().GetOutposts()[1]; int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); LaunchEvent launch1 = new LaunchEvent(new GameTick(), outpost1, 1, outpost2); Assert.AreEqual(true, launch1.ForwardAction()); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(1, Game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); // Ensure a combat event has been added. int combatEvents = 0; GameEvent combat = null; foreach (GameEvent gameEvent in Game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combat = gameEvent; combatEvents++; } } Assert.AreEqual(1, combatEvents); // Go to the event and ensure the arrival is successful Game.TimeMachine.GoTo(combat); Game.TimeMachine.Advance(1); Assert.AreEqual(true, combat.WasEventSuccessful()); Assert.AreEqual(outpost1.GetOwner(), outpost2.GetOwner()); Assert.AreEqual(1, outpost2.GetDrillerCount()); }
public void SubLaunchCreatesCombatEvents() { Outpost outpost1 = new Outpost("0", new RftVector(new Rft(300, 300), 0, 0)); Outpost outpost2 = new Outpost("1", new RftVector(new Rft(300, 300), 0, 0)); outpost1.SetDrillerCount(10); outpost2.SetDrillerCount(10); outpost1.SetOwner(_game.TimeMachine.GetState().GetPlayers()[0]); outpost2.SetOwner(_game.TimeMachine.GetState().GetPlayers()[1]); int outpostOneInitial = outpost1.GetDrillerCount(); int outpostTwoInitial = outpost2.GetDrillerCount(); _game.TimeMachine.GetState().GetOutposts().Add(outpost1); _game.TimeMachine.GetState().GetOutposts().Add(outpost2); LaunchEvent launch1 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost2.GetId(), DrillerCount = 1, SourceId = outpost1.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); LaunchEvent launch2 = new LaunchEvent(new GameEventModel() { EventData = new LaunchEventData() { DestinationId = outpost1.GetId(), DrillerCount = 1, SourceId = outpost2.GetId(), }.ToByteString(), EventId = "a", EventType = EventType.LaunchEvent, OccursAtTick = 1, }); Assert.AreEqual(true, launch1.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); Assert.AreEqual(true, launch2.ForwardAction(_game.TimeMachine, _game.TimeMachine.GetState())); // Ensure the sub was launched, outpost lost drillers, etc. Assert.AreEqual(2, _game.TimeMachine.GetState().GetSubList().Count); Assert.AreEqual(outpostOneInitial - 1, outpost1.GetDrillerCount()); Assert.AreEqual(outpostTwoInitial - 1, outpost2.GetDrillerCount()); // Ensure a combat event has been added that includes both subs. int subToSubBattles = 0; int subToOutpostBattles = 0; GameEvent arriveEvent = null; CombatEvent combatEvent = null; foreach (GameEvent gameEvent in _game.TimeMachine.GetQueuedEvents()) { if (gameEvent is CombatEvent) { combatEvent = (CombatEvent)gameEvent; if (combatEvent.GetCombatants()[0] is Sub && combatEvent.GetCombatants()[1] is Sub) { subToSubBattles++; } else { subToOutpostBattles++; arriveEvent = gameEvent; } } } // There should be 3 combats, one on each outpost, one on both subs. Assert.AreEqual(1, subToSubBattles); Assert.AreEqual(2, subToOutpostBattles); }
// Update is called once per frame void Update() { // Set color based on the owner textMesh.text = outpost.GetDrillerCount().ToString(); SpriteRenderer renderer = GetComponent <SpriteRenderer>(); int playerId = 0; if (outpost.GetOwner() != null) { playerId = Game.TimeMachine.GetState().GetPlayers().IndexOf(outpost.GetOwner()) + 1; } switch (playerId) { case 0: renderer.color = subSky; break; case 1: renderer.color = subRed; break; case 2: renderer.color = subOlive; break; case 3: renderer.color = subOrange; break; case 4: renderer.color = subPink; break; case 5: renderer.color = subBrown; break; case 6: renderer.color = subPurple; break; case 7: renderer.color = subBiege; break; } if (Input.GetMouseButtonDown(0)) { downtime = Time.time; return; } if (Input.GetMouseButtonUp(0)) { downtime = Time.time - downtime; } if (Input.GetMouseButton(0)) { return; } if (downtime < 0.25 && downtime > 0) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.collider.gameObject == gameObject && expanded == false) { hit.collider.gameObject.GetComponent <OutpostManager>().Expand(); //gameManager.SelectedOutpost = hit.transform.GetComponent<OutpostManager>().ID; } else { gameObject.GetComponent <OutpostManager>().Contract(); } } else { gameObject.GetComponent <OutpostManager>().Contract(); } downtime = 0; } }
// Start is called before the first frame update void Start() { slider.minValue = 0; slider.maxValue = sourceOutpost.GetDrillerCount(); }
// Update is called once per frame void Update() { // Set color based on the owner textMesh.text = outpost.GetDrillerCount().ToString(); // Determine the outpost vision mask. if (outpost.GetOwner()?.GetId() == ApplicationState.player.GetId()) { // Apply vision mask. gameObject.GetComponentInChildren <SpriteMask>().transform.localScale = new Vector3(outpost.getVisionRange() / 15.0f, outpost.getVisionRange() / 15.0f, 1); gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(1, 1, 1); } else { // remove vision mask. gameObject.GetComponentInChildren <SpriteMask>().transform.localScale = new Vector3(0, 0, 1); if (ApplicationState.CurrentGame.TimeMachine.GetState().isInVisionRange(outpost, ApplicationState.player)) { gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(1, 1, 1); } else { gameObject.GetComponentInChildren <TextMeshPro>().transform.localScale = new Vector3(0, 0, 1); } } SpriteRenderer renderer = GetComponent <SpriteRenderer>(); int playerId = 0; if (outpost.GetOwner() != null) { playerId = ApplicationState.CurrentGame.TimeMachine.GetState().GetPlayers().IndexOf(outpost.GetOwner()) + 1; } switch (playerId) { case 0: renderer.color = subGrey; break; case 1: renderer.color = subRed; break; case 2: renderer.color = subOlive; break; case 3: renderer.color = subOrange; break; case 4: renderer.color = subPink; break; case 5: renderer.color = subBrown; break; case 6: renderer.color = subPurple; break; case 7: renderer.color = subBiege; break; case 8: renderer.color = subSky; break; } if (Input.GetMouseButtonDown(0)) { downtime = Time.time; return; } if (Input.GetMouseButtonUp(0)) { downtime = Time.time - downtime; } if (Input.GetMouseButton(0)) { return; } if (downtime < 0.25 && downtime > 0) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { if (hit.collider.gameObject == gameObject && expanded == false) { hit.collider.gameObject.GetComponent <OutpostManager>().Expand(); //gameManager.SelectedOutpost = hit.transform.GetComponent<OutpostManager>().ID; } else { gameObject.GetComponent <OutpostManager>().Contract(); } } else { gameObject.GetComponent <OutpostManager>().Contract(); } downtime = 0; } }