コード例 #1
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;
                }
            });
        }
コード例 #2
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;
                }
            });
        }