public void RemoveNeighbour(Puzzel neighbour) { if (Neighbours.Contains(neighbour)) { Neighbours.Remove(neighbour); } }
public void AddNeighbour(Puzzel neighbour) { if (!Neighbours.Contains(neighbour)) { Neighbours.Add(neighbour); } }
public void UnStick(Puzzel puzzel) { var maxGroup = (from item in Puzzles orderby item.Group descending select item.Group).FirstOrDefault(); puzzel.AssignToGroup(maxGroup + 1); }
private void ChangeGroup(Puzzel fromGroup, Puzzel toGroup) { List <Puzzel> group = GetGroup(fromGroup); for (int i = 0; i < group.Count; i++) { group[i].AssignToGroup(toGroup.Group); } }
private List <Puzzel> GetGroup(Puzzel puzzel) { var groupped = (from puzzles in Puzzles where puzzles.Group == puzzel.Group && puzzles.Group >= 0 select puzzles).ToList(); System.Diagnostics.Debug.WriteLine(groupped.Count); return(groupped); }
public void Move(Puzzel puzzel, Point location) { puzzel.Move(location); OnPuzzelChanged(puzzel, puzzel.Location); if (CheckMatrix() == true) { OnGameOver(); } }
private void Align(Puzzel basePuzzel, Puzzel puzzelToAlign) { double horizontal = basePuzzel.Location.X - puzzelToAlign.Location.X; double vertical = basePuzzel.Location.Y - puzzelToAlign.Location.Y; double span = _puzzleSize.Width; //frame if (puzzelToAlign.Location.X < _puzzleSize.Width) { Move(puzzelToAlign, new Point(0, puzzelToAlign.Location.Y)); } if (puzzelToAlign.Location.Y < _puzzleSize.Height) { Move(puzzelToAlign, new Point(puzzelToAlign.Location.X, 0)); } //left if (puzzelToAlign.Location.X > basePuzzel.Location.X - _puzzleSize.Width - span && puzzelToAlign.Location.X < basePuzzel.Location.X - _puzzleSize.Width + span && puzzelToAlign.Location.Y > basePuzzel.Location.Y - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + span) { Move(puzzelToAlign, new Point(basePuzzel.Location.X - _puzzleSize.Width, basePuzzel.Location.Y)); ChangeGroup(puzzelToAlign, basePuzzel); } //right else if (puzzelToAlign.Location.X > basePuzzel.Location.X + _puzzleSize.Width - span && puzzelToAlign.Location.X < basePuzzel.Location.X + _puzzleSize.Width + span && puzzelToAlign.Location.Y > basePuzzel.Location.Y - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + span) { Move(puzzelToAlign, new Point(basePuzzel.Location.X + _puzzleSize.Width, basePuzzel.Location.Y)); ChangeGroup(puzzelToAlign, basePuzzel); } //top else if (puzzelToAlign.Location.X > basePuzzel.Location.X - span && puzzelToAlign.Location.X < basePuzzel.Location.X + span && puzzelToAlign.Location.Y > basePuzzel.Location.Y - _puzzleSize.Height - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y - _puzzleSize.Height + span) { Move(puzzelToAlign, new Point(basePuzzel.Location.X, basePuzzel.Location.Y - _puzzleSize.Height)); ChangeGroup(puzzelToAlign, basePuzzel); } //bottom else if (puzzelToAlign.Location.X > basePuzzel.Location.X - span && puzzelToAlign.Location.X < basePuzzel.Location.X + span && puzzelToAlign.Location.Y > basePuzzel.Location.Y + _puzzleSize.Height - span && puzzelToAlign.Location.Y < basePuzzel.Location.Y + _puzzleSize.Height + span) { Move(puzzelToAlign, new Point(basePuzzel.Location.X, basePuzzel.Location.Y + _puzzleSize.Height)); ChangeGroup(puzzelToAlign, basePuzzel); } else { puzzelToAlign.AssignToGroup(-1); } }
public void MoveGroup(Puzzel puzzel, Point location) { List <Puzzel> groupped = GetGroup(puzzel); Point savedLocation = new Point(puzzel.Location.X, puzzel.Location.Y); for (int i = 0; i < groupped.Count; i++) { if (groupped.Count > 1) { System.Diagnostics.Debug.WriteLine("."); } Double offsetX = (savedLocation.X - groupped[i].Location.X) - (savedLocation.X - groupped[i].Location.X) % 100; Double offsetY = (savedLocation.Y - groupped[i].Location.Y) - (savedLocation.Y - groupped[i].Location.Y) % 100; Move(groupped[i], new Point(location.X - offsetX, location.Y - offsetY)); } }
public void Stick(Puzzel puzzel) { var toStick = (from puzzleToStick in Puzzles where puzzleToStick != puzzel && checkLocation(puzzel.Location, puzzleToStick.Location) orderby Math.Abs(puzzleToStick.Location.X - puzzel.Location.X), Math.Abs(puzzleToStick.Location.Y - puzzel.Location.Y) select puzzleToStick).ToList(); if (toStick.Count > 0) { Align(toStick[0], puzzel); OnPuzzelChanged(puzzel, puzzel.Location); } //align to border else if (puzzel.Location.X < _puzzleSize.Width && puzzel.Location.Y < _puzzleSize.Height) { Align(puzzel, puzzel); OnPuzzelChanged(puzzel, puzzel.Location); } }
public PuzzelChangedEventArgs(Puzzel Puzzel, Point Location) { this.Location = Location; this.Puzzel = Puzzel; }