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()); }
public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir) { if (!(square is PushyFigure)) { return(false); } return(this.Move(field, dir)); }
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); }
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); } }
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); }
public override bool CollidesWithFigure(PushyField field, PushyFigure figure) { return(false); }
public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir) { return(false); }
public override bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir) { //Todo: Check if won return(true); }
internal List <PushySquare> GetCollidingChilds(PushyField field, PushyFigure fig) { return(this.ChildSquares.Where(x => x.CollidesWithFigure(field, fig)).ToList()); }
public abstract bool CollidesWithFigure(PushyField field, PushyFigure figure);
public abstract bool Move(PushyField field, PushyMoveDirection dir);
public abstract bool Entered(PushyField field, PushySquare square, PushyMoveDirection dir);
public override bool Move(PushyField field, PushyMoveDirection dir) { return(false); }