public Bombset(MapElements me) { this.me_ = me; this.meIdx_ = 0; InitializeComponent(); FillBombList(); }
/// <summary> /// Instanciate and fill a new board /// </summary> /// <param name="w">width in square</param> /// <param name="h">height in square</param> private void CreateBoard(int w, int h) { var uniformGrid = (UniformGrid)this.FindName("Board"); if (uniformGrid == null) return; this.mapElements_ = new MapElements(w, h); uniformGrid.Children.Clear(); uniformGrid.Columns = w; uniformGrid.Rows = h; for (var i = 0; i < h; i++) { for (var j = 0; j < w; j++) { var elt = new SquareLabel(i, j); elt.Entities[KeResources.Index[KeResources.Type.Background]] = KeResources.Proxy[KeResources.Type.Background].Clone(); elt.Content = new AssetImage(KeResources.Type.Background); elt.MouseLeftButtonUp += OnLeftButtonUp; elt.MouseLeftButtonDown += OnLeftButtonDown; elt.MouseRightButtonUp += OnRightButtonUp; elt.MouseRightButtonDown += OnRightButtonDown; elt.MouseEnter += OnBucketAction; uniformGrid.Children.Add(elt); } } }
/// <summary> /// Initialize a new map from a MapElements /// </summary> /// <param name="g">Game</param> /// <param name="sb">Spritebatch used to render texture</param> /// <param name="me">MapElement used to construct entities in the map</param> public Map(Game g, SpriteBatch sb, MapElements me) : base(g) { this.sb_ = sb; this.SizeX = me.SizeX; this.SizeY = me.SizeY; var typeArray = Pattern.All; this.bombsets_ = new List<List<Hud.BombInfo>>(); foreach (var bombset in me.Bombset) { this.bombsets_.Add( bombset.Select(bomb => new Hud.BombInfo(typeArray[bomb.Type], bomb.Quantity, bomb.Name)) .ToList()); } ((MainGame)this.Game).BombSet(this.bombsets_[0]); this.board_ = new Square[this.SizeX,this.SizeY]; for (var i = 0; i < this.SizeX; i++) { for (var j = 0; j < this.SizeY; j++) { this.board_[i, j] = new Square(new Point(i, j)); this.board_[i, j].Explosion += ExplosionRuler; this.board_[i, j].EndGame += ManageEndGame; this.board_[i, j].Bombset += (sender, args) => ((MainGame) this.Game).BombSet(this.bombsets_[((CheckPoint) sender).BombsetIdx]); foreach (var entity in me.Board[i][j].Entities) { var bombProxy = entity as BombProxy; var blockProxy = entity as BlockProxy; var checkPointProxy = entity as CheckPointProxy; if (bombProxy != null) { this.board_[i, j].AddEntity( new Bomb(typeArray[bombProxy.Type], KaboomResources.Sprites[bombProxy.TileIdentifier].Clone(), "")); } else if (checkPointProxy != null) { this.board_[i, j].AddEntity( new CheckPoint(KaboomResources.Sprites[checkPointProxy.TileIdentifier].Clone(), 500, checkPointProxy.Activated, checkPointProxy.Bombsetidx)); } else if (blockProxy != null) { this.board_[i, j].AddEntity( new Block(KaboomResources.Sprites[blockProxy.TileIdentifier].Clone(), blockProxy.Destroyable, blockProxy.GameEnd)); } else { this.board_[i, j].AddEntity( new Entity(entity.ZIndex, new SpriteSheet( KaboomResources.Textures[entity.TileIdentifier], entity.TileFramePerAnim, entity.TileTotalAnim, entity.TileFrameSpeed))); } } } } }
/// <summary> /// Open a file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonOpen_OnClick(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); var mySerializer = new XmlSerializer(typeof(MapElements)); dialog.ShowDialog(); dialog.CheckFileExists = true; if (!string.IsNullOrEmpty(dialog.FileName)) { using (var stream = dialog.OpenFile()) { try { this.mapElements_ = (MapElements) mySerializer.Deserialize(stream); } catch (Exception) { var se = this.FindName("SelectedEntity") as Label; if (se != null) se.Content = "Fail to load file. "; } this.Title = Path.GetFileName(dialog.FileName); var box = this.FindName("TextBoxFilename") as TextBox; if (box != null) { box.Text = Path.GetFileNameWithoutExtension(dialog.FileName); } var uniformGrid = (UniformGrid) this.FindName("Board"); if (uniformGrid == null) return; uniformGrid.Children.Clear(); uniformGrid.Columns = this.mapElements_.SizeX; uniformGrid.Rows = this.mapElements_.SizeY; for (var i = 0; i < this.mapElements_.SizeY; i++) { for (var j = 0; j < this.mapElements_.SizeX; j++) { var elt = new SquareLabel(i, j); foreach (var entity in this.mapElements_.Board[j][i].Entities) { elt.Entities[KeResources.Index[KeResources.TypeLink[entity.TileIdentifier]]] = entity.Clone(); elt.Content = new AssetImage(entity.TileIdentifier); } elt.MouseLeftButtonUp += OnLeftButtonUp; elt.MouseLeftButtonDown += OnLeftButtonDown; elt.MouseRightButtonUp += OnRightButtonUp; elt.MouseRightButtonDown += OnRightButtonDown; elt.MouseEnter += OnBucketAction; uniformGrid.Children.Add(elt); } } var turn = this.FindName("TextBoxTurn") as TextBox; turn.Text = this.mapElements_.Score.Turn.ToString(CultureInfo.InvariantCulture); var score1 = this.FindName("TextBoxScore1") as TextBox; score1.Text = this.mapElements_.Score.Score1.ToString(CultureInfo.InvariantCulture); var score2 = this.FindName("TextBoxScore2") as TextBox; score2.Text = this.mapElements_.Score.Score2.ToString(CultureInfo.InvariantCulture); var score3 = this.FindName("TextBoxScore3") as TextBox; score3.Text = this.mapElements_.Score.Score3.ToString(CultureInfo.InvariantCulture); } } }