当前位置: 首页>>代码示例>>C#>>正文


C# Book.CreateBookList方法代码示例

本文整理汇总了C#中Book.CreateBookList方法的典型用法代码示例。如果您正苦于以下问题:C# Book.CreateBookList方法的具体用法?C# Book.CreateBookList怎么用?C# Book.CreateBookList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book.CreateBookList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateBookFromFiles

        /// <summary>
        /// Create a book from files selected by the user
        /// </summary>
        public void CreateBookFromFiles()
        {
            OpenFileDialog          openDlg;
            SaveFileDialog          saveDlg;
            PgnParser               parser;
            Stream                  stream;
            TextReader              reader;
            Book                    book;
            string                  strText;
            List<int[]>             arrMoveList;
            int                     iSkip;
            int                     iTruncated;
            int                     iTotalSkip = 0;
            int                     iTotalTruncated = 0;
            int                     iTotalFiles = 0;
            int                     iBookEntries;
            bool                    bAbort = false;

            arrMoveList = new List<int[]>(8192);
            book        = new Book();
            openDlg = new OpenFileDialog();
            openDlg.AddExtension        = true;
            openDlg.CheckFileExists     = true;
            openDlg.CheckPathExists     = true;
            openDlg.DefaultExt          = "pgn";
            openDlg.Filter              = "Chess PGN Files (*.pgn)|*.pgn";
            openDlg.Multiselect         = true;
            if (openDlg.ShowDialog() == true) {
                foreach (string strFileName in openDlg.FileNames) {
                    try {
                        stream = File.OpenRead(strFileName);
                    } catch(System.Exception) {
                        MessageBox.Show("Unable to open the file - " + strFileName);
                        stream = null;
                    }
                    if (stream != null) {
                        reader  = new StreamReader(stream);
                        strText = reader.ReadToEnd();
                        parser  = new PgnParser(false);
                        try {
                            parser.Parse(strText, arrMoveList, out iSkip, out iTruncated);
                            iTotalSkip      += iSkip;
                            iTotalTruncated += iTruncated;
                            iTotalFiles++;
                        } catch(PgnParserException exc) {
                            MessageBox.Show("Error processing file '" + strFileName + "'\r\n" + exc.Message + "\r\n" + exc.CodeInError);
                            bAbort =  true;
                        }
                        stream.Close();
                    }
                    if (bAbort) {
                        break;
                    }
                }
                if (!bAbort) {
                    iBookEntries = book.CreateBookList(arrMoveList, 30, 10);
                    MessageBox.Show(iTotalFiles.ToString() + " PNG file(s) read. " + arrMoveList.Count.ToString() + " games processed. " + iTotalTruncated.ToString() + " truncated. " + iTotalSkip.ToString() + " skipped. " + iBookEntries.ToString() + " book entries defined.");
                    saveDlg = new SaveFileDialog();
                    saveDlg.AddExtension        = true;
                    saveDlg.CheckPathExists     = true;
                    saveDlg.DefaultExt          = "bin";
                    saveDlg.Filter              = "Chess Opening Book (*.bin)|*.bin";
                    saveDlg.OverwritePrompt     = true;
                    if (saveDlg.ShowDialog() == true) {
                        try {
                            book.SaveBookToFile(saveDlg.FileName);
                        } catch (System.Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
开发者ID:enesyteam,项目名称:EChess,代码行数:76,代码来源:ChessBoardControl.xaml.cs


注:本文中的Book.CreateBookList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。