首页 > > 详细

Java辅导:CSE11 Puzzle Game调试Java

GUI3x3。Project。

Overview

We have a 3 x 3 puzzle, which gives us 9 puzzle pieces that are movable on the right. They can be dragged anywhere on the canvas, but not off the canvas. On the left, we have a 3 x 3 board. After a puzzle piece is dragged onto its correct location, the puzzle piece is “locked” into the board and is no longer movable.

The reason “locked” is in quotes is because the puzzle piece is actually not locked. We created this illusion by having two different types of Pieces here: PuzzlePiece and BoardPiece. When a PuzzlePiece (movable piece on the right) is dragged onto a BoardPiece (fixed piece on the left), your program will do some verification to see if they match. If so, it’s going to hide the PuzzlePiece and reveal the BoardPiece with the same image as the PuzzlePiece.

So it may seem like the PuzzlePiece is locked in place, but it’s actually a different BoardPiece that’s displayed on the canvas. Now that we know the basic idea/hack behind this game, how do we implement it?

Useful Interfaces

Take advantage of interfaces! We have two different kinds of Piece types here, but they share a lot in common. We’ll implement the Piece interface later in PuzzlePiece and BoardPiece classes.
The Highlightable interface is used to draw borders and highlights around each piece:

1
2
3
4
5
6
import java.awt.Color;

public interface Highlightable #123;
public abstract void showHighlight( Color color );
public abstract void hideHighlight();
#125;

 

The Hideable interface is used to hide and show pieces:

1
2
3
4
public interface Hideable #123;
public abstract void show();
public abstract void hide();
#125;

 

The Piece interface, which extends the two interfaces above and includes a few other methods:

objectdraw.*;
1
2
3
4
5
6
7
8

public interface Piece extends Highlightable, Hideable #123;
public abstract boolean contains(Location point);
public abstract boolean equals(Object o);
public abstract Location getCenter();
public abstract int getId();
public abstract void move(double dx, double dy);
#125;

 

Piece Classes

You will create 2 Piece classes: class BoardPiece and class PuzzlePiece.

Each of these classes will implement the Piece interface. For example:

1
public class BoardPiece⁳⁥‾⁰ ⸼⁳⡣⥬⁡‽⁣ ⁡⁰‾‮‣‼ⸯ⁰☠㬠†‼††‾†♤㭴⁡‾⁦⁵ ‼⁢‼†⁣⁳⁨††⹩⁣䵳ⱥ›‾‍†⁩⁡
⁖⁣⁴⁦⹳㱳⽩㹧ഠ੡†⁉㱡⽧㹯ൢ੪㱥⽣㹴൯ਠ㱩㉳†㵮≳⵴㍯⵲ⴾ∼㹬†㌨㩩†㱤⼠㉲㹯൭ਠ㰰㹴†☠㬠†⁴⁧⁣Ⱐ⁲⁲⁰⁤⁩‼†⹩‾䍣⁲⁣⁴䍰⁨⁥⁩⡦⤠⁴⁰ ⁩†⁥䅲⹩䵧䙧⸨⁐††⁥⁩㝥㍣㕥⁳㌠㡴と⁥⸩㰠⽨㹳ഠ੯㱮㌠⁢㵣≫䜠ⵡ䥭≴㸠䝯⁥䥣㱨⽴㍯㹮ഠੴ㱯㸠⁨ㅥ〠づ⁥ㅦ〠ぴ†⁡⁡⁵⁩⁢⁥⁂⁲⽐⹩⹥⽣⼠䅩㕸ⵥ⽥⹳†⁨⁥⁴⁲ね⁥⁥㡴†⡯⹪⹣⁴〬⸠Ⱐ⁲ㅧ⹨Ɱ†♴㭴⥨⹥㰠⽥㹧൥ਠ㱯㸠䥴⁥⁥⁡⁴※⁳⁢Ɐ†⁣⁴䥡⡣⥫⁥⁩‮†⡥⁲⁴䝡䥴⁳⁣⁩䍴⥨⹩⁧䙨⁧㩬㱡⽣㸮ഩ਼㰯㹩㰾‾㵔≨≵㹣൴੯㱲㹂൯੡⁲⁤⁐⁩㱥㹤ഠ੐⁵⁺⁺⁥⁐⁩⁥㱣㹳൨੯⁵⁤†⁢⁥†⁩⁤⁥⁴㱩㴠≥∺㸼യੰ‾‍ ‼⁰‾‼⁦⁩⁧⁵⁲㱥㹡㱳⁩㵨≴≡㸢ㄾ㰍⼊㹬㱥 ⼠㸠㰠⼠㹯൤੹‾‍ ††††††††‼㱴⽲㸊ഠਠ††††††††††‼⁴㱤㵧≵∢㸾഍ਊ††††††††††††㰼㸾㰼†㴽∢∢㸾䥳⠼㱢‼㴍∊∠㸠☠㬯つ⸾☠㬠㰠⼠㹴⥤㬠㱣⽬㸢㱣⁥⼢㸾㰍⼊㸠ഠਠ††††††‼⁰⁲⁥‾‼㱳⽰㸠ൣ੬⁡⁳⁳‽•⁩㱥⼢㹳൰੡†⁣㱡⽳㹮ൣੴ㱩⽯㹰ൡ੮㰠⽣㹫㱥⽹㹯൲੤㰢㹰♵㬼㰯⽳㹡൮ਾ㰠㹳⁳•⁥㤢‾⁩ ⁡䥮⁡⁳⡳⁡•䤾⁧⤼⹳⁰䥡⁳⁴㤼 †‬䥣⡮⤠ⱬ†⁷⁧⁡⁣‼‾⁰″⹳⁰䤼⠾⤼ ‍††䤠⁴⸠†† ‼⁤䥹 ‍ ⁧⁰⁢※‍‾⁣䉨⽣♬㬠Ⱐ†䉐⼠☯㭵‾Ⰺ†⁰⁳䥬
⁨⁧⁩
䤩†⸠㱡⽮㸠ൣ੨㱡㍧⁥㵨≥䰠≩㹬䱩㰠⽴㍥㸠െੲ㱡㹥⁣⁨⁧⁨⁣⁥⁰䈾‾†⁨
†⁺⁐⹥†䅩Ⱐ⁡⁢⁣⁣ㅴ㠠⁨†Ⱐ⁂⁲⁥⁤⁳⁨†⁡⁥䰠ⱬ†⁷⁨䉬†⁴†⹧⁲†††⁣†⁥⁥⁩†⁲⁢䱯⁥⁴‼‍†㩬㱩⼾㸊ഠਠ㰠㸼㱬†㵩≤⁺≩㹥ൣ੥㰠㹤ഠ੨⁩⁤⁥†㱴㹡൧੥†⁡⁤†⁴⁨⁥㰠㹧൨੬⁩⁧⁨⁴‮†⁨⁩⁤⁥

㰠†㵐≩≥㹳ഠ੮⁴⁨⁩⁧†⁵⁥⁳㱳㹵㰠†㵰≬≴㸠ㅴ㱨⽥㹲㱡⁲⽥㹤㱩⁰㴠∠∾㸍㈊㰠⼠㹩㰾†⼠㸠㰠㵳∨∠㹐㍵㱺⽺㹥㱣⁤⽥㹴㱥⁥㵴≨≯㹭㑥㰠⽰㸠㱩⁣⽯㹮㱴⁤㵨≥≩㹢㕬㱥⽉㸠㱡⽣㹩㱡⁷㵨≡≥㹣㙥㰠⼨㸺㰠⁥⼠㹖㱩⁥㴦≲∻㹳㜠㱣⽯㹮㱳†⽭㹥㱴⽨㸮ഠ੣⁴⁡⁩⁳

†⁥㱴⽨㸠൩੮†⁂⁡⁲⁤⁐⁩⁥⁣⁥†㱲⁵㵡∠≬㹥ഠ੭⁲⁥†⁧⁩⁣‮†⁉㱦㹵㰠⁧㴠≴≰㹵㱺⁴㵥≯∠㹤㱯⼻㹮⁴㰠⁨㴠≳≩㹳㱩⽣㹢⁹㰠†㵩≮≵㹺㱥⽣㹬㱳㵯∠≲㹤㱣⽥㸠⁴䥥䕹䌠䕧䕬䍫䱤†㵩㰠㵬≬≹㹯㍵㰠⽡㹨㭥†㱰⁲㴠≡∦㹲⽳⽱⁵††⁲†⁧㱵⽺㹩㱥⽣㸠㱹⁲⼠㹣㱵 㵥≐∠㹦㱡⁰㵴≬≮㸠㱲⽤㹥‮㰠⁨㴠≡≧㸠㱨⽥㹳†㱡†㵲≥≫㸺㱥⽡㸠⁰㱡⁧㵰≯≲㹥㱥⼠㹯⁲䥩䕳䌬䔠䕡⁩㵮⁧㰠⁡㵥∠∠㹯㍦㰠⽴㹵㭺⁺㱬⁣㵡≲≩㹮⽧⼠⁴⁡⁉⁴⁴㱐⽵㹐㱩⽥㹳㰠⁴⽨㹩㱮‰㴰∠≬㹳㰠⁲㵴≨≲㸠㱂⽯㹩⁥㱣⁨㴠≣∦㹬㱨⽥㹮⁴㰠㵥≤∠㹩㰠⽂㹐⁩㱥⁗㵥∠≬㹬㱨⽥㹧†䰠䕩䅨䍥䥴䝥⁲㴠⁴㱨㵦∠≺㹺㉬づ㱐⽩㹩㭳†㱣⁩㵮∠≸㸠⼵⼰⁰ⁱ⁲⁩㰾⼍㸠㰼⼯㸊㰠†⼼㹬㱩†㵥≱∨㸩㰠㵴≷≳㸠㱡⽬㹲†㱥㵥≳≺㹺㱥⼠㹨†㱷⁴㵡≲≩㹮㱢⽯㹧⁲㱩†㵩≳≹㸠㱣⽫㹴⁨䱩䕱䘠䙉䔠‰㴠‭㰠⁥㵧≮≥㹡㍣㕨㔠㱰⽩㸼㬯⁰㰾†㴾∍≩㸾⼍⼊†⁧
⁴†⁥㱥⼠㹦㰠⽴㹩㱥‮⼼㸯㱰†㵩∾∠㸠㰼 㵰∾≥㹲㱲⽮㹥†㱣⁲㵨≥∼㸯㰠⼠㸾‍㰊‼㴠∠≶㹥㰠⽂㹐⁩㱥⁨㵤≯≧㸠㱣⽥㹲⁤䉐䅥䑥䴠䅡䝥䤠⁥㵤‮㰠⁷㵨≡≡㹤㉤㔠㱳⽯㹭㭰㱥⁥㵤∠≥㹤⼠⽩††⁥†㰠⽐㹥㱐⽩㸠㱗⁡⽲㹥㰠⁧㵥≴≴㹨㱩⁥㴠≲∠㹣㱡⽮㹯⁲㱥⁥㵣≥≩㹮㱣⽥㹡⁹㰮⁲㵬≬≳㸠㱥⽳㹰㱡㴠≐≥㹣㰠⽎㹴⁨䉡䄠䑨䴠䅉䜠䥩⁵㵺⁺㱬⁣㵎≏≣㹩㑡ぴ㱥⽤㹨㬠⁩㱴㵲≲≸㸠⽢⽵⁴⁴⁵ⁱ⁰㱩⽭㸼㰯⽰㹰㰾†⽡㹶㱯⁳㵡≧≵㹭㱢㴬∠∠㹣㰠⽍㹕⁍㱟⁉㵣≯∠㹉㱣⽡㹍⁁㱘 㵅≃∮㸠㱷⽥㹤†㱴⁥㴠≡≤㹥㱷⽥㸠⁤䤠䑍䕁䱟䕎䝍䡏⁆㵟⁐㱉†㵨∻≩㹣ㅨ〠ぴ㱡⽫㹡㭲⁥㰠⁨㵳≥≺㹥⽲⽯‭⁤⁩‮‍㱯⽯㸠㱎⽯㹵㰠⽵㹬㱤⼠㹡ൢ੬⁥†⁴†⁳⁥⁥†⁡㰠⽴㸠ൂ੯⁡⁲⁤⁐⁩⁥⁣⁥㱳⼠㹤ഠ੐⁵⁺⁺㱥⽐㸠൯੮㰠⽹㹡൮੶㱡⽳㹷㱥⼠㹲൥ਠ㱮㹴☠㭥㰠⽴㹥൲੥㰠㹥䉴⁉⁴⁲
⁡㰠⽮㹥൤ੳ㰠㹯㰠†㵨≥⁥≡㹮൤ਠ㱴㹧൩੣†⁦†㱶㹩൮੧†⁴⁨⁥†⁐⁩⁥㱣㸮ഠ੔⁡⁥†⁡†⁢⁲⁥⁡†㱢㵵∠≤㸮ഠ਺
‼ ⁰‾‍ ‼⁨″†⁩㱤㹲㱡⁧㵬≥≥㸢ㄾ㱄⽲㹮㱧⁵⽺㹺㱬⽥㹣൥਼ ⁨″‾‍ ‼⁰‾⁂⁹†㱐⽁㸠൹੯⁵†⁳⁨⁵⁤†⁢⁥†㱰⁴㵭≩∠㹷൩ੴ⁨†⁍⁵⁳⁥⁐⁲⁥㱳㸬㰠⁵㵧∨≮㹤㵮⁍䉯䅳䑒䵬䅥䝳䥥†⭔⁨䤠䑬䕯䱩䕣䝩䠠⁳⩴⁩⡬†╴⁨䤠䕳䍡䕭䕙䌠䱡⥮㱴⼠㹥㱥⁡⼠㹲㱥⽦㹮ൣ੥†⁴†⁡⁳⁴⁐⁩㱴⼠㹤ഠ੦⁩⁤†⁴⁨⁥†㱤⽩㹥൲੥⁣⁥†㱢⽥㸠൬੡㱳⽴㸠ൡ੮㱤⼠㹴㰠⽰㹩൮ੴ㰮㹙♯㬠㱮⽥㹤ഠੴ㱯㹤㱮⽥㹡൤੤㱩㹩㱯⁩㵲≥⁴≫㹥൥ੰ㰠㸠൯੦†⁷⁨⁩㱣㹺൬੥⁐⁩⁥⁣⁥†⁩⁳㰠㹩൮੧†⁧⁲⁡⁢⁢⁥⁤‮‼ ⁰㰾‼㴠≣≳㹯ഠ੢⁹†⁰⁩⁧†⁴⁨㱲㹨㰠⁐㵡≲≨㹯ㅬ㱤⽩㹬㱬⁨⽥㸠㱐⽵㹥൐੩⁥⁣⁥⁳†⁡⁤†⁦⁩㱤⼠㹩ൣ੨†⁐⁵⁺⁺⁥⁐⁩⁥⁣⁥㰠㴠≴≯㹩൮ੴ‮‼ ⁰‾‍ ‼⁨″†⁩㱤㹥㱲㵺≬≣㹥‾㵖⁥䉲䅦䑩䵧䄠䝵䥺⁐⭩⁥䥥䐼䔯䰳䔾䜊䡰‾⩈⡭…⽨⁥䥬䕩䍰䔻䕥⥯⹵㱬⽤㸠㱢⁣⽨㹥㱣⽫㸠൩੦†⁴⁨⁥†⁰⁵⁺⁺⁥†㱰⽩㹥ഠ੨⁡⁳†⁢⁥⁥†㱰⽬㹥൤ਠ
⁴㰠⽷㹳൴੩㱬⽬㹧൩੮㱧⼩㹥㰠⽣㹲൲੥㱣㸠♳㭯㱮⼠㹨൥ਠ㱢㹡⁥⁔⁲ⁱ※㰠⽰㹡ൣ੥㰬㹡㱮ⁱ㴠≬⁳≩㹴ഠਨ㱈㹩൴ਠ⁩⁳†⁎㱏㹯൮੍⁵⁳⁥⁄⁲⁡⁧㰨㸮഼ਯ⁰‾‍ ‼⁰‾⁂⁵⁴†⁉㰦ⁱ㴠≷≵㸠൴੨⁲⁵⁧⁨†⁨⁷†⁴㰠㹩㱦⁰㴠≰∠㹨ㅡ㱳⼠㸠㱰⁣⽥㹤㰠⽣㹥ൣੴ⁹‮†⁒⁥⁥⁢⁥⁲㰠⽭㹹ഠ੷⁲⁤⁳†⁡⁧‬†⁷⁥㰠⁩㵴≨≮㹴൥ੲ†⁦†⁴⁨⁥†⁐⁵⁺⁺㱬㹥㱣†㵮∠∠㹢†㴵‰䱥䕬䙳䙱䕡⁥⬠⁩䱥䔠䅴䍥䥲䝯⁦⨠⁴⡨†╂䥲䕤䍐䕩䔬䍥䱣⁡⭮†㱳⁨㵺≬∠㹩ㅳ㰠⼦㹯⤻⁣⭯䥡䑩䕮䱤䔦䝤䡵⨻†⡩†╴⁨䤠䕂䍯䕡䕩䍥䰨⥴㱨⽩㹥㱣⁩⽳㸠㱡⽬㹤൹ਠ⁤⁥†⁩†⁣⁴㱡⽩㸨ഩ਩‮†⁈⁥⁲⁥‬†㱴⽨㹭൥ੴ⁨⁤⁳㰠⽹㹱൵੯㰻⽶㹬൥੭㱥⽮㸠㱂⽯㹲൤੐㱩㹣♥㬠㱐⽵㹺൬੥㱐㹥㱣⽯㹥ഠ੩㱮㹨㱡㴠≵⁴∠㹴൯ਠ㱧㹥ഠ੣⁥⁴⁥㱲㹨൥ਠ⁧⁲⁡⁢⁢⁥⁤†㱰㹺൬੥†⁰⁩⁥⁣⁥†⁡⁤†⁣㱡†㵩≮∠㹥൶੥⁲⁹†⁂⁡⁲⁤⁐⁩⁥⁣㱥㸠㱡⁰㵷≥≥㸠ㅡ㱢⽬㸠㱦⁤⼠㹡㰠⽂㹤൐੩⁥⁣⁥†⁴⁨⁡⁴†⁣㱴⽡㹳ഠੴ⁨⁥†⁣⁥⁴⁥⁲†⁦㰠⁥㵢≥≺㹺൬੥†⁰⁩⁥⁣⁥†⁁⁎⁄†⁴㱨㹡㱲⁵㵡≴≧㸠⁄㵳
䱥䕮䄠䍣䥡䜠⁧⩯†⡡⁥⽡⁤䥡䕮䍤䔠䕱⁣⭫…㱲※㴠≐≁㹧ㅡ㱩⽮㹥⤠…⭬⁤䥵䑯䔻䱯䕣䝩䡧…⩲⁤⡱⼻†䥳䔠䍤䕯䕢⥩⹮㱧⼠㹧㱲⁢⽥㹤㰠⽰㹬൥ਠ⁰⁩⁥⁣⁥†⁡⁤†⁳⁨㱯⽷㹧ഠੴ⁨⁥†⁂⁡⁲⁤㱐⽩㹥ഠ੡⁳†⁤⁥㱳⽣㸠൩੮㰠⽴㹥൲੶㱩⽥㸦㱲⽳㹵൯਻㱴㹦♯㬠㱴⽯㹳൨੯㱷㹧⁨⁧⁧⁴⁥⁣⁴⁲⁳䥴⁲⁵†⹤††⁣⁲⁰ †•♣㬾⁥⁦†⁴⁨‼⹥㱲⽥㹨൥੬㱬㹰䈻⁡†⁦⁲⁡ⱨ⁥⁩†⁰⁩⁦⁳⁥⁡♹㭯⁩ⅳ☠㭧†⁴⁡㵮㍴㕨㕥⁲⁲⁹㴮†⁳⁡⁷䉯⹴†䥲⁰†⁨†⁥⁡㕳㔠⁢ⁱ⸦⁲䡤※⁩†⁨†ⱱ⁵⁄⁦‰‸†⁵⁥⠠⁳⁩⁩⁥⁹⁥⁣⁵⥥⸠㱩⽳㹤൯੮㱥㹡⁲♥㭥⁥⁩⁨⁡⁹⹥⁳⁁⁨䉥†⁣⸬†⁵†††䥧†⁩⁳䱵†⁐⁥䈠⹹†⁳⁥⁰‹⁥⁳⁤†⁥⁩†⁳䉡⹨′⁤⁩ 䥨‼⁣⁩⁹䱯⁥⁹⁳䈠⁥⁩ⸯ⁰䔾⁰䉲⁴䤻䐠⁣⁣⁡ ⁴⁡⁡⁵⹪㱡⽶㸠഼ਯ㱣㹤䙥 ⁲Ⱳ†⁺⁧⁥⁰⁨††⁡⸼⁰‾⁤⁧†⁶‮⁡⁷⠾⤼ ‍䱵††䑴䍥⹴⁨‵⁴⁩⁵⁩䥥䝡⁲⁢†⁹‮な⁡⁳㡯⹵⁲†⁳†⁲⁲⁴ⁱ⁴⁳⁧♴㬍‼⁔⹮•䤾⁵Ⱪ⁨‼⁔⁵⁵‬⁧†ⱡ⁨‍⁥‼⁴⸱‱⁩♰/code>

You may turn in your programming assignment as many times as you like. The last submission you turn in before the deadline is the one that we will collect.

Verify

To verify a previously turned in assignment,

gt; cse11verify pa5 

If you are unsure your program has been turned in, use the verify command. We will not take any late files you forgot to turn in. Verify will help you check which files you have successfully submitted. It is your responsibility to make sure you properly turned in your assignment.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!