示例#1
0
        private static void LoadToTurnNo(string strFileName, int NoOfTurns)
        {
            New();
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(strFileName);
            XmlNodeList xmlnodelist;

            xmlnodelist = xmldoc.SelectNodes("/Game/Move");
            int      intTurnNo = 0;
            TimeSpan tsnTimeStamp;

            foreach (XmlElement xmlnode in xmlnodelist)
            {
                if (NoOfTurns != -1 && intTurnNo > NoOfTurns)
                {
                    break;
                }
                MakeAMove(Move.MoveNameFromString(xmlnode.GetAttribute("Name")), Board.GetPiece(Convert.ToInt32(xmlnode.GetAttribute("FromFile")), Convert.ToInt32(xmlnode.GetAttribute("FromRank"))), Board.GetSquare(Convert.ToInt32(xmlnode.GetAttribute("ToFile")), Convert.ToInt32(xmlnode.GetAttribute("ToRank"))));
                if (xmlnode.GetAttribute("SecondsElapsed") == "")
                {
                    if (m_movesHistory.Count <= 2)
                    {
                        tsnTimeStamp = (new TimeSpan(0));
                    }
                    else
                    {
                        tsnTimeStamp = (m_movesHistory.PenultimateForSameSide.TimeStamp + (new TimeSpan(0, 0, 30)));
                    }
                }
                else
                {
                    tsnTimeStamp = new TimeSpan(0, 0, int.Parse(xmlnode.GetAttribute("SecondsElapsed")));
                }
                m_movesHistory.Last.TimeStamp = tsnTimeStamp;
                m_movesHistory.Last.Piece.Player.Clock.TimeElapsed = tsnTimeStamp;
                intTurnNo++;
            }
        }