Example #1
0
        static void Main(string[] args)
        {
            DiceBag toHit        = "1d20 + 4";
            var     summedResult = toHit.Roll(new BasicPresenter());

            Console.WriteLine("Final result: " + summedResult);

            DiceBag damage = DiceBag.Create(
                new List <Die> {
                new Die("1d6", 1, 6)
            },
                new List <Modifier> {
                new Modifier(2)
            });

            summedResult = damage.Roll(new BasicPresenter());
            Console.WriteLine("Final result: " + summedResult);

            try
            {
                DiceBag error = "-12dd";
            }
            catch (DiceParseException ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
Example #2
0
            public void GivenInitativeCostLessThanCurrentInitiative_ThenCurrentInitiativeDecrementedAndActionRun()
            {
                // arrange
                var character    = new Character();
                var bag          = new DiceBag();
                var mockAction   = new Mock <IInitiativeAction>(MockBehavior.Strict);
                var actionResult = new ActionResult("", new DicePoolResults(new List <int>()));
                var cost         = new InitiativeCost()
                {
                    Cost = 5, IsCostRequired = false
                };
                var actual = new InitiativePassSlot()
                {
                    Participant       = character,
                    CurrentInitiative = 7
                };

                mockAction.Setup(x => x.InitiativeCost)
                .Returns(cost);
                mockAction.Setup(x => x.Do(bag, character))
                .Returns(actionResult);

                // act
                actual.PerformAction(bag, mockAction.Object);

                // assert
                Assert.AreEqual(2, actual.CurrentInitiative);
                mockAction.Verify(x => x.Do(bag, character), Times.Once);
            }
Example #3
0
        public void TestRollPercentage()
        {
            DiceBag dice   = new DiceBag();
            int     result = dice.Roll_Percent();

            Assert.IsTrue(Enumerable.Range(1, 100).Contains(result));
        }
Example #4
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">Startup arguments.</param>
        private static void Main(string[] args)
        {
            Console.WriteLine("What dice would you like to roll?");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("> ");
            var input = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Gray;

            Console.WriteLine();

            var diceBag = new DiceBag(new RandomNumberGenerator());

            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);
            Console.WriteLine(diceBag.Roll(input).Total);

            Console.WriteLine();
        }
Example #5
0
        public void TestRollWithAdvantage()
        {
            DiceBag dice   = new DiceBag();
            int     result = dice.Roll_d20(true);

            Assert.IsTrue(Enumerable.Range(1, 20).Contains(result));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            DiceBag diceBag = db.diceBags.Find(id);

            db.diceBags.Remove(diceBag);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #7
0
        /// <summary>
        /// This method attempts to find a way to fit the candidate into the level without colliding with any existing components.
        /// </summary>
        /// <param name="level"></param>
        /// <param name="entrance"></param>
        /// <param name="candidate"></param>
        /// <returns>false if the component could not be placed.</returns>
        protected bool tryPlaceComponent(DungeonLevel level, Doorway entrance, component candidate)
        {
            switch (entrance.SideIn)
            {
            case Side.North:
                candidate.y = entrance.y;
                break;

            case Side.South:
                candidate.y = entrance.y - candidate.Height;
                break;

            case Side.West:
                candidate.x = entrance.x - candidate.Width;
                break;

            case Side.East:
                candidate.x = entrance.x;
                break;
            }
            IList <int> potentialOrigins = new List <int>();

            if (entrance.SideIn == Side.North || entrance.SideIn == Side.South)
            {
                for (int i = entrance.x - candidate.Width; i < entrance.x; i++)
                {
                    potentialOrigins.Add(i + 1);
                }
                while (potentialOrigins.Count > 0)
                {
                    int i = DiceBag.getDice().rand.Next(potentialOrigins.Count);
                    candidate.x = potentialOrigins[i];
                    if (level.Add(candidate))
                    {
                        return(true);
                    }
                    potentialOrigins.RemoveAt(i);
                }
            }
            else
            {
                for (int i = entrance.y - candidate.Height; i < entrance.y; i++)
                {
                    potentialOrigins.Add(i + 1);
                }
                while (potentialOrigins.Count > 0)
                {
                    int i = DiceBag.getDice().rand.Next(potentialOrigins.Count);
                    candidate.y = potentialOrigins[i];
                    if (level.Add(candidate))
                    {
                        return(true);
                    }
                    potentialOrigins.RemoveAt(i);
                }
            }
            return(false);
        }
 public ActionResult Edit([Bind(Include = "ID,Colors,Etched,Glow,Size,Price,Quantity")] DiceBag diceBag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(diceBag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(diceBag));
 }
Example #9
0
        public void TestRollCharacterCreation()
        {
            DiceBag dice = new DiceBag();

            int[] results = dice.RollCharacterCreation();
            foreach (var result in results)
            {
                Assert.IsTrue(Enumerable.Range(3, 18).Contains(result));
            }
        }
        public ActionResult Create([Bind(Include = "ID,Colors,Etched,Glow,Size,Price,Quantity")] DiceBag diceBag)
        {
            if (ModelState.IsValid)
            {
                db.diceBags.Add(diceBag);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(diceBag));
        }
Example #11
0
        public void Roll1Plus3D6_6s()
        {
            var randomMock = new Mock <IRandomNumberGenerator>();

            randomMock.Setup(x => x.Next(It.IsAny <int>(), It.IsAny <int>())).Returns(6);
            var diceBag = new DiceBag(randomMock.Object);

            var result = diceBag.Roll("1+3d6");

            Assert.AreEqual(19, result.Total);
        }
Example #12
0
            public void ResultsAreWithinRange()
            {
                // arrange
                var actual = new DiceBag();

                // act
                var results = actual.d6(10000);

                // assert
                Assert.AreEqual(0, results.Count(x => x < 1));
                Assert.AreEqual(0, results.Count(x => x > 6));
            }
Example #13
0
        public int SavingThrow(int proficiencyBonus)
        {
            DiceBag dice = new DiceBag();
            int     roll = dice.Roll_d20(false);

            roll += Modifier();
            if (SavingThrowProficiency)
            {
                roll += proficiencyBonus;
            }
            return(roll);
        }
Example #14
0
            public void GivenZeroTimes_ThenEmptyResults()
            {
                // arrange
                var actual   = new DiceBag();
                var expected = 0;

                // act
                var results = actual.d6(0);

                // assert
                Assert.AreEqual(expected, results.Count());
            }
Example #15
0
            public void Valid()
            {
                // arrange
                const int seed     = 1234;
                var       actual   = new DiceBag(seed);
                var       expected = new Random(seed).Next(1, 6);

                // act
                var results = actual.d6();

                // assert
                Assert.AreEqual(expected, results);
            }
Example #16
0
        public int Check(int modifier, int proficiencyBonus)
        {
            DiceBag dice = new DiceBag();
            int     roll = dice.Roll_d20(false);

            roll += modifier;
            if (Proficiency)
            {
                roll += proficiencyBonus;
            }

            return(roll);
        }
Example #17
0
        static void Main(string[] args)
        {
            bool      inMenu = true;
            char      keyPressed;
            DiceBag   dice = new DiceBag();
            Character c    = new Character();

            while (inMenu)
            {
                System.Console.WriteLine();
                System.Console.WriteLine(HorizontalRule);
                System.Console.WriteLine("What would you like to do now?");
                System.Console.WriteLine("1. Roll d20");
                System.Console.WriteLine("2. Roll with advantage");
                System.Console.WriteLine("3. Roll from dice bag");
                System.Console.WriteLine("4. Character Creation");
                System.Console.WriteLine("Q. Quit");

                keyPressed = System.Console.ReadKey().KeyChar;
                System.Console.WriteLine();
                switch (keyPressed)
                {
                case '1':
                    dice.Roll_d20(false);
                    break;

                case '2':
                    dice.Roll_d20(true);
                    break;

                case '3':
                    RollFromDiceBag();
                    break;

                case '4':
                    //c.RollCharacterCreation();

                    break;

                case '5':
                    c.Strength.Score = 14;

                    break;

                case 'Q':
                case 'q':
                    inMenu = false;
                    break;
                }
            }
        }
        private int AttributeRoll()
        {
            int        attribute = 0;
            DiceBag    diceBag   = new DiceBag();
            List <int> rolls     = new List <int>();

            rolls = diceBag.RollQuantity(DiceBag.Dice.D6, 4);
            foreach (int roll in rolls)
            {
                attribute = attribute + roll;
            }

            return(attribute);
        }
            public void GivenCreateType_ThenSetupAndReturnInstance()
            {
                // arrange
                var bag        = new DiceBag();
                var characters = new List <ICharacter>();
                var actual     = new InitiativePassFactory(bag, characters);

                // act
                var results = actual.Create <MockInitiativePass>();

                // assert
                Assert.IsNotNull(results);
                Assert.IsTrue(results.WasSetupCalled);
            }
        // GET: DiceBags/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DiceBag diceBag = db.diceBags.Find(id);

            if (diceBag == null)
            {
                return(HttpNotFound());
            }
            return(View(diceBag));
        }
        private double HitPointCalculator(int constitutionModifier)
        {
            int        modifier = constitutionModifier;
            int        addRoll  = 0;
            double     rollsMod;
            DiceBag    diceBag = new DiceBag();
            List <int> rolls   = diceBag.RollQuantity(DiceBag.Dice.D8, 4);

            foreach (int roll in rolls)
            {
                addRoll = addRoll + roll;
            }
            rollsMod = addRoll + modifier;
            return(rollsMod);
        }
Example #22
0
        public void TestRollEach()
        {
            DiceBag dice = new DiceBag();

            int[] sides = { 2, 3, 4, 6, 8, 10, 12 };
            foreach (int side in sides)
            {
                for (int i = 1; i < 6; i++)
                {
                    Console.WriteLine($"Rolling {i}d{side}");
                    var result = dice.Roll(i, side);
                    Assert.IsTrue(Enumerable.Range(i, side * i).Contains(result));
                }
            }
        }
Example #23
0
        protected override bool tryAddDetails(Models.DungeonLevel Level, Models.Doorway Entrance, Models.Room room)
        {
            int numberOfExits = RollNumberOfExits(room.Area);

            if (numberOfExits == 0)
            {
                addHiddenExits(Level, room);
            }
            for (int i = 0; i < numberOfExits; i++)
            {
                Doorway exit = new Doorway();
                do
                {
                    exit.SideIn = RollExitSide(Entrance.SideIn);
                    if (exit.SideIn == Side.North || exit.SideIn == Side.South)
                    {
                        exit.Height = 0;
                        exit.Width  = 1;
                        if (exit.SideIn == Side.North)
                        {
                            exit.y = room.getYEdge();
                        }
                        else
                        {
                            exit.y = room.y;
                        }
                        exit.x = DiceBag.getDice().rand.Next(room.x, room.getXEdge());
                    }
                    else
                    {
                        exit.Width  = 0;
                        exit.Height = 1;
                        if (exit.SideIn == Side.East)
                        {
                            exit.x = room.getXEdge();
                        }
                        else
                        {
                            exit.x = room.x;
                        }
                        exit.y = DiceBag.getDice().rand.Next(room.y, room.getYEdge());
                    }
                } while (room.hasDoorAt(exit.x, exit.y) && !FindDoorType(Level, exit));
                room.Doors.Add(exit);
                Level.Add(exit);
            }
            return(true);
        }
Example #24
0
        private Side RollExitSide(Side entrance)
        {
            int          roll = DiceBag.getDice().d20(); // TABL V.D
            RelativeSide rel  = RelativeSide.Same;

            if (roll <= 7)                      // 1-7 opposite wall
            {
                rel = RelativeSide.Opposite;
            }
            else if (roll <= 12)                // 8-12 left wall
            {
                rel = RelativeSide.Left;
            }
            else if (roll <= 17)                // 13-17 right wall
            {
                rel = RelativeSide.Right;
            }
            return((Side)((((int)entrance + (int)rel) % 4)));
        }
Example #25
0
            public void GivenPassIsCompletedAndNoOneLeftToAct_ThenMarkCompletedAndReturnNull()
            {
                // arrange
                var bag        = new DiceBag();
                var characters = new List <ICharacter>();
                var actual     = new CombatTurnService <MockInitiativePass>(bag);

                actual.Setup(characters);
                (actual.CurrentInitiativePass as MockInitiativePass).IsComplete       = true;
                (actual.CurrentInitiativePass as MockInitiativePass).NeedsAnotherPass = false;

                // act
                var results = actual.Next();

                // assert
                Assert.IsNull(results);
                Assert.IsFalse((actual.CurrentInitiativePass as MockInitiativePass).WasResetCalled);
                Assert.IsFalse((actual.CurrentInitiativePass as MockInitiativePass).WasNextCalled);
            }
Example #26
0
            public void GivenParticipantsLeftToActInCurrentPass_ThenReturnNextParticipant()
            {
                // arrange
                var bag        = new DiceBag();
                var characters = new List <ICharacter>();
                var actual     = new CombatTurnService <MockInitiativePass>(bag);

                actual.Setup(characters);
                (actual.CurrentInitiativePass as MockInitiativePass).IsComplete       = false;
                (actual.CurrentInitiativePass as MockInitiativePass).ShouldReturnNext = true;

                // act
                var results = actual.Next();

                // assert
                Assert.IsNotNull(results);
                Assert.IsFalse((actual.CurrentInitiativePass as MockInitiativePass).WasResetCalled);
                Assert.IsTrue((actual.CurrentInitiativePass as MockInitiativePass).WasNextCalled);
            }
Example #27
0
        private bool FindDoorType(DungeonLevel level, Doorway door)
        {
            DungeonComponent tester = new DungeonComponent(door.x, door.y, 1, 1);

            switch (door.SideIn)
            {
            case Side.South:
                tester.y--;
                break;

            case Side.West:
                tester.x--;
                break;
            }
            if (level.Collision(tester))
            {
                int roll = DiceBag.getDice().d20();
                if (roll > 10)
                {
                    return(false);
                }
                else
                {
                    door.connected = true;
                    if (roll > 5)
                    {
                        door.Type = DoorType.OneWay;
                    }
                    else
                    {
                        door.Type = DoorType.Secret;
                    }
                }
            }
            else
            {
                door.connected = false;
                door.Type      = DoorType.TwoWay;
            }
            return(true);
        }
Example #28
0
            public void Valid()
            {
                // arrange
                const int seed          = 1234;
                const int _numberOfDice = 3;
                var       bag           = new DiceBag(seed);
                var       actual        = new DicePool(bag, _numberOfDice);
                var       expected      = new DicePoolResults(new List <int> {
                    2, 5, 2
                });

                // act
                var results = actual.Roll();

                // assert
                Assert.AreEqual(expected.RollResults.Count, results.RollResults.Count);
                for (int i = 0; i < results.RollResults.Count; i++)
                {
                    Assert.AreEqual(expected.RollResults[i], results.RollResults[i]);
                }
            }
Example #29
0
            public void GivenDiceBagAndCharacterList_ThenStoreAndSortOrder()
            {
                // arrange
                var diceBag    = new DiceBag();
                var characters = new List <Character>()
                {
                    new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character(), new Character()
                };
                var actual = new InitiativePass();

                // act
                actual.Setup(diceBag, characters);

                // assert
                Assert.AreEqual(characters.Count, actual.InitiativeOrder.Count);
                Assert.IsTrue(actual.InitiativeOrder.TrueForAll(x => x.HasActed == false));
                for (int i = 1; i < actual.InitiativeOrder.Count; i++)
                {
                    Assert.IsTrue(actual.InitiativeOrder[i].CurrentInitiative <= actual.InitiativeOrder[i - 1].CurrentInitiative);
                }
            }
Example #30
0
            public void Valid_List()
            {
                // arrange
                const int seed     = 1234;
                var       actual   = new DiceBag(seed);
                var       random   = new Random(seed);
                var       expected = new List <int>
                {
                    random.Next(1, 6),
                    random.Next(1, 6),
                    random.Next(1, 6),
                    random.Next(1, 6)
                };

                // act
                var results = actual.d6(4).ToList();

                // assert
                Assert.AreEqual(expected.Count, results.Count);
                for (int i = 0; i < results.Count; i++)
                {
                    Assert.AreEqual(expected[i], results[i]);
                }
            }