//ENEMY heals ENEMY public void e_resolve_heal(Enemy unit, EnemyMap eMap) { reset_targetLists(); EnemyMove move = unit.nextMove; //gather targets switch (move.get_highlightType()) { case 0: //standard rectangular. for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++) { for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++) { if (eMap.search_enemy(c, r) != null) { if (!e_targets.Contains(eMap.search_enemy(c, r))) { e_targets.Add(eMap.search_enemy(c, r)); } } else { eMap.tilegrid[r, c].GetComponent <EnemyTile>().show_heal_text("miss"); } } } break; case 1: //self e_targets.Add(unit); break; } //now, heal the targets foreach (Enemy target in e_targets) { //calc heal: bool ignoreMax = false; int heal = 0; if (move.get_hasCustomHeal()) { //Debug.Log("custom heal going"); StartCoroutine(show_battleNumbers(target.stats.get_floatingHp().gameObject, 2.25f)); heal = move.calc_custom_heal(unit); ignoreMax = move.get_ignoreHealMax(); } else { StartCoroutine(show_battleNumbers(target.stats.get_floatingHp().gameObject, 1)); heal = e_calc_heal(unit, target); } //display heal number if (heal != -1) { e_do_heal(target, heal, ignoreMax); eMap.tilegrid[target.get_x(), target.get_y()].GetComponent <EnemyTile>().show_heal_text(heal.ToString()); } } }
public bool e_check_targets(EnemyMap eMap, Enemy unit) { //returns false if there are no targets left in the area. EnemyMove move = unit.nextMove; //index: //0: rectangular //1: 1x1 self //2: 3x3 centerless cross //3: 3x3 cross switch (move.get_highlightType()) { case 0: //standard rectangular for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++) { for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++) { if (eMap.search_enemy(c, r) != null) { return(true); } } } break; case 1: return(true); case 2: //3x3 centerless cross. if (eMap.search_enemy(unit.nextX - 1, unit.nextY) != null) { return(true); } if (eMap.search_enemy(unit.nextX + 1, unit.nextY) != null) { return(true); } if (eMap.search_enemy(unit.nextX, unit.nextY - 1) != null) { return(true); } if (eMap.search_enemy(unit.nextX, unit.nextY + 1) != null) { return(true); } break; } return(false); }
public void e_translate(Enemy unit, EnemyMap eMap, int displaceX, int displaceY) { //moves a playerunit to a new location. displaceX,Y are how far the unit is move in those directions. eMap.remove_enemy(unit); //pMap.restore_old_tile(unit.get_x(), unit.get_y()); unit.set_x(Math.Max(Math.Min(unit.get_x() + displaceX, 4), 0)); //must be between 0 and 4, inclusive unit.set_y(Math.Max(Math.Min(unit.get_y() + displaceY, 3), 0)); //must be between 0 and 3, inclusive eMap.place_enemy(unit); //pMap.select_move_highlight(unit.get_x(), unit.get_y()); //<--highlights new tile correctly. unit.status.trigger_move(unit); }
public Turn Iteration(LevelView level, IMessageReporter messageReporter, out bool isAttack) { isAttack = false; var monsterMap = new EnemyMap(level, 1); var trapMap = new TrapMap(level); var travelMap = Map.Sum(trapMap, WallMap); var pathMap = Map.Sum(monsterMap, travelMap); List <Location> path = null; if (level.Player.Health < 50 && level.HealthPacks.Any()) { path = pathMap.FindPath(level.Player.Location, level.HealthPacks.OrderBy(h => h.Location.Distance(level.Player.Location)).First().Location); messageReporter.ReportMessage("Healing"); } else if (level.Monsters.Any(m => m.Location.IsInRange(level.Player.Location, 1))) { messageReporter.ReportMessage("Attack"); isAttack = false; return(Turn.Attack(level.Monsters.First(m => m.Location.IsInRange(level.Player.Location, 1)).Location - level.Player.Location)); } else if (level.Monsters.Any()) { int i = 0; path = travelMap.FindPath(level.Player.Location, level .Monsters.OrderBy(h => h.Location.Distance(level.Player.Location)).First().Location); if (i > 10) { return(Turn.None); } messageReporter.ReportMessage("Far attack"); } else if (level.Player.Health < 100 && level.HealthPacks.Any()) { messageReporter.ReportMessage("100 Healing"); path = pathMap.FindPath(level.Player.Location, level.HealthPacks.OrderBy(h => h.Location.Distance(level.Player.Location)).First().Location); } else if (Math.Max(BestItem(level).AttackBonus, BestItem(level).DefenceBonus) > Math.Max(level.Player.TotalAttack - level.Player.Attack, level.Player.TotalDefence - level.Player.Defence)) { path = pathMap.FindPath(level.Player.Location, BestItem(level).Location); } else { messageReporter.ReportMessage("Leave"); var leaveMap = Map.Sum(travelMap, new BadObjectMap(level, (view, location) => level.Items.Any(i => i.Location.Equals(location)), view => level.Items.Select(i => i.Location), 1)); path = leaveMap.FindPath(level.Player.Location, Exit); } if (path != null) { return(Turn.Step(path[1] - path[0])); } return(Turn.None); }
public Enviroment(LevelView level, int enemyRadius = 4, int trapRadius = 1, WallMap wallMap = null, int wallRadius = 4) { if (wallMap == null) { wallMap = new WallMap(level, wallRadius); } WallMap = wallMap; TrapMap = new TrapMap(level, trapRadius); EnemyMap = new EnemyMap(level, enemyRadius); Exit = level.Field.GetCellsOfType(CellType.Exit).First(); Start = level.Field.GetCellsOfType(CellType.PlayerStart).First(); }
public void ResetGame() { if (Finder.Score > Finder.Highscore) { Finder.Highscore = Finder.Score; } Finder.Score = 0; Finder.TimeInMillisecondsBeforeEnemyMoves = Constants.World.STARTING_MILLISECOND_DIFFERENCE_BEFORE_ENEMY_MOVES; Updatable.Updatables.Clear(); Actors.Drawable.Drawables.Clear(); Enemy.Enemies.Clear(); EnemyMap.Reset(); Finder.Player = new Player(); }
/*to add: * - prep cancelling * - map dodging */ public void checkUp_tick(PlayerMap pMap, EnemyMap eMap, BattleBrain brain) { //checks up on the unit each tick. /*looking for: * - moves that will hit no one -> enter recovery. * - if self is about to be hit and own nextMove has a low weight -> if a sidestep is possible -> enter prep to dodge. */ if (state == unitState.RECOVERING) { return; } //AI TIER 1 - cancel prep if (aiTier < 1) { return; } if (nextMove.get_iff() == true) { if (brain.f_check_targets(pMap, this) == false) { //our move would affect no one, so cancel it and enter recovery. cancel_move(); } } else { if (brain.e_check_targets(eMap, this) == false) { //our move would affect no one, so cancel it and enter recovery. cancel_move(); } } //AI TIER 2 // -sidestep/map dodges //if (aiTier < 2) return; //AI TIER 3 // -? //if (aiTier < 3) return; }
EnemyMove pick_move(EnemyMap eMap, PlayerMap pMap, PlayerUnit[] pl, Enemy[] el) { //pick move section int chance = UnityEngine.Random.Range(1, 101); //high weight means move is more likely to be used EnemyMove[] moveList; int chosen = 0; if (y < 2) //if we're in front { moveList = frontList; } else //if we're in back { moveList = backList; } //cycle through moveList until we find a suitable move. //requirements for a move to be eligible // -move's weight <= generated weight // -move must pass clearance for (int i = 0; i < moveList.Length; i++) { //move is chosen iff: // -stamina and weighting allows // -clearance allows // -move's unique check_conditions() function also allows if ((moveList[i].get_weight() + stamina) > chance && moveList[i].check_clearance(x, y, eMap) && moveList[i].check_conditions(this, pMap, eMap, pl, el)) { chosen = i; break; } } //movelists need to be designed so that the unit can always choose a move, no matter the circumstances drain_stamina(moveList[chosen].get_stamina_drain()); //drain stamina right now //return move return(moveList[chosen]); }
//AI public void e_choose_move(PlayerMap pMap, EnemyMap eMap, PlayerUnit[] pl, Enemy[] el) { //METHOD // -pick move using weighting system. // -choose target/location of target using move's prioritization. // -log move nextMove = pick_move(eMap, pMap, pl, el); if (nextMove.get_isHeal()) { //move is a heal, so pick target on enemymap pick_friendly_target(nextMove.get_targeting(), eMap, el, nextMove.get_xsize(), nextMove.get_ysize()); //finds coordinates of tile through pMap's tilegrid object. } else { //move is an attack, so pick target on playermap pick_hostile_target(nextMove.get_targeting(), pMap, pl, nextMove.get_xsize(), nextMove.get_ysize()); //finds coordinates of tile through pMap's tilegrid object. } enter_prepare(); //set up delay and stuff. }
internal void Update() { if (DateTime.Now.Millisecond - time.Millisecond > Constants.World.NUMBER_OF_MILLISECONDS_BEFORE_SPEED_CHANGE) { if (Finder.TimeInMillisecondsBeforeEnemyMoves > 1) { Finder.TimeInMillisecondsBeforeEnemyMoves--; } } if (EnemyMap.AllEnemiesAreDead()) { SpawnEnemies(); Thread.Sleep(100); } Finder.CollisionDetecter.DetectCollision(); for (int i = 0; i < Updatable.Updatables.Count; i++) { Updatable.Updatables[i].Update(); } }
/// <summary>Preforms a turn based on a string. Used for LAN games</summary> /// <param name="Text">The specified string.</param> public override void DoTextTurn(string Text) { string[] inArray = Text.Split(IndexDelimiter.ToCharArray()); EnemyMap.ETargetLocation[0] = int.Parse(inArray[0]); EnemyMap.ETargetLocation[1] = int.Parse(inArray[1]); FriendlyMap.FTargetLocation[0] = int.Parse(inArray[2]); FriendlyMap.FTargetLocation[1] = int.Parse(inArray[3]); SelectedOption = int.Parse(inArray[4]); UsingSelectedAttack = bool.Parse(inArray[5]); UsingSelectedAA = bool.Parse(inArray[6]); for (int i = 0; i < SelectedIndex[SelectedOption].Length; i++) SelectedIndex[SelectedOption][i] = int.Parse(inArray[7 + i]); UpdateMapData(); switch (SelectedOption) { case 0: EnemyMap.AdvancedFire(false, false, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; case 1: EnemyMap.AdvancedFire(true, false, EnemyMap.SelectedPlane.Attacks, SelectedIndex[SelectedOption][2]); break; case 2: FriendlyMap.SelectedPlane.Location = new int[] { EnemyMap.ETargetLocation[0], EnemyMap.ETargetLocation[1] }; EnemyMap.EPlanes.Add(FriendlyMap.SelectedPlane); FriendlyMap.FPlanes.Remove(FriendlyMap.SelectedPlane); break; case 3: EnemyMap.SelectedPlane.Location = new int[] { FriendlyMap.FTargetLocation[0], FriendlyMap.FTargetLocation[1] }; EnemyMap.EPlanes.Remove(EnemyMap.SelectedPlane); FriendlyMap.FPlanes.Add(EnemyMap.SelectedPlane); break; case 4: FriendlyMap.AdvancedFire(false, true, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; } }
//function must pass for enemy to select move public virtual bool check_conditions(Enemy self, PlayerMap pMap, EnemyMap eMap, PlayerUnit[] pl, Enemy[] el) { return(true); }
//PLAYER attacks ENEMY public void f_resolve_attack(PlayerUnit unit, EnemyMap eMap) { //method: //first assemble targets (keeping in mind cases) //then deal damage reset_targetLists(); PlayerMove move = unit.nextMove; //gather targets switch (move.get_highlightType()) { case 0: //standard rectangular. for (int c = unit.nextX; c < (unit.nextX + move.get_ysize()); c++) { for (int r = unit.nextY; r < (unit.nextY + move.get_xsize()); r++) { if (eMap.search_enemy(c, r) != null) { if (!e_targets.Contains(eMap.search_enemy(c, r))) { e_targets.Add(eMap.search_enemy(c, r)); } } else { eMap.tilegrid[r, c].GetComponent <EnemyTile>().show_damage_text("miss"); } } } break; case 2: //3x3 centerless cross. if (eMap.search_enemy(unit.nextX - 1, unit.nextY) != null) { if (!e_targets.Contains(eMap.search_enemy(unit.nextX - 1, unit.nextY))) { e_targets.Add(eMap.search_enemy(unit.nextX - 1, unit.nextY)); } } else { eMap.tilegrid[unit.nextY, unit.nextX - 1].GetComponent <EnemyTile>().show_damage_text("miss"); } if (eMap.search_enemy(unit.nextX + 1, unit.nextY) != null) { if (!e_targets.Contains(eMap.search_enemy(unit.nextX + 1, unit.nextY))) { e_targets.Add(eMap.search_enemy(unit.nextX + 1, unit.nextY)); } } else { eMap.tilegrid[unit.nextY, unit.nextX + 1].GetComponent <EnemyTile>().show_damage_text("miss"); } if (eMap.search_enemy(unit.nextX, unit.nextY - 1) != null) { if (!e_targets.Contains(eMap.search_enemy(unit.nextX, unit.nextY - 1))) { e_targets.Add(eMap.search_enemy(unit.nextX, unit.nextY - 1)); } } else { eMap.tilegrid[unit.nextY - 1, unit.nextX].GetComponent <EnemyTile>().show_damage_text("miss"); } if (eMap.search_enemy(unit.nextX, unit.nextY + 1) != null) { if (!e_targets.Contains(eMap.search_enemy(unit.nextX, unit.nextY + 1))) { e_targets.Add(eMap.search_enemy(unit.nextX, unit.nextY + 1)); } } else { eMap.tilegrid[unit.nextY + 1, unit.nextX].GetComponent <EnemyTile>().show_damage_text("miss"); } break; } //now, damage the targets if (e_targets.Count > 0) { all_ooa = true; } int runs = e_targets.Count; for (int i = 0; i < runs; i++) { int damage = f_calc_damage(unit, e_targets[0]); if (move.get_appliesStatus()) { StartCoroutine(show_battleNumbers(e_targets[0].stats.get_floatingHp().gameObject, 2.25f)); } else { StartCoroutine(show_battleNumbers(e_targets[0].stats.get_floatingHp().gameObject, 1)); } if (damage == -1) { eMap.tilegrid[e_targets[0].get_x(), e_targets[0].get_y()].GetComponent <EnemyTile>().show_damage_text("dodge"); } else if (damage > 0) { f_do_damage(e_targets[0], damage); eMap.tilegrid[e_targets[0].get_x(), e_targets[0].get_y()].GetComponent <EnemyTile>().show_damage_text(damage.ToString()); //check if enemy was killed if (e_targets[0].ooa != true) { all_ooa = false; } else { cLog.remove_enemy(e_targets[0]); e_targets.RemoveAt(0); } } } }
public void Update(LevelView level, int enemyRadius = 4, int trapRadius = 1) { TrapMap = new TrapMap(level, trapRadius); EnemyMap = new EnemyMap(level, enemyRadius); FillAdditionMaps(level); }
//check clearance public bool check_clearance(int unit_x, int unit_y, EnemyMap eMap) { //called once in show_moves: if returns false, then the move is not interactable //called again in exert(), if the space is occupied, then the move fails. //MOVEMENT CHECK if (clearType == 0) { return(true); } if ((unit_x + clearX >= 0) && (unit_x + clearX < 5) && (unit_y + clearY >= 0) && (unit_y + clearY < 4)) { //hop: needs only end tile clear if (clearType == 1 && eMap.search_enemy(unit_y + clearY, unit_x + clearX) == null) //works as intended. tested, good to go. { return(true); } else //full path: needs every time in path to be clear { //NOTE: //units ALWAYS move vertical first, followed by horizontal. if (clearType == 2) { //VERTICAL PORTION if (clearY > 0) //if we're moving backwards { for (int i = unit_y + 1; i <= unit_y + clearY; i++) //vertical part { if (eMap.search_enemy(i, unit_x) != null) { return(false); } } } else { if (clearY < 0) //if we're moving forwards { for (int i = unit_y - 1; i >= unit_y + clearY; i--) //vertical part { if (eMap.search_enemy(i, unit_x) != null) { return(false); } } } } //HORIZONTAL PORTION if (clearX > 0) //we're moving to the right { for (int i = unit_x + 1; i <= unit_x + clearX; i++) { if (eMap.search_enemy(unit_y + clearY, i) != null) { return(false); } } } else { if (clearX < 0) //we're moving to the left { for (int i = unit_x - 1; i >= unit_x + clearX; i--) { if (eMap.search_enemy(unit_y + clearY, i) != null) { return(false); } } } } return(true); } } } return(false); }
public void LoadMapData() { PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); if (File.Exists(mapFileName)) { string jsonSave = File.ReadAllText(mapFileName); MapData loadedMapData = JsonUtility.FromJson <MapData>(jsonSave); player.transform.position = loadedMapData.playerPos; playerCont.actionPoints = loadedMapData.playerAP; playerCont.maxHealth = loadedMapData.playerMaxHealth; playerCont.maxActionPoints = loadedMapData.playerMaxAP; playerCont.actionPoints = loadedMapData.playerCurrAP; Debug.Log(loadedMapData.playerCurrAP); playerCont.visibilityMultiplier = loadedMapData.playerVisibility; playerCont.isRepelAvailable = loadedMapData.isRepelAvailable; playerCont.isRevealAvailable = loadedMapData.isRevealAvailable; playerCont.isConvertAvailable = loadedMapData.isConvertAvailable; TurnController._instance.speedChangeTgl.isOn = loadedMapData.isFastForward; TurnController._instance.ChangeSpeed(loadedMapData.isFastForward); OverlayController._instance.areHotkeysDisplayed = loadedMapData.areHotkeysDisplayed; foreach (GameObject enemy in enemies) { EnemyMap enemyData = enemy.GetComponent <EnemyMap>(); enemy.transform.position = loadedMapData.enemyPos[enemyData.enemyID]; enemyData.isAlive = loadedMapData.enemyState[enemyData.enemyID]; if (!enemyData.isAlive) { Destroy(enemy); } } foreach (PowerUpObject power in powerUps) { if (power.gameObject != null) { power.isCollected = loadedMapData.powerUpState[power.id]; if (power.isCollected) { power.gameObject.SetActive(false); } } } if (key != null) { KeyController keyData = key.GetComponent <KeyController>(); keyData.isCollected = loadedMapData.keyState; if (keyData.isCollected) { Destroy(key); } } } if (File.Exists(combatFileName)) { string jsonSave = File.ReadAllText(combatFileName); CombatData loadedCombatData = JsonUtility.FromJson <CombatData>(jsonSave); playerCont.currHealth = loadedCombatData.health; playerCont.damage = loadedCombatData.damage; playerCont.actionPoints = playerCont.actionPoints + loadedCombatData.apToAdd; Debug.Log(loadedCombatData.apToAdd); } }
public void SaveMapData(GameObject details) { MapData data = new MapData(); PlayerProgramController playerCont = player.GetComponent <PlayerProgramController>(); data.playerPos = playerCont.lastPos; data.playerAP = playerCont.actionPoints; data.playerMaxHealth = playerCont.maxHealth; data.playerMaxAP = playerCont.maxActionPoints; data.playerCurrAP = playerCont.actionPoints; Debug.Log(data.playerCurrAP); data.playerVisibility = playerCont.visibilityMultiplier; data.isRepelAvailable = playerCont.isRepelAvailable; data.isRevealAvailable = playerCont.isRevealAvailable; data.isConvertAvailable = playerCont.isConvertAvailable; data.enemyPos = new Vector3[enemiesCount]; data.enemyState = new bool[enemiesCount]; data.powerUpState = new bool[powerUps.Length]; data.keyState = (key == null); data.isFastForward = TurnController._instance.speedChangeTgl.isOn; data.areHotkeysDisplayed = OverlayController._instance.areHotkeysDisplayed; foreach (GameObject enemy in enemies) { if (enemy != null) { EnemyMap enemyData = enemy.GetComponent <EnemyMap>(); data.enemyPos[enemyData.enemyID] = enemy.transform.position; data.enemyState[enemyData.enemyID] = enemyData.isAlive; } } foreach (PowerUpObject power in powerUps) { if (power.gameObject != null) { data.powerUpState[power.id] = power.isCollected; } } if (details != null) { data.isEnemy = details.GetComponent <EnemyMap>().isEnemy; data.isSpider = details.GetComponent <EnemyMap>().isSpider; data.isTurret = details.GetComponent <EnemyMap>().isTurret; data.isTank = details.GetComponent <EnemyMap>().isTank; data.enemyAmt = details.GetComponent <EnemyMap>().enemyAmt; data.spiderAmt = details.GetComponent <EnemyMap>().spiderAmt; data.turretAmt = details.GetComponent <EnemyMap>().turretAmt; data.tankAmt = details.GetComponent <EnemyMap>().tankAmt; } string json = JsonUtility.ToJson(data); if (File.Exists(mapFileName)) { File.Delete(mapFileName); } File.WriteAllText(mapFileName, json); CombatData combatData = new CombatData(); combatData.health = playerCont.currHealth; combatData.damage = playerCont.damage; json = JsonUtility.ToJson(combatData); if (File.Exists(combatFileName)) { File.Delete(combatFileName); } File.WriteAllText(combatFileName, json); }
void Start() { em = FindObjectOfType <EnemyMap>(); sprite = GetComponent <SpriteRenderer>(); }
void pick_friendly_target(int targeting, EnemyMap eMap, Enemy[] el, int aoe_x, int aoe_y) { //pick unit from eMap based on targeting legend. //legend: // 0: random target // 1: least hp value // 2: least hp percentage // 3: most debuffed // 4: aoe, most targets List <Enemy> f_targets = new List <Enemy>(); double chosen; int chosenIndex; switch (targeting) { case 0: // 0: random target bool find = true; while (find) { chosenIndex = UnityEngine.Random.Range(0, el.Length); if (el[chosenIndex].ooa == false) { nextX = el[chosenIndex].get_y(); nextY = el[chosenIndex].get_x(); find = false; } } break; case 1: // 1: least hp chosenIndex = 0; chosen = el[0].get_hp(); for (int i = 1; i < el.Length; i++) { if (el[i].ooa == false && el[i].get_hp() <= chosen) { chosen = el[i].get_hp(); chosenIndex = i; } } nextX = el[chosenIndex].get_y(); nextY = el[chosenIndex].get_x(); break; case 2: // 2: least proportional hp chosenIndex = 0; chosen = el[0].get_hp() / el[0].get_hpMax_actual(); for (int i = 1; i < el.Length; i++) { if (el[i].ooa == false && (el[i].get_hp() / el[i].get_hpMax_actual()) <= chosen) { chosen = el[i].get_hp() / el[i].get_hpMax_actual(); chosenIndex = i; } } nextX = el[chosenIndex].get_y(); nextY = el[chosenIndex].get_x(); break; case 3: // most debuffed // todo //add a isDebuffed identifier to enemies, then, target the enemy with the highest score. //a move with this targeting type will be a move that applies the dispel status break; case 4: // 8: aoe, most targets List <Enemy> max_f_targets = new List <Enemy>(); int currentTargetNumber = 0; int maxTargetNumber = 0; //method: //for each tile: // gen list of affected targets // take running max targetlist. for (int c = 0; c < 5 - aoe_y; c++) { for (int r = 0; r < 6 - aoe_x; r++) { //generate aoe area for each tile currentTargetNumber = 0; for (int i = c; i < c + aoe_y; i++) { for (int j = r; j < r + aoe_x; j++) { //if tile is occupied if (eMap.search_enemy(i, j) != null) { //and if unit on tile is not already in f_targets and is not ooa if (!f_targets.Contains(eMap.search_enemy(i, j)) && eMap.search_enemy(i, j).ooa == false) { f_targets.Add(eMap.search_enemy(i, j)); currentTargetNumber++; } } } } if (currentTargetNumber > 0 && currentTargetNumber >= maxTargetNumber) { if (currentTargetNumber == maxTargetNumber) { //50% chance to replace if same target count, chosen = UnityEngine.Random.Range(0, 2); //can be 0 or 1 //Debug.Log(chosen); if (chosen == 0) { max_f_targets = f_targets; nextX = c; nextY = r; } //else, do nothing } else { max_f_targets = f_targets; maxTargetNumber = currentTargetNumber; nextX = c; nextY = r; } } f_targets.Clear(); } } break; } }
/// <summary>Preforms a turn based on user input</summary> /// <returns>A bool representing if the player scored a hit during the turn</returns> public override bool DoManualTurn() { SelectedOption = 0; SetSelectedIndex(); UpdateMapData(); do { Console.Clear(); Console.Write("Options available: "); Game.DisplayControlKey("1 ", true); Game.DisplayControlKey("2 ", EnemyMap.EPlanes.Count > 0); Game.DisplayControlKey("3 ", FriendlyMap.FPlanes.Count > 0); Game.DisplayControlKey("4 ", EnemyMap.EPlanes.Count > 0); Game.DisplayControlKey("5 ", FriendlyMap.EPlanes.Count > 0 || EnemyMap.FPlanes.Count > 0); Console.WriteLine(); Console.Write("Selected option (Use # to change): " + (SelectedOption + 1).ToString() + "."); Map AdjustingMap = null; switch (SelectedOption) { case 0: Console.WriteLine("attack ships"); EnemyMap.PrintMap(false, EnemyMap.SelectedAttack != null ? Map.Display.Attack : Map.Display.Center, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, UsingSelectedAttack ? Map.Display.Ship : Map.Display.Nothing, -1); Console.WriteLine("\nShip: " + (UsingSelectedAttack ? FriendlyMap.Selected.ShipName : "none")); Console.WriteLine("Attack: " + (EnemyMap.SelectedAttack == null ? "default" : EnemyMap.SelectedAttack.AttackString)); if (EnemyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[0][2]).ToString() + "/" + EnemyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between ships, F/G for attacks and V/B for attack layout."); if (UsingSelectedAttack) Console.WriteLine("Use C deselect ship and use default attack"); Console.WriteLine("Use arrow keys to move selection, use enter to fire."); AdjustingMap = EnemyMap; break; case 1: Console.WriteLine("use aircraft"); EnemyMap.PrintMap(false, Map.Display.AttackingPlane, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, Map.Display.Nothing, -1); Console.WriteLine("Attack: " + (EnemyMap.SelectedAttack == null ? "nothing!" : (EnemyMap.SelectedAttack.AttackName + (EnemyMap.SelectedAttack.Amount > 0 ? " x"+ EnemyMap.SelectedAttack.Amount.ToString() : "")))); if (EnemyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[0][2]).ToString() + "/" + EnemyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes"); Game.DisplayControl("Use enter to fire.",EnemyMap.SelectedAttack != null); AdjustingMap = null; break; case 2: Console.WriteLine("deploy aircraft"); EnemyMap.PrintMap(false, Map.Display.Center, -1); FriendlyMap.PrintMap(true, Map.Display.Plane, -1); AdjustingMap = EnemyMap; Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes."); Console.WriteLine("Use arrow keys to move selection."); Game.DisplayControl("Use enter to deploy.", EnemyMap.CanPlaceEPlane(EnemyMap.ETargetLocation)); break; case 3: Console.Write("recall aircraft"); EnemyMap.PrintMap(false, Map.Display.Plane, -1); FriendlyMap.PrintMap(true, Map.Display.Center, -1); Console.WriteLine(); Console.WriteLine("Use R/T to browse between planes."); Console.WriteLine("Use arrow keys to move selection."); Game.DisplayControl("Use enter to recall.", FriendlyMap.CanPlaceFPlane(FriendlyMap.FTargetLocation)); AdjustingMap = FriendlyMap; break; case 4: Console.WriteLine("AA"); AdjustingMap = FriendlyMap; FriendlyMap.PrintMap(true, FriendlyMap.SelectedAttack != null ? Map.Display.Attack : Map.Display.Center, SelectedIndex[SelectedOption][2]); FriendlyMap.PrintMap(true, Map.Display.Ship, -1); Console.WriteLine("Ship: " + (UsingSelectedAA ? FriendlyMap.Selected.ShipName : "none")); Console.WriteLine("\nAA: " + (FriendlyMap.SelectedAttack == null ? "default" : FriendlyMap.SelectedAttack.AttackString)); if (FriendlyMap.SelectedAttack != null) Console.WriteLine("Firing pattern: " + (1 + SelectedIndex[4][2]).ToString() + "/" + FriendlyMap.SelectedAttack.SplashDamage.Length); Console.WriteLine(); Console.WriteLine("Use R/T to browse between ships, F/G for attacks and V/B for attack layout."); if (UsingSelectedAA) Console.WriteLine("Use C deselect ship and use default attack"); Console.WriteLine("Use arrow keys to move selection, use enter to fire."); break; } System.ConsoleKey k; switch (k = Console.ReadKey().Key) { case ConsoleKey.UpArrow: case ConsoleKey.DownArrow: case ConsoleKey.LeftArrow: case ConsoleKey.RightArrow: AttemptMoveTarget(k, AdjustingMap); break; case ConsoleKey.D1: case ConsoleKey.D2: case ConsoleKey.D3: case ConsoleKey.D4: case ConsoleKey.D5: AttemptChangeOption(k); break; case ConsoleKey.R: case ConsoleKey.T: if (SelectedOption == 0 && UsingSelectedAttack) AttemptChangeSelectedIndex(0, k); else if (SelectedOption == 0) { UsingSelectedAttack = true; UpdateMapData(); } else if (SelectedOption == 4 && UsingSelectedAA) AttemptChangeSelectedIndex(0, k); else if (SelectedOption == 4) { UsingSelectedAA = true; UpdateMapData(); } else AttemptChangeSelectedIndex(0, k); break; case ConsoleKey.F: case ConsoleKey.G: AttemptChangeSelectedIndex(1, k); break; case ConsoleKey.V: case ConsoleKey.B: AttemptChangeSelectedIndex(2, k); break; case ConsoleKey.C: if (SelectedOption == 0 && UsingSelectedAttack) { UsingSelectedAttack = false; UpdateMapData(); } else if (SelectedOption == 4 && UsingSelectedAA) { UsingSelectedAA = false; UpdateMapData(); } break; case ConsoleKey.Enter: bool t = false; switch (SelectedOption) { case 0: t= EnemyMap.AdvancedFire(false, false, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; case 1: if (EnemyMap.SelectedAttack == null) continue; t = EnemyMap.AdvancedFire(true, false, EnemyMap.SelectedPlane.Attacks, SelectedIndex[SelectedOption][2]); break; case 2: if (!EnemyMap.CanPlaceEPlane(EnemyMap.ETargetLocation)) continue; FriendlyMap.SelectedPlane.Location = new int[] { EnemyMap.ETargetLocation[0], EnemyMap.ETargetLocation[1] }; EnemyMap.EPlanes.Add(FriendlyMap.SelectedPlane); FriendlyMap.FPlanes.Remove(FriendlyMap.SelectedPlane); break; case 3: if (!FriendlyMap.CanPlaceFPlane(FriendlyMap.FTargetLocation)) continue; EnemyMap.SelectedPlane.Location = new int[] { FriendlyMap.FTargetLocation[0], FriendlyMap.FTargetLocation[1] }; EnemyMap.EPlanes.Remove(EnemyMap.SelectedPlane); FriendlyMap.FPlanes.Add(EnemyMap.SelectedPlane); break; case 4: FriendlyMap.AdvancedFire(false, true, FriendlyMap.Selected == null ? null : FriendlyMap.Selected.Attacks, SelectedIndex[SelectedOption][2]); break; } string outp = "The results of your turn."; if (EnemyMap.DestroyedList.Count > 0) { outp += "\nThe following were destroyed on the enemy map: "; foreach (string i in EnemyMap.DestroyedList) outp += i + ", "; outp = outp.Substring(0, outp.Length - 2); EnemyMap.DestroyedList = new List<string>(); } if (FriendlyMap.DestroyedList.Count > 0) { outp += "\nThe following were destroyed over your map: "; foreach (string i in FriendlyMap.DestroyedList) outp += i + ", "; outp = outp.Substring(0, outp.Length - 2); FriendlyMap.DestroyedList = new List<string>(); } outp += "\nPress SPACE to continue."; Console.Clear(); EnemyMap.PrintMap(false, Map.Display.Nothing, -1); FriendlyMap.PrintMap(true, Map.Display.Nothing, -1); Console.Write(outp); do { } while (Console.ReadKey().Key != ConsoleKey.Spacebar); TurnText += EnemyMap.ETargetLocation[0].ToString() + IndexDelimiter + EnemyMap.ETargetLocation[1].ToString() + IndexDelimiter + FriendlyMap.FTargetLocation[0].ToString() + IndexDelimiter + FriendlyMap.FTargetLocation[1].ToString() + IndexDelimiter + SelectedOption + IndexDelimiter + UsingSelectedAttack + IndexDelimiter + UsingSelectedAA; for (int i = 0; i < SelectedIndex[SelectedOption].Length; i++) TurnText += IndexDelimiter + SelectedIndex[SelectedOption][i].ToString(); TurnText += TurnDelimiter; return t; } } while (true); }