コード例 #1
0
        /// <summary>
        /// Metoda rozstrzygająca czy puzzle pasują do siebie oraz czy są na tyle blisko by je scalić/złączyć
        /// </summary>
        /// <param name="currentPiece">Aktualny puzzel</param>
        /// <param name="adjacentPiece">Sąsiedni puzzel</param>
        /// <returns>True - jeśli puzzle pasują do siebie, False - jeśli nie pasują, bądź są za daleko od siebie</returns>
        public bool DetermineIfMergePieces(IPuzzlePiece currentPiece, IPuzzlePiece adjacentPiece)
        {
            // jeżeli obrót jest różny od 0 to nie można scalić dwóch kawałków
            if (currentPiece.Rotation != 0 || adjacentPiece.Rotation != 0)
            {
                return(false);
            }

            if (adjacentPiece.ClusterId != currentPiece.ClusterId)
            {
                double topPositionDifference  = Canvas.GetTop(currentPiece.PieceImage) - Canvas.GetTop(adjacentPiece.PieceImage);
                double leftPositionDifference = Canvas.GetLeft(currentPiece.PieceImage) - Canvas.GetLeft(adjacentPiece.PieceImage);

                // Sklejanie kawałków które przykładane są z lewej bądź prawej strony
                if (currentPiece.Location.Y == adjacentPiece.Location.Y && Math.Abs(topPositionDifference) <= PuzzleSettings.SNAP_TOLERANCE)
                {
                    if ((currentPiece.Location.X + 1 == adjacentPiece.Location.X && Math.Abs(leftPositionDifference + currentPiece.Width) <= PuzzleSettings.SNAP_TOLERANCE) ||
                        (currentPiece.Location.X - 1 == adjacentPiece.Location.X && Math.Abs(leftPositionDifference - currentPiece.Width) <= PuzzleSettings.SNAP_TOLERANCE))
                    {
                        return(true);
                    }
                }
                // Sklejanie kawałków które przykładane są z góry bądź z dołu
                else if (currentPiece.Location.X == adjacentPiece.Location.X && Math.Abs(leftPositionDifference) <= PuzzleSettings.SNAP_TOLERANCE)
                {
                    if ((currentPiece.Location.Y - 1 == adjacentPiece.Location.Y && Math.Abs(topPositionDifference - currentPiece.Height) <= PuzzleSettings.SNAP_TOLERANCE) ||
                        (currentPiece.Location.Y + 1 == adjacentPiece.Location.Y && Math.Abs(topPositionDifference + currentPiece.Height) <= PuzzleSettings.SNAP_TOLERANCE))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Metoda dokonująca inicjalizacji pojedynczego kawałka puzzli
        /// </summary>
        /// <param name="piece">Kawałek puzzli</param>
        private void InitPiece(IPuzzlePiece piece)
        {
            Image pieceImage = new Image
            {
                Source = piece.Picture,
                Width  = piece.Width,
                Height = piece.Height,
                Name   = "p" + piece.ID
            };

            pieceImage.FocusVisualStyle = null;

            pieceImage.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(PieceCluster_MouseLeftButtonDown));
            pieceImage.AddHandler(MouseRightButtonDownEvent, new MouseButtonEventHandler(PieceCluster_MouseRightButtonDown));
            pieceImage.AddHandler(MouseRightButtonUpEvent, new MouseButtonEventHandler(PieceCluster_MouseRightButtonUp));
            pieceImage.AddHandler(MouseMoveEvent, new MouseEventHandler(PieceCluster_MouseMove));
            pieceImage.AddHandler(MouseUpEvent, new MouseButtonEventHandler(PieceCluster_MouseUp));
            pieceImage.AddHandler(MouseWheelEvent, new MouseWheelEventHandler(PieceCluster_MouseWheel));
            pieceImage.AddHandler(KeyDownEvent, new KeyEventHandler(PieceCluster_KeyDown));

            canvasRoot.Children.Add(pieceImage);
            piece.PieceImage = pieceImage;

            Canvas.SetLeft(pieceImage, _random.Next(0, (int)(mainGrid.ActualWidth - pieceImage.Width - 50)));
            Canvas.SetTop(pieceImage, _random.Next(0, (int)(mainGrid.ActualHeight - pieceImage.Height - 50)));
        }
コード例 #3
0
 protected override IRequest InternalToTransferCodeBase(IPuzzlePiece root, ITree<IPuzzlePiece> matchtree, Dictionary<string, object> bindings)
 {
     ILocation loca = TilingUtils.MatchLocation (matchtree.ChildAt(0x00).ChildAt(0x00).Data);
     ILocation locb = TilingUtils.MatchLocation (matchtree.ChildAt(0x00).ChildAt(0x01).Data);
     DateTime dt = bindings.ValueOrDefault<string,object,DateTime>("time");
     string als = bindings.ValueOrDefault<string,object,string>("airlinecode");
     string scs = bindings.ValueOrDefault<string,object,string>("classname");
     Airline al = null;
     SeatClass sc = null;
     if(als != null) {
         al = new Airline (als);
     }
     if(scs != null) {
         sc = new SeatClass (scs);
     }
     if (loca is Country && locb is Country) {
         return new RequestGetFlights ((Country)loca, (Country)locb, dt, al, sc);
     } else if (loca is City && locb is City) {
         return new RequestGetFlights ((City)loca, (City)locb, dt, al, sc);
     } else if (loca is Airport && locb is Airport) {
         return new RequestGetFlights ((Airport)loca, (Airport)locb, dt, al, sc);
     } else {
         return null;
     }
 }
コード例 #4
0
 public IXmlRequest ToTransferCode(IPuzzlePiece root)
 {
     ITree<IPuzzlePiece> tmp;
     Tree<TypeBind>.ConjunctiveTreeSwapMatchPredicate(this.pattern,0x00,root,TypeBind.Match,out tmp);
     Dictionary<string,object> bindings = new Dictionary<string, object>();
     Tree<TypeBind>.ConjunctiveTreeNonSwapMatchPredicate(this.pattern,0x00,root,(x,y,z) => TypeBind.MatchAndBind(x,y,z,bindings));
     return InternalToTransferCode(root, bindings);
 }
コード例 #5
0
 public IRequest Tile(IPuzzlePiece ipp)
 {
     foreach(ITilePattern tp in patterns) {
         if(tp.Match(ipp)) {
             return tp.ToTransferCode(ipp);
         }
     }
     return null;
 }
コード例 #6
0
 protected override IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     string ftc = (string) bindings["flighttemplatecode"];
     string sac = (string) bindings["startcode"];
     string soc = (string) bindings["stopcode"];
     string apc = (string) bindings["airplanecode"];
     int distance = (int) bindings["distance"];
     DateTime sat = (DateTime) bindings["starttime"];
     DateTime sot = (DateTime) bindings["stoptime"];
     return new RequestAddFlight(new Flight(new FlightTemplate(ftc),sat,sot,new Airport(sac),new Airport(soc),new Airplane(apc),distance));
 }
コード例 #7
0
 public IPuzzlePiece[] Resolve(IPuzzlePiece query)
 {
     IRequest ixq = Tile((RunPiece) query);
     if(ixq == null) {
         return new IPuzzlePiece[] {new SucceedFailPiece("No template")};
     }
     try {
         return ixq.execute().ToPuzzlePieces().ToArray();
     }
     catch(Exception e) {
         return new IPuzzlePiece[] {new SucceedFailPiece(e)};
     }
 }
コード例 #8
0
        /// <summary>
        /// Metoda obracająca pojedynczy puzzel o losowy kąt (0, 90, 180, 270)
        /// </summary>
        /// <param name="pieceToRotate">Kawałek puzzli do obracania</param>
        public void RotatePieceRandom(IPuzzlePiece pieceToRotate)
        {
            Matrix matrix = pieceToRotate.PieceImage.RenderTransform.Value;

            int[] degrees  = { 0, 90, 180, 270 };
            int   rotation = degrees[_random.Next(0, degrees.Length)];

            double centerX = pieceToRotate.Width / 2;
            double centerY = pieceToRotate.Height / 2;

            pieceToRotate.Rotation = rotation;
            matrix.RotateAtPrepend(rotation, centerX, centerY);

            MatrixTransform matrixTransform = new MatrixTransform(matrix);

            pieceToRotate.PieceImage.RenderTransform = matrixTransform;
        }
コード例 #9
0
 protected override IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     List<Seat> seats = new List<Seat>();
     int n = root.NumberOfChildren;
     Dictionary<string,object> bind = new Dictionary<string,object>();
     for(int i = 0x01; i < n; i++) {
         if(Tree<TypeBind>.ConjunctiveTreeNonSwapMatchPredicate(bindseattree,0x00,root[i],(x,y,z) => TypeBind.MatchBind(x,y,z,bind),TypeBind.GetOptional)) {
            //(bindseat.MatchBind(i,root[i],bind))) {
             //if(bind["number"] != null) {
             int m = (int) bind["number"];
             SeatClass sc = new SeatClass((string) bind["name"]);
             seats.Add(new Seat(sc,m));
             //}
             bind.Clear();
         }
     }
     return new RequestAddAirplane(new Airplane((string) bindings["airplanetype"],seats,(string) bindings["airplanecode"]));
 }
コード例 #10
0
 public virtual void MatchesConstraintsParent(IPuzzlePiece piece)
 {
 }
コード例 #11
0
 protected override IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     return new RequestAddCity(new City((string) bindings["cityname"],new Country((string) bindings["countryname"])));
 }
コード例 #12
0
 public virtual void MatchesConstraintsChildren(int index, IPuzzlePiece piece)
 {
     if (!ExtensionMethods.IsTypeColorMatch (this.TypeColorArguments [index], piece.TypeColors)) {
         throw new ArgumentException(string.Format("The given piece doesn't match with it's parent: {0} versus {1}",piece.TypeColors,this.TypeColorArguments[index]));
     }
 }
コード例 #13
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public static bool MatchAndBind(TypeBind tb, int index, IPuzzlePiece ipp, Dictionary<string,object> tobind)
 {
     if(Match(tb,index,ipp)) {
         if(tb.bindingtable != null && tb.bindingtable.Count > 0x00) {
             if(!(ipp is IKeyValueTablePuzzlePiece<string,object>)) {
                 return false;
             }
             KeyValueTable<string,object> conv = ((IKeyValueTablePuzzlePiece<string,object>) ipp).Table;
             foreach(KeyValuePair<string,string> entry in tb.bindingtable) {
                 Console.WriteLine("Bind key {0} of {1}",entry.Key,ipp);
                 try {
                     tobind.Add(entry.Value,conv[entry.Key]);
                 }
                 catch {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
コード例 #14
0
ファイル: SketchPad.cs プロジェクト: KommuSoft/CplKul2012
 public void MatchesConstraintsChildren(int index, IPuzzlePiece piece)
 {
 }
コード例 #15
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public static bool Match(TypeBind tb, int index, IPuzzlePiece ipp)
 {
     return (ipp != null && (tb.index == -0x01 || tb.index == index) && ipp.Match(tb));
 }
コード例 #16
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public bool Match(IPuzzlePiece ipp, int index)
 {
     return Match(this,index,ipp);
 }
コード例 #17
0
ファイル: SketchPad.cs プロジェクト: KommuSoft/CplKul2012
 private void AddGap(Gdk.EventButton evnt, IPuzzlePiece source)
 {
     int index;
     IPuzzlePiece ipp = this.rootpiece.GetPuzzleGap (this.subcontext, new PointD (evnt.X - Margin, evnt.Y - Margin), out index);
     if (ipp != null) {
         try {
             ipp [index] = source;
         } catch (Exception e) {
             ExtensionMethods.ShowException (e);
         }
     }
 }
コード例 #18
0
ファイル: SketchPad.cs プロジェクト: KommuSoft/CplKul2012
 protected override bool OnButtonPressEvent(Gdk.EventButton evnt)
 {
     PointD p = new PointD(evnt.X,evnt.Y);
     IPuzzlePiece ipp;
     switch (this.Tool) {
     case SketchPadTool.CreateNew:
         if (this.injectionPiece != null && this.rootpiece != null) {
             this.AddGap(evnt,(IPuzzlePiece)this.injectionPiece.Invoke (emptyArgs));
         }
         break;
     case SketchPadTool.Link :
         if(this.linkpiece == null) {
             this.linkpiece = this.GetPuzzlePiece(p);
         }
         else {
             this.AddGap(evnt,new LinkPiece(this.linkpiece));
             this.linkpiece = null;
         }
         break;
     case SketchPadTool.Remove :
         ipp = this.GetPuzzlePiece(p);
         if(ipp != null) {
             if(ipp.PieceParent != null) {
                 ipp.Kill();
                 ipp.PieceParent[ipp.Index] = null;
             }
         }
         break;
     case SketchPadTool.Modify :
         ipp = this.GetPuzzlePiece(p);
         if(ipp != null) {
             if(ipp is IKeyValueTablePuzzlePiece<string,object>) {
                 KeyValueTableEditor<string,object>.RunDialog((ipp as IKeyValueTablePuzzlePiece<string,object>).Table);
             }
             else {
                 ExtensionMethods.ShowException("Cannot modify: the selected piece doesn't contain any information!");
             }
             ipp.InvalidateSizeCache();
         }
         break;
     }
     this.QueueDraw ();
     return base.OnButtonPressEvent (evnt);
 }
コード例 #19
0
 protected virtual IRequest InternalToTransferCode(IPuzzlePiece root)
 {
     return null;
 }
コード例 #20
0
 protected virtual IRequest InternalToTransferCodeBase(IPuzzlePiece root, ITree<IPuzzlePiece> sortedtree, Dictionary<string, object> bindings)
 {
     return InternalToTransferCode(root,bindings);
 }
コード例 #21
0
 protected virtual IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     return InternalToTransferCode(root);
 }
コード例 #22
0
 public IRequest ToTransferCode(IPuzzlePiece root)
 {
     return TilingUtils.MatchBindExecute (this.pattern, root, this.InternalToTransferCodeBase);
 }
コード例 #23
0
 public bool Match(IPuzzlePiece root)
 {
     ITree<IPuzzlePiece> tmp;
     bool res = Tree<TypeBind>.ConjunctiveTreeSwapMatchPredicate(this.pattern,0x00,root,TypeBind.Match,TypeBind.GetOptional,out tmp);
     return res;
 }
コード例 #24
0
 protected void SetArgumentSize()
 {
     int nmin = Math.Min(this.arguments.Length,this.NumberOfArguments);
     IPuzzlePiece[] newarguments = new IPuzzlePiece[this.NumberOfArguments];
     Rectangle[] newsubpieces = new Rectangle[this.NumberOfArguments];
     for(int i = 0x00; i < nmin; i++) {
         newarguments[i] = this.arguments[i];
     }
     for(int i = nmin; i < this.arguments.Length; i++) {
         this[i] = null;
     }
     this.arguments = newarguments;
     this.subpieces = newsubpieces;
     this.PerformBoundsChanged(this,EventArgs.Empty);
 }
コード例 #25
0
 protected override IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     return new RequestAddAirline(new Airline((string) bindings["airlinename"],(string) bindings["airlinecode"]));
 }
コード例 #26
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public static bool MatchBind(TypeBind tb, int index, IPuzzlePiece ipp, Dictionary<string,object> tobind)
 {
     if(Match(tb,index,ipp)) {
         return ipp.MatchBind(tb,tobind);
     }
     return false;
 }
コード例 #27
0
 public bool Match(IPuzzlePiece root)
 {
     ITree<IPuzzlePiece> tmp;
     return Tree<TypeBind>.ConjunctiveTreeSwapMatchPredicate(this.pattern,0x00,root,TypeBind.Match,out tmp);
 }
コード例 #28
0
 public UnableToBindException(string key, IPuzzlePiece piece)
 {
     this.key = key;
     this.piece = piece;
 }
コード例 #29
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public bool MatchBind(int index, IPuzzlePiece ipp, Dictionary<string,object> tobind)
 {
     return TypeBind.MatchBind(this,index,ipp,tobind);
 }
コード例 #30
0
ファイル: TypeBind.cs プロジェクト: KommuSoft/CplKul2012
 public static bool Match(TypeBind tb, int index, IPuzzlePiece ipp)
 {
     return (ipp != null && tb.type.IsAssignableFrom(ipp.GetType()) && (tb.index == -0x01 || tb.index == index));
 }
コード例 #31
0
 protected abstract IXmlRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings);
コード例 #32
0
 protected override IRequest InternalToTransferCode(IPuzzlePiece root, Dictionary<string, object> bindings)
 {
     return new RequestAddBooking(new Booking(new Passenger((string) bindings["passengername"]),
                                              new Flight(new FlightTemplate((string) bindings["flighttemplatecode"]),
                (DateTime) bindings["time"]),new Seat(new SeatClass((string) bindings["classname"]),(int) bindings["seatnumber"])));
 }
コード例 #33
0
ファイル: SketchPad.cs プロジェクト: KommuSoft/CplKul2012
 private QueryAnswerLocations(RunPiece query, PointD offset, IPuzzlePiece[] answer, PointD[] locations)
 {
     this.query = query;
     this.offset = offset;
     this.answers = answer;
     this.locations = locations;
     this.registerChildren();
 }