コード例 #1
0
        private void roll_players_attributes(BattleEngine.Player.Player p)
        {
            int    min_stat = 8;
            double total    = 0.0;
            int    rolls    = 0;
            double seeking  = (6.0 * (double)min_stat);

            while (total < seeking)
            {
                rolls++;
                total = (double)p.RollAttributes(this.RandomEngine);
            }
        }
コード例 #2
0
        private void attack(BattleEngine.Player.Player source, BattleEngine.Player.Player target)
        {
            string details = string.Format("<u>Round {0}</u>: <i>{1}</i> is <b>attacking</b> <i>{2}</i>",
                                           this.round, source.Name, target.Name);

            this.BattleGui.ShowAttackDialog(details);
            Location sloc  = this.GameMap.GetPlayerOnMap(source);
            Location tloc  = this.GameMap.GetPlayerOnMap(target);
            double   dist  = sloc.DistanceTo(tloc);
            int      range = source.GetAttribute("Range").Current;

            if ((double)dist <= range)
            {
                int attackroll  = source.ThrowForAttack();
                int defenseroll = target.ThrowForDefense();
                this.Console.ConsoleWrite(string.Format("\t\"{0}\" attack rolls {1} at a distance of {2} with range {3}",
                                                        source.Name, attackroll, dist, range));
                this.Console.ConsoleWrite(string.Format(" : \"{0}\" defense rolls {1}", target.Name, defenseroll));
                if (attackroll >= defenseroll)
                {
                    this.Console.ConsoleWrite(" HIT");
                    int power = source.RollDamage();
                    this.Console.ConsoleWrite(string.Format(" for {0} damage", power));
                    int armor  = target.GetAttribute("Armor").Current;
                    int damage = armor - power;
                    if (damage < 0)
                    {
                        target.TakeDamage(damage);
                        this.Console.ConsoleWriteLine(string.Format(" \"{0}\" took {1} damage leaving {2} armor",
                                                                    target.Name, damage, target.GetAttribute("Armor").Current));
                    }
                    else
                    {
                        this.Console.ConsoleWriteLine(string.Format(" \"{0}\" took no damage \"{1}\" could not penetrate armor of {2}",
                                                                    target.Name, source.Name, target.GetAttribute("Armor").Current));
                    }
                }
                else
                {
                    this.Console.ConsoleWriteLine(" MISSED");
                }
            }
            else
            {
                this.Console.ConsoleWriteLine(string.Format("\tOUT OF RANGE: \"{0}\" is {1} meters away from \"{2}\"", target.Name, dist, source.Name));
                int move = source.GetAttribute("Speed").Current;
                this.Console.ConsoleWriteLine(string.Format("{0} closing {1} meters", source.Name, move));
                this.GameMap.MovePlayerToTarget(source, move, target);
            }
        }
コード例 #3
0
        private BattleEngine.Player.Player pick_target_by_shortest_distance(BattleEngine.Player.Player source)
        {
            List <BattleEngine.Player.Player> potential_targets = new List <BattleEngine.Player.Player>();

            foreach (BattleEngine.Player.Player p in this.players.Values)
            {
                if ((source != p) && (!p.IsDead()))
                {
                    potential_targets.Add(p);
                }
            }
            if (potential_targets.Count < 1)
            {
                throw new Exception("No potential targets!");
            }
            Location myloc = this.GameMap.GetPlayerOnMap(source);
            Dictionary <BattleEngine.Player.Player, double> distances = new Dictionary <BattleEngine.Player.Player, double>();

            foreach (BattleEngine.Player.Player target in potential_targets)
            {
                Location tgtloc = this.GameMap.GetPlayerOnMap(target);
                distances.Add(target, myloc.DistanceTo(tgtloc));
            }
            double lowest_dist = (double)(this.GameMap.Length + this.GameMap.Width + this.GameMap.Height) * 2;

            BattleEngine.Player.Player target_player = null;
            foreach (KeyValuePair <BattleEngine.Player.Player, double> kvp in distances)
            {
                this.Console.ConsoleWriteLine(string.Format("\"{0}\" distance to \"{1}\" is {2}", source.Name, kvp.Key.Name, kvp.Value));
                if (kvp.Value < lowest_dist)
                {
                    lowest_dist   = kvp.Value;
                    target_player = kvp.Key;
                }
            }
            return(target_player);
        }
コード例 #4
0
 public void RemovePlayer(BattleEngine.Player.Player player)
 {
     this.players.Remove(player.Name);
     this.Console.ConsoleWriteLine(player.Summarize() + " removed");
 }
コード例 #5
0
 public void AddPlayer(BattleEngine.Player.Player player)
 {
     this.players.Add(player.Name, player);
     this.Console.ConsoleWriteLine(player.Summarize());
 }
コード例 #6
0
        public void Battle()
        {
            this.round = 0;
            if (this.players.Count < 2)
            {
                throw new Exception("Need at least 2 players to battle, add more players.");
            }
            this.Console.ConsoleWriteLine("==========================");
            this.Console.ConsoleWriteLine("=   THE BATTLE BEGINS!   =");
            this.Console.ConsoleWriteLine("==========================");
            // initial targetting

            this.place_players_on_map();
            foreach (BattleEngine.Player.Player p in this.players.Values)
            {
                p.Reset();
            }

            foreach (BattleEngine.Player.Player p in this.players.Values)
            {
                p.Target = this.pick_target_by_shortest_distance(p);
                this.Console.ConsoleWriteLine(string.Format("\"{0}\" targets \"{1}\"", p.Name, p.Target.Name));
            }

            BattleEngine.Player.Player winner = null;
            while (this.PlayersLeftStanding() > 1)
            {
                this.Console.ConsoleWriteLine("");
                this.Console.ConsoleWriteLine("ROUND " + this.round.ToString());
                this.BattleGui.DoEvents();
                foreach (BattleEngine.Player.Player p in this.players.Values)
                {
                    if (!p.IsDead())
                    {
                        if (!p.Target.IsDead())
                        {
                            this.attack(p, p.Target);
                        }
                        else if (this.PlayersLeftStanding() > 1)
                        {
                            p.Target = this.pick_target_by_shortest_distance(p);
                        }
                    }
                }
                // show current stats
                foreach (BattleEngine.Player.Player p in this.players.Values)
                {
                    if (!p.IsDead())
                    {
                        this.Console.ConsoleWriteLine(p.SummarizeHealth());
                    }
                }
                this.round++;
                if (this.round > 1000)
                {
                    this.Console.ConsoleWriteLine("Battle has lasted too long");
                    winner = null;
                    break;
                }
            }
            foreach (BattleEngine.Player.Player p in this.players.Values)
            {
                if (!p.IsDead())
                {
                    winner = p;
                }
            }
            this.Console.ConsoleWriteLine("==========================");
            this.Console.ConsoleWriteLine("=    THE BATTLE ENDS!    =");
            this.Console.ConsoleWriteLine("==========================");
            if (winner != null)
            {
                this.Console.ConsoleWriteLine(string.Format("\"{0}\" wins the battle in {1} rounds!", winner.Name, this.round));
                this.Console.ConsoleWriteLine(winner.Summarize());
            }
            else
            {
                this.Console.ConsoleWriteLine("Its a draw");
            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: sgtnasty/battle
 public override void Reset()
 {
     foreach (PlayerAttribute a in this.attributes.Values)
     {
         a.Current = a.Base;
     }
     this.Target = null;
 }