示例#1
0
        public bool PutInfoToFile(CStudents cs, string ext, bool Save)
        {
            cs.CleanList();
            if (!cs.IsAllCorrect())
            {
                MessageBox.Show("You did not filled all fields", "Uncorrect data", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Save = true;
                return(false);
            }
            else
            {
                ext = ext.Trim();
                ext = ext.ToLower();
                switch (ext)
                {
                case ".bin":
                    WorkWithBinary work = new WorkWithBinary();
                    work.PutAllToFile(cs);
                    break;

                case ".xml":
                    WorkWithXml xml = new WorkWithXml();
                    xml.PutAllToFile(cs);
                    break;

                case ".txt":
                default:
                    WorkWithText text = new WorkWithText();
                    text.PutAllToFile(cs);
                    break;
                }
                Save = false;
                return(true);
            }
        }
示例#2
0
        public bool GetInfoFromFile(string ext, ref CStudents cs)
        {
            bool res = true;

            if (cs == null)
            {
                cs = new CStudents();
            }
            else
            {
                cs.Collection.Clear();
            }
            ext = ext.Trim();
            ext = ext.ToLower();
            switch (ext)
            {
            case ".bin":
                WorkWithBinary work = new WorkWithBinary();
                res = work.GetAllFromFile(ref cs);
                break;

            case ".xml":
                WorkWithXml xml = new WorkWithXml();
                res = xml.GetAllFromFile(ref cs);
                break;

            case ".txt":
                WorkWithText text = new WorkWithText();
                res = text.GetAllFromFile(ref cs);
                break;
            }
            return(res);
        }
示例#3
0
        /// <summary>
        /// Здесь будет определяться, кто ходит и выводить нужную информацию на экран.
        /// Также, именно здесь будет обрабатываться финал игры.
        /// </summary>
        private void WhoseMove()
        {
            goButton.Visible = false;

            if (round < 31)
            {
                try
                {
                    if (tempRoundForSave != round)
                    {
                        WorkWithXml.AutoSaveToXml(firstPlayer, secondPlayer, round, logGameBox.Text);

                        tempRoundForSave = round;
                    }

                    if (round % 2 == 1)
                    {
                        listPlayer1.Visible        = listPlayer2.Visible = true;
                        infoLabel1.Visible         = infoLabel2.Visible = picturePlayer1.Visible =
                            picturePlayer2.Visible = false;

                        moveLabel.Text = $"ROUND {round}. First player attacks.";
                    }
                    else if (round % 2 == 0)
                    {
                        CreateRandomFootballer();

                        listPlayer2.Visible = infoLabel1.Visible = picturePlayer1.Visible = false;
                        infoLabel2.Visible  = picturePlayer2.Visible = listPlayer1.Visible = true;

                        moveLabel.Text = $"ROUND {round}. Second player attacks.";
                    }
                }
                catch (IOException)
                {
                    ErrorMessageAfterXml("Ошибка ввода-вывода, возможно файл занят чужим процессом." +
                                         "Игра будет закрыта.");
                }
                catch (System.Security.SecurityException)
                {
                    ErrorMessageAfterXml("Ошибка безопасности. Игра будет закрыта.");
                }
                catch (UnauthorizedAccessException)
                {
                    ErrorMessageAfterXml("У вас нет разрешения на создание файла! Игра будет закрыта.");
                }
                catch (Exception)
                {
                    ErrorMessageAfterXml("Произошел конец света(ошибка программы)... Игра будет закрыта.");
                }
            }
            else
            {
                Final();
            }
        }
        static void Main(string[] args)
        {
            //var path = "Books.txt";
            var path1 = "Book.XML";
            //IRepository<Book> rep = new BookRepository(path);
            IRepository<Book> rep1 = new WorkWithXml(path1);
            var bookService = new BookListService(rep1);
            Book book = new Book("3qw", "23", "fantasy", 1);
            bookService.Add(book);
            //bookService.Delete(book);
            var books = bookService.Sort(x => x.Publication);
            foreach (var b in books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }
            /*
            Console.WriteLine();
            var _books = bookService.SearchBooks(x => x.Author == "qqq");
            foreach (var b in _books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }

            Console.WriteLine();
            var find = bookService.Search(x => x.Author == "qqq");
            Console.Write("{0}\t{1}\t{2}\t{3}", find.Author, find.Title, find.Genre, find.Publication);
            Console.ReadKey();
            foreach (var b in books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }*/

            Console.ReadKey();
        }
示例#5
0
        public LaunchForm(int userId)
        {
            InitializeComponent();

            this.userId = userId;
            WorkWithXml xml = new WorkWithXml("users.xml");

            username = xml.GetUserById(userId);

            dataGridView1.ColumnCount = 3;
            dataGridView1.Columns[0].HeaderCell.Value = "Гравець";
            dataGridView1.Columns[1].HeaderCell.Value = "Рівень";
            dataGridView1.Columns[2].HeaderCell.Value = "Очки";

            if (userId == 1)
            {
                button2.Visible = true;
            }

            GetUserGames(username);

            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
        }
示例#6
0
        private void RestoreGame(string gamePath)
        {
            if (gamePath != null)
            {
                WorkWithXml savedData = new WorkWithXml("gamesaves/" + gamePath);

                characterState = savedData.ReadCharacterDataFromFile();
                character.RestoreState(characterState);
                character.SaveState();

                GameState = savedData.ReadGameDataFromFile();
                level     = GameState.level;
                score     = GameState.score;

                Map = savedData.ReadMapDataFromFile();
                Map.SaveState();

                int t = 0;
                for (int i = 0; i < 25; i++)
                {
                    for (int j = 0; j < 25; j++)
                    {
                        if (Map.map[i, j] == 1)
                        {
                            GenerateBorder(i, j);
                        }
                        else if (Map.map[i, j] == 2)
                        {
                            GenerateDoors(i, j, t);
                            t++;
                        }
                    }
                }

                enemyStateList = savedData.ReadEnemyDataFromFile();
                enemyList      = new Enemy1[enemyStateList.Length];

                for (int i = 0; i < enemyStateList.Length; i++)
                {
                    if (enemyStateList[i] == null)
                    {
                        break;
                    }
                    enemyList[i] = new Enemy1(enemyStateList[i].id, enemyStateList[i].HitPoints, enemyStateList[i].damage, enemyStateList[i].Name, enemyStateList[i].sprite);
                    this.Controls.Add(enemyList[i].sprite);

                    countOfEnemies++;
                }

                if (countOfEnemies == 0)
                {
                    OpenDoors();
                }

                GenerateWorld(true);
            }
            else
            {
                PictureBox sprite = new PictureBox();
                sprite.Image    = Image.FromFile(pathForCharacterGoBack);
                sprite.SizeMode = PictureBoxSizeMode.StretchImage;
                sprite.Location = new Point(300, 300);
                sprite.Size     = new Size(sizeOfSides, sizeOfSides);

                characterState = new HeroMemento(300, 100, 0, sprite);
                character.RestoreState(characterState);
                characterState = character.SaveState();

                GenerateWorld(false);
            }
        }