protected override void Update() { if (Randomizer.Between(0, 10) % 3 == 0) { if (Randomizer.Between(0, 2) % 2 == 0) { TurnRight(); if (Randomizer.Between(0, 20) == 3) { TurnRight(); } } else { TurnLeft(); if (Randomizer.Between(0, 20) == 3) { TurnLeft(); } } } else { Move(); } }
public Robot CreateRobot <T>() where T : Robot { var robot = RobotManager.CreateRobot <T>(); robot.Spawn(this); var x = _x == -1 ? (_x = Randomizer.Between(1, Width - 1)) : _x + 1; var y = _y == -1 ? (_y = Randomizer.Between(1, Height - 2)) : _y; Tiles[x, y] = new Tile(this, x, y, false); robot.CurrentTile = Tiles[x, y]; return(robot); }
protected override void Update() { Robot robot = null; var dirs = new[] { Direction.Up, Direction.Right, Direction.Down, Direction.Left }; for (var i = 0; i < 4; i++) { for (var j = 0; j < 4; j++) { var tile = dirs[i] == dirs[j] ? InspectTile(dirs[i]) : InspectTile(dirs[i] | dirs[j]); if (tile?.Robot != null && tile?.Robot != this) { robot = tile.Value.Robot; break; } } if (robot != null) { break; } } if (robot != null && robot.IsAlive) { Attack(robot); } else { while (!CanMove) { if (Randomizer.Between(0, 2) % 2 == 0) { TurnRight(); } else { TurnLeft(); } } Move(); } }
internal void SpawnItems() { int x, y; do { x = Randomizer.Between(0, Width - 1); y = Randomizer.Between(0, Height - 1); if (!Tiles[x, y].IsObstacle) { var weapon = new Weapon("Test Gun", WeaponType.Handgun, 10, 12); ItemManager.AddItem(weapon); Tiles[x, y] = Tiles[x, y].UpdateItem(weapon); break; } }while (Tiles[x, y].IsObstacle); }
public World(Game game, int width, int height) { this.game = game; Width = width; Height = height; RobotManager = new RobotManager(game); ItemManager = new ItemManager(game); Tiles = new Tile[width + 1, height + 1]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var isObstacle = Randomizer.Between(0, 10) % 4 == 0; Tiles[x, y] = new Tile(this, x, y, isObstacle); } } }
private void CreatePlayer() { string name; bool validName; do { Console.Write("Enter your name: "); name = Console.ReadLine(); validName = Player.ValidateName(name); if (!validName) { Console.WriteLine("Name too short! Minimum of 3 characters."); } } while (!validName); int attack = Randomizer.Between(5, 10); player = new Player(name, 25, attack); creatures.Add(player); }
protected int Attack(Robot target) { if (target == this) { return(0); } if (attackCooldown > 0) { return(0); } // Default values when no weapon is held. var damageRate = 7; var cooldown = 50; if (Inventory?.CurrentWeapon != null) { damageRate = Inventory.CurrentWeapon.DamageRate; cooldown = cooldown - Inventory.CurrentWeapon.SpeedRate; } if (!IsInRange(target)) { return(0); } var damage = Randomizer.Between(0, damageRate); lock (healthObject) { target.Health -= damage; } attackCooldown = cooldown; return(damage); }
internal Damage GenerateDamage(AbilityPowerTypes powerType, Randomizer randomizer) { var multipleTargetsFactor = 1.0f; switch (DamageType) { case DamageTypes.Cleave: multipleTargetsFactor = 0.5f; break; case DamageTypes.PointBlankArea: multipleTargetsFactor = 0.3f; break; } var damage = new Damage(); damage.Value = randomizer.Between(1f, 5f) * multipleTargetsFactor; switch (powerType) { case AbilityPowerTypes.AttackPower: damage.AttackPowerScale = randomizer.Between(0.5f, 2f) * multipleTargetsFactor; break; case AbilityPowerTypes.SpellPower: damage.SpellPowerScale = randomizer.Between(0.5f, 2f) * multipleTargetsFactor; break; case AbilityPowerTypes.Hybrid: damage.AttackPowerScale = randomizer.Between(0.25f, 1f) * multipleTargetsFactor; damage.SpellPowerScale = randomizer.Between(0.25f, 1f) * multipleTargetsFactor; break; } return damage; }