// Use this for initialization void Start() { if (Destroyer.instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); } }
// Create the about dialog public void About() { // This will destroy all, because we shouldn't have anything left at the main menu Destroyer.Destroy(); Sprite bannerSprite; Texture2D newTex = Resources.Load("sprites/banner") as Texture2D; GameObject banner = new GameObject("banner"); banner.tag = Game.DIALOG; banner.transform.SetParent(Game.Get().uICanvas.transform); RectTransform trans = banner.AddComponent <RectTransform>(); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit()); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit()); banner.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = banner.AddComponent <UnityEngine.UI.Image>(); bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.sprite = bannerSprite; image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit()); UIElement ui = new UIElement(); ui.SetLocation((UIScaler.GetWidthUnits() - 30f) / 2, 10, 30, 6); ui.SetText(ABOUT_FFG); ui.SetFontSize(UIScaler.GetMediumFont()); ui = new UIElement(); ui.SetLocation((UIScaler.GetWidthUnits() - 30f) / 2, 18, 30, 5); ui.SetText(ABOUT_LIBS); ui.SetFontSize(UIScaler.GetMediumFont()); ui = new UIElement(); ui.SetLocation(UIScaler.GetWidthUnits() - 5, UIScaler.GetBottom(-3), 5, 2); ui.SetText(Game.Get().version); ui.SetFontSize(UIScaler.GetMediumFont()); ui = new UIElement(); ui.SetLocation(1, UIScaler.GetBottom(-3), 8, 2); ui.SetText(CommonStringKeys.BACK); ui.SetFont(Game.Get().gameType.GetHeaderFont()); ui.SetFontSize(UIScaler.GetMediumFont()); ui.SetButton(Destroyer.MainMenu); ui.SetBGColor(new Color(0, 0.03f, 0f)); new UIElementBorder(ui); }
public void Update(bool toggle = false) { Destroyer.Dialog(); developerToggle ^= toggle; Game game = Game.Get(); game.logWindow = this; game.cc.panDisable = true; // white background because font rendering is broken string log = ""; foreach (Quest.LogEntry e in game.quest.log) { log += e.GetEntry(developerToggle); } log.Trim('\n'); DialogBox db = null; if (developerToggle) { db = new DialogBox(new Vector2(UIScaler.GetHCenter(-18f), 0.5f), new Vector2(20, 24.5f), new StringKey(null, log, false), Color.black, new Color(1, 1, 1, 0.9f)); } else { db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28, 24.5f), new StringKey(null, log, false), Color.black, new Color(1, 1, 1, 0.9f)); } db.AddBorder(); // This material works for the mask, but only renders in black db.textObj.GetComponent <UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial"); UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent <UnityEngine.UI.ScrollRect>(); scrollRect.content = db.textObj.GetComponent <RectTransform>(); scrollRect.horizontal = false; RectTransform textRect = db.textObj.GetComponent <RectTransform>(); textRect.sizeDelta = new Vector2(textRect.rect.width, db.textObj.GetComponent <UnityEngine.UI.Text>().preferredHeight); scrollRect.verticalNormalizedPosition = 0f; UnityEngine.UI.Mask mask = db.background.AddComponent <UnityEngine.UI.Mask>(); new TextButton(new Vector2(UIScaler.GetHCenter(-3f), 25f), new Vector2(6, 2), CommonStringKeys.CLOSE, delegate { Destroyer.Dialog(); }); if (developerToggle) { DrawVarList(); } }
// Event ended (pass or set as fail) public void EndEvent(int state = 0) { // Get list of next events List <string> eventList = new List <string>(); if (currentEvent.qEvent.nextEvent.Count > state) { eventList = currentEvent.qEvent.nextEvent[state]; } // Only take enabled events from list List <string> enabledEvents = new List <string>(); foreach (string s in eventList) { if (!game.quest.eManager.events[s].Disabled()) { enabledEvents.Add(s); } } // Are there any events? if (enabledEvents.Count > 0) { // Are we picking at random? if (currentEvent.qEvent.randomEvents) { currentEvent = null; // Start a random event game.quest.eManager.QueueEvent(enabledEvents[Random.Range(0, enabledEvents.Count)]); } else { currentEvent = null; // Start the first valid event game.quest.eManager.QueueEvent(enabledEvents[0]); } // Chained event ongoing return; } // Does this event end the quest? if (currentEvent.qEvent.sectionName.IndexOf("EventEnd") == 0) { Destroyer.MainMenu(); return; } // Trigger a stacked event currentEvent = null; TriggerEvent(); }
public SaveSelectScreen(bool performSave = false, Texture2D s = null) { save = performSave; if (!save) { // This will destroy all, because we shouldn't have anything left at the main menu Destroyer.Destroy(); } saves = SaveManager.GetSaves(); // Create elements for the screen CreateElements(); }
public void IsSegmentWithInGridRange_WhenXAxisIsGreaterThanDimension_ReturnFalse() { // Arrange IShip firstDestroyer = new Destroyer(1); int x = XInitialPoint + GridDimension + Index; int y = Index; // Act bool result = BattleshipExtensions.IsSegmentWithInGridRange(x, y); // Assert Assert.IsFalse(result); }
public void QuestStartEvent() { Destroyer.Dialog(); // Create the menu button new MenuButton(); new LogButton(); // Draw next stage button if required stageUI = new NextStageButton(); // Start round events quest.eManager.EventTriggerType("StartRound", false); // Start the quest (top of stack) quest.eManager.EventTriggerType("EventStart"); }
private void HLineDestroyHandler(List <Destroyer> destroyers, Cell cell, Point pos) { Destroyer leftDestr = _entityManager.CreateDestroyer(); leftDestr.Type = DestroyerType.Left; leftDestr.Position = pos; destroyers.Add(leftDestr); Destroyer rightDestr = _entityManager.CreateDestroyer(); rightDestr.Type = DestroyerType.Right; rightDestr.Position = pos; destroyers.Add(rightDestr); CoroutineManager.StartCoroutine(cell, BitDestroyCoroutine(cell)); }
private void VLineDestroyHandler(List <Destroyer> destroyers, Cell cell, Point pos) { Destroyer topDestr = _entityManager.CreateDestroyer(); topDestr.Type = DestroyerType.Top; topDestr.Position = pos; destroyers.Add(topDestr); Destroyer bottomDestr = _entityManager.CreateDestroyer(); bottomDestr.Type = DestroyerType.Bottom; bottomDestr.Position = pos; destroyers.Add(bottomDestr); CoroutineManager.StartCoroutine(cell, BitDestroyCoroutine(cell)); }
// Unique Defeated (others still around) public void UniqueDefeated() { Game game = Game.Get(); Destroyer.Dialog(); // Add to undo stack game.quest.Save(); // Monster is no longer unique monster.unique = false; monster.healthMod = 0; game.monsterCanvas.UpdateList(); // Trigger unique defeated event TriggerDefeatedEvents(game, "DefeatedUnique"); }
// Start game as MoM public void MoM() { // Check if import neeeded if (!fcMoM.NeedImport()) { Game.Get().gameType = new MoMGameType(); // MoM also has a special reound controller Game.Get().roundControl = new RoundControllerMoM(); Texture2D cursor = Resources.Load("sprites/CursorMoM") as Texture2D; Cursor.SetCursor(cursor, Vector2.zero, CursorMode.Auto); loadLocalization(); Destroyer.MainMenu(); } }
// This function takes us back to the main menu public static void MainMenu() { // Destroy everything Destroyer.Destroy(); Game game = Game.Get(); // All content data has been loaded by editor, cleanup everything game.cd = new ContentData(game.gameType.DataDirectory()); // Load the base content - pack will be loaded later if required game.ContentLoader.LoadContentID(""); new MainMenuScreen(); }
public override void Cast() { GameObject firedProjectile = Instantiate(projectile, castPoint.transform.position, castPoint.transform.rotation); Rigidbody2D rb2d = firedProjectile.GetComponent<Rigidbody2D>(); Destroyer destroyer = firedProjectile.GetComponent<Destroyer>(); destroyer.projectile = firedProjectile; destroyer.projectileLife = duration; float theta = Mathf.Deg2Rad * crosshair.angleToPlayer; float x = castPoint.transform.position.x; float y = castPoint.transform.position.y; Vector2 forceAngle = new Vector2(Mathf.Cos(theta) * forceModifier, Mathf.Sin(theta) * forceModifier); rb2d.AddForce(forceAngle, ForceMode2D.Impulse); }
// Unique Defeated (others still around) public void UniqueDefeated() { Game game = Game.Get(); Destroyer.Dialog(); // Add to undo stack game.quest.Save(); // Monster is no longer unique monster.unique = false; monster.healthMod = 0; game.monsterCanvas.UpdateList(); // Trigger unique defeated event game.quest.eManager.EventTriggerType("DefeatedUnique" + monster.monsterData.sectionName); }
/// <summary> /// Executes the command. /// </summary> /// <param name="parameter">Possible specified command arguments.</param> /// <exception cref="ArgumentOutOfRangeException">If the ShipType is undefined.</exception> public override void Execute(object parameter) { if (this.battleFieldViewModel.ShipToPlace.ShipType == ShipType.Undefined) { return; } Position position = (Position)parameter; Ship ship; switch (this.battleFieldViewModel.ShipToPlace.ShipType) { case ShipType.Battleship: ship = new Battleship(position); break; case ShipType.Carrier: ship = new Carrier(position); break; case ShipType.Cruiser: ship = new Cruiser(position); break; case ShipType.Destroyer: ship = new Destroyer(position); break; case ShipType.Sub: ship = new Sub(position); break; default: throw new ArgumentOutOfRangeException(nameof(this.battleFieldViewModel.ShipToPlace.ShipType)); } ship.Orientation = this.battleFieldViewModel.ShipToPlace.ShipOrientation; this.battleFieldViewModel.ShipToPlace.Ship = ship; this.battleFieldAreaViewModel.ClearHighlighted(); bool validPosition = this.battleFieldAreaViewModel.HighlightSquares(ship); if (!validPosition) { this.battleFieldViewModel.ShipToPlace.ValidPosition = false; } else { this.battleFieldViewModel.ShipToPlace.ValidPosition = true; } }
// Send data to Google forms private void SendStats() { if (game_won == "not set" || selected_rating == 0) { error_message.SetText(STATS_MISSING_INFO, Color.red); error_message.SetBGColor(Color.clear); return; } Game.Get().stats.PrepareStats(game_won, selected_rating, comments.GetText()); Game.Get().stats.PublishData(); // todo: manage the result / error with a callback Destroyer.MainMenu(); }
// Activated hero public void activated() { Destroyer.Dialog(); Game game = Game.Get(); // Save state to undo stack game.quest.Save(); hero.activated = true; // Let the game know that a hero has activated Game.Get().roundControl.HeroActivated(); // Should this be before the roundControl? updateDisplay(); }
// Restarts the current quest public static void Restart() { Game game = Game.Get(); if (!GetCurrentQuest(game, out QuestData.Quest currentQuest)) { // Failsafe. Go to quest selection if there's no valid quest loaded List(); return; } // Go back to quest details Destroyer.Destroy(); new QuestDetailsScreen(currentQuest); }
/* int[][] grid = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, * {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, * {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; */ public void setShips() { Boat[] ship; ship = new Boat[10]; ship[0] = new Portaviones(); ship[1] = new Crucero(); ship[2] = new Crucero(); ship[3] = new Destroyer(); ship[4] = new Destroyer(); ship[5] = new Destroyer(); ship[6] = new Submarine(); ship[7] = new Submarine(); ship[8] = new Submarine(); ship[9] = new Submarine(); }
public void Close() { Destroyer.Dialog(); Game game = Game.Get(); if (game.quest.puzzle.ContainsKey(questPuzzle.sectionName)) { game.quest.puzzle.Remove(questPuzzle.sectionName); } game.quest.puzzle.Add(questPuzzle.sectionName, puzzle); game.quest.eManager.currentEvent = null; game.quest.eManager.currentEvent = null; game.quest.eManager.TriggerEvent(); }
// Create page public ContentSelectScreen() { // Clean everything up Destroyer.Destroy(); game = Game.Get(); if (game.cd.Count <PackTypeData>() > 1) { DrawTypeList(); } else { DrawList(""); } }
public void Select(int num) { if (save) { SaveManager.Save(num); Destroyer.Dialog(); } else { if (saves[num].valid) { SaveManager.Load(num); } } }
public void OnChangeScene(string sceneName) { if (sceneName != originalSceneName) { return; } GameObject g = new GameObject(); Destroyer d = g.AddComponent <Destroyer>(); d.originalSceneName = originalSceneName; d.originalObjectName = originalObjectName; d.destroyAllThatMatch = destroyAllThatMatch; d.Start(); }
// Create the about dialog public void About() { // This will destroy all, because we shouldn't have anything left at the main menu Destroyer.Destroy(); Sprite bannerSprite; Texture2D newTex = Resources.Load("sprites/banner") as Texture2D; GameObject banner = new GameObject("banner"); banner.tag = "dialog"; banner.transform.parent = Game.Get().uICanvas.transform; RectTransform trans = banner.AddComponent <RectTransform>(); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit()); trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit()); banner.AddComponent <CanvasRenderer>(); UnityEngine.UI.Image image = banner.AddComponent <UnityEngine.UI.Image>(); bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1); image.sprite = bannerSprite; image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit()); DialogBox db = new DialogBox( new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 10f), new Vector2(30, 6), ABOUT_FFG); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db = new DialogBox( new Vector2((UIScaler.GetWidthUnits() - 30f) / 2, 18f), new Vector2(30, 5), ABOUT_LIBS); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); TextButton tb = new TextButton( new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), CommonStringKeys.BACK, delegate { Destroyer.MainMenu(); }); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f); tb.SetFont(Game.Get().gameType.GetHeaderFont()); }
public void CreateWindow() { Destroyer.Dialog(); DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-14f), 0.5f), new Vector2(28f, 22f), ""); db.AddBorder(); // Puzzle goes here db = new DialogBox(new Vector2(UIScaler.GetHCenter(10f), 8f), new Vector2(3f, 2f), "Skill:"); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db = new DialogBox(new Vector2(UIScaler.GetHCenter(10f), 10f), new Vector2(3f, 2f), EventManager.SymbolReplace(questPuzzle.skill)); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db.AddBorder(); bool solved = puzzle.Solved(); foreach (KeyValuePair <PuzzleImage.TilePosition, PuzzleImage.TilePosition> kv in puzzle.state) { Draw(kv.Key, kv.Value, solved); } db = new DialogBox(new Vector2(UIScaler.GetHCenter(-11f), 20f), new Vector2(6f, 2f), "Moves:"); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db = new DialogBox(new Vector2(UIScaler.GetHCenter(-5f), 20f), new Vector2(3f, 2f), (puzzle.moves - previousMoves).ToString()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db.AddBorder(); db = new DialogBox(new Vector2(UIScaler.GetHCenter(-2f), 20f), new Vector2(10f, 2f), "Total Moves:"); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db = new DialogBox(new Vector2(UIScaler.GetHCenter(8f), 20f), new Vector2(3f, 2f), puzzle.moves.ToString()); db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont(); db.AddBorder(); if (solved) { new TextButton(new Vector2(UIScaler.GetHCenter(-13f), 23.5f), new Vector2(8f, 2), "Close", delegate {; }, Color.grey); new TextButton(new Vector2(UIScaler.GetHCenter(5f), 23.5f), new Vector2(8f, 2), eventData.GetButtons()[0].label, delegate { Finished(); }); } else { new TextButton(new Vector2(UIScaler.GetHCenter(-13f), 23.5f), new Vector2(8f, 2), "Close", delegate { Close(); }); new TextButton(new Vector2(UIScaler.GetHCenter(5f), 23.5f), new Vector2(8f, 2), eventData.GetButtons()[0].label, delegate {; }, Color.grey); } }
// Destroy list, call on cancel public void SelectItem(UnityEngine.Events.UnityAction call) { Destroyer.Dialog(); cancelCall = call; // Border DialogBox db = new DialogBox(new Vector2(21, 0), new Vector2(20, 26), ""); db.AddBorder(); // Title db = new DialogBox(new Vector2(21, 0), new Vector2(20, 1), title); float offset = 2; TextButton tb = null; // All items on this page for (int i = indexOffset; i < (20 + indexOffset); i++) { // limit to array length if (items.Count > i) { string key = items[i]; Color c = colours[i]; tb = new TextButton(new Vector2(21, offset), new Vector2(20, 1), key, delegate { SelectComponent(key); }, c); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); } offset += 1; } // Paged if (items.Count > 20) { // Prev button offset += 1; tb = new TextButton(new Vector2(22f, offset), new Vector2(1, 1), "<", delegate { PreviousPage(); }); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); // Next button tb = new TextButton(new Vector2(39f, offset), new Vector2(1, 1), ">", delegate { NextPage(); }); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); } // Cancel button offset += 1; tb = new TextButton(new Vector2(26.5f, offset), new Vector2(9, 1), "Cancel", cancelCall); tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f); tb.button.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont(); }
public void DestroyerSunkInFourShoots() { var destroyer = new Destroyer(); destroyer.Locate(0, 0, false); var touched1 = destroyer.Shoot(0, 0); var touched2 = destroyer.Shoot(1, 0); var touched3 = destroyer.Shoot(2, 0); var touched4 = destroyer.Shoot(3, 0); Assert.IsTrue(touched1); Assert.IsTrue(touched2); Assert.IsTrue(touched3); Assert.IsTrue(touched4); Assert.IsTrue(destroyer.Sunk); }
public void Destroyer_HitCounterEqualsShipLength_ReturnIsShipSunkTrue() { // Arrange IShip destroyer = new Destroyer(1); // Act for (int i = 0; i < destroyer.ShipLength; i++) { destroyer.CoordinateStatus++; } bool isSunk = destroyer.CoordinateStatus == destroyer.ShipLength; // Assert Assert.IsTrue(isSunk); }
private void InitializeComponent() { health = GetComponent <Health>(); mover = GetComponent <Mover>(); destroyer = GetComponent <RootDestroyer>(); var rootTransform = transform.root; npcSensorSight = rootTransform.GetComponentInChildren <NpcSensorSight>(); npcSensorSound = rootTransform.GetComponentInChildren <NpcSensorSound>(); hitSensor = rootTransform.GetComponentInChildren <HitSensor>(); handController = hand.GetComponent <HandController>(); npcDeathEventChannel = GameObject.FindWithTag(Tags.GameController).GetComponent <NpcDeathEventChannel>(); hitEventChannel = GameObject.FindWithTag(Tags.GameController).GetComponent <HitEventChannel>(); }
public ContentSelect() { Destroyer.Destroy(); game = Game.Get(); // Find any content packs at the location game.cd = new ContentData(game.gameType.DataDirectory()); // Check if we found anything if (game.cd.allPacks.Count == 0) { Debug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine); Application.Quit(); } Update(); }
//This method needs refactoring as it violates CQRS, therefore making testing difficult public Grid Create() { var grid = new Grid(10, _randomNumberGenerator); var battleShip = new BattleShip(); var destroyer1 = new Destroyer(); var destroyer2 = new Destroyer(); grid.Ships.Add(battleShip); grid.Ships.Add(destroyer1); grid.Ships.Add(destroyer2); grid.PositionShipsOnGrid(); return(grid); }