Beispiel #1
0
 public savegame(gameobjser mycannon, gameobjser[] myenemies, gameobjser[] mycannonballs, int myscore, int myhealth)
 {
     _mycannon      = mycannon;
     _myenemies     = myenemies;
     _mycannonballs = mycannonballs;
     _myscore       = myscore;
     _myhealth      = myhealth;
 }
Beispiel #2
0
        private void SaveGame()
        {
            _gamepause = true;

            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream fs = new FileStream("savegame.dat", FileMode.Create))
            {
                try
                {
                    _mycannon = new gameobjser(_cannon.Position.X, _cannon.Position.Y, _cannon.Center.X,
                                               _cannon.Center.Y, _cannon.Velocity.X, _cannon.Velocity.Y,
                                               _cannon.Rotation, _cannon.Alive);
                    _mycannonballs = new gameobjser[MaxCannonBalls];
                    for (int i = 0; i < _mycannonballs.Length; i++)
                    {
                        _mycannonballs[i] = new gameobjser(_cannonballs[i].Position.X, _cannonballs[i].Position.Y, _cannonballs[i].Center.X,
                                                           _cannonballs[i].Center.Y, _cannonballs[i].Velocity.X, _cannonballs[i].Velocity.Y,
                                                           _cannonballs[i].Rotation, _cannonballs[i].Alive);
                    }
                    _myenemies = new gameobjser[MaxEnimies];
                    for (int i = 0; i < _myenemies.Length; i++)
                    {
                        _myenemies[i] = new gameobjser(_enemies[i].Position.X, _enemies[i].Position.Y, _enemies[i].Center.X,
                                                       _enemies[i].Center.Y, _enemies[i].Velocity.X, _enemies[i].Velocity.Y,
                                                       _enemies[i].Rotation, _enemies[i].Alive);
                    }
                    mysave = new savegame(_mycannon, _myenemies, _mycannonballs, _score, _health);
                    formatter.Serialize(fs, mysave);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }

            _gamepause = false;
        }