static void MonsterIntro(Player player1, int howManyMonsters) { #region DeclareClassVariables Render array = new Render(); Program code = new Program(); MonsterFactory code1 = new MonsterFactory(); List <Monster> monsters = new List <Monster>(); #endregion while (howManyMonsters > 0) { Monster monster = code1.CreateRandomMonster(); if (monster.Name == "Grauldog, champion of the Trolls") { code.isFightBossFight = true; } monsters.Add(monster); howManyMonsters -= 1; } for (int i = 0; i < monsters.Count; i++) { array.RenderMonsterStats(monsters[i]); } Thread.Sleep(1000); code.Fight(monsters, player1); }
public static Room WithRandomMonster(this Room room) { Position randomAvailablePosition = room.GetRandomAvailablePosition(); var monster = MonsterFactory.CreateRandomMonster(room, randomAvailablePosition); room.Monsters.Add(monster); return(room); }
void Start() { monsterProps = MonsterFactory.CreateRandomMonster(); print(monsterProps); monsterChanceEscape = monsterProps.Power * monsterProps.Level; monsterWarmRate = .0001f * monsterProps.Power; catching = true; StartCoroutine(CheckEscape()); }
public void SpawnMonsters(int monsterCount) { Enumerable.Range(0, monsterCount).ToList().ForEach(_ => { Position randomPosition; do { randomPosition = _dice.RollPosition(Size.Width, Size.Height); } while (!MonsterCanSpawnOn(randomPosition)); Monsters.Add(MonsterFactory.CreateRandomMonster(randomPosition)); }); }
/// <summary> /// Generates new game with given parameters. If aiCount+1 (1 for human player) is greater than width*heght, exception is thrown. /// </summary> /// <param name="width">Width of the map.</param> /// <param name="height">Height of the map.</param> /// <param name="mapSeed">Map seed.</param> /// <param name="aiCount">Number of AIs (simple AI is used).</param> /// <param name="monsterDensity">Density of monsters 0..1</param> /// <param name="itemDensity">Density of items 0..1</param> /// <param name="humanPlayerName">Name of the human player.</param> /// <returns>Generated game instance.</returns> public static Game GenerateGame(int width, int height, int mapSeed, int aiCount, double monsterDensity, double itemDensity, string humanPlayerName) { // check if (aiCount + 1 > width * height) { throw new Exception($"Počet protihráčů {aiCount} je na plochu {width}x{height} moc velký!"); } Map.Map gameMap = MapGeneratorFactory.CreateSimpleMapGenerator().GenerateMap(width, height, mapSeed); Game game = new Game() { GameMap = gameMap }; Random r = new Random(); // sets of occupied position for creatures and items, '{x}:{y}' HashSet <String> creatureOccupiedPositions = new HashSet <string>(); HashSet <string> itemsOccupiedPositions = new HashSet <string>(); // place human player int x = r.Next(width); int y = r.Next(height); AbstractPlayer player = new HumanPlayer(humanPlayerName, gameMap.Grid[x, y]); game.AddHumanPlayer(player); creatureOccupiedPositions.Add($"{x}:{y}"); // place AI players int pCount = 1; AddObjectsToGame(width, height, aiCount, 20, (ox, oy) => { if (!creatureOccupiedPositions.Contains($"{ox}:{oy}")) { game.AddAIPlayer(AIPlayerFactory.CreateSimpleAIPLayer($"Simple AI Player {pCount}", gameMap.Grid[ox, oy])); creatureOccupiedPositions.Add(($"{ox}:{oy}")); pCount++; return(true); } else { return(false); } }); // monster count from density: // density is expected to be in range 0..1 and will be mapped to the count of remaining free map blocks // this number is then lowered to 2/3 and this result is used as a base // then monsterCount = base + random.next(base/3) double monsterCountBase = 2 * (monsterDensity * (width * height - aiCount)) / 3; int monsterCount = (int)(monsterCountBase + r.NextDouble() * (monsterCountBase / 3)); // place monsters AddObjectsToGame(width, height, monsterCount, 20, (ox, oy) => { if (!creatureOccupiedPositions.Contains($"{ox}:{oy}")) { game.AddMonster(MonsterFactory.CreateRandomMonster(gameMap.Grid[ox, oy])); creatureOccupiedPositions.Add(($"{ox}:{oy}")); return(true); } else { return(false); } }); // item count is calculated the same way as monster count is double itemCountBase = 2 * (itemDensity * (width * height - aiCount)) / 3; int itemCount = (int)(itemCountBase + r.NextDouble() * (itemCountBase / 3)); // place items AddObjectsToGame(width, height, itemCount, 20, (ox, oy) => { if (!itemsOccupiedPositions.Contains($"{ox}:{oy}")) { game.AddItem(ItemFactory.CreateRandomItem(gameMap.Grid[ox, oy])); itemsOccupiedPositions.Add(($"{ox}:{oy}")); return(true); } else { return(false); } }); return(game); }
/// <summary> /// Places SelectedToolboxItem to the map. If no item is selected, nothing happnes. /// /// If the map block is occupied, coordinates are out of range, map is null or item type is unknown, exception is raised. /// /// </summary> /// <param name="mapX">X coordinate of map block to place this item.</param> /// <param name="mapY">Y coordinate of map block to place this item.</param> public void PlaceSelectedToolboxItem(int mapX, int mapY) { EditorToolboxItem item = SelectedToolboxItem; // no item selected => do nothing if (item == null) { return; } if (GameMap == null) { throw new Exception("Není herní mapa!"); } else if (mapX < 0 || mapX >= GameMap.Width || mapY < 0 || mapY >= GameMap.Height) { throw new Exception($"[{mapX},{mapY}] není v rozsahu mapy!"); } else if ((item.ItemType == EditorToolboxItemType.AI_PLAYER || item.ItemType == EditorToolboxItemType.MONSTER) && GameMap.Grid[mapX, mapY].Occupied) { throw new Exception($"Na pozici [{mapX},{mapY}] už je umístěn hráč, nebo monstrum!"); } else if ((item.ItemType == EditorToolboxItemType.ITEM || item.ItemType == EditorToolboxItemType.ARMOR || item.ItemType == EditorToolboxItemType.WEAPON) && GameMap.Grid[mapX, mapY].Item != null) { throw new Exception($"Na pozici [{mapX},{mapY}] už je umístěn předmět!"); } int uid = -1; switch (item.ItemType) { case EditorToolboxItemType.HUMAN_PLAYER: if (HumanPlayerPlaced) { throw new Exception("Na hrací plochu lze umístit pouze jednoho lidského hráče!"); } GameMap.Grid[mapX, mapY].Creature = new HumanPlayer("Human player", GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Creature.UniqueId; HumanPlayerPlaced = true; break; case EditorToolboxItemType.AI_PLAYER: GameMap.Grid[mapX, mapY].Creature = AIPlayerFactory.CreateSimpleAIPLayer("Simple AI Player", GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Creature.UniqueId; break; case EditorToolboxItemType.MONSTER: GameMap.Grid[mapX, mapY].Creature = MonsterFactory.CreateRandomMonster(GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Creature.UniqueId; break; case EditorToolboxItemType.ITEM: GameMap.Grid[mapX, mapY].Item = ItemFactory.CreateBasicItem(GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Item.UniqueId; break; case EditorToolboxItemType.ARMOR: GameMap.Grid[mapX, mapY].Item = ItemFactory.CreateLeatherArmor(GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Item.UniqueId; break; case EditorToolboxItemType.WEAPON: GameMap.Grid[mapX, mapY].Item = ItemFactory.CreateAxe(GameMap.Grid[mapX, mapY]); uid = GameMap.Grid[mapX, mapY].Item.UniqueId; break; default: throw new Exception($"Neznámý typ umisťovaného předmětu: {item.ItemType}!"); } EditorToolboxItem placedItem = item.Clone(); placedItem.UID = uid; PlacedItems.Add(placedItem); OnPropertyChanged("PlacedItems"); }
public static void Main() { var player = PlayerFactory.LoadPlayer(); var monster = MonsterFactory.CreateRandomMonster(); }
public void LootPhase(Player player1, List <Monster> monsters, int itemLevel) { #region DeclareLootPhaseVariables ItemFactory code = new ItemFactory(); Item newItem = code.CreateRandomItem(itemLevel); MonsterFactory code1 = new MonsterFactory(); Monster monster1; Program code2 = new Program(); int howManyMoreMonsters = GetRandom(1, 5); int playerAnswer = 0; #endregion int howMuchLoot = GetRandom(0, 3 + player1.level); while (howMuchLoot > 0) { //if (monsters.Contains(monsters.Where(c => c.Name == "Grauldog, champion of the Trolls").Single())) //{ // Console.WriteLine("Both Weapon Slots Full!"); // Grauldogs_Trusty_Club newWeaponForPlayer = new Grauldogs_Trusty_Club("Grauldog's Trusty Club", itemLevel); // Console.WriteLine("Do you want to replace a weapon with: " + newWeaponForPlayer + " level " + itemLevel + "?\n"); // Console.WriteLine("Your weapon(Slot 1): " + player1.EntityWeapon.name + " level " + player1.EntityWeapon.weaponlevel); // if (player1.PlayerWeapon2 != null) // { // Console.WriteLine("Your weapon(Slot 2): " + player1.PlayerWeapon2.name + " level " + player1.PlayerWeapon2.weaponlevel); // } // Console.WriteLine("1) Yes"); // Console.WriteLine("2) No"); // string playerInput = Console.ReadLine(); // try // { // playerAnswer = Int32.Parse(playerInput); // } // catch // { // LootPhase(player1, monsters, itemLevel); // } // if (playerAnswer == 1) // { // Console.WriteLine("Which Slot?"); // Console.WriteLine("1) Slot 1"); // Console.WriteLine("2) Slot 2"); // string playerInput1 = Console.ReadLine(); // try // { // playerAnswer = Int32.Parse(playerInput1); // } // catch // { // LootPhase(player1, monsters, itemLevel); // } // if (playerAnswer == 1) // { // player1.EntityWeapon = newWeaponForPlayer; // } // } // player1.XP += 50; //} if (newItem.itemType == "Weapon") { int weaponLevel = GetRandom(1, 5); Weapon newWeapon = code.CreateRandomWeapon(weaponLevel); if (player1.EntityWeapon == null) { player1.EntityWeapon = newWeapon; } else if (player1.PlayerWeapon2 == null) { player1.PlayerWeapon2 = newWeapon; } else { Console.WriteLine("Both Weapon Slots Full!"); } Console.WriteLine("Do you want to replace a weapon with: " + newWeapon.name + " level " + newWeapon.weaponlevel + "?\n"); Console.WriteLine("Your weapon(Slot 1): " + player1.EntityWeapon.name + " level " + player1.EntityWeapon.weaponlevel); if (player1.PlayerWeapon2 != null) { Console.WriteLine("Your weapon(Slot 2): " + player1.PlayerWeapon2.name + " level " + player1.PlayerWeapon2.weaponlevel); } Console.WriteLine("1) Yes"); Console.WriteLine("2) No"); string playerInput = Console.ReadLine(); try { playerAnswer = Int32.Parse(playerInput); } catch { monster1 = code1.CreateRandomMonster(); Console.WriteLine("next foe, " + monster1.Name + "!"); MonsterIntro(player1, howManyMoreMonsters); Fight(monsters, player1); } if (playerAnswer == 1) { Console.WriteLine("Which Slot?"); Console.WriteLine("1) Slot 1"); Console.WriteLine("2) Slot 2"); string playerInput1 = Console.ReadLine(); try { playerAnswer = Int32.Parse(playerInput1); } catch { LootPhase(player1, monsters, itemLevel); } if (playerAnswer == 1) { player1.EntityWeapon = newWeapon; } else { player1.PlayerWeapon2 = newWeapon; } } } else if (newItem.itemType == "Armor") { Armor newArmor = code.CreateRandomArmor(itemLevel); Console.WriteLine("Armor Slot is full, would you like to replace it with: " + newArmor.name + " Level " + newArmor.gearLevel + "?\n"); Console.WriteLine("Your Armor: " + player1.EntityArmor.name + " Level " + player1.EntityArmor.gearLevel); Console.WriteLine("1) Yes"); Console.WriteLine("2) No"); string playerInput = Console.ReadLine(); try { playerAnswer = Int32.Parse(playerInput); } catch { LootPhase(player1, monsters, itemLevel); } if (playerAnswer == 1) { player1.EntityArmor = newArmor; } if (playerAnswer == 2) { } } howMuchLoot -= 1; } monster1 = code1.CreateRandomMonster(); Console.WriteLine("next foe, " + monster1.Name + "!"); MonsterIntro(player1, howManyMoreMonsters); Fight(monsters, player1); }
public static void PlayerChooseGameMode() { Program code = new Program(); int playerAnswer = 0; Console.WriteLine("which mode?\n1) gameplay\n2) debugger\n3) Dictionary"); string playerInput = Console.ReadLine(); try { playerAnswer = Int32.Parse(playerInput); } catch { PlayerChooseGameMode(); } if (playerAnswer == 1) { Console.WriteLine("type a name for your Character"); string PlayerName = Console.ReadLine(); #region DeclarePlayerVariables player1 = new Player(PlayerName, 5, 5, "Y"); player1.Health += 40; player1.maxHealth += 40; player1.Strength += 2; player1.Dodge += 1; player1.Intellect += 1; player1.level = 0; #endregion PlayerChooseLoadout(); } if (playerAnswer == 2) { #region DeclareDebuggerVariables int howManyMonsters = GetRandom(2, 5); player1 = new Player("", 5, 5, "Y"); MonsterFactory code1 = new MonsterFactory(); List <Monster> monsters = new List <Monster>(); int playerHowFast = 0; #endregion while (howManyMonsters > 0) { Monster monster = code1.CreateRandomMonster(); if (howManyMonsters > 0) { monsters.Add(monster); howManyMonsters -= 1; } } Console.WriteLine("How fast?"); string playerInput2 = Console.ReadLine(); try { playerHowFast = Int32.Parse(playerInput2); } catch { } Thread.Sleep(playerHowFast); code.isDebuggerFight = true; code.DebuggerFight(monsters, playerHowFast); } if (playerAnswer == 3) { Dictionary.StartUp(); } }