Exemplo n.º 1
0
        /// <summary>
        /// Reads the details for chance and community chest cards from a csv file
        /// </summary>
        /// <returns>A list of Luck objects that represent each card</returns>
        public List <Luck> ReadCardDetailsFromCSV()
        {
            try
            {
                var luckFactory        = new LuckFactory();
                var reader             = new StreamReader(File.OpenRead("carddetails.csv"));
                var cardDetailsFromCSV = new List <Luck>();

                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (line.Contains("Name"))
                    {
                        continue;                        // Ignore the column headings
                    }
                    var values = line.Split(',');

                    var card = luckFactory.create(values[0], Convert.ToBoolean(values[1]), Convert.ToDecimal(values[2]));

                    cardDetailsFromCSV.Add(card);
                }

                return(cardDetailsFromCSV);
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
Exemplo n.º 2
0
        public void verify_ToString_methods()
        {
            // need to reset and add a property to the board for these tests
            var luckFactory = new LuckFactory();

            Board.Access().ResetBoard();
            Board.Access().AddProperty(luckFactory.create("Go", false, 200));

            _emptyPlayer.SetBalance(500);
            _emptyPlayer.SetName("Josh");
            _emptyPlayer.SetLocation(0);

            const string expectedStandardToString = "Josh";
            var          actualStandardToString   = _emptyPlayer.ToString();

            Assert.AreEqual(expectedStandardToString, actualStandardToString);

            const string expectedBriefDetailToString = "You are on Go.\tYou have $500.";
            var          actualBriefDetailToString   = _emptyPlayer.BriefDetailToString();

            Assert.AreEqual(expectedBriefDetailToString, actualBriefDetailToString);

            var expectedFullDetailToString = string.Format("Player:Josh.\nBalance: $500\nLocation: Go: \t Owned by: Leeroy Jenkins (Square 0) \nProperties Owned:\n{0}", _emptyPlayer.PropertiesOwnedToString());
            var actualFullDetailToString   = _emptyPlayer.FullDetailToString();

            Assert.AreEqual(expectedFullDetailToString, actualFullDetailToString);

            const string expectedDiceRollToString = "Rolling dice: \t Dice 1: 0 \t Dice 2: 0";
            var          actualDiceRollToString   = _emptyPlayer.DiceRollingToString();
        }
Exemplo n.º 3
0
        public void TestCrate()
        {
            LuckFactory luckFactory = new LuckFactory();
            Luck        luck;

            luck = luckFactory.create("Luck", true, 50);
            Assert.AreEqual("Luck", luck.getName());
        }
 public void testLuck()
 {
     //create instance of factory
     LuckFactory f = new LuckFactory();
     //create instance from factory
     Luck p = f.create("Luck", true, 50) ;
     //check that it is right type
     Type t = new Luck().GetType();
     Assert.IsInstanceOfType(t, p);
 }
        public void CreateProperties()
        {
            var resFactory     = new ResidentialFactory();
            var transFactory   = new TransportFactory();
            var utilFactory    = new UtilityFactory();
            var genericFactory = new PropertyFactory();
            var luckFactory    = new LuckFactory();


            try
            {
                var propertyDetails = _fileReader.ReadPropertyDetailsFromCSV();

                // Add the properties to the board
                foreach (var propertyDetail in propertyDetails)
                {
                    switch (propertyDetail.Type.ToLower())
                    {
                    case "luck":
                        Board.Access()
                        .AddProperty(luckFactory.create(propertyDetail.Name, propertyDetail.IsPenalty,
                                                        propertyDetail.Amount));
                        break;

                    case "residential":
                        Board.Access()
                        .AddProperty(resFactory.create(propertyDetail.Name, propertyDetail.Price,
                                                       propertyDetail.Rent, propertyDetail.HouseCost, propertyDetail.HouseColour));
                        break;

                    case "transport":
                        Board.Access().AddProperty(transFactory.create(propertyDetail.Name));
                        break;

                    case "utility":
                        Board.Access().AddProperty(utilFactory.create(propertyDetail.Name));
                        break;

                    case "generic":
                        Board.Access().AddProperty(genericFactory.Create(propertyDetail.Name));
                        break;
                    }
                }

                Console.WriteLine("Properties have been setup");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Oops, something went wrong setting up the properties: {0}", ex.Message);
            }
        }
Exemplo n.º 6
0
        public void getting_a_chance_card()
        {
            var luckFactory = new LuckFactory();
            var chanceCard  = luckFactory.create("It's your birthday, collect $40.", false, 40);

            Board.Access().AddChanceCard(chanceCard);

            var cardFromBoard = Board.Access().GetChanceCard();

            // First we should get the card
            Assert.IsNotNull(cardFromBoard);

            // It should be the one we added
            Assert.AreSame(cardFromBoard, chanceCard);

            // Now we have it, should be removed
            Assert.IsNull(Board.Access().GetChanceCard());

            // So they'll be no cards left
            Assert.AreEqual(0, Board.Access().GetChanceCards().Count);
        }