Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChiamataLibrary.Player"/> class.
        /// </summary>
        /// <param name="name">The player's name.</param>
        /// <param name="order">The player's order (aka index).</param>
        internal Player(string name, int order)
        {
            if (!Board.Instance.IsCreationPhase)
            {
                throw new WrongPhaseException("A player must be instantiated during the creation time", "Creation");
            }

            this._role = EnRole.ALTRO;
            this.name  = name;
            this.order = order;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChiamataLibrary.GameData"/> class.
        /// </summary>
        /// <param name="path">The path of the XML file from which will be reading the <see cref="ChiamataLibrary.GameData"/>.</param>
        internal GameData(Stream s)
        {
            Board.Instance.Reset();
            _players = new Player[Board.PLAYER_NUMBER];
            _cards   = new Card[Board.Instance.nSemi, Board.Instance.nNumber];
            _bids    = new List <BidBase> ();

            //create the xml reader
            XmlReaderSettings setting = new XmlReaderSettings();

            setting.IgnoreComments = true;

            using (XmlReader reader = XmlReader.Create(s, setting)) {
                reader.ReadToFollowing("Game");                 //game

                reader.MoveToFirstAttribute();                  //datetime
                this.time = DateTime.Parse(reader.Value.ToString());

                reader.MoveToNextAttribute();                   //gametype
                this.gameType = (EnGameType)Enum.Parse(typeof(EnGameType), reader.Value, true);

                reader.MoveToNextAttribute();                   //winningPoint
                this.winningPoint = int.Parse(reader.Value);

                //Players
                reader.ReadToFollowing("Players");
                for (int i = 0; i < Board.PLAYER_NUMBER; i++)
                {
                    reader.ReadToFollowing("Player");

                    reader.ReadToFollowing("Name");                             //name
                    string name = reader.ReadElementContentAsString();

                    reader.ReadToFollowing("Role");                             //role
                    EnRole role = (EnRole)Enum.Parse(typeof(EnRole), reader.ReadElementContentAsString(), true);

                    reader.ReadToFollowing("Order");                            //order

                    int order = reader.ReadElementContentAsInt();

                    _players [i]      = new Player(name, order);
                    _players [i].Role = role;
                }

                //bids
                reader.ReadToFollowing("BidList");

                reader.MoveToFirstAttribute();                  //bid's number
                int nBids = int.Parse(reader.Value);

                for (int i = 0; i < nBids; i++)
                {
                    reader.ReadToFollowing("Bid");

                    reader.MoveToFirstAttribute();                      //bid's type
                    string type = reader.Value;

                    reader.ReadToFollowing("Bidder");                           //bidder

                    int bidder = reader.ReadElementContentAsInt();

                    if (type == "Pass")
                    {
                        _bids.Add(new PassBid(_players [bidder]));
                    }
                    else
                    {
                        reader.ReadToFollowing("Point");                                //point

                        int point = reader.ReadElementContentAsInt();

                        if (type == "Carichi")
                        {
                            _bids.Add(new CarichiBid(_players [bidder], point));
                        }
                        else
                        {
                            reader.ReadToFollowing("Number");                                   //number
                            EnNumbers number = (EnNumbers)Enum.Parse(typeof(EnNumbers), reader.ReadElementContentAsString(), true);

                            _bids.Add(new NormalBid(_players [bidder], number, point));
                        }
                    }
                }

                //Cards
                reader.ReadToFollowing("Cards");

                for (int seme = 0; seme < Board.Instance.nSemi; seme++)
                {
                    for (int number = 0; number < Board.Instance.nNumber; number++)
                    {
                        reader.ReadToFollowing("Card");
                        reader.MoveToFirstAttribute();                          //seme
                        reader.MoveToNextAttribute();                           //number
                        reader.MoveToNextAttribute();                           //called card
                        bool cc = bool.Parse(reader.Value);

                        reader.ReadToFollowing("InitialPlayer");
                        Player ip = _players [reader.ReadElementContentAsInt()];

                        _cards [seme, number] = new Card((EnNumbers)number, (EnSemi)seme, ip);

                        reader.ReadToFollowing("FinalPlayer");
                        Player fp = _players [reader.ReadElementContentAsInt()];

                        reader.ReadToFollowing("PlayingTime");
                        int tp = reader.ReadElementContentAsInt();

                        _cards [seme, number].PlayingTime = tp;
                        _cards [seme, number].FinalPlayer = fp;

                        if (cc)
                        {
                            calledCard = _cards [seme, number];
                        }
                    }
                }
            }
        }