Exemple #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();
 }
Exemple #2
0
        public GameView(Game game)
        {
            _game = game;
            Turns = TurnLabel(_game.NbTurns);

            _game.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                Turns = TurnLabel(_game.NbTurns);
            });
        }
Exemple #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();
        }
Exemple #4
0
        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;
                }
            });
        }
Exemple #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;
 }
 public InGameMenuWindow(Game currentGame)
 {
     _game = currentGame;
     InitializeComponent();
 }
 public InGameMenuSavePage(Game currentGame)
 {
     _game = currentGame;
     InitializeComponent();
 }
Exemple #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;
 }