public bool Attack(Creature creature1, Creature creature2) //Attack method { int score1, score2 = 0; bool succeeded = false; int dateSeed = DateTime.Now.Millisecond; Random roll = new Random(dateSeed); int rollValue = roll.Next(1, 21);//Dice roll between 1 and 20 if (rollValue == 1) { return(false);//returns false when its 1 which means it is a miss } if (rollValue == 20) { return(true);//returns true when its 20 which means it is a hit } //run the attack of creature1 on creature2, return if it succeeded or not //attack is successful(true) if creature1 score > creature2 score if (creature1.Type == 0) //checks if creature1 is a character { score1 = rollValue + creature1.Level + cc.GetBaseAttack(creature1); //score1 will be given to the character score2 = mc.GetBaseDefense(creature2) + creature2.Level; //score2 will be given to the monster } else { score1 = rollValue + creature1.Level + mc.GetBaseAttack(creature1); //score1 will be given to the monster score2 = cc.GetBaseDefense(creature2) + creature2.Level; //score2 will be given to the character } if (score1 > score2) { succeeded = true; //when the attacking creature has higher score the attack is a success } return(succeeded); }
public int Attack(Creature creature1, Creature creature2) { int score1, score2 = 0; //bool succeeded = false; int hit = 0; int dateSeed = DateTime.Now.Millisecond; Random roll = new Random(dateSeed); //run the attack of creature1 on creature2, return if it succeeded or not //attack is successful(true) if creature1 score > creature2 score int rollValue = roll.Next(1, 21); if (GameGlobals.DisableRandomNumbers) { rollValue = 19; } if (GameGlobals.RollValue >= 0) { rollValue = GameGlobals.RollValue; } if (rollValue == 1) { if (GameGlobals.EnableCriticalMiss == true) { return(-1); } return(0); } if (rollValue == 20) { if (GameGlobals.EnableCriticalHit == true) { return(2); } return(1); } if (creature1.Type == 0) { score1 = rollValue + creature1.Level + cc.GetBaseAttack(creature1); score2 = mc.GetBaseDefense(creature2) + creature2.Level; } else { score1 = rollValue + creature2.Level + mc.GetBaseAttack(creature2); score2 = cc.GetBaseDefense(creature1) + creature1.Level; } if (score1 > score2) { hit = 1; } return(hit); }
public Score Start(bool auto) { TeamViewModel Team = TeamViewModel.Instance; BattleController battle = new BattleController(); int Miracle = 1; while (Team.Dataset.Count > 0) { round++; int Potions = 6; int Volcano = 20; string message = ""; Debug.WriteLine("New Round " + round.ToString()); foreach (var character in Team.Dataset) { character.CanFocusAttack = true; } if (GameGlobals.EnableRandomBadThings == true) { int dateSeed = DateTime.Now.Millisecond; Random rand = new Random(dateSeed); Volcano = rand.Next(1, 21); //Volcano = 4; //to force one of the effects if (GameGlobals.DisableRandomNumbers) { Volcano = 20; } if (Volcano == 1) { foreach (var character in Team.Dataset) { character.CurrHealth = character.MaxHealth; } message = "Volcano erupted, characters feel stronger"; } if (Volcano == 2) { foreach (var character in Team.Dataset) { double damage = character.CurrHealth * .2; character.CurrHealth -= (int)Math.Ceiling(damage); if (character.CurrHealth < 1) { character.CurrHealth = 1; } } message = "Volcano erupted, characters are sickened by the fumes"; } if (Volcano > 4) { message = "Volcano did not explode"; } } if (auto) { battle.SetBattleController(round); if (Volcano == 3) { foreach (var monster in battle.CurrMonsters.Dataset) { double damage = monster.CurrHealth * .2; monster.CurrHealth -= (int)Math.Ceiling(damage); if (monster.CurrHealth < 1) { monster.CurrHealth = 1; } } message = "Volcano erupted, falling ash hurts the monsters"; } if (Volcano == 4) { MonsterController mc = new MonsterController(); Creature strongestMonster = null; int strongest = 0; foreach (var monster in battle.CurrMonsters.Dataset) { int newStrongest = monster.CurrHealth + mc.GetBaseAttack(monster); if (strongest < newStrongest) { strongest = newStrongest; strongestMonster = monster; } } message = "Volcano erupted, " + strongestMonster.Name + " ran to watch"; battle.CurrMonsters.Dataset.Remove(strongestMonster); battle.TurnOrder.Remove(strongestMonster); battle.GameBoardRemove(strongestMonster); } if (GameGlobals.EnableRandomBadThings == true) { Debug.WriteLine(message); } GameScore = battle.AutoBattle(GameScore, round, Potions, Miracle); GameScore.Auto = true; } else { GameScore.Auto = false; battle.Battle(); } } return(ReportScore()); }