예제 #1
0
        public PushyGame(string userId)
        {
            Field         = new PushyField();
            Field.Squares = new List <List <PushySquare> >();
            for (int i = 0; i < 10; i++)
            {
                Field.Squares.Add(new List <PushySquare>());
                for (int j = 0; j < 10; j++)
                {
                    if (j == 0 || i == 0 || j == 9 || i == 9)
                    {
                        Field.Squares[i].Add(new PushySquareWall());
                    }
                    else
                    {
                        Field.Squares[i].Add(new PushySquareAir());
                    }
                }
            }
            var fig = new PushyFigure();

            fig.UserId = userId;
            Field.Squares[5][5].ChildSquares.Add(fig);
            Field.Squares[1][1].ChildSquares.Add(new PushySquareHouse());
            Field.Squares[5][7].ChildSquares.Add(new PushySquareBox());
            Field.Squares[6][7].ChildSquares.Add(new PushySquareBox());
        }
예제 #2
0
 public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir)
 {
     if (!(square is PushyFigure))
     {
         return(false);
     }
     return(this.Move(field, dir));
 }
예제 #3
0
        public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir)
        {
            if (this.ChildSquares?.Count > 0)
            {
                var oldSquares = new List <PushySquare>(this.ChildSquares);
                var failed     = oldSquares.Any(s => !s.Entered(field, square, dir));
                if (failed)
                {
                    return(false);
                }
            }

            this.ChildSquares.Add(square);
            return(true);
        }
예제 #4
0
        public PushyPosition GetRelativePos(PushyMoveDirection dir, PushyField field)
        {
            switch (dir)
            {
            case PushyMoveDirection.Up:
                if (X == 0)
                {
                    return(null);
                }
                return(new PushyPosition(X, Y - 1));

            case PushyMoveDirection.Right:
                if (X == field.Width - 1)
                {
                    return(null);
                }
                return(new PushyPosition(X + 1, Y));

            case PushyMoveDirection.Down:
                if (Y == field.Height - 1)
                {
                    return(null);
                }
                return(new PushyPosition(X, Y + 1));

            case PushyMoveDirection.Left:
                if (Y == 0)
                {
                    return(null);
                }
                return(new PushyPosition(X - 1, Y));

            case PushyMoveDirection.Unknown:
            default:
                return(null);
            }
        }
예제 #5
0
        public override bool Move(PushyField field, PushyMoveDirection dir)
        {
            var parentSquare = field.GetParent(this);
            var myCoords     = field.GetSquareCoords(this);
            var relativePos  = myCoords.GetRelativePos(dir, field);

            if (relativePos == null)
            {
                return(false);
            }

            var targetSquare = field.Squares[relativePos.X][relativePos.Y];

            parentSquare.ChildSquares.Remove(this);

            var success = targetSquare.Entered(field, this, dir);

            if (!success)
            {
                return(false);
            }

            return(true);
        }
예제 #6
0
 public override bool CollidesWithFigure(PushyField field, PushyFigure figure)
 {
     return(false);
 }
예제 #7
0
 public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir)
 {
     return(false);
 }
예제 #8
0
        public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir)
        {
            //Todo: Check if won

            return(true);
        }
예제 #9
0
 internal List <PushySquare> GetCollidingChilds(PushyField field, PushyFigure fig)
 {
     return(this.ChildSquares.Where(x => x.CollidesWithFigure(field, fig)).ToList());
 }
예제 #10
0
 public abstract bool CollidesWithFigure(PushyField field, PushyFigure figure);
예제 #11
0
 public abstract bool Move(PushyField field, PushyMoveDirection dir);
예제 #12
0
 public abstract bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir);
예제 #13
0
 public override bool Move(PushyField field, PushyMoveDirection dir)
 {
     return(false);
 }