示例#1
0
 /// <summary>
 /// Saves the current game state into the given file.
 /// </summary>
 /// <param name="filename">Location of the save file.</param>
 public static void SaveGame(string filename, Game g)
 {
     Stream stream = File.Open(filename, FileMode.Create);
     BinaryFormatter formatter = new BinaryFormatter();
     formatter.Serialize(stream, g);
     stream.Close();
 }
示例#2
0
文件: GameView.cs 项目: eske/INSAWars
        public GameView(Game game)
        {
            _game = game;
            Turns = TurnLabel(_game.NbTurns);

            _game.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                Turns = TurnLabel(_game.NbTurns);
            });
        }
示例#3
0
        /// <summary>
        /// Creates a new GameWindow from the given Game.
        /// </summary>
        /// <param name="builder"></param>
        public GameWindow(Game game)
        {
            _game = game;
            _game.GameIsOver += GameIsOver;

            _gameView = new GameView(_game);

            InitializeComponent();
            InitializeGameControl();
            InitializeDataContexts();
            InitializeClock();
            InitializeLastSelectedCases();
            ResetUIState();
        }
示例#4
0
文件: CaseView.cs 项目: eske/INSAWars
        public CaseView(Game g, Case c)
        {
            _game = g;
            _case = c;

            Units = c.Units.Select(u => new UnitView(u)).ToList();
            HasCity = c.HasCity;

            if (c.City != null)
            {
                City = new CityView(c.City);
            }

            OccupantName = (c.Occupant == null) ? "Free" : c.Occupant.Name.ToString();
            Food = c.Food;
            Iron = c.Iron;
            SelectedUnitCanMove = false;
            SelectedUnitCanBuildCity = false;
            SelectedUnitCanAttack = false;
            SelectedUnitView = null;

            c.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                var updatedCase = (Case)sender;

                switch (args.PropertyName)
                {
                    case "Units":
                        Units = updatedCase.Units.Select(u => new UnitView(u)).ToList();

                        break;
                    case "HasCity":
                        HasCity = updatedCase.HasCity;
                        break;
                    case "Occupant":
                        OccupantName = (updatedCase.Occupant == null) ? "Free" : updatedCase.Occupant.Name.ToString();
                        break;
                    case "City":
                        // The new city could be null, we need to update only if it's not null
                        if (updatedCase.City != null)
                        {
                            City = new CityView(updatedCase.City);
                        }
                        break;
                    default:
                        break;
                }
            });
        }
示例#5
0
 /// <summary>
 /// Note: ideally, this class should not be coupled to Game. Refactoring needed.
 /// </summary>
 /// <param name="g"></param>
 /// <param name="control"></param>
 public SelectCaseCommand(Game g, GameControl control)
 {
     _game = g;
     _control = control;
 }
示例#6
0
 public InGameMenuWindow(Game currentGame)
 {
     _game = currentGame;
     InitializeComponent();
 }
示例#7
0
 public InGameMenuSavePage(Game currentGame)
 {
     _game = currentGame;
     InitializeComponent();
 }
示例#8
0
 /// <summary>
 /// Note: ideally, this class should not be coupled to Game. Refactoring needed.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="unit"></param>
 public MoveUnitCommand(Game game, Unit unit)
 {
     _unit = unit;
     _game = game;
 }