Пример #1
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            File.WriteAllText(PLAYER_DATA_FILE_NAME, _player.Toxmlstring());

            PlayerDataMapper.SaveToDatabase(_player);
        }
Пример #2
0
        public Game()
        {
            InitializeComponent();

            _player = PlayerDataMapper.CreateFromDataBase();
            if (_player == null)
            {
                if (File.Exists(PLAYER_DATA_FILE_NAME))
                {
                    _player = Player.createplayerformxmlString(File.ReadAllText(PLAYER_DATA_FILE_NAME));
                }
                else
                {
                    Player.CreateDefaultPlayer();
                    //Start(false, this);
                }
            }
            if (_player != null)
            {
                Strength.Text         = Convert.ToString(_player.Strength);
                Speed.Text            = Convert.ToString(_player.Speed);
                Intelligence.Text     = Convert.ToString(_player.Intelligence);
                Sight.Text            = Convert.ToString(_player.Sight);
                Endurance.Text        = Convert.ToString(_player.Endurance);
                StrengthBar.Value     = _player.Strength;
                SpeedBar.Value        = _player.Speed;
                IntelligenceBar.Value = _player.Intelligence;
                SightBar.Value        = _player.Sight;
                EnduranceBar.Value    = _player.Endurance;
                Health.DataBindings.Add("Text", _player, "HP");
                Gold.DataBindings.Add("Text", _player, "Gold");
                Stamina.DataBindings.Add("Text", _player, "Stamina");
                StaminaBar.DataBindings.Add("Value", _player, "Stamina");
                dgvInventory.RowHeadersVisible   = false;
                dgvInventory.AutoGenerateColumns = false;
                dgvInventory.DataSource          = _player.Inventory;

                dgvInventory.Columns.Add(new DataGridViewTextBoxColumn
                {
                    HeaderText       = "Name",
                    Width            = 197,
                    DataPropertyName = "Description"
                });

                dgvInventory.Columns.Add(new DataGridViewTextBoxColumn
                {
                    HeaderText       = "Quantity",
                    DataPropertyName = "Quantity"
                });

                dgvQuest.RowHeadersVisible   = false;
                dgvQuest.AutoGenerateColumns = false;
                dgvQuest.DataSource          = _player.Quest;

                dgvQuest.Columns.Add(new DataGridViewTextBoxColumn
                {
                    HeaderText       = "Name",
                    Width            = 197,
                    DataPropertyName = "Name"
                });

                dgvQuest.Columns.Add(new DataGridViewTextBoxColumn
                {
                    HeaderText       = "Done?",
                    DataPropertyName = "IsCompleted"
                });

                cobweapons.DataSource    = _player.Weapons;
                cobweapons.DisplayMember = "Name";
                cobweapons.ValueMember   = "Id";
                if (_player.CurrentLocation != null)
                {
                    cobweapons.SelectedItem = _player.CurrentWeapon;
                }

                cobweapons.SelectedIndexChanged += cobweapons_SelectedIndexChanged;
                cobpotion.DataSource             = _player.Potions;
                cobpotion.DisplayMember          = "Name";
                cobpotion.ValueMember            = "Id";


                _player.PropertyChanged += PlayerOnPropertyChanged;
                _player.OnMessage       += displaymessage;

                _player.MoveTo(_player.CurrentLocation);
            }
        }