Esempio n. 1
0
        public bool Misjudgement()
        {
            int BeCount = 0;
            int DeCount = 0;
            int PeCount = 0;

            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    GameElement ge = map[i, j];
                    if (ge.GetType() == typeof(BoxElement))
                    {
                        BeCount++;
                    }
                    else if (ge.GetType() == typeof(DestinitionElement))
                    {
                        DeCount++;
                    }
                    else if (ge.GetType() == typeof(PersonInDestinitionElement))
                    {
                        PeCount++;
                    }
                }
            }
            if (BeCount == DeCount + PeCount)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public override void MoveInForm(System.Windows.Forms.Form winForm, Direction direction, System.ComponentModel.ComponentResourceManager resources)
        {
            GameElement ge = this.Game.GetNeighbor(this, direction);

            if (ge.GetType() == typeof(EmptyElement))
            {
                this.Game.SwapElement(this, ge);
                ge.Game = this.Game;
            }
            else if (ge.GetType() == typeof(DestinitionElement))
            {
                EmptyElement be = new EmptyElement();
                be.Control = this.Control;
                be.Control.BackgroundImage = null;
                be.Game = this.Game;
                this.Game.UpdateMap(be);

                BoxInDestinitionElement bid = new BoxInDestinitionElement();
                bid.Control = ge.Control;
                bid.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.sheep.cage")));
                //set this property for each new operaiton
                bid.Game = this.Game;
                this.Game.UpdateMap(bid);
            }
        }
Esempio n. 3
0
 public bool CheckOver()
 {
     for (int i = 0; i < row; i++)
     {
         for (int j = 0; j < column; j++)
         {
             GameElement ge = map[i, j];
             if (ge.GetType() == typeof(BoxElement) || ge.GetType() == typeof(DestinitionElement))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Esempio n. 4
0
        public override bool CanMove(Direction direction)
        {
            GameElement ge = this.Game.GetNeighbor(this, direction);

            if (ge.GetType() == typeof(WallElement))
            {
                return(false);
            }
            else if (ge.GetType() == typeof(BoxElement))
            {
                return(false);
            }
            else if (ge.GetType() == typeof(BoxInDestinitionElement))
            {
                return(false);
            }
            return(true);
        }
Esempio n. 5
0
        public override void MoveInForm(System.Windows.Forms.Form winForm, Direction direction, System.ComponentModel.ComponentResourceManager resources)
        {
            bool result = CanMove(direction);

            if (!result)
            {
                return;
            }
            GameElement ge = this.Game.GetNeighbor(this, direction);

            if (ge.GetType() == typeof(EmptyElement))
            {
                DestinitionElement de = new DestinitionElement();
                de.Control = this.Control;
                de.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.cage")));
                de.Game = this.Game;
                this.Game.UpdateMap(de);

                BoxElement be = new BoxElement();
                be.Control = ge.Control;
                be.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.sheep")));
                be.Game = this.Game;
                this.Game.UpdateMap(be);
            }
            else if (ge.GetType() == typeof(DestinitionElement))
            {
//				DestinitionElement de = new DestinitionElement();
//				de.Control = this.Control;
//				de.Control.BackgroundImage =  ((System.Drawing.Image)(resources.GetObject("$this.cage")));
//				de.Game = this.Game;
//				this.Game.UpdateMap(de);
//
//				BoxInDestinitionElement be = new BoxInDestinitionElement();
//				be.Control = ge.Control;
//				be.Control.BackgroundImage =  ((System.Drawing.Image)(resources.GetObject("$this.sheep.cage")));
//				de.Game = this.Game;
//				this.Game.UpdateMap(be);

                this.Game.SwapElement(this, ge);
                ge.Game = this.Game;
            }
        }
Esempio n. 6
0
        public override bool CanMove(Direction direction)
        {
            bool pass = true;

            switch (direction)
            {
            case Direction.UP:
                pass = !(this.CurrentPosition.Row < 0);
                break;

            case Direction.DOWN:
                pass = !(this.CurrentPosition.Row > 10);
                break;

            case Direction.LEFT:
                pass = !(this.CurrentPosition.column < 0);
                break;

            case Direction.RIGHT:
                pass = !(this.CurrentPosition.column > 14);
                break;
            }
            GameElement ge = this.Game.GetNeighbor(direction);

            if (ge.GetType() == typeof(WallElement))
            {
                pass = false;
            }
            else if (ge.GetType() == typeof(BoxElement))
            {
                pass = ge.CanMove(direction);
            }
            else if (ge.GetType() == typeof(BoxInDestinitionElement))
            {
                pass = ge.CanMove(direction);
            }
            return(pass);
        }
Esempio n. 7
0
 public PersonInDestinitionElement GetCurrentPersonInCage()
 {
     for (int i = 0; i < row; i++)
     {
         for (int j = 0; j < column; j++)
         {
             GameElement ge = map[i, j];
             if (ge.GetType() == typeof(PersonInDestinitionElement))
             {
                 return((PersonInDestinitionElement)ge);
             }
         }
     }
     return(null);
 }
Esempio n. 8
0
        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;
        }
Esempio n. 9
0
        public override void MoveInForm(System.Windows.Forms.Form winForm, Direction direction, System.ComponentModel.ComponentResourceManager resources)
        {
            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))
            {
                DestinitionElement de = new DestinitionElement();
                de.Control = this.Control;
                de.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.cage")));
                de.Game = this.Game;
                this.Game.UpdateMap(de);

                PersonElement pe = new PersonElement();
                pe.Control = ge.Control;
//				pe.Control.BackgroundImage =  ((System.Drawing.Image)(resources.GetObject("$this.wolf.down")));
                pe.Turn(direction, resources);
                pe.Game = this.Game;
                this.Game.UpdateMap(pe);
            }
            else if (ge.GetType() == typeof(BoxElement))
            {
                ge.MoveInForm(winForm, direction, resources);
                ge.Game = this.Game;
                ge      = this.Game.GetNeighbor(direction);

                DestinitionElement de = new DestinitionElement();
                de.Control = this.Control;
                de.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.cage")));
                de.Game = this.Game;
                this.Game.UpdateMap(de);

                PersonElement pe = new PersonElement();
                pe.Control = ge.Control;
//				pe.Control.BackgroundImage =  ((System.Drawing.Image)(resources.GetObject("$this.wolf.down")));
                pe.Turn(direction, resources);
                pe.Game = this.Game;
                this.Game.UpdateMap(pe);
            }
            else if (ge.GetType() == typeof(DestinitionElement))
            {
                this.Game.SwapElement(this, ge);
                ge.Game = this.Game;
                Turn(direction, resources);
//				DestinitionElement de = new DestinitionElement();
//				de.Control = this.Control;
//				de.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("this.cage")));
//				de.Game = this.Game;
//				this.Game.UpdateMap(de);
//
//				PersonInDestinitionElement pe = new PersonInDestinitionElement();
//				pe.Control = ge.Control;
//				pe.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("this.wolf.down")));
//				pe.Game = this.Game;
//				this.Game.UpdateMap(pe);
            }
            else if (ge.GetType() == typeof(BoxInDestinitionElement))
            {
                result = ge.CanMove(direction);
                if (!result)
                {
                    return;
                }
                ge.MoveInForm(winForm, direction, resources);
                ge      = this.Game.GetNeighbor(direction);
                ge.Game = this.Game;
                this.Game.UpdateMap(ge);

                this.Game.SwapElement(this, ge);
                ge.Game = this.Game;

//				DestinitionElement de = new DestinitionElement();
//				de.Control = this.Control;
//				de.Control.BackgroundImage = null;
//				de.Game = this.Game;
//				this.Game.UpdateMap(de);
//
//				PersonInDestinitionElement pe = new PersonInDestinitionElement();
//				pe.Control = ge.Control;
//				pe.Control.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.wolf.cage.down")));
//				pe.Game = this.Game;
//				this.Game.UpdateMap(pe);
            }

            this.Control.BringToFront();
        }