我想用java写一个拼图游戏,可不知道如何下手,希望各位前辈给些意见。

解决方案 »

  1.   

    javaFX 我记得介绍里面有一个介绍拼图游戏的哇  我还记得其中有一个是拼一个老虎
    LZ看看去哇 
      

  2.   

    swing的东西比较多,我的思路就是定义一个棋盘类,设计好大小,每个图作为一个类,每次移动改变类的位置属性,如果所有的类位置和目标类(总体图的位置信息静态类)相同则成功
      

  3.   

    http://www.javafx.com/samples/PuzzlePieces/index.html
    Understanding the Code
    Each of the jigsaw pieces is constructed from a square with four tabs that are either added or subtracted from the square. Each of the tabs is made from an ellipse for the bulb end and a rectangle to join the bulb end to the edge of the square. Two circles are subtracted to round the connection between the square and the bulb.Figure 1: Diagram Showing the Shapes That Are Joined to Form a Jigsaw Piece. 
    Figure 2 shows the code for how to create a single tab for the jigsaw piece.
    Source Code
    ShapeSubtract {
            a: [
                Ellipse {
                    centerX: 139
                    centerY: 0
                    radiusX: 20
                    radiusY: 35
                },
                Rectangle {
                    x: 100
                    y: -25
                    width: 22
                    height: 50
                }
            ]
            b: [
                Circle {
                    centerX: 112.5
                    centerY: -28
                    radius: 12.5
                },
                Circle {
                    centerX: 112.5
                    centerY: 28
                    radius: 12.5
                }
            ]
        }
    Figure 2: Code for Creating the Right Tab of the Jigsaw Shape 
    Taking that code a stage further in Figure 3 is the complete code for how to create a jigsaw piece shape.
    Source Code
            ShapeSubtract {
                    a: [
                        // main rectangle
                        Rectangle {
                            x: -100
                            y: -100
                            width: 200
                            height: 200
                        }
                        // right tab
                        ShapeSubtract {
                            a: [
                                Ellipse {
                                    centerX: 139
                                    centerY: 0
                                    radiusX: 20
                                    radiusY: 35
                                },
                                Rectangle {
                                    x: 100
                                    y: -25
                                    width: 22
                                    height: 50
                                }
                            ]
                            b: [
                                Circle {
                                    centerX: 112.5
                                    centerY: -28
                                    radius: 12.5
                                },
                                Circle {
                                    centerX: 112.5
                                    centerY: 28
                                    radius: 12.5
                                }
                            ]
                        }
                        // bottom tab
                        ShapeSubtract {
                            a: [
                                Ellipse {
                                    centerX: 0
                                    centerY: 139
                                    radiusX: 35
                                    radiusY: 20
                                },
                                Rectangle {
                                    x: -25
                                    y: 100
                                    width: 50
                                    height: 22
                                }
                            ]
                            b: [
                                Circle {
                                    centerX: -28
                                    centerY: 112.5
                                    radius: 12.5
                                },
                                Circle {
                                    centerX: 28
                                    centerY: 112.5
                                    radius: 12.5
                                }
                            ]                    }
                    ]
                    b: [
                        // left tab
                        ShapeSubtract {
                            a: [
                                Ellipse {
                                    centerX: -62
                                    centerY: 0
                                    radiusX: 20
                                    radiusY: 35
                                },
                                Rectangle {
                                    x: -100
                                    y: -25
                                    width: 22
                                    height: 50
                                }
                            ]
                            b: [
                                Circle {
                                    centerX: -87.5
                                    centerY: -28
                                    radius: 12.5
                                },
                                Circle {
                                    centerX: -87.5
                                    centerY: 28
                                    radius: 12.5
                                }
                            ]
                        }
                        // top tab
                        ShapeSubtract {
                            a: [
                                Ellipse {
                                    centerX: 0
                                    centerY: -62
                                    radiusX: 35
                                    radiusY: 20
                                },
                                Rectangle {
                                    x: -25
                                    y: -100
                                    width: 50
                                    height: 25
                                }
                            ]
                            b: [
                                Circle {
                                    centerX: -28
                                    centerY: -87.5
                                    radius: 12.5
                                },
                                Circle {
                                    centerX: 28
                                    centerY: -87.5
                                    radius: 12.5
                                }
                            ]                    }
                    ]
                }Figure 3: Code for Creating Jigsaw Shape 
    After you have created a jigsaw shape, it is simple to take it from there and use it as the clip on an image. From that point all you have to do is add dragging and you have a simple jigsaw game. From this simple beginning, you could easily extend the code to make the jigsaw more complicated by having many smaller pieces and more of them or enabling the user to choose any image to turn into a jigsaw.