public GameElement GetNeighbor(Direction direction) { if (GetCurrentPerson() != null) { PersonElement pe = GetCurrentPerson(); return(GetNeighbor(pe, direction)); } else { PersonInDestinitionElement pe = GetCurrentPersonInCage(); return(GetNeighbor(pe, direction)); } }
private void person(){ PictureBox pbx = new PictureBox(); if(game.GetCurrentPerson() != null){ pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.down"))); pbx.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; pbx.Size = new Size(new Point(50,50)); pbx.Location = new Point(100,100); this.Controls.Add(pbx); element = new Sokoban.model.PersonElement(); element.Control = pbx; element.ShowInForm(this); }else{ pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down"))); pbx.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; pbx.Size = new Size(new Point(50,50)); pbx.Location = new Point(100,100); this.Controls.Add(pbx); element1 = new Sokoban.model.PersonInDestinitionElement(); element1.Control = pbx; element1.ShowInForm(this); } }
public override void MoveInForm(System.Windows.Forms.Form winForm, Direction direction, System.ComponentModel.ComponentResourceManager resources) { s++; bool result = CanMove(direction); if (!result) { return; } PictureBox pbx = this.Control; Point oldLocation = pbx.Location; Point newPoint = Point.Empty; Position oldPosition = this.CurrentPosition; GameElement ge = this.Game.GetNeighbor(direction); if (ge.GetType() == typeof(EmptyElement)) { this.Game.SwapElement(this, ge); ge.Game = this.Game; Turn(direction, resources); } else if (ge.GetType() == typeof(BoxElement)) { ge.MoveInForm(winForm, direction, resources); ge = this.Game.GetNeighbor(direction); this.Game.SwapElement(this, ge); ge.Game = this.Game; Turn(direction, resources); } else if (ge.GetType() == typeof(DestinitionElement)) { EmptyElement ee = new EmptyElement(); ee.Control = ge.Control; ee.Control.BackgroundImage = null; ee.Game = this.Game; this.Game.UpdateMap(ee); PersonInDestinitionElement pe = new PersonInDestinitionElement(); pe.Control = this.Control; // pe.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down"))); pe.Turn(direction, resources); pe.Game = this.Game; this.Game.UpdateMap(pe); } else if (ge.GetType() == typeof(BoxInDestinitionElement)) { ge.MoveInForm(winForm, direction, resources); ge = this.Game.GetNeighbor(direction); ge.Game = this.Game; this.Game.UpdateMap(ge); EmptyElement ee = new EmptyElement(); ee.Control = ge.Control; ee.Control.BackgroundImage = null; ee.Game = this.Game; this.Game.UpdateMap(ee); PersonInDestinitionElement pe = new PersonInDestinitionElement(); pe.Control = this.Control; // pe.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down"))); pe.Turn(direction, resources); pe.Game = this.Game; this.Game.UpdateMap(pe); } this.Control.BringToFront(); if (ge.GetType() == typeof(DestinitionElement)) { ge.MoveInForm(winForm, direction, resources); ge.Game = this.Game; ge = this.Game.GetNeighbor(direction); EmptyElement ee = new EmptyElement(); ee.Control = this.Control; ee.Control.BackgroundImage = null; ee.Game = this.Game; this.Game.UpdateMap(ee); PersonInDestinitionElement pe = new PersonInDestinitionElement(); pe.Control = ge.Control; // pe.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down"))); pe.Turn(direction, resources); pe.Game = this.Game; this.Game.UpdateMap(pe); } if (this.Game.CheckOver()) { // MessageBox.Show("不是一个人的王者,而是团队的荣耀!"); string count = s + ""; MessageBox.Show("您的步数为" + count + ",恭喜进入下一关!"); // MainForm mf = (MainForm)winForm; // mf.map2(); MainForm mf = new MainForm(); mf.Show(); winForm.Close(); } // switch(direction){ // case Direction.LEFT: // newPoint = new Point(oldLocation.X-50,oldLocation.Y); // //this.CurrentPosition = new Position(oldPosition.Row,oldPosition.column-1); // pbx.Location = newPoint; // this.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.left"))); // break; // case Direction.RIGHT: // newPoint = new Point(oldLocation.X+50,oldLocation.Y); // //this.CurrentPosition = new Position(oldPosition.Row,oldPosition.column+1); // pbx.Location = newPoint; // this.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.right"))); // break; // case Direction.UP: // newPoint = new Point(oldLocation.X,oldLocation.Y-50); // //this.CurrentPosition = new Position(oldPosition.Row-1,oldPosition.column); // pbx.Location = newPoint; // this.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.up"))); // break; // case Direction.DOWN: // newPoint = new Point(oldLocation.X,oldLocation.Y+50); // //this.CurrentPosition = new Position(oldPosition.Row+1,oldPosition.column); // pbx.Location = newPoint; // this.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.down"))); // break; }
public static GameElement getElement(int type, System.ComponentModel.ComponentResourceManager resources, Form winform, int row, int column) { PictureBox pbx = new PictureBox(); pbx.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; pbx.Size = new Size(new Point(50, 50)); //element.CurrentPosition = new Sokoban.model.Position(1,1); switch (type) { case 1: DestinitionElement de = new DestinitionElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.cage"))); pbx.Location = new Point(column * 50, row * 50); de.Control = pbx; de.ShowInForm(winform); return(de); case 2: EmptyElement emp = new EmptyElement(); pbx.Location = new Point(column * 50, row * 50); emp.Control = pbx; emp.ShowInForm(winform); return(emp); case 4: WallElement wall = new WallElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.tree"))); pbx.Location = new Point(column * 50, row * 50); wall.Control = pbx; wall.ShowInForm(winform); return(wall); case 8: PersonElement per = new PersonElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.down"))); pbx.Location = new Point(column * 50, row * 50); per.Control = pbx; per.ShowInForm(winform); return(per); case 16: BoxElement box = new BoxElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.sheep"))); pbx.Location = new Point(column * 50, row * 50); box.Control = pbx; box.ShowInForm(winform); return(box); case 32: BoxInDestinitionElement bid = new BoxInDestinitionElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.sheep.cage"))); pbx.Location = new Point(column * 50, row * 50); bid.Control = pbx; bid.ShowInForm(winform); return(bid); case 64: PersonInDestinitionElement pid = new PersonInDestinitionElement(); pbx.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down"))); pbx.Location = new Point(column * 50, row * 50); pid.Control = pbx; pid.ShowInForm(winform); return(pid); case 128: NothingElement not = new NothingElement(); pbx.BackColor = Color.Black; pbx.Location = new Point(column * 50, row * 50); not.Control = pbx; not.ShowInForm(winform); return(not); default: return(null); } }