コード例 #1
0
        public void Run()
        {
            NumberGenerator theNumberGenerator = new NumberGenerator();
            BattleLog theLog = new BattleLog();

            Hero theHero = new Hero(theNumberGenerator, theLog);
            Beast theBeast = new Beast(theNumberGenerator, theLog);

            // Now battle...How do we do that (Hint: You need a loop)
            // YOUR JOB: Insert code here to make theHero and theBeast battle

            theLog.PrintEntireBattleLog();
        }
        public void Run()
        {
            NumberGenerator theNumberGenerator = new NumberGenerator();
            BattleLog theLog = new BattleLog();

            Hero theHero = new Hero(theNumberGenerator, theLog);
            Beast theBeast = new Beast(theNumberGenerator, theLog);

            while (!theHero.IsDead() && !theBeast.IsDead()) {
                // Let hero deal damage to beast:
                theBeast.ReceiveDamage(theHero.DealDamage());

                // Let beast deal damage to hero (if it is not dead...)
                if (!theBeast.IsDead()) {
                    theHero.ReceiveDamage(theBeast.DealDamage());
                }
            }

            theLog.PrintEntireBattleLog();
        }
コード例 #3
0
 // Create a Beast, using references to a random number generator and a battle log
 public Beast(NumberGenerator generator, BattleLog log)
 {
     this.generator = generator;
     this.log = log;
     Reset();
 }