public void OccupyPlatform() { shipGen = GameObject.FindGameObjectWithTag("GameController").GetComponent <ShipGenerator> (); ship = shipGen.GetFirstShipInList(); ship.myPlatform = this; ship.StartCoroutine("MoveTo"); }
private void OnTriggerStay2D(Collider2D collision) { if ((collision.CompareTag("Player")) && (Input.GetButtonDown("Interact"))) { ShipGenerator.Generate(collision.transform, backgroundPrefab, alienPrefab, holderPrefab, platformPrefab, blockPrefab, pointPrefab, sizeX, sizeY, incrementX, incrementY, threshold, enemySpawnRate, exitSpawnRate); } }
public static void StartGame(GameState providedGameState = default) { var effectiveGameState = providedGameState; if (effectiveGameState == default) { effectiveGameState = new GameState(); effectiveGameState.ConsumptionRates = consumptionRates; effectiveGameState.Ship = ShipGenerator.GenerateShip(ShipGenerator.ShipTypes[0]); //{ // ConsumptionRates = consumptionRates, // Ship = ShipGenerator.GenerateShip(ShipGenerator.ShipTypes[0]), // Options = new GameStateOptions() // { // AreAnimationsEnabled = true, // BackgroundVolume = 0.125f // } //}; effectiveGameState.Planets.AddRange(PlanetGenerator.GeneratePlanets(4)); effectiveGameState.CurrentScene = SceneNames.Far; } GameState = effectiveGameState; ChangeScene(effectiveGameState.CurrentScene); }
public Result <int> CreateGame(List <ShipDto> ships, string connectionId) { var enemyShips = new ShipGenerator().GenerateShips(); var model = new GameDto { ConnectionId = connectionId, UserArea = new AreaDto { Ships = ships }, ComputerArea = new AreaDto { Ships = enemyShips } }; try { var dbModel = _mapper.Map <GameDb>(model); _context.Games.Add(dbModel); _context.SaveChanges(); return(Result.Success(dbModel.Id)); } catch (DbUpdateException ex) { return(Result.Failure <int>(ex.Message)); } }
public void GenerateShip_WithSmallerPanelThanShip_ThrowsInvalidArgumentException() { ShipGenerator generator = new ShipGenerator(); var panelSize = 3; Action a = () => generator.GenerateShip(new ShipType("Battleship", "B", 5), panelSize); a.Should().Throw <ArgumentException>(); }
public void GenerateShipFields_ShipSize_ShouldCreateShipSizeFieldsCount() { PrepareSequenceForRandomShipsStartPoint(); _random.Setup(r => r.GetRandomNumber(NUMBER_OF_DIRECTIONS)).Returns(0); var shipSize = 4; var sut = new ShipGenerator(_random.Object); var result = sut.GenerateShipFields(shipSize); Assert.That(result, Has.Exactly(shipSize).Items); }
void Start() { transform.rotation = Quaternion.identity; gameManager = GameObject.FindGameObjectWithTag("GameController"); shipGen = gameManager.GetComponent <ShipGenerator> (); thisShipNumber = shipGen.nextShipNumber; Debug.Log("Ship №" + thisShipNumber + " has arrived"); int randomIndex = Random.Range(0, shipGen.spriteList.Count); this.GetComponentInChildren <SpriteRenderer> ().sprite = shipGen.spriteList[randomIndex]; isGoodShip = (Random.value > 0.5f); }
public void GenerateShip_WithNormalSizePanel_ReturnsValidShip() { ShipGenerator generator = new ShipGenerator(); var panelSize = 10; var ship = generator.GenerateShip(new ShipType("Battleship", "B", 5), panelSize); ship.HeadPoint.X.Should().BeLessThan(panelSize); ship.HeadPoint.Y.Should().BeLessThan(panelSize); ship.TailPoint.Y.Should().BeLessThan(panelSize); ship.TailPoint.Y.Should().BeLessThan(panelSize); }
public static IDrawBoard CreateDrawBoard(bool has_debug) { int board_size = 10; var gen = new ShipGenerator(board_size);//.EnableDebug(); return(new DrawBoard(new List <IDestroyer>() { new Ships(5, gen.GenerateShipCoordonates(5)), new Ships(4, gen.GenerateShipCoordonates(4)), new Ships(4, gen.GenerateShipCoordonates(4)) }, board_size)); }
public void GenerateShipFields_ForColumnDirection_ShouldAllFieldsHaveSameColumnNumber(int columnNumber, string expectedColumnNumberResult) { _random.SetupSequence(r => r.GetRandomNumber(BOARD_SIZE)) .Returns(columnNumber) .Returns(COMMON_ROW_NUMBER); _random.Setup(r => r.GetRandomNumber(NUMBER_OF_DIRECTIONS)).Returns((int)ShipDirection.Column); var shipSize = 3; var sut = new ShipGenerator(_random.Object); var result = sut.GenerateShipFields(shipSize); result.ForEach(f => Assert.That(f.Substring(1), Is.EqualTo(expectedColumnNumberResult))); }
public void GenerateShipFields_ForRowDirection_ShouldAllFieldsHaveSameRowLetter(int rowNumber, string expectedLetter) { _random.SetupSequence(r => r.GetRandomNumber(BOARD_SIZE)) .Returns(COMMON_COLUMN_NUMBER) .Returns(rowNumber); _random.Setup(r => r.GetRandomNumber(NUMBER_OF_DIRECTIONS)).Returns((int)ShipDirection.Row); var shipSize = 3; var sut = new ShipGenerator(_random.Object); var result = sut.GenerateShipFields(shipSize); result.ForEach(f => Assert.That(f.Substring(0, 1), Is.EqualTo(expectedLetter))); }
public void GenerateShipFields_ShouldReturnProperRowLetters(int rowNumber, string expectedLetter) { _random.SetupSequence(r => r.GetRandomNumber(BOARD_SIZE)) .Returns(COMMON_COLUMN_NUMBER) .Returns(rowNumber); _random.Setup(r => r.GetRandomNumber(NUMBER_OF_DIRECTIONS)).Returns(0); var shipSize = 1; var sut = new ShipGenerator(_random.Object); var result = sut.GenerateShipFields(shipSize); Assert.That(result.First().Substring(0, 1), Is.EqualTo(expectedLetter)); }
public void GenerateShipFields_ShouldReturnColumnNumberStaredFromOne(int columnNumber, string expectedColumnNumberResult) { _random.SetupSequence(r => r.GetRandomNumber(BOARD_SIZE)) .Returns(columnNumber) .Returns(COMMON_ROW_NUMBER); _random.Setup(r => r.GetRandomNumber(NUMBER_OF_DIRECTIONS)).Returns(0); var shipSize = 1; var sut = new ShipGenerator(_random.Object); var result = sut.GenerateShipFields(shipSize); Assert.That(result.First().Substring(1), Is.EqualTo(expectedColumnNumberResult)); }
// [Fact] public void BenchMarkShipGenerator() { File.Delete("generate.txt"); var stopWatch = new Stopwatch(); for (int i = 0; i < 10; i++) { stopWatch.Start(); var ships = new ShipGenerator().Generate().ToList(); stopWatch.Stop(); File.AppendAllText("generate.txt", $"\n{i} \t {stopWatch.ElapsedMilliseconds} ms"); } }
public static void InitGame() { if (Application.platform == RuntimePlatform.WebGLPlayer || Application.platform == RuntimePlatform.Android) { IsFileAccessPossible = false; } else { IsFileAccessPossible = true; } LoadPlayerOptions(); LoadConsumptionRates(); LoadSavegames(); PlanetGenerator.LoadPlanetTypes(); ShipGenerator.LoadShipTypes(); }
private void Awake() { _current = this; parts = new Dictionary<ShipPartType, List<GameObject>>(); parts.Add(ShipPartType.Front, LoadParts("Front")); parts.Add(ShipPartType.Centre, LoadParts("Centre")); parts.Add(ShipPartType.Back, LoadParts("Back")); if (GenerateOnAwake) Generate(); }
public void AddShipGenerator(string name, ShipGenerator gen) { gen.Name = name; dctShipGenerators.Add(name, gen); }
public LodiiisBot(ShipGenerator sg, HeatMapGenerator hmg, bool useOptimalization) { _sg = sg; _hmg = hmg; _opt = useOptimalization; }
public void Awake() { setter = this; ShipGenerator.SetExitPrefab(exitPrefab); Generate(); }
public void WriteFile(string jsonFile = "") //Objective objective) { // List<InventoryData> objList = new List<InventoryData>(); // foreach(QI_ItemData entry in itemDatabase.Items) // { // if (inventory.GetStock(entry.Name) > 0) { // InventoryData data = new InventoryData(entry.Name, inventory.GetStock(entry.Name)); // objList.Add(data); // } // } if (jsonFile == "") { jsonFile = jsonFileName; } //Debug.Log("Saving -> " + jsonFile); //if (objList == null) objList = masterObjectiveList; string path = Application.persistentDataPath + "/" + jsonFile; //Write some text to the test.txt file StreamWriter writer = new StreamWriter(path, false); writer.Close(); writer = new StreamWriter(path, true); Engines engine = characterData.shipEngine; //prefabManager.currentPrefab.GetComponent<ShipControls>().engine; Weapons shipWeapon = characterData.shipWeapon; ShipGenerator shipGenerator = characterData.shipGenerator; //prefabManager.currentPrefab.GetComponent<ShipControls>().weapon; Weapons groundWeapon = characterData.groundWeapon; //null; if (gameManager.playerLocation == locationType.Ground) { groundWeapon = gameManager.prefabManager.currentPrefab.GetComponent <SimpleTankController>().groundWeapon; } if (engine != null) { characterData.shipEngineName = engine.name; } if (shipWeapon != null) { characterData.shipWeaponName = shipWeapon.name; } if (shipGenerator != null) { //characterData.currentEnergy = shipGenerator.currentEnergy; characterData.shipGeneratorName = shipGenerator.name; } if (gameManager.playerLocation == locationType.Ground) { characterData.groundWeaponName = groundWeapon.name; } writer.WriteLine(CreateJSON(characterData)); // foreach (NewCharacterData obj in objList) { // //WriteFile(obj); //Debug.Log("Write -> " + CreateJSON(characterData)); // writer.WriteLine(CreateJSON(obj)); // } writer.Close(); }
public void AddShipGenerator(string name, ShipGenerator gen) { gen.Name = name; dctShipGenerators.Add(name, gen); }
protected MonteCarloPrediciton() { _shipGenerator = new ShipGenerator(); }
public GameBoardBase CreateGameBoard() { var ships = new ShipGenerator().Generate().ToList(); return(new GameBoardBase(new Player("test", PlayerType.Computer)).WithShips(ships)); }
void OnGUI() { if (!gameManager.gameStarted) { return; } GUILayout.BeginArea(uiManager.inventoryUIRect); GUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { inventoryManager.WriteFile(""); } if (GUILayout.Button("Load")) { inventoryManager.ReadFile(""); } GUILayout.EndHorizontal(); scrollPosition = GUILayout.BeginScrollView( scrollPosition, GUILayout.Width(MaxScrollWidth), GUILayout.Height(MaxScrollHeight)); foreach (QI_ItemData entry in inventoryManager.itemDatabase.Items) { // do something with entry.Value or entry.Key if (inventoryManager.inventory.GetStock(entry.Name) > 0) { GUILayout.BeginHorizontal(); GUILayout.Box(string.Format("{0}", inventoryManager.inventory.GetStock(entry.Name)), GUILayout.Width(35)); GUILayout.Box(entry.Name, GUILayout.Width(MaxItemWidth)); QI_ItemData item = inventoryManager.itemDatabase.GetItem(entry.Name); if (item.ItemPrefab != null) { Projectile projectile = item.ItemPrefab.gameObject.GetComponent <Projectile>(); Weapons weapon = item.ItemPrefab.gameObject.GetComponent <Weapons>(); Engines engine = item.ItemPrefab.gameObject.GetComponent <Engines>(); ShipGenerator generator = item.ItemPrefab.gameObject.GetComponent <ShipGenerator>(); //ShipControls shipControls = prefabManager.currentPrefab.GetComponent<ShipControls>(); //SimpleTankController tankController = prefabManager.currentPrefab.GetComponent<SimpleTankController>(); if (projectile != null) { GUILayout.Box("Ammo"); } if (generator != null) { GUILayout.Box("Ship Generator", GUILayout.Width(MaxTypeWidth)); if (characterManager.characterData.shipGenerator != generator) { if (GUILayout.Button("Equip", GUILayout.Width(EquipButtonWidth))) { characterManager.characterData.shipGenerator = item.ItemPrefab.gameObject.GetComponent <ShipGenerator>(); inventoryManager.Drop(entry.Name); } } } if (weapon != null) { if (weapon.weaponPlacement == WeaponPlacement.Ship) { GUILayout.Box("Ship Weapon", GUILayout.Width(MaxTypeWidth)); if (characterManager.characterData.shipWeapon != weapon) { if (GUILayout.Button("Equip", GUILayout.Width(EquipButtonWidth))) { characterManager.characterData.shipWeapon = item.ItemPrefab.gameObject.GetComponent <Weapons>(); inventoryManager.Drop(entry.Name); } } } if (weapon.weaponPlacement == WeaponPlacement.Person) { GUILayout.Box("Personal Weapon", GUILayout.Width(MaxTypeWidth)); if (characterManager.characterData.groundWeapon != weapon) { if (GUILayout.Button("Equip", GUILayout.Width(EquipButtonWidth))) { characterManager.characterData.groundWeapon = item.ItemPrefab.gameObject.GetComponent <Weapons>(); inventoryManager.Drop(entry.Name); } } } } if (engine != null) { GUILayout.Box("Engine", GUILayout.Width(MaxTypeWidth)); if (characterManager.characterData.shipEngine != engine) { if (GUILayout.Button("Equip", GUILayout.Width(EquipButtonWidth))) { characterManager.characterData.shipEngine = item.ItemPrefab.gameObject.GetComponent <Engines>(); inventoryManager.Drop(entry.Name); } } } //GUILayout.Box(item.ItemPrefab.gameObject.name, GUILayout.Width(MaxItemWidth)); } if (inventoryManager.inventory.GetStock(entry.Name) >= 1) { if (GUILayout.Button("Drop", GUILayout.Width(DropButtonWidth))) { inventoryManager.Drop(entry.Name, 1); } } if (inventoryManager.inventory.GetStock(entry.Name) > 1) { if (GUILayout.Button("Drop All", GUILayout.Width(DropAllButtonWidth))) { inventoryManager.Drop(entry.Name, inventoryManager.inventory.GetStock(entry.Name)); } } else { GUILayout.Box("Drop All", GUILayout.Width(DropAllButtonWidth)); } GUILayout.EndHorizontal(); } // End the scrollview we began above. } GUILayout.EndScrollView(); //GUILayout.Box(entry.Key); //GUILayout.Box(string.Format("{0}",inventoryManager.inventory.GetStock("ShipEngine1"))); //GUILayout.Box(string.Format("{0}",inventoryManager.inventory.GetStock("Health Potion"))); //if (GUILayout.Button("+Potion")) inventoryManager.PickupPotion("nothing"); //if (GUILayout.Button("=Potion")) inventoryManager.DropPotion("nothing"); GUILayout.EndArea(); }
public void Generate() { ShipGenerator.Generate(player, backgroundPrefab, alienPrefab, holderPrefab, platformPrefab, blockPrefab, pointPrefab, sizeX, sizeY, incrementX, incrementY, threshold); }