コード例 #1
0
ファイル: Game.cs プロジェクト: jcolag/Landlord-Game
 /// <summary>
 /// Add the specified location to the board.
 /// </summary>
 /// <param name="l">The new location.</param>
 public void Add(Location l)
 {
     this.Board.Add(l);
 }
コード例 #2
0
ファイル: Game.cs プロジェクト: jcolag/Landlord-Game
        /// <summary>
        /// Initializes a new instance of the <see cref="LlConsole.Game"/> class.
        /// </summary>
        /// <param name="configuration">XML configuration.</param>
        public Game(XmlDocument configuration)
        {
            if (configuration == null)
                        {
                                throw new ArgumentNullException(
                                        "configuration",
                                        "Cannot create new game with empty XML");
                        }

                        XmlNodeList dice = configuration.GetElementsByTagName("Dice");
                        if (dice.Count > 0)
                        {
                                this.diceCount = XmlHelper.FromXmlIfExists<int>(dice[0], "Count", this.diceCount);
                                this.diceSides = XmlHelper.FromXmlIfExists<int>(dice[0], "Sides", this.diceSides);
                        }

                        XmlNodeList props = configuration.GetElementsByTagName("Location");
                        foreach (XmlNode prop in props)
                        {
                                var l = new Location(prop);
                                this.Add(l);
                        }

                        Location.SetBoard(this.Board);

                        XmlNodeList peeps = configuration.GetElementsByTagName("Player");
                        foreach (XmlNode pers in peeps)
                        {
                                var p = new Player(pers);
                                p.Where = this.Board[0];
                                this.Add(p);
                        }

                        XmlNodeList cards = configuration.GetElementsByTagName("FirstCard");
                        foreach (XmlNode card in cards)
                        {
                                var c = new Card(card);
                                this.Add(c, false);
                        }

                        cards = configuration.GetElementsByTagName("SecondCard");
                        foreach (XmlNode card in cards)
                        {
                                var c = new Card(card);
                                this.Add(c, true);
                        }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: jcolag/Landlord-Game
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// Initializes the game, preferably from an XML file, and goes into the main
        /// loop.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            var gamecfg = new XmlDocument();
                        Game g;
                        string playerName = string.Empty;

                        foreach (string arg in args)
                        {
                                if (arg.ToLower(System.Globalization.CultureInfo.CurrentCulture).EndsWith(".xml", StringComparison.CurrentCulture))
                                {
                                        gamecfg.Load(arg);
                                        break;
                                }
                        }

                        if (gamecfg != null)
                        {
                                g = new Game(gamecfg);
                        }
                        else
                        {
                                g = new Game();
                                for (int i = 0; i < 40; i++)
                                {
                                        var l = new Location(
                                                Zoning.Residential,
                                                "Property " + (i + 1).ToString(),
                                                0,
                                                0,
                                                0,
                                                0,
                                                100,
                                                10);
                                        g.Add(l);
                                }
                        }

                        if (g.PlayerCount < 2)
                        {
                                Console.WriteLine("Input player names, empty line when done:");
                                while (true)
                                {
                                        playerName = Console.ReadLine();
                                        if (string.IsNullOrWhiteSpace(playerName))
                                        {
                                                break;
                                        }

                                        var p = new Player(playerName);
                                        p.Where = g.Board[0];
                                        g.Add(p);
                                }
                        }

                        Player player = g.Who();
                        while (g.Continue)
                        {
                                Func<Player, string, string> question = null;
                                Location landing = g.Where();
                                string answer = string.Empty;

                                Console.WriteLine("* " + player.ToString());
                                if (player.InJail)
                                {
                                        Console.WriteLine(player.Name + " is in jail!");
                                }

                                answer = g.Roll();
                                Console.Write(answer);
                                landing = g.Where();
                                Console.WriteLine("Lands on " + landing.Name);

                                Console.WriteLine(landing.PrintOnLanding(player, ref question));
                                answer = string.Empty;
                                while (question != null && string.IsNullOrWhiteSpace(answer))
                                {
                                        answer = Console.ReadLine();
                                        answer = question(player, answer);
                                        Console.WriteLine(answer);
                                }

                                if (player.Balance < 0)
                                {
                                        Console.WriteLine(player.Name + " has gone bankrupt!");
                                }

                                player = g.NextPlayer();
                        }

                        Player winner = g.Who();
                        Console.WriteLine(winner.Name + " wins with $"
                                + winner.Balance.ToString());
        }