diff --git a/FishGame/.project b/FishGame/.project index c54f1d8..bc30b95 100644 --- a/FishGame/.project +++ b/FishGame/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1776587835694 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/FishGame/bin/com/mypro/base/graphics/Bitmap.class b/FishGame/bin/com/mypro/base/graphics/Bitmap.class index 93488c9..77b0b90 100644 Binary files a/FishGame/bin/com/mypro/base/graphics/Bitmap.class and b/FishGame/bin/com/mypro/base/graphics/Bitmap.class differ diff --git a/FishGame/bin/com/mypro/base/graphics/Canvas.class b/FishGame/bin/com/mypro/base/graphics/Canvas.class index 49a1758..9c8af2b 100644 Binary files a/FishGame/bin/com/mypro/base/graphics/Canvas.class and b/FishGame/bin/com/mypro/base/graphics/Canvas.class differ diff --git a/FishGame/bin/com/mypro/base/graphics/Matrix.class b/FishGame/bin/com/mypro/base/graphics/Matrix.class index dc2fd27..cf1e9fd 100644 Binary files a/FishGame/bin/com/mypro/base/graphics/Matrix.class and b/FishGame/bin/com/mypro/base/graphics/Matrix.class differ diff --git a/FishGame/bin/com/mypro/base/graphics/Paint.class b/FishGame/bin/com/mypro/base/graphics/Paint.class index 58edecf..9a24c50 100644 Binary files a/FishGame/bin/com/mypro/base/graphics/Paint.class and b/FishGame/bin/com/mypro/base/graphics/Paint.class differ diff --git a/FishGame/bin/com/mypro/base/tools/Log.class b/FishGame/bin/com/mypro/base/tools/Log.class index 3230347..6113e42 100644 Binary files a/FishGame/bin/com/mypro/base/tools/Log.class and b/FishGame/bin/com/mypro/base/tools/Log.class differ diff --git a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$1.class b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$1.class index e905583..7d9426d 100644 Binary files a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$1.class and b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$1.class differ diff --git a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$2.class b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$2.class index 837aff6..06e9f4e 100644 Binary files a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$2.class and b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$2.class differ diff --git a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$3.class b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$3.class new file mode 100644 index 0000000..7bcbbf3 Binary files /dev/null and b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet$3.class differ diff --git a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet.class b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet.class index 88a9e67..b694684 100644 Binary files a/FishGame/bin/com/mypro/basecomponet/AwtMainComponet.class and b/FishGame/bin/com/mypro/basecomponet/AwtMainComponet.class differ diff --git a/FishGame/bin/com/mypro/basecomponet/JMatrix.class b/FishGame/bin/com/mypro/basecomponet/JMatrix.class index 81c1ac1..562dbd0 100644 Binary files a/FishGame/bin/com/mypro/basecomponet/JMatrix.class and b/FishGame/bin/com/mypro/basecomponet/JMatrix.class differ diff --git a/FishGame/bin/com/mypro/constant/Constant.class b/FishGame/bin/com/mypro/constant/Constant.class index 25bbcd8..cc226c7 100644 Binary files a/FishGame/bin/com/mypro/constant/Constant.class and b/FishGame/bin/com/mypro/constant/Constant.class differ diff --git a/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas$JPaint.class b/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas$JPaint.class index f663116..4d42b5a 100644 Binary files a/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas$JPaint.class and b/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas$JPaint.class differ diff --git a/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas.class b/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas.class index 3268fe3..cafdce3 100644 Binary files a/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas.class and b/FishGame/bin/com/mypro/mainsurface/MainSurface$JCanvas.class differ diff --git a/FishGame/bin/com/mypro/mainsurface/MainSurface$OnDrawThread.class b/FishGame/bin/com/mypro/mainsurface/MainSurface$OnDrawThread.class index 835ffea..cac5adf 100644 Binary files a/FishGame/bin/com/mypro/mainsurface/MainSurface$OnDrawThread.class and b/FishGame/bin/com/mypro/mainsurface/MainSurface$OnDrawThread.class differ diff --git a/FishGame/bin/com/mypro/mainsurface/MainSurface.class b/FishGame/bin/com/mypro/mainsurface/MainSurface.class index 98bf355..f59ae3d 100644 Binary files a/FishGame/bin/com/mypro/mainsurface/MainSurface.class and b/FishGame/bin/com/mypro/mainsurface/MainSurface.class differ diff --git a/FishGame/bin/com/mypro/manager/CannonManager$1.class b/FishGame/bin/com/mypro/manager/CannonManager$1.class index 92d6ac6..37634ff 100644 Binary files a/FishGame/bin/com/mypro/manager/CannonManager$1.class and b/FishGame/bin/com/mypro/manager/CannonManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/CannonManager.class b/FishGame/bin/com/mypro/manager/CannonManager.class index 76a6e69..2a3e18e 100644 Binary files a/FishGame/bin/com/mypro/manager/CannonManager.class and b/FishGame/bin/com/mypro/manager/CannonManager.class differ diff --git a/FishGame/bin/com/mypro/manager/CatchFishManager$1.class b/FishGame/bin/com/mypro/manager/CatchFishManager$1.class index 2f4f010..aa28dd8 100644 Binary files a/FishGame/bin/com/mypro/manager/CatchFishManager$1.class and b/FishGame/bin/com/mypro/manager/CatchFishManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/CatchFishManager$2.class b/FishGame/bin/com/mypro/manager/CatchFishManager$2.class index a44c539..2fa501e 100644 Binary files a/FishGame/bin/com/mypro/manager/CatchFishManager$2.class and b/FishGame/bin/com/mypro/manager/CatchFishManager$2.class differ diff --git a/FishGame/bin/com/mypro/manager/CatchFishManager.class b/FishGame/bin/com/mypro/manager/CatchFishManager.class index 6673f45..f53df02 100644 Binary files a/FishGame/bin/com/mypro/manager/CatchFishManager.class and b/FishGame/bin/com/mypro/manager/CatchFishManager.class differ diff --git a/FishGame/bin/com/mypro/manager/FishManager.class b/FishGame/bin/com/mypro/manager/FishManager.class index d23eb1e..a0daeb9 100644 Binary files a/FishGame/bin/com/mypro/manager/FishManager.class and b/FishGame/bin/com/mypro/manager/FishManager.class differ diff --git a/FishGame/bin/com/mypro/manager/GameInitManager.class b/FishGame/bin/com/mypro/manager/GameInitManager.class index 35b3832..472f941 100644 Binary files a/FishGame/bin/com/mypro/manager/GameInitManager.class and b/FishGame/bin/com/mypro/manager/GameInitManager.class differ diff --git a/FishGame/bin/com/mypro/manager/GamePartInfo.class b/FishGame/bin/com/mypro/manager/GamePartInfo.class index c5c082a..8147b3e 100644 Binary files a/FishGame/bin/com/mypro/manager/GamePartInfo.class and b/FishGame/bin/com/mypro/manager/GamePartInfo.class differ diff --git a/FishGame/bin/com/mypro/manager/GamePartManager$1.class b/FishGame/bin/com/mypro/manager/GamePartManager$1.class index 3853456..87b4125 100644 Binary files a/FishGame/bin/com/mypro/manager/GamePartManager$1.class and b/FishGame/bin/com/mypro/manager/GamePartManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/GamePartManager.class b/FishGame/bin/com/mypro/manager/GamePartManager.class index 035e72f..b6c87d0 100644 Binary files a/FishGame/bin/com/mypro/manager/GamePartManager.class and b/FishGame/bin/com/mypro/manager/GamePartManager.class differ diff --git a/FishGame/bin/com/mypro/manager/HeadFish.class b/FishGame/bin/com/mypro/manager/HeadFish.class index 6cdb160..29b4ce3 100644 Binary files a/FishGame/bin/com/mypro/manager/HeadFish.class and b/FishGame/bin/com/mypro/manager/HeadFish.class differ diff --git a/FishGame/bin/com/mypro/manager/ImageConfig$ActConfig.class b/FishGame/bin/com/mypro/manager/ImageConfig$ActConfig.class index 95e1e64..a2679b7 100644 Binary files a/FishGame/bin/com/mypro/manager/ImageConfig$ActConfig.class and b/FishGame/bin/com/mypro/manager/ImageConfig$ActConfig.class differ diff --git a/FishGame/bin/com/mypro/manager/ImageConfig.class b/FishGame/bin/com/mypro/manager/ImageConfig.class index a325291..ee72d52 100644 Binary files a/FishGame/bin/com/mypro/manager/ImageConfig.class and b/FishGame/bin/com/mypro/manager/ImageConfig.class differ diff --git a/FishGame/bin/com/mypro/manager/ImageManager.class b/FishGame/bin/com/mypro/manager/ImageManager.class index 29fef39..7f0e173 100644 Binary files a/FishGame/bin/com/mypro/manager/ImageManager.class and b/FishGame/bin/com/mypro/manager/ImageManager.class differ diff --git a/FishGame/bin/com/mypro/manager/LayoutInfo.class b/FishGame/bin/com/mypro/manager/LayoutInfo.class index ff759f1..6d56d7e 100644 Binary files a/FishGame/bin/com/mypro/manager/LayoutInfo.class and b/FishGame/bin/com/mypro/manager/LayoutInfo.class differ diff --git a/FishGame/bin/com/mypro/manager/LayoutManager$1.class b/FishGame/bin/com/mypro/manager/LayoutManager$1.class index 5190980..96f5f1b 100644 Binary files a/FishGame/bin/com/mypro/manager/LayoutManager$1.class and b/FishGame/bin/com/mypro/manager/LayoutManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/LayoutManager.class b/FishGame/bin/com/mypro/manager/LayoutManager.class index 7bedda7..3219bbe 100644 Binary files a/FishGame/bin/com/mypro/manager/LayoutManager.class and b/FishGame/bin/com/mypro/manager/LayoutManager.class differ diff --git a/FishGame/bin/com/mypro/manager/PathManager.class b/FishGame/bin/com/mypro/manager/PathManager.class index 90c0de1..6ef0348 100644 Binary files a/FishGame/bin/com/mypro/manager/PathManager.class and b/FishGame/bin/com/mypro/manager/PathManager.class differ diff --git a/FishGame/bin/com/mypro/manager/ScoreManager$1.class b/FishGame/bin/com/mypro/manager/ScoreManager$1.class index 35070f7..6f13bc2 100644 Binary files a/FishGame/bin/com/mypro/manager/ScoreManager$1.class and b/FishGame/bin/com/mypro/manager/ScoreManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/ScoreManager$2.class b/FishGame/bin/com/mypro/manager/ScoreManager$2.class index d52b3d0..03f8f79 100644 Binary files a/FishGame/bin/com/mypro/manager/ScoreManager$2.class and b/FishGame/bin/com/mypro/manager/ScoreManager$2.class differ diff --git a/FishGame/bin/com/mypro/manager/ScoreManager$3.class b/FishGame/bin/com/mypro/manager/ScoreManager$3.class index 03ebbcf..61dd6db 100644 Binary files a/FishGame/bin/com/mypro/manager/ScoreManager$3.class and b/FishGame/bin/com/mypro/manager/ScoreManager$3.class differ diff --git a/FishGame/bin/com/mypro/manager/ScoreManager.class b/FishGame/bin/com/mypro/manager/ScoreManager.class index b77c0f7..94408a0 100644 Binary files a/FishGame/bin/com/mypro/manager/ScoreManager.class and b/FishGame/bin/com/mypro/manager/ScoreManager.class differ diff --git a/FishGame/bin/com/mypro/manager/ShoalManager$1.class b/FishGame/bin/com/mypro/manager/ShoalManager$1.class index f37564d..da512d0 100644 Binary files a/FishGame/bin/com/mypro/manager/ShoalManager$1.class and b/FishGame/bin/com/mypro/manager/ShoalManager$1.class differ diff --git a/FishGame/bin/com/mypro/manager/ShoalManager$2.class b/FishGame/bin/com/mypro/manager/ShoalManager$2.class index 77292cc..519f080 100644 Binary files a/FishGame/bin/com/mypro/manager/ShoalManager$2.class and b/FishGame/bin/com/mypro/manager/ShoalManager$2.class differ diff --git a/FishGame/bin/com/mypro/manager/ShoalManager.class b/FishGame/bin/com/mypro/manager/ShoalManager.class index a3e1ee5..9e9283b 100644 Binary files a/FishGame/bin/com/mypro/manager/ShoalManager.class and b/FishGame/bin/com/mypro/manager/ShoalManager.class differ diff --git a/FishGame/bin/com/mypro/manager/XmlManager.class b/FishGame/bin/com/mypro/manager/XmlManager.class index dca91e0..1b9c1a5 100644 Binary files a/FishGame/bin/com/mypro/manager/XmlManager.class and b/FishGame/bin/com/mypro/manager/XmlManager.class differ diff --git a/FishGame/bin/com/mypro/model/Ammo.class b/FishGame/bin/com/mypro/model/Ammo.class index c6882d3..4975212 100644 Binary files a/FishGame/bin/com/mypro/model/Ammo.class and b/FishGame/bin/com/mypro/model/Ammo.class differ diff --git a/FishGame/bin/com/mypro/model/BackGround.class b/FishGame/bin/com/mypro/model/BackGround.class index 9966891..ea76bb6 100644 Binary files a/FishGame/bin/com/mypro/model/BackGround.class and b/FishGame/bin/com/mypro/model/BackGround.class differ diff --git a/FishGame/bin/com/mypro/model/DrawableAdapter.class b/FishGame/bin/com/mypro/model/DrawableAdapter.class index e34e5ba..ecd3e58 100644 Binary files a/FishGame/bin/com/mypro/model/DrawableAdapter.class and b/FishGame/bin/com/mypro/model/DrawableAdapter.class differ diff --git a/FishGame/bin/com/mypro/model/FishGold.class b/FishGame/bin/com/mypro/model/FishGold.class index 32d4adf..ee9b46c 100644 Binary files a/FishGame/bin/com/mypro/model/FishGold.class and b/FishGame/bin/com/mypro/model/FishGold.class differ diff --git a/FishGame/bin/com/mypro/model/FishInfo.class b/FishGame/bin/com/mypro/model/FishInfo.class index 96bbf25..1085b36 100644 Binary files a/FishGame/bin/com/mypro/model/FishInfo.class and b/FishGame/bin/com/mypro/model/FishInfo.class differ diff --git a/FishGame/bin/com/mypro/model/FishingNet.class b/FishGame/bin/com/mypro/model/FishingNet.class index 98777a5..e81a727 100644 Binary files a/FishGame/bin/com/mypro/model/FishingNet.class and b/FishGame/bin/com/mypro/model/FishingNet.class differ diff --git a/FishGame/bin/com/mypro/model/GamingInfo.class b/FishGame/bin/com/mypro/model/GamingInfo.class index 5472baf..830f835 100644 Binary files a/FishGame/bin/com/mypro/model/GamingInfo.class and b/FishGame/bin/com/mypro/model/GamingInfo.class differ diff --git a/FishGame/bin/com/mypro/model/HighPoint.class b/FishGame/bin/com/mypro/model/HighPoint.class index 79be576..aaebc19 100644 Binary files a/FishGame/bin/com/mypro/model/HighPoint.class and b/FishGame/bin/com/mypro/model/HighPoint.class differ diff --git a/FishGame/bin/com/mypro/model/HundredPoint.class b/FishGame/bin/com/mypro/model/HundredPoint.class index af24a73..fe326f3 100644 Binary files a/FishGame/bin/com/mypro/model/HundredPoint.class and b/FishGame/bin/com/mypro/model/HundredPoint.class differ diff --git a/FishGame/bin/com/mypro/model/componets/Bottom.class b/FishGame/bin/com/mypro/model/componets/Bottom.class index 248d1d7..10f6755 100644 Binary files a/FishGame/bin/com/mypro/model/componets/Bottom.class and b/FishGame/bin/com/mypro/model/componets/Bottom.class differ diff --git a/FishGame/bin/com/mypro/model/componets/BottomGold.class b/FishGame/bin/com/mypro/model/componets/BottomGold.class index 819c2cc..750c110 100644 Binary files a/FishGame/bin/com/mypro/model/componets/BottomGold.class and b/FishGame/bin/com/mypro/model/componets/BottomGold.class differ diff --git a/FishGame/bin/com/mypro/model/componets/BottomTime.class b/FishGame/bin/com/mypro/model/componets/BottomTime.class index fb809c7..e8703f0 100644 Binary files a/FishGame/bin/com/mypro/model/componets/BottomTime.class and b/FishGame/bin/com/mypro/model/componets/BottomTime.class differ diff --git a/FishGame/bin/com/mypro/model/componets/ButtonAdapter.class b/FishGame/bin/com/mypro/model/componets/ButtonAdapter.class index 22cb5a4..4a8869a 100644 Binary files a/FishGame/bin/com/mypro/model/componets/ButtonAdapter.class and b/FishGame/bin/com/mypro/model/componets/ButtonAdapter.class differ diff --git a/FishGame/bin/com/mypro/model/componets/Cannon$1.class b/FishGame/bin/com/mypro/model/componets/Cannon$1.class index 965e3ec..a491439 100644 Binary files a/FishGame/bin/com/mypro/model/componets/Cannon$1.class and b/FishGame/bin/com/mypro/model/componets/Cannon$1.class differ diff --git a/FishGame/bin/com/mypro/model/componets/Cannon.class b/FishGame/bin/com/mypro/model/componets/Cannon.class index 0d6e73f..5e7cadf 100644 Binary files a/FishGame/bin/com/mypro/model/componets/Cannon.class and b/FishGame/bin/com/mypro/model/componets/Cannon.class differ diff --git a/FishGame/bin/com/mypro/model/componets/Componet.class b/FishGame/bin/com/mypro/model/componets/Componet.class index 30b7a2e..a1fb181 100644 Binary files a/FishGame/bin/com/mypro/model/componets/Componet.class and b/FishGame/bin/com/mypro/model/componets/Componet.class differ diff --git a/FishGame/bin/com/mypro/model/componets/DownCannonButtonListener.class b/FishGame/bin/com/mypro/model/componets/DownCannonButtonListener.class index b234f38..ae8c871 100644 Binary files a/FishGame/bin/com/mypro/model/componets/DownCannonButtonListener.class and b/FishGame/bin/com/mypro/model/componets/DownCannonButtonListener.class differ diff --git a/FishGame/bin/com/mypro/model/componets/UpCannonButtonListener.class b/FishGame/bin/com/mypro/model/componets/UpCannonButtonListener.class index 9ca3705..1ca38df 100644 Binary files a/FishGame/bin/com/mypro/model/componets/UpCannonButtonListener.class and b/FishGame/bin/com/mypro/model/componets/UpCannonButtonListener.class differ diff --git a/FishGame/bin/com/mypro/model/fish/Fish$1.class b/FishGame/bin/com/mypro/model/fish/Fish$1.class index 739c5d0..8354262 100644 Binary files a/FishGame/bin/com/mypro/model/fish/Fish$1.class and b/FishGame/bin/com/mypro/model/fish/Fish$1.class differ diff --git a/FishGame/bin/com/mypro/model/fish/Fish.class b/FishGame/bin/com/mypro/model/fish/Fish.class index 678d4fe..d1827a7 100644 Binary files a/FishGame/bin/com/mypro/model/fish/Fish.class and b/FishGame/bin/com/mypro/model/fish/Fish.class differ diff --git a/FishGame/bin/com/mypro/model/interfaces/Button.class b/FishGame/bin/com/mypro/model/interfaces/Button.class index 01c72ae..1b8d768 100644 Binary files a/FishGame/bin/com/mypro/model/interfaces/Button.class and b/FishGame/bin/com/mypro/model/interfaces/Button.class differ diff --git a/FishGame/bin/com/mypro/model/interfaces/Drawable.class b/FishGame/bin/com/mypro/model/interfaces/Drawable.class index 3fe1688..d572e8d 100644 Binary files a/FishGame/bin/com/mypro/model/interfaces/Drawable.class and b/FishGame/bin/com/mypro/model/interfaces/Drawable.class differ diff --git a/FishGame/bin/com/mypro/model/interfaces/OnClickListener.class b/FishGame/bin/com/mypro/model/interfaces/OnClickListener.class index 9ad9ea1..d41d0ce 100644 Binary files a/FishGame/bin/com/mypro/model/interfaces/OnClickListener.class and b/FishGame/bin/com/mypro/model/interfaces/OnClickListener.class differ diff --git a/FishGame/bin/com/mypro/threads/FishRunThread$1.class b/FishGame/bin/com/mypro/threads/FishRunThread$1.class index def7e4a..07178f5 100644 Binary files a/FishGame/bin/com/mypro/threads/FishRunThread$1.class and b/FishGame/bin/com/mypro/threads/FishRunThread$1.class differ diff --git a/FishGame/bin/com/mypro/threads/FishRunThread.class b/FishGame/bin/com/mypro/threads/FishRunThread.class index 2d74d6c..d9562f9 100644 Binary files a/FishGame/bin/com/mypro/threads/FishRunThread.class and b/FishGame/bin/com/mypro/threads/FishRunThread.class differ diff --git a/FishGame/bin/com/mypro/threads/PicActThread.class b/FishGame/bin/com/mypro/threads/PicActThread.class index f3b6a43..2f7f9d0 100644 Binary files a/FishGame/bin/com/mypro/threads/PicActThread.class and b/FishGame/bin/com/mypro/threads/PicActThread.class differ diff --git a/FishGame/bin/com/mypro/threads/ShotThread$1.class b/FishGame/bin/com/mypro/threads/ShotThread$1.class index 3ac8324..deeb060 100644 Binary files a/FishGame/bin/com/mypro/threads/ShotThread$1.class and b/FishGame/bin/com/mypro/threads/ShotThread$1.class differ diff --git a/FishGame/bin/com/mypro/threads/ShotThread.class b/FishGame/bin/com/mypro/threads/ShotThread.class index 6d94063..0662904 100644 Binary files a/FishGame/bin/com/mypro/threads/ShotThread.class and b/FishGame/bin/com/mypro/threads/ShotThread.class differ diff --git a/FishGame/bin/com/mypro/tools/CircleRectangleIntersect.class b/FishGame/bin/com/mypro/tools/CircleRectangleIntersect.class index d90aa0b..3ce72c4 100644 Binary files a/FishGame/bin/com/mypro/tools/CircleRectangleIntersect.class and b/FishGame/bin/com/mypro/tools/CircleRectangleIntersect.class differ diff --git a/FishGame/bin/com/mypro/tools/LogTools.class b/FishGame/bin/com/mypro/tools/LogTools.class index 0c890ac..5be8377 100644 Binary files a/FishGame/bin/com/mypro/tools/LogTools.class and b/FishGame/bin/com/mypro/tools/LogTools.class differ diff --git a/FishGame/bin/com/mypro/tools/Tool.class b/FishGame/bin/com/mypro/tools/Tool.class index 2e04e0c..20519ed 100644 Binary files a/FishGame/bin/com/mypro/tools/Tool.class and b/FishGame/bin/com/mypro/tools/Tool.class differ diff --git a/FishGame/src/com/mypro/base/graphics/Bitmap.java b/FishGame/src/com/mypro/base/graphics/Bitmap.java index a0261e7..02d7868 100644 --- a/FishGame/src/com/mypro/base/graphics/Bitmap.java +++ b/FishGame/src/com/mypro/base/graphics/Bitmap.java @@ -20,73 +20,52 @@ public Image getImage() { return image; } - /** - * 获取图片宽度 - * @return - */ public int getWidth() { - // TODO Auto-generated method stub + if(image == null) return 0; return image.getWidth(null); } - /** - * 获取图片高度 - * @return - */ public int getHeight() { - // TODO Auto-generated method stub + if(image == null) return 0; return image.getHeight(null); } - /** - * 缩放图片 - * @param src - * @param width - * @param height - * @param tf - */ public static Bitmap createScaledBitmap(Bitmap src,int width,int height,boolean tf){ + if(src == null || src.image == null){ + return new Bitmap(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR)); + } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); g.drawImage(src.image, 0, 0, width, height, 0, 0, src.getWidth(), src.getHeight(), null); return new Bitmap(img); } - /** - * 复制图片 - * @param src - * @return - */ + public static Bitmap createBitmap(Bitmap src){ + if(src == null){ + return new Bitmap(null); + } return src.copy(); } - public Bitmap copy(){ - BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); - Graphics g = image.getGraphics(); + public Bitmap copy(){ + if(image == null){ + return new Bitmap(null); + } + BufferedImage newImage = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_4BYTE_ABGR); + Graphics g = newImage.getGraphics(); g.drawImage(this.image, 0, 0, null); - return new Bitmap(image); + return new Bitmap(newImage); } - /** - * 返回像素颜色 - * @param x - * @param y - * @return - */ public int getPixel(int x,int y){ + if(image == null) return 0; + if(x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return 0; return image.getRGB(x, y); } - /** - * 设置像素颜色 - * @param x - * @param y - * @param color - */ public void setPixel(int x,int y,int color){ + if(image == null) return; + if(x < 0 || x >= getWidth() || y < 0 || y >= getHeight()) return; image.setRGB(x, y, color); } -} - - - +} \ No newline at end of file diff --git a/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java b/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java index 3329389..d8bdd9e 100644 --- a/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java +++ b/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java @@ -1,9 +1,13 @@ package com.mypro.basecomponet; import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; import javax.swing.JFrame; @@ -14,75 +18,203 @@ import com.mypro.model.GamingInfo; public class AwtMainComponet{ + private static Point initialClick; + private static JFrame frame; + private static MainSurface mainSurface; + private static boolean isMaximized = false; + private static Rectangle normalBounds; + + private static final int TITLE_BAR_HEIGHT = 55; + private static final int BUTTON_WIDTH = 60; + private static final int BUTTON_HEIGHT = 55; + private static int hoveredButton = -1; + public static void main(String[] args) throws Exception { Toolkit tool = Toolkit.getDefaultToolkit(); Dimension d = tool.getScreenSize(); - JFrame frame = new JFrame(); + frame = new JFrame(); GamingInfo.getGamingInfo().setGaming(true); - GamingInfo.getGamingInfo().setScreenWidth(900); - GamingInfo.getGamingInfo().setScreenHeight(600); + GamingInfo.getGamingInfo().setScreenWidth(1280); + GamingInfo.getGamingInfo().setScreenHeight(800); + GamingInfo.getGamingInfo().setCurrentState(GamingInfo.STATE_START_SCREEN); frame.setSize(GamingInfo.getGamingInfo().getScreenWidth(), GamingInfo.getGamingInfo().getScreenHeight()); - frame.setUndecorated(true); // 去掉窗口的装饰 -// frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);//采用指定的窗口装饰风格 -// frame.setResizable(false); + frame.setUndecorated(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); - MainSurface pane = new MainSurface(); - GamingInfo.getGamingInfo().setSurface(pane); - frame.setContentPane(pane); -// frame.setAlwaysOnTop(true); + mainSurface = new MainSurface(); + GamingInfo.getGamingInfo().setSurface(mainSurface); + frame.setContentPane(mainSurface); frame.setVisible(true); + frame.addMouseListener(new MouseListener() { - @Override public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub - } @Override public void mousePressed(MouseEvent e) { + initialClick = e.getPoint(); + + int x = e.getX(); + int y = e.getY(); + int frameWidth = frame.getWidth(); + + if (y < TITLE_BAR_HEIGHT) { + if (x >= frameWidth - BUTTON_WIDTH * 3 && x < frameWidth - BUTTON_WIDTH * 2) { + minimizeWindow(); + return; + } else if (x >= frameWidth - BUTTON_WIDTH * 2 && x < frameWidth - BUTTON_WIDTH) { + maximizeWindow(); + return; + } else if (x >= frameWidth - BUTTON_WIDTH) { + closeWindow(); + return; + } + } + + int currentState = GamingInfo.getGamingInfo().getCurrentState(); + if (currentState == GamingInfo.STATE_START_SCREEN || currentState == GamingInfo.STATE_HELP_SCREEN) { + if (mainSurface.handleClick(x, y)) { + if (GamingInfo.getGamingInfo().getCurrentState() == GamingInfo.STATE_GAME_SCREEN) { + startGameInit(); + } + return; + } + } + if(GameInitManager.getGameInitManager().isIniting()){ return ; } - //先看布局管理器是否有相应 if(!LayoutManager.getLayoutManager().onClick(e.getX(), e.getY())){ - //发射子弹 CannonManager.getCannonManager().shot(e.getX(), e.getY()); } } @Override public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - } @Override public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - } @Override public void mouseClicked(MouseEvent e) { - // TODO Auto-generated method stub + } + }); + + frame.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + int frameWidth = frame.getWidth(); + if (y < TITLE_BAR_HEIGHT) { + if (x >= frameWidth - BUTTON_WIDTH * 3 && x < frameWidth - BUTTON_WIDTH * 2) { + hoveredButton = 0; + } else if (x >= frameWidth - BUTTON_WIDTH * 2 && x < frameWidth - BUTTON_WIDTH) { + hoveredButton = 1; + } else if (x >= frameWidth - BUTTON_WIDTH) { + hoveredButton = 2; + } else { + hoveredButton = -1; + } + } else { + hoveredButton = -1; + } + } + + @Override + public void mouseDragged(MouseEvent e) { + if (isMaximized) { + return; + } + if (initialClick != null && initialClick.y < TITLE_BAR_HEIGHT) { + int x = frame.getLocation().x + e.getX() - initialClick.x; + int y = frame.getLocation().y + e.getY() - initialClick.y; + frame.setLocation(x, y); + } } }); -// frame.pack(); - pane.action(); - /** - * 创建一个线程来异步初始化游戏内容 - */ + + mainSurface.action(); + } + + private static void startGameInit() { new Thread(new Runnable(){ - public void run() { - //使用游戏初始化管理器初始化游戏 GameInitManager.getGameInitManager().init(); } - - }).start(); + }).start(); + } + + private static void minimizeWindow() { + frame.setState(JFrame.ICONIFIED); + } + + private static void maximizeWindow() { + if (isMaximized) { + frame.setBounds(normalBounds); + isMaximized = false; + } else { + normalBounds = frame.getBounds(); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Dimension screenSize = toolkit.getScreenSize(); + frame.setBounds(0, 0, screenSize.width, screenSize.height); + isMaximized = true; + } + } + + private static void closeWindow() { + GameInitManager.getGameInitManager().stop(); + System.exit(0); + } + + public static void drawTitleBar(Graphics g, int width, int height) { + g.setColor(new java.awt.Color(30, 30, 50)); + g.fillRect(0, 0, width, TITLE_BAR_HEIGHT); + + g.setColor(new java.awt.Color(100, 100, 150)); + g.fillRect(0, TITLE_BAR_HEIGHT - 3, width, 3); + + g.setColor(java.awt.Color.WHITE); + g.setFont(new java.awt.Font("Microsoft YaHei", java.awt.Font.BOLD, 18)); + g.drawString("鎹曢奔娓告垙", 20, 36); + + int buttonX = width - BUTTON_WIDTH * 3; + + java.awt.Color minimizeColor = (hoveredButton == 0) ? new java.awt.Color(100, 150, 200) : new java.awt.Color(70, 70, 100); + g.setColor(minimizeColor); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(new java.awt.Color(150, 150, 180)); + g.drawRect(buttonX, 0, BUTTON_WIDTH - 1, BUTTON_HEIGHT - 1); + g.setColor(java.awt.Color.WHITE); + g.fillRect(buttonX + 15, 26, BUTTON_WIDTH - 30, 6); + + buttonX += BUTTON_WIDTH; + java.awt.Color maximizeColor = (hoveredButton == 1) ? new java.awt.Color(100, 150, 200) : new java.awt.Color(70, 70, 100); + g.setColor(maximizeColor); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(new java.awt.Color(150, 150, 180)); + g.drawRect(buttonX, 0, BUTTON_WIDTH - 1, BUTTON_HEIGHT - 1); + g.setColor(java.awt.Color.WHITE); + if (isMaximized) { + g.drawRect(buttonX + 14, 12, BUTTON_WIDTH - 30, BUTTON_HEIGHT - 26); + g.drawRect(buttonX + 18, 10, BUTTON_WIDTH - 30, BUTTON_HEIGHT - 26); + } else { + g.drawRect(buttonX + 14, 12, BUTTON_WIDTH - 28, BUTTON_HEIGHT - 24); + } + + buttonX += BUTTON_WIDTH; + java.awt.Color closeColor = (hoveredButton == 2) ? new java.awt.Color(255, 80, 80) : new java.awt.Color(220, 50, 50); + g.setColor(closeColor); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(new java.awt.Color(255, 120, 120)); + g.drawRect(buttonX, 0, BUTTON_WIDTH - 1, BUTTON_HEIGHT - 1); + g.setColor(java.awt.Color.WHITE); + g.drawLine(buttonX + 18, 15, buttonX + BUTTON_WIDTH - 18, BUTTON_HEIGHT - 15); + g.drawLine(buttonX + BUTTON_WIDTH - 18, 15, buttonX + 18, BUTTON_HEIGHT - 15); } } diff --git a/FishGame/src/com/mypro/mainsurface/MainSurface.java b/FishGame/src/com/mypro/mainsurface/MainSurface.java index f9565f0..95352f9 100644 --- a/FishGame/src/com/mypro/mainsurface/MainSurface.java +++ b/FishGame/src/com/mypro/mainsurface/MainSurface.java @@ -1,4 +1,6 @@ package com.mypro.mainsurface; +import java.awt.Color; +import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -12,34 +14,31 @@ import com.mypro.base.graphics.Canvas; import com.mypro.base.graphics.Matrix; import com.mypro.base.graphics.Paint; +import com.mypro.basecomponet.AwtMainComponet; import com.mypro.basecomponet.JMatrix; import com.mypro.constant.Constant; +import com.mypro.manager.GameInitManager; import com.mypro.model.GamingInfo; import com.mypro.model.interfaces.Drawable; public class MainSurface extends JPanel{ - /** - * 修改图层的操作定义 - */ - //更新图层 + private static final int TITLE_BAR_HEIGHT = 55; + private boolean gameInitialized = false; + private boolean gameStarted = false; + private final static int CHANGE_MODE_UPDATE = 0; - //添加元素到图层 private final static int CHANGE_MODE_ADD = 1; - //删除元素从图层 private final static int CHANGE_MODE_REMOVE = 2; - // 图片的图层分布 private HashMap> picLayer =new HashMap>(); - // 修改后的图片的图层分布,这里根据操作分为了两个图层,分别是添加的元素,和删除的元素 private HashMap> addPicLayer = new HashMap>(),removePicLayer = new HashMap>(); - // 是否修改过图层 private boolean changeLayer = false; - private int picLayerId[] = new int[0]; // 定义一个图层ID,加速获取图层绘制(省去了从map中获取各个图层排序问题) - private Paint paint; // 画笔 - private OnDrawThread odt; // 屏幕绘制线程,用于控制绘制帧数,周期性调用onDraw方法 + private int picLayerId[] = new int[0]; + private Paint paint; + private OnDrawThread odt; public MainSurface() { setSize(GamingInfo.getGamingInfo().getScreenWidth(), GamingInfo.getGamingInfo().getScreenHeight()); paint = canvas.getPaint(); - paint.setAntiAlias(true);//设置抗锯齿 + paint.setAntiAlias(true); paint.setDither(true); odt = new OnDrawThread(this); @@ -47,37 +46,200 @@ public MainSurface() { public void action() throws Exception { odt.start(); } - /** - * 绘图方法,这个方法是由线程控制,周期性调用的 - */ + + public void startGame() { + if (!gameStarted) { + gameStarted = true; + GamingInfo.getGamingInfo().setCurrentState(GamingInfo.STATE_GAME_SCREEN); + if (!gameInitialized) { + gameInitialized = true; + } + } + } + + public void showStartScreen() { + GamingInfo.getGamingInfo().setCurrentState(GamingInfo.STATE_START_SCREEN); + } + + public void showHelpScreen() { + GamingInfo.getGamingInfo().setCurrentState(GamingInfo.STATE_HELP_SCREEN); + } + + public boolean handleClick(int x, int y) { + int state = GamingInfo.getGamingInfo().getCurrentState(); + int screenWidth = GamingInfo.getGamingInfo().getScreenWidth(); + int screenHeight = GamingInfo.getGamingInfo().getScreenHeight(); + + if (state == GamingInfo.STATE_START_SCREEN) { + int buttonWidth = 200; + int buttonHeight = 50; + int buttonX = (screenWidth - buttonWidth) / 2; + int startButtonY = screenHeight / 2 - 30; + int helpButtonY = screenHeight / 2 + 40; + + if (x >= buttonX && x <= buttonX + buttonWidth && + y >= startButtonY && y <= startButtonY + buttonHeight) { + startGame(); + return true; + } + + if (x >= buttonX && x <= buttonX + buttonWidth && + y >= helpButtonY && y <= helpButtonY + buttonHeight) { + showHelpScreen(); + return true; + } + } else if (state == GamingInfo.STATE_HELP_SCREEN) { + int buttonWidth = 150; + int buttonHeight = 40; + int buttonX = (screenWidth - buttonWidth) / 2; + int buttonY = screenHeight - 80; + + if (x >= buttonX && x <= buttonX + buttonWidth && + y >= buttonY && y <= buttonY + buttonHeight) { + showStartScreen(); + return true; + } + } + return false; + } + + private void drawStartScreen(Graphics2D g) { + int screenWidth = GamingInfo.getGamingInfo().getScreenWidth(); + int screenHeight = GamingInfo.getGamingInfo().getScreenHeight(); + + Color oceanColor1 = new Color(0, 50, 100); + + g.setColor(oceanColor1); + g.fillRect(0, TITLE_BAR_HEIGHT, screenWidth, screenHeight - TITLE_BAR_HEIGHT); + + for (int i = 0; i < 20; i++) { + int bubbleX = (int)(Math.random() * screenWidth); + int bubbleY = TITLE_BAR_HEIGHT + (int)(Math.random() * (screenHeight - TITLE_BAR_HEIGHT)); + int bubbleSize = 5 + (int)(Math.random() * 15); + g.setColor(new Color(255, 255, 255, 50)); + g.fillOval(bubbleX, bubbleY, bubbleSize, bubbleSize); + } + + g.setColor(Color.WHITE); + g.setFont(new Font("Microsoft YaHei", Font.BOLD, 48)); + String title = "\u6355\u9c7c\u6e38\u620f"; + int titleWidth = g.getFontMetrics().stringWidth(title); + g.drawString(title, (screenWidth - titleWidth) / 2, screenHeight / 3); + + int buttonWidth = 200; + int buttonHeight = 50; + int buttonX = (screenWidth - buttonWidth) / 2; + int startButtonY = screenHeight / 2 - 30; + int helpButtonY = screenHeight / 2 + 40; + + g.setColor(new Color(0, 150, 200)); + g.fillRoundRect(buttonX, startButtonY, buttonWidth, buttonHeight, 10, 10); + g.setColor(Color.WHITE); + g.setFont(new Font("Microsoft YaHei", Font.BOLD, 24)); + String startText = "\u5f00\u59cb\u6e38\u620f"; + int startTextWidth = g.getFontMetrics().stringWidth(startText); + g.drawString(startText, (screenWidth - startTextWidth) / 2, startButtonY + 35); + + g.setColor(new Color(100, 150, 50)); + g.fillRoundRect(buttonX, helpButtonY, buttonWidth, buttonHeight, 10, 10); + g.setColor(Color.WHITE); + String helpText = "\u6e38\u620f\u8bf4\u660e"; + int helpTextWidth = g.getFontMetrics().stringWidth(helpText); + g.drawString(helpText, (screenWidth - helpTextWidth) / 2, helpButtonY + 35); + } + + private void drawHelpScreen(Graphics2D g) { + int screenWidth = GamingInfo.getGamingInfo().getScreenWidth(); + int screenHeight = GamingInfo.getGamingInfo().getScreenHeight(); + + g.setColor(new Color(30, 30, 50)); + g.fillRect(0, TITLE_BAR_HEIGHT, screenWidth, screenHeight - TITLE_BAR_HEIGHT); + + g.setColor(Color.WHITE); + g.setFont(new Font("Microsoft YaHei", Font.BOLD, 36)); + String title = "\u6e38\u620f\u8bf4\u660e"; + int titleWidth = g.getFontMetrics().stringWidth(title); + g.drawString(title, (screenWidth - titleWidth) / 2, TITLE_BAR_HEIGHT + 60); + + g.setFont(new Font("Microsoft YaHei", Font.PLAIN, 18)); + g.setColor(new Color(200, 200, 200)); + + int y = TITLE_BAR_HEIGHT + 100; + int lineHeight = 35; + int leftMargin = 80; + + String[] helpTexts = { + "\u3010\u6e38\u620f\u73a9\u6cd5\u3011", + "1. \u70b9\u51fb\u5c4f\u5e55\u4efb\u610f\u4f4d\u7f6e\u53d1\u5c04\u70ae\u5f39\uff0c\u6355\u83b7\u6e38\u52a8\u7684\u9c7c\u7fa4", + "2. \u4f7f\u7528 + / - \u6309\u94ae\u5207\u6362\u4e0d\u540c\u7b49\u7ea7\u7684\u70ae\u53f0\uff081-7\u7ea7\uff09", + "3. \u70ae\u53f0\u7b49\u7ea7\u8d8a\u9ad8\uff0c\u70ae\u5f39\u5a01\u529b\u8d8a\u5927\uff0c\u4f46\u6d88\u8017\u91d1\u5e01\u4e5f\u8d8a\u591a", + "", + "\u3010\u91d1\u5e01\u7cfb\u7edf\u3011", + "4. \u6355\u83b7\u4e0d\u540c\u79cd\u7c7b\u7684\u9c7c\u83b7\u5f97\u4e0d\u540c\u6570\u91cf\u7684\u91d1\u5e01", + "5. \u521d\u59cb\u91d1\u5e01\u4e3a100\uff0c\u91d1\u5e01\u4e0d\u8db3\u65f6\u6e38\u620f\u7ed3\u675f", + "6. \u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u7cfb\u7edf\u4f1a\u81ea\u52a8\u53d1\u653e\u91d1\u5e01", + "", + "\u3010\u901a\u5173\u6761\u4ef6\u3011", + "7. \u6e38\u620f\u8bbe\u6709\u591a\u4e2a\u5173\u5361\uff0c\u6bcf\u4e2a\u5173\u5361\u6709\u4e0d\u540c\u7684\u76ee\u6807", + "8. \u79ef\u7d2f\u8db3\u591f\u7684\u91d1\u5e01\u6216\u6355\u83b7\u7279\u5b9a\u9c7c\u7c7b\u5373\u53ef\u901a\u5173", + "9. \u6311\u6218\u66f4\u9ad8\u5206\u6570\uff0c\u6210\u4e3a\u6355\u9c7c\u5927\u5e08\uff01" + }; + + for (String text : helpTexts) { + if (text.isEmpty()) { + y += lineHeight / 2; + } else { + g.drawString(text, leftMargin, y); + y += lineHeight; + } + } + + int buttonWidth = 150; + int buttonHeight = 40; + int buttonX = (screenWidth - buttonWidth) / 2; + int buttonY = screenHeight - 80; + + g.setColor(new Color(100, 100, 150)); + g.fillRoundRect(buttonX, buttonY, buttonWidth, buttonHeight, 10, 10); + g.setColor(Color.WHITE); + g.setFont(new Font("Microsoft YaHei", Font.BOLD, 18)); + String backText = "\u8fd4\u56de"; + int backTextWidth = g.getFontMetrics().stringWidth(backText); + g.drawString(backText, (screenWidth - backTextWidth) / 2, buttonY + 28); + } + + private void drawTitleBar(Graphics2D g) { + int screenWidth = GamingInfo.getGamingInfo().getScreenWidth(); + AwtMainComponet.drawTitleBar(g, screenWidth, TITLE_BAR_HEIGHT); + } + public void onDraw(Canvas canvas) { - //更新图层内容 - updatePicLayer(CHANGE_MODE_UPDATE,0,null); + int state = GamingInfo.getGamingInfo().getCurrentState(); + Graphics2D g = ((JCanvas.JPaint) paint).getGraphics(); - // 遍历所有图层,按图层先后顺序绘制 - for (int id : picLayerId) { - for (Drawable drawable : picLayer.get(id)) { - drawable.onDraw(canvas, paint); - } + if (state == GamingInfo.STATE_START_SCREEN) { + drawStartScreen(g); + } else if (state == GamingInfo.STATE_HELP_SCREEN) { + drawHelpScreen(g); + } else if (state == GamingInfo.STATE_GAME_SCREEN) { + updatePicLayer(CHANGE_MODE_UPDATE,0,null); + + for (int id : picLayerId) { + for (Drawable drawable : picLayer.get(id)) { + drawable.onDraw(canvas, paint); + } + } } + + drawTitleBar(g); } - /** - * 更新图层,这里分为三种操作,分别是更新临时图层中的内容到绘制图层中,删除绘制图层中的元素,添加绘制图层中的元素 - * 这里加了个线程锁,保证多线程下操作图层的安全性 - * @param mode 对绘制图层的操作类型,对应当前类的CHANGE_MODE常量 - * @param layerId 操作的图层ID - * @param draw 操作的图层元素 - */ + private synchronized void updatePicLayer(int mode,int layerId,Drawable draw){ switch(mode){ - //将临时图层中的内容更新至绘制图层中 case CHANGE_MODE_UPDATE: - //如果有修改 if(changeLayer){ - //向图层添加新的元素 for(Integer id:addPicLayer.keySet()){ for(Drawable d:addPicLayer.get(id)){ - //如果要添加的元素所处图层不存在,则创建这个图层,并更新图层ID数组 if(this.picLayer.get(id)==null){ this.picLayer.put(id, new ArrayList()); updateLayerIds(id); @@ -86,13 +248,12 @@ private synchronized void updatePicLayer(int mode,int layerId,Drawable draw){ } } addPicLayer.clear(); - //删除图层中的元素 for(Integer id:removePicLayer.keySet()){ for(Drawable d:removePicLayer.get(id)){ try { this.picLayer.get(id).remove(d); } catch (Exception e) { - System.out.println("图层内容不存在:"+id); + System.out.println("Pic layer error:"+id); } } @@ -101,11 +262,7 @@ private synchronized void updatePicLayer(int mode,int layerId,Drawable draw){ changeLayer = false; } break; - /** - * 无论是向绘图图层中添加还是删除元素,都不是直接操作绘制图层,都是存放在对应的临时图层中,等待绘制方法绘制周期中将变化的内容更新到绘制图层中 - * 保证多线程操作情况下的安全性 - */ - //添加一个元素 + case CHANGE_MODE_ADD: ArrayList al = addPicLayer.get(layerId); if(al==null){ @@ -115,7 +272,6 @@ private synchronized void updatePicLayer(int mode,int layerId,Drawable draw){ al.add(draw); changeLayer = true; break; - //删除一个元素 case CHANGE_MODE_REMOVE: ArrayList al1 = removePicLayer.get(layerId); if(al1==null){ @@ -129,51 +285,32 @@ private synchronized void updatePicLayer(int mode,int layerId,Drawable draw){ } - /** - * 将一个可绘制的图放入图层中 - * - * @param layer - * 图层号 图层号虽然是int,但是实际上只支持到byte,原因是图层没有必要那么多 - * @param pic - * 可绘制的图 - */ + public void putDrawablePic(int layer, Drawable pic) { if(pic==null){ - System.out.println("图层内容不能为空:对应图层:"+layer); + System.out.println("Drawable is null, layer:"+layer); return; } updatePicLayer(CHANGE_MODE_ADD,layer,pic); } - /** - * 将一个可绘制的图从图层中移除 - * - * @param layer - * @param pic - */ + public void removeDrawablePic(int layer, Drawable pic) { if(pic==null){ - System.out.println("图层内容不能为空:对应图层:"+layer); + System.out.println("Drawable is null, layer:"+layer); return; } updatePicLayer(CHANGE_MODE_REMOVE,layer,pic); } - /** - * 更新图层Id - * - * @param newLayerId - */ + private void updateLayerIds(int newLayerId) { - // 初始化图层 if (picLayerId.length == 0) { picLayerId = new int[1]; - picLayerId[0] = newLayerId; // 将新的图层ID添加到初始化的图层ID数组中 + picLayerId[0] = newLayerId; } else { - // 创建一个新的图层数组,长度比原来的大1位 int picLayerIdFlag[] = new int[picLayerId.length + 1]; for (int i = 0; i < picLayerId.length; i++) { - // 排序操作,如果新的图层ID小于当前图层ID,讲新的图层ID插入其中 if (picLayerId[i] > newLayerId) { for (int f = picLayerIdFlag.length - 1; f > i; f--) { picLayerIdFlag[f] = picLayerId[f - 1]; @@ -183,16 +320,14 @@ private void updateLayerIds(int newLayerId) { } else { picLayerIdFlag[i] = picLayerId[i]; } - // 如果到了最后,都没有比新图层ID大的,就将新的图层ID存入最后 if (i == picLayerId.length - 1) { picLayerIdFlag[picLayerIdFlag.length - 1] = newLayerId; } } - // 将新的图层ID数组覆盖原有的 this.picLayerId = picLayerIdFlag; } } - //画板 + private JCanvas canvas = new JCanvas(); @Override public synchronized void paint(Graphics g) { @@ -203,20 +338,15 @@ public synchronized Canvas lockCanvas() { return canvas; } + public void unlockCanvasAndPost(Canvas canvas) { repaint(); } - /** - * 画板类 - * @author Xiloer - * - */ + private class JCanvas implements Canvas{ - /* - * 绘制画板 - */ + private BufferedImage canvas = new BufferedImage(GamingInfo.getGamingInfo().getScreenWidth(), GamingInfo.getGamingInfo().getScreenHeight(), BufferedImage.TYPE_4BYTE_ABGR); private JPaint paint = new JPaint(canvas); @@ -231,11 +361,17 @@ public BufferedImage getCanvas() { @Override - public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { + public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) { + if(bitmap == null || bitmap.getImage() == null || matrix == null){ + return; + } this.paint.getGraphics().drawImage(bitmap.getImage(),((JMatrix)matrix).trans, null); } @Override public void drawBitmap(Bitmap bitmap, float x, float y, Paint paint) { + if(bitmap == null || bitmap.getImage() == null){ + return; + } this.paint.getGraphics().drawImage(bitmap.getImage(),(int)x,(int)y, null); } @@ -311,7 +447,7 @@ public void setColor(int color) { public class OnDrawThread extends Thread{ private MainSurface surface; - private int drawSpeed;//每次绘制后的休息毫秒数,这个值是根据常量中的绘制帧数决定的 + private int drawSpeed; public OnDrawThread(MainSurface surface){ super(); this.surface = surface; @@ -324,19 +460,15 @@ public void run(){ while(GamingInfo.getGamingInfo().isGaming()){ try{ canvas = lockCanvas(); -// synchronized (this.sh) { if(canvas!=null){ surface.onDraw(canvas); } -// } }catch(Exception e){ -// Log.e(this.getName(), e.toString()); e.printStackTrace(); }finally{ try{ unlockCanvasAndPost(canvas); }catch(Exception e){ -// Log.e(this.getName(), e.toString()); } } try{ diff --git a/FishGame/src/com/mypro/manager/ImageManager.java b/FishGame/src/com/mypro/manager/ImageManager.java index ce6dbfd..b58d100 100644 --- a/FishGame/src/com/mypro/manager/ImageManager.java +++ b/FishGame/src/com/mypro/manager/ImageManager.java @@ -17,11 +17,7 @@ import com.mypro.manager.ImageConfig.ActConfig; import com.mypro.model.GamingInfo; import com.mypro.tools.LogTools; -/** - * 图片管理器 - * @author Leslie Leung - * - */ + public class ImageManager { private static ImageManager manager; private ImageManager(){ @@ -33,24 +29,16 @@ public static ImageManager getImageMnagaer(){ } return manager; } - //缩放比例 public float scaleNum = 1; - //鱼缩放比例 public float fishScaleNum = 1; - //图片缓存,用于裁图时大图的降低加载次数 private Bitmap baseImageCache; - //缓存图片的名字 private String baseImageString; - /** - * 清楚管理器缓存,释放空间 - */ + public void clearImageCache(){ baseImageCache = null; baseImageString = null; } -// /** -// * 初始化管理器 -// */ + public void initManager(){ int len = GamingInfo.getGamingInfo().getScreenHeight(); if(len<=500){ @@ -58,35 +46,22 @@ public void initManager(){ fishScaleNum = 0.5f; } } - /** - * 根据给定的配置文件,创建相关的配置信息类 - * @param configFileName 相对assets的带路径的文件 例 fish/fish2(fish2.plist) - * @return 返回一个ImageConfig对象 - */ + public ImageConfig createImageConfigByPlist( String configFileName) { ImageConfig config = new ImageConfig(); try { XmlPullParser xml = XmlManager.getXmlParser(configFileName, "UTF-8"); if(xml==null){ - throw new Exception("ImageManager:解析的xml文件为null!"); + throw new Exception("ImageManager: xml file is null!"); } config.setSrcImageFileName(configFileName); while (GamingInfo.getGamingInfo().isGaming()) { - /** - * 标签为key的 - */ XmlManager.gotoTagByTagName(xml, "key"); String value = XmlManager.getValueByCurrentTag(xml); if (value != null) { - /** - * 设置缩放源图信息 - */ if (value.equals("texture")) { setScaleInfo(xml, config); - /** - * 设置截取每帧画面信息 - */ } else if (value.equals("frames")) { XmlManager.gotoTagByTagName(xml, "dict"); getCutImageInfo(xml, config); @@ -100,14 +75,8 @@ public ImageConfig createImageConfigByPlist( return config; } - - - /** - * 设置源图缩放信息 - * @param xml - * @param config - */ + private void setScaleInfo(XmlPullParser xml,ImageConfig config){ XmlManager.gotoTagByTagName(xml, "key"); String mode = XmlManager.getValueByCurrentTag(xml); @@ -126,18 +95,13 @@ private void setScaleInfo(XmlPullParser xml,ImageConfig config){ config.setSrcImageHeight(Integer.parseInt(XmlManager.getValueByCurrentTag(xml))); } } - /** - * 缩放素材图 - * @param config 图片的配置信息 - * @return 返回缩放后的图片,如果图片没找到返回null - */ + private synchronized Bitmap scaledSrcBitmap(ImageConfig config) { try { if(this.baseImageString!=null&&this.baseImageString.equals(config.getSrcImageFileName())){ return this.baseImageCache; }else{ if(this.baseImageCache!=null){ -// this.baseImageCache.recycle(); this.baseImageCache=null; System.gc(); } @@ -151,11 +115,7 @@ private synchronized Bitmap scaledSrcBitmap(ImageConfig config) { } return null; } - /** - * 获取裁图信息 - * @param xml 相应的配置文件xml文件 - * @param ImageConfig 将解析的内容保存在这个配置对象里 - */ + private void getCutImageInfo(XmlPullParser xml, ImageConfig config) { String imageName = null; @@ -166,19 +126,12 @@ private void getCutImageInfo(XmlPullParser xml, config.getAllActs().put(imageName,actConfig); actConfig.setImageName(imageName); actConfig.setConfig(config); -// getFishActImage(xml, src); } } } - /** - * 解析图片配置信息 - * 这里严格按照顺序解析,不忽略属性顺序问题,所以xml那边配置的顺序要比较严格 - * @param xml - * @return - */ + private ActConfig getActConfig(XmlPullParser xml){ ActConfig imageConfig = new ActConfig(); - //找到相应配置信息 XmlManager.gotoTagByTagName(xml, "integer"); imageConfig.setImageX(Integer.parseInt(XmlManager.getValueByCurrentTag(xml))); XmlManager.gotoTagByTagName(xml, "integer"); @@ -198,17 +151,10 @@ private ActConfig getActConfig(XmlPullParser xml){ return imageConfig; } - /** - * 根据图片的配置信息获取图片 - * @param config 图片的配置文件 - * @param src 源图 - * @return 裁出来的图 - */ + private Bitmap getImage(ActConfig config, Bitmap src,float proportion) { - // 创建一个图片 BufferedImage newImage = new BufferedImage(config.getOriginalWidth(), config.getOriginalHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = newImage.getGraphics(); - // 裁出来的图片 g.drawImage( src.getImage(), (int)(config.getOriginalWidth() / 2 + config.getOffsetX() - config.getImageWidth()/ 2), @@ -223,11 +169,7 @@ private Bitmap getImage(ActConfig config, Bitmap src,float proportion) { ); return new Bitmap(newImage); } - /** - * 返回给定配置信息的一组图片 - * @param configs - * @return - */ + public Bitmap[] getImagesByActConfigs(ActConfig[] configs,float proportion){ Bitmap []imgs = new Bitmap[configs.length]; Bitmap src = null; @@ -243,16 +185,11 @@ public Bitmap[] getImagesByActConfigs(ActConfig[] configs,float proportion){ System.gc(); return imgs; } - /** - * 根据图片配置对象信息获取对应的一组图片的HashMap对象 - * @param config 对应的图片配置对象 - * @return 一个HashMap集合 key:图片名称 value:对应的图片 - */ + public HashMap getImagesMapByImageConfig(ImageConfig config,float proportion){ HashMap allAct = new HashMap(); try{ Bitmap src = scaledSrcBitmap(config); - //将所有配置信息中的图片放置到集合中 for(ActConfig act : config.getAllActs().values()){ allAct.put(act.getImageName(), getImage(act,src,proportion)); } @@ -262,12 +199,7 @@ public HashMap getImagesMapByImageConfig(ImageConfig config,float return allAct; } - /** - * 旋转图片 - * @param angle 给定角度 - * @param newImage 旋转的图片 - * @return - */ + public Bitmap rotateImage(int angle,Bitmap newImage){ AffineTransform trans = new AffineTransform(); trans.rotate(Math.toRadians(angle), newImage.getWidth()/2, newImage.getHeight()/2); @@ -278,12 +210,7 @@ public Bitmap rotateImage(int angle,Bitmap newImage){ return new Bitmap(img); } - /** - * 根据屏幕尺寸缩放图片 - * 这里需要注意的一点是,要初始化GamingInfo里的屏幕尺寸,因为是依据这个来缩放图片的 - * @param src 需要缩放的图片 - * @return 缩放后的图片 - */ + public Bitmap scaleImageByScreen(Bitmap src){ AffineTransform trans = new AffineTransform(); trans.scale(scaleNum, scaleNum); @@ -293,13 +220,7 @@ public Bitmap scaleImageByScreen(Bitmap src){ g.drawImage(src.getImage(), trans, null); return new Bitmap(img); } - /** - * 根据给定尺寸缩放图片 - * @param src - * @param width - * @param height - * @return - */ + public Bitmap sacleImageByWidthAndHeight(Bitmap src,int width,int height){ AffineTransform trans = new AffineTransform(); trans.scale(width*1f/src.getWidth(), height*1f/src.getHeight()); @@ -309,26 +230,24 @@ public Bitmap sacleImageByWidthAndHeight(Bitmap src,int width,int height){ g.drawImage(src.getImage(), trans, null); return new Bitmap(img); } - /** - * 从资产中获取图片 - * @param imageName 相对资产assets跟目录下的带路径的图片名称 - * @return 返回指定的图片 - * @throws Exception - */ + public Bitmap getBitmapByAssets(String imageName)throws Exception{ try { - return new Bitmap(ImageIO.read(new File(imageName))); + File file = new File(imageName); + if(!file.exists()){ + throw new IOException("Image file not found: " + file.getAbsolutePath()); + } + BufferedImage img = ImageIO.read(file); + if(img == null){ + throw new IOException("Failed to read image file: " + file.getAbsolutePath()); + } + return new Bitmap(img); } catch (IOException e) { LogTools.doLogForException(e); throw e; } } - /** - * 从资产中获取根据屏幕尺寸缩放后的图片 - * @param imageName - * @return - * @throws Exception - */ + public Bitmap getscaleImageByScreenFromAssets(String imageName)throws Exception{ try { return scaleImageByScreen(getBitmapByAssets(imageName)); @@ -338,4 +257,3 @@ public Bitmap getscaleImageByScreenFromAssets(String imageName)throws Exception{ } } - diff --git a/FishGame/src/com/mypro/manager/XmlManager.java b/FishGame/src/com/mypro/manager/XmlManager.java index c8c67c6..a3b1669 100644 --- a/FishGame/src/com/mypro/manager/XmlManager.java +++ b/FishGame/src/com/mypro/manager/XmlManager.java @@ -1,58 +1,42 @@ package com.mypro.manager; +import java.io.File; import java.io.FileInputStream; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserFactory; -/** - * Xml管理器 - * @author Leslie Leung - * - */ public class XmlManager { - /** - * 获取XML解析器 - * @param fileName 需要解析的xml文件路径加文件名(不含后缀,这里后缀统一用plist,有必要在修改) - * @param encode 字符集编码 - * @return - */ - public static XmlPullParser getXmlParser(String fileName,String encode){ - try{ - // 获得处理 xml 文件的 XmlResourceParser 对象 -// XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); - XmlPullParserFactory factory = XmlPullParserFactory.newInstance( - - System.getProperty(XmlPullParserFactory.PROPERTY_NAME), - - Thread.currentThread().getContextClassLoader().getClass() ); + public static XmlPullParser getXmlParser(String fileName, String encode) { + try { + File file = new File(fileName + ".plist"); + if (!file.exists()) { + System.err.println("XML file not found: " + file.getAbsolutePath()); + return null; + } + + XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xml = factory.newPullParser(); - xml.setInput(new FileInputStream(fileName + ".plist"), encode); + xml.setInput(new FileInputStream(file), encode); return xml; - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); } return null; } - - /** - * 获取当前标签的值 - * - * @return - */ + public static String getValueByCurrentTag(XmlPullParser xml) { + if (xml == null) { + return null; + } try { int eventType = xml.next(); while (true) { - // 读取标签内容状态 if (eventType == XmlPullParser.TEXT) { return xml.getText().trim(); - } - // 文档结束状态 - else if (eventType == XmlPullParser.END_DOCUMENT) { - // 文档分析结束后,退出 while 循环 + } else if (eventType == XmlPullParser.END_DOCUMENT) { break; } eventType = xml.next(); @@ -62,36 +46,28 @@ else if (eventType == XmlPullParser.END_DOCUMENT) { } return null; } - - /** - * 获取指定名称的标签 - * - * @return true:到达这个标签 false没有这个标签 - */ + public static boolean gotoTagByTagName(XmlPullParser xml, String tagName) { + if (xml == null || tagName == null) { + return false; + } try { int eventType = xml.next(); String key = null; while (true) { - // 标签开始状态 if (eventType == XmlPullParser.START_TAG) { key = xml.getName(); - if (key.trim().equals(tagName)) { + if (key != null && key.trim().equals(tagName)) { return true; } - } - // 文档结束状态 - else if (eventType == XmlPullParser.END_DOCUMENT) { - // 文档分析结束后,退出 while 循环 + } else if (eventType == XmlPullParser.END_DOCUMENT) { return false; } - // 切换到下一个状态,并获得当前状态的类型 eventType = xml.next(); - } } catch (Exception e) { e.printStackTrace(); } return false; } -} +} \ No newline at end of file diff --git a/FishGame/src/com/mypro/model/GamingInfo.java b/FishGame/src/com/mypro/model/GamingInfo.java index 03b6a57..876636b 100644 --- a/FishGame/src/com/mypro/model/GamingInfo.java +++ b/FishGame/src/com/mypro/model/GamingInfo.java @@ -7,19 +7,24 @@ //import com.mypro.manager.SoundManager; import com.mypro.model.fish.Fish; -//游戏进行中一些需要共用的变量 +//锟斤拷戏锟斤拷锟斤拷锟斤拷一些锟斤拷要锟斤拷锟矫的憋拷锟斤拷 public class GamingInfo { + public static final int STATE_START_SCREEN = 0; + public static final int STATE_GAME_SCREEN = 1; + public static final int STATE_HELP_SCREEN = 2; + private int screenWidth; private int screenHeight; - private static GamingInfo gameInfo; // 单例模式需要 - private boolean isGaming; // 是否处于游戏状态 - private boolean isPause;//是否处于暂停状态 - private MainSurface surface; // 主屏幕 - private ArrayList fish = new ArrayList(); // 所有的鱼 - private ShoalManager shoalManager; // 鱼群管理器 - private float cannonLayoutX; //大炮旋转X坐标 - private float cannonLayoutY; //大炮旋转Y坐标 - private int score = 100; //当前的分 + private static GamingInfo gameInfo; // 锟斤拷锟斤拷模式锟斤拷要 + private boolean isGaming; // 锟角凤拷锟斤拷锟斤拷戏状态 + private boolean isPause;//锟角凤拷锟斤拷锟斤拷停状态 + private int currentState = STATE_START_SCREEN; // 锟斤拷前锟斤拷幕状态 + private MainSurface surface; // 锟斤拷锟斤拷幕 + private ArrayList fish = new ArrayList(); // 锟斤拷锟叫碉拷锟斤拷 + private ShoalManager shoalManager; // 锟斤拷群锟斤拷锟斤拷锟斤拷 + private float cannonLayoutX; //锟斤拷锟斤拷锟斤拷转X锟斤拷锟斤拷 + private float cannonLayoutY; //锟斤拷锟斤拷锟斤拷转Y锟斤拷锟斤拷 + private int score = 100; //锟斤拷前锟侥凤拷 public int getScore() { return score; @@ -30,7 +35,7 @@ public void setScore(int score) { } /** - * 清除GamingInfo实例 + * 锟斤拷锟紾amingInfo实锟斤拷 */ public static void clearGameInfo() { gameInfo = null; @@ -117,5 +122,13 @@ public boolean isPause() { public void setPause(boolean isPause) { this.isPause = isPause; } + + public int getCurrentState() { + return currentState; + } + + public void setCurrentState(int currentState) { + this.currentState = currentState; + } } diff --git a/FishGame/src/com/mypro/model/componets/Bottom.java b/FishGame/src/com/mypro/model/componets/Bottom.java index 4c4642a..e084f2a 100644 --- a/FishGame/src/com/mypro/model/componets/Bottom.java +++ b/FishGame/src/com/mypro/model/componets/Bottom.java @@ -1,11 +1,13 @@ package com.mypro.model.componets; +import java.awt.image.BufferedImage; + import com.mypro.base.graphics.Bitmap; import com.mypro.base.tools.Log; import com.mypro.manager.ImageManager; import com.mypro.model.GamingInfo; /** - * 大炮底座 + * Bottom bar component * @author Leslie Leung * */ @@ -13,27 +15,34 @@ public class Bottom extends Componet{ private Bitmap pic; public Bottom(){ try{ - pic = ImageManager.getImageMnagaer().getscaleImageByScreenFromAssets("componet/bottom.png"); - this.setLayout_x(GamingInfo.getGamingInfo().getScreenWidth()/2-getPicWidth()/2); - this.setLayout_y(GamingInfo.getGamingInfo().getScreenHeight()-getPicHeight()); - this.getPicMatrix().setTranslate(this.getLayout_x(),this.getLayout_y()); + pic = ImageManager.getImageMnagaer().getscaleImageByScreenFromAssets("componet/bottom.png"); }catch(Exception e){ Log.e("Bottom", e.toString()); + pic = createDefaultBitmap(); + } + if(pic != null){ + this.setLayout_x(GamingInfo.getGamingInfo().getScreenWidth()/2-getPicWidth()/2); + this.setLayout_y(GamingInfo.getGamingInfo().getScreenHeight()-getPicHeight()); + this.getPicMatrix().setTranslate(this.getLayout_x(),this.getLayout_y()); } } + + private Bitmap createDefaultBitmap(){ + BufferedImage img = new BufferedImage(200, 100, BufferedImage.TYPE_4BYTE_ABGR); + return new Bitmap(img); + } public Bitmap getCurrentPic() { - // TODO Auto-generated method stub return pic; } public int getPicWidth() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getWidth(); } public int getPicHeight() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getHeight(); } diff --git a/FishGame/src/com/mypro/model/componets/BottomGold.java b/FishGame/src/com/mypro/model/componets/BottomGold.java index 70cd1eb..12e2125 100644 --- a/FishGame/src/com/mypro/model/componets/BottomGold.java +++ b/FishGame/src/com/mypro/model/componets/BottomGold.java @@ -1,5 +1,6 @@ package com.mypro.model.componets; +import java.awt.image.BufferedImage; import java.util.HashMap; import com.mypro.base.graphics.Bitmap; @@ -10,45 +11,68 @@ import com.mypro.tools.LogTools; /** - * 金币显示组件 + * Score display bar * @author Leslie Leung * */ public class BottomGold extends Componet{ - private int gold;//这个值记录当前组件应显示的金币数 - private int[] num_index = new int[1];//所有数字的索引,这里第一个元素代表得分的最大位数,往后类推 + private int gold; + private int[] num_index = new int[1]; private Bitmap pic; private Bitmap[] num; - private int numShowX,numShowY;//数字显示的X和Y坐标 - private int numPicWidth; //数字宽度,所有数字宽度是一样的 + private int numShowX,numShowY; + private int numPicWidth; + private Bitmap defaultBitmap; + public BottomGold(int layoutX,int layoutY){ + defaultBitmap = createDefaultBitmap(); try { initNum(); pic = ImageManager.getImageMnagaer().getscaleImageByScreenFromAssets("componet/bottom_gold.png"); - this.setLayout_x(layoutX); - this.setLayout_y(layoutY); + } catch (Exception e) { + LogTools.doLogForException(e); + if(pic == null){ + pic = defaultBitmap; + } + } + this.setLayout_x(layoutX); + this.setLayout_y(layoutY); + if(pic != null){ numShowX = layoutX+pic.getWidth()/3; numShowY = layoutY+pic.getHeight()/4; + } + if(num != null && num[0] != null){ numPicWidth = num[0].getWidth(); - this.getPicMatrix().setTranslate(this.getLayout_x(),this.getLayout_y()); - } catch (Exception e) { - LogTools.doLogForException(e); } + this.getPicMatrix().setTranslate(this.getLayout_x(),this.getLayout_y()); + } + private Bitmap createDefaultBitmap(){ + BufferedImage img = new BufferedImage(100, 50, BufferedImage.TYPE_4BYTE_ABGR); + return new Bitmap(img); } + /** - * 初始化显示的数字 + * 鍒濆鍖栨樉绀虹殑鏁板瓧 */ private void initNum(){ - HashMap allNum = ImageManager.getImageMnagaer().getImagesMapByImageConfig(ImageManager.getImageMnagaer().createImageConfigByPlist("componet/num_gold"),ImageManager.getImageMnagaer().scaleNum); - //效果图全名(num_0.png) - StringBuffer numFullName = new StringBuffer(); - String numName = "num_"; - num = new Bitmap[10]; - for(int num = 0;num<10&&GamingInfo.getGamingInfo().isGaming();num++){ - numFullName.delete(0, numFullName.length()); - numFullName.append(numName+num+".png"); - this.num[num] = allNum.get(numFullName.toString()); + try{ + HashMap allNum = ImageManager.getImageMnagaer().getImagesMapByImageConfig(ImageManager.getImageMnagaer().createImageConfigByPlist("componet/num_gold"),ImageManager.getImageMnagaer().scaleNum); + StringBuffer numFullName = new StringBuffer(); + String numName = "num_"; + num = new Bitmap[10]; + for(int num = 0;num<10&&GamingInfo.getGamingInfo().isGaming();num++){ + numFullName.delete(0, numFullName.length()); + numFullName.append(numName+num+".png"); + Bitmap bmp = allNum.get(numFullName.toString()); + this.num[num] = (bmp != null) ? bmp : defaultBitmap; + } + }catch(Exception e){ + LogTools.doLogForException(e); + num = new Bitmap[10]; + for(int i=0;i<10;i++){ + num[i] = defaultBitmap; + } } } @Override @@ -58,35 +82,39 @@ public void onDraw(Canvas canvas, Paint paint) { gold = GamingInfo.getGamingInfo().getScore(); updateNumIndex(); } - for(int i=0;i= 0 && idx < num.length && num[idx] != null){ + canvas.drawBitmap(num[idx], numShowX+(i*numPicWidth), numShowY, paint); + } + } } } /** - * 更新数字索引 + * 鏇存柊鏁板瓧绱㈠紩 */ private void updateNumIndex(){ - String num = gold+""; - num_index = new int[num.length()]; + String numStr = gold+""; + num_index = new int[numStr.length()]; int index = 0; - for(char n:num.toCharArray()){ + for(char n:numStr.toCharArray()){ num_index[index] = n-48; index++; } } public Bitmap getCurrentPic() { - // TODO Auto-generated method stub return pic; } public int getPicWidth() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getWidth(); } public int getPicHeight() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getHeight(); } diff --git a/FishGame/src/com/mypro/model/componets/BottomTime.java b/FishGame/src/com/mypro/model/componets/BottomTime.java index 83f3aa7..bba2a20 100644 --- a/FishGame/src/com/mypro/model/componets/BottomTime.java +++ b/FishGame/src/com/mypro/model/componets/BottomTime.java @@ -1,5 +1,6 @@ package com.mypro.model.componets; +import java.awt.image.BufferedImage; import java.util.HashMap; import com.mypro.base.graphics.Bitmap; @@ -10,80 +11,107 @@ import com.mypro.tools.LogTools; /** - * 金币显示组件 + * Countdown display bar * @author Leslie Leung * */ public class BottomTime extends Componet{ - private int[] num_index = new int[1];//所有数字的索引,这里第一个元素代表得分的最大位数,往后类推 + private int[] num_index = new int[1]; private Bitmap pic; private Bitmap[] num; - private int numShowX,numShowY;//数字显示的X和Y坐标 - private int numPicWidth; //数字宽度,所有数字宽度是一样的 + private int numShowX,numShowY; + private int numPicWidth; + private Bitmap defaultBitmap; + public BottomTime(){ + defaultBitmap = createDefaultBitmap(); try { initNum(); pic = ImageManager.getImageMnagaer().getscaleImageByScreenFromAssets("componet/bottom_time.png"); - numPicWidth = num[0].getWidth(); + if(num != null && num[0] != null){ + numPicWidth = num[0].getWidth(); + } } catch (Exception e) { LogTools.doLogForException(e); + if(pic == null){ + pic = defaultBitmap; + } } + } + private Bitmap createDefaultBitmap(){ + BufferedImage img = new BufferedImage(100, 50, BufferedImage.TYPE_4BYTE_ABGR); + return new Bitmap(img); } + public void setPosition(int layoutX,int layoutY){ this.setLayout_x(layoutX); this.setLayout_y(layoutY); - numShowX = layoutX+pic.getWidth()/3; - numShowY = layoutY+pic.getHeight()/4; + if(pic != null){ + numShowX = layoutX+pic.getWidth()/3; + numShowY = layoutY+pic.getHeight()/4; + } this.getPicMatrix().setTranslate(this.getLayout_x(),this.getLayout_y()); } /** - * 初始化显示的数字 + * 鍒濆鍖栨樉绀虹殑鏁板瓧 */ private void initNum(){ - HashMap allNum = ImageManager.getImageMnagaer().getImagesMapByImageConfig(ImageManager.getImageMnagaer().createImageConfigByPlist("componet/num_gold"),ImageManager.getImageMnagaer().scaleNum); - //效果图全名(num_0.png) - StringBuffer numFullName = new StringBuffer(); - String numName = "num_"; - num = new Bitmap[10]; - for(int num = 0;num<10&&GamingInfo.getGamingInfo().isGaming();num++){ - numFullName.delete(0, numFullName.length()); - numFullName.append(numName+num+".png"); - this.num[num] = allNum.get(numFullName.toString()); + try{ + HashMap allNum = ImageManager.getImageMnagaer().getImagesMapByImageConfig(ImageManager.getImageMnagaer().createImageConfigByPlist("componet/num_gold"),ImageManager.getImageMnagaer().scaleNum); + StringBuffer numFullName = new StringBuffer(); + String numName = "num_"; + num = new Bitmap[10]; + for(int num = 0;num<10&&GamingInfo.getGamingInfo().isGaming();num++){ + numFullName.delete(0, numFullName.length()); + numFullName.append(numName+num+".png"); + Bitmap bmp = allNum.get(numFullName.toString()); + this.num[num] = (bmp != null) ? bmp : defaultBitmap; + } + }catch(Exception e){ + LogTools.doLogForException(e); + num = new Bitmap[10]; + for(int i=0;i<10;i++){ + num[i] = defaultBitmap; + } } } @Override public void onDraw(Canvas canvas, Paint paint) { super.onDraw(canvas, paint); - for(int i=0;i= 0 && idx < num.length && num[idx] != null){ + canvas.drawBitmap(num[idx], numShowX+(i*numPicWidth), numShowY, paint); + } + } } } /** - * 更新数字索引 + * 鏇存柊鏁板瓧绱㈠紩 */ public void updateNumIndex(int time){ - String num = time+""; - num_index = new int[num.length()]; + String numStr = time+""; + num_index = new int[numStr.length()]; int index = 0; - for(char n:num.toCharArray()){ + for(char n:numStr.toCharArray()){ num_index[index] = n-48; index++; } } public Bitmap getCurrentPic() { - // TODO Auto-generated method stub return pic; } public int getPicWidth() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getWidth(); } public int getPicHeight() { - // TODO Auto-generated method stub + if(pic == null) return 0; return pic.getHeight(); } diff --git a/Mines/.project b/Mines/.project index 8d14707..d822d8a 100644 --- a/Mines/.project +++ b/Mines/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1776589793069 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Mines/bin/mines/Field.class b/Mines/bin/mines/Field.class index 8193508..f899e0d 100644 Binary files a/Mines/bin/mines/Field.class and b/Mines/bin/mines/Field.class differ diff --git a/Mines/bin/mines/MinesFields$GameRunScript.class b/Mines/bin/mines/MinesFields$GameRunScript.class index 7288d13..79bcba4 100644 Binary files a/Mines/bin/mines/MinesFields$GameRunScript.class and b/Mines/bin/mines/MinesFields$GameRunScript.class differ diff --git a/Mines/bin/mines/MinesFields.class b/Mines/bin/mines/MinesFields.class index 6f97085..385c7ff 100644 Binary files a/Mines/bin/mines/MinesFields.class and b/Mines/bin/mines/MinesFields.class differ diff --git a/Mines/bin/mines/MinesFrame$1.class b/Mines/bin/mines/MinesFrame$1.class new file mode 100644 index 0000000..553ad8c Binary files /dev/null and b/Mines/bin/mines/MinesFrame$1.class differ diff --git a/Mines/bin/mines/MinesFrame$Restart.class b/Mines/bin/mines/MinesFrame$Restart.class index 541e3ae..fbe5367 100644 Binary files a/Mines/bin/mines/MinesFrame$Restart.class and b/Mines/bin/mines/MinesFrame$Restart.class differ diff --git a/Mines/bin/mines/MinesFrame.class b/Mines/bin/mines/MinesFrame.class index 993cfa3..9ddce6f 100644 Binary files a/Mines/bin/mines/MinesFrame.class and b/Mines/bin/mines/MinesFrame.class differ diff --git a/Mines/bin/mines/StartFrame$1.class b/Mines/bin/mines/StartFrame$1.class new file mode 100644 index 0000000..ed09786 Binary files /dev/null and b/Mines/bin/mines/StartFrame$1.class differ diff --git a/Mines/bin/mines/StartFrame$2.class b/Mines/bin/mines/StartFrame$2.class new file mode 100644 index 0000000..e8c3734 Binary files /dev/null and b/Mines/bin/mines/StartFrame$2.class differ diff --git a/Mines/bin/mines/StartFrame$3.class b/Mines/bin/mines/StartFrame$3.class new file mode 100644 index 0000000..a724504 Binary files /dev/null and b/Mines/bin/mines/StartFrame$3.class differ diff --git a/Mines/bin/mines/StartFrame.class b/Mines/bin/mines/StartFrame.class new file mode 100644 index 0000000..754e2bd Binary files /dev/null and b/Mines/bin/mines/StartFrame.class differ diff --git a/Mines/src/mines/Field.java b/Mines/src/mines/Field.java index f54a3b6..18c0a73 100644 --- a/Mines/src/mines/Field.java +++ b/Mines/src/mines/Field.java @@ -3,147 +3,111 @@ import java.awt.*; /** - * 网格类 + * Grid cell class * @author Leslie Leung */ public class Field { - public static final int STYLE_COVERED = 1; //Field覆盖时的样式 - public static final int STYLE_OPENED = 2; //Field打开时的样式 - public static final int STYLE_MARKED = 3; //Field被标记时的样式 - public static final int FIELD_SIZE = 25; //一个格子的大小 + public static final int STYLE_COVERED = 1; + public static final int STYLE_OPENED = 2; + public static final int STYLE_MARKED = 3; + public static final int FIELD_SIZE = 25; - private int mineValue; //Field的附近地雷值 - private int x; //Field的横坐标 - private int y; //Field的纵坐标 - private int style; //Field的样式 + private int mineValue; + private int x; + private int y; + private int style; /** - * Field类构造方法 - * @param x 横坐标 - * @param y 纵坐标 + * Field constructor + * @param x row index + * @param y column index */ public Field(int x, int y) { this.x = x; this.y = y; - style = STYLE_COVERED; //初始化样式为覆盖 - mineValue = 0; //初始化该Field不为地雷,用mineValue值为0来表示 + style = STYLE_COVERED; + mineValue = 0; } - /** - * 获取该Field的横坐标 - * @return 横坐标 - */ public int getX() { return x; } - /** - * 获取该Field的纵坐标 - * @return 纵坐标 - */ public int getY() { return y; } - /** - * 设置某个Field的样式 - * @param style 样式 - */ public void setStyle(int style) { this.style = style; } /** - * 通过把mineValue值设置为-100表示该Field为地雷 + * Mark this field as a mine by setting mineValue to -100 */ public void setMine() { mineValue = -100; } - /** - * 返回该Field的mineValue - * @return mineValue - */ public int getMineValue() { return mineValue; } - /** - * 设置该Field的地雷值 - * @param value 地雷值 - */ public void setMineValue(int value) { mineValue = value; } - /** - * 判断该Field是否地雷 - * @return true,是;否则,false - */ public boolean isMine() { return mineValue == -100; } - /** - * 判断该Field是否被标记 - * @return true,被标记;false,没被标记 - */ public boolean isMarked() { return style == STYLE_MARKED; } - /** - * 判断该Field是否覆盖 - * @return true,覆盖;false,没覆盖 - */ public boolean isCovered() { return style == STYLE_COVERED; } - /** - * 判断该Field是否已打开 - * @return true,已打开;false,没打开 - */ public boolean isOpened() { return style == STYLE_OPENED; } /** - * 绘图方法 - * @param g Graphics g + * Paint the field + * @param g Graphics context */ public void paintField(Graphics g) { int yCoordinate = x * FIELD_SIZE + 1; int xCoordinate = y * FIELD_SIZE + 1; - if(isCovered()) {//样式为覆盖时候所做的绘图 + if(isCovered()) { g.setColor(Color.CYAN); g.fillRect(xCoordinate, yCoordinate, FIELD_SIZE - 2, FIELD_SIZE - 2); } - if(isOpened()) {//样式为打开时所做的绘图 - if(mineValue > 0) {//当该Field的附近地雷值大于0时 + if(isOpened()) { + if(mineValue > 0) { g.setColor(Color.WHITE); g.fillRect(xCoordinate, yCoordinate, FIELD_SIZE - 2, FIELD_SIZE - 2); g.setColor(Color.BLACK); g.drawString(mineValue + "", y * FIELD_SIZE + FIELD_SIZE / 2, x * FIELD_SIZE + FIELD_SIZE / 2); - } else if(mineValue == -100) {//当该Field是地雷时 + } else if(mineValue == -100) { g.setColor(Color.RED); g.fillRect(xCoordinate, yCoordinate, FIELD_SIZE - 2, FIELD_SIZE - 2); - } else if(mineValue == 0) {//当该Field的附近地雷值为0 + } else if(mineValue == 0) { g.setColor(Color.WHITE); g.fillRect(xCoordinate, yCoordinate, FIELD_SIZE - 2, FIELD_SIZE - 2); } } - if(isMarked()) {//样式为标记时所做的绘图 + if(isMarked()) { g.setColor(Color.CYAN); g.fillRect(xCoordinate, yCoordinate, FIELD_SIZE - 2, FIELD_SIZE - 2); g.setColor(Color.MAGENTA); - g.drawString("?", y * FIELD_SIZE + FIELD_SIZE / 2, x * FIELD_SIZE + FIELD_SIZE / 2); + g.drawString("?", y * FIELD_SIZE + FIELD_SIZE / 2, x * FIELD_SIZE + FIELD_SIZE / 2); } } } diff --git a/Mines/src/mines/MinesFields.java b/Mines/src/mines/MinesFields.java index a32f9fd..389520d 100644 --- a/Mines/src/mines/MinesFields.java +++ b/Mines/src/mines/MinesFields.java @@ -10,62 +10,67 @@ import javax.swing.*; /** - * 扫雷场景类 + * Mine field panel * @author Leslie Leung */ public class MinesFields extends JPanel { - public static final int ROWS = 16; //整个场景的行数 - public static final int COLUMNS = 16; //整个场景的列数 - public static final int MINES_NUM = 40; //地雷的数目 + private int rows; + private int columns; + private int minesNum; - private Map fields; //表示雷域中所有Field - private List notMineFields; //表示所有不是地雷的Field的集合 - private GameRunScript mouseListener; //表示鼠标事件的监听器 + private Map fields; + private List notMineFields; + private GameRunScript mouseListener; /** - * MinesFields类构造方法 + * MinesFields constructor + * @param rows number of rows + * @param columns number of columns + * @param minesNum number of mines */ - public MinesFields() { - setPreferredSize(new Dimension(ROWS * Field.FIELD_SIZE, COLUMNS * Field.FIELD_SIZE)); //设置扫雷面板大小 + public MinesFields(int rows, int columns, int minesNum) { + this.rows = rows; + this.columns = columns; + this.minesNum = minesNum; - fields = new HashMap(); //用哈希表表示所有的Field + setPreferredSize(new Dimension(columns * Field.FIELD_SIZE, rows * Field.FIELD_SIZE)); + + fields = new HashMap(); notMineFields = new ArrayList(); mouseListener = new GameRunScript(); Random random = new Random(); - int mineX, mineY; //记录生成地雷的坐标 - List aroundList; //表示获取的该Field的附近的Field的集合 + int mineX, mineY; + List aroundList; - /* 生成雷域中的每个Field */ - for(int x = 0; x < COLUMNS; x ++) { - for(int y = 0; y < ROWS; y ++) { - fields.put(x + "," + y, new Field(x, y)); //创建Field对象,并把对象添加到fields中 + // Create all fields + for(int x = 0; x < columns; x ++) { + for(int y = 0; y < rows; y ++) { + fields.put(x + "," + y, new Field(x, y)); } } - /* 随机生成40个地雷并设置附近地雷数 */ - for(int i = 0; i < MINES_NUM; i ++) { - /* 如果生成的地雷坐标重复,重新设置地雷的坐标 */ + // Place mines randomly + for(int i = 0; i < minesNum; i ++) { do { - mineX = random.nextInt(COLUMNS); - mineY = random.nextInt(ROWS); + mineX = random.nextInt(columns); + mineY = random.nextInt(rows); } while(isMine(mineX, mineY)); - setMine(mineX, mineY); //根据相应的键值把该Field设置为地雷 - aroundList = getAround(mineX, mineY); //获取该地雷附近的所有Field + setMine(mineX, mineY); + aroundList = getAround(mineX, mineY); - /* 遍历aroundList,把不是地雷的Field的地雷值加1 */ + // Increment mine value for surrounding fields for(Field field: aroundList) { if(!field.isMine()) { field.setMineValue(field.getMineValue() + 1); } } - } - /* 把不是地雷的Field添加到notMineFields中 */ - for(int x = 0; x < COLUMNS; x ++) { - for(int y = 0; y < ROWS; y ++) { + // Collect all non-mine fields + for(int x = 0; x < columns; x ++) { + for(int y = 0; y < rows; y ++) { if(!getField(x, y).isMine()) { notMineFields.add(getField(x, y)); } @@ -74,43 +79,42 @@ public MinesFields() { } /** - * 获取内部类的实例 - * @return 内部类的实例 + * Get inner mouse listener instance + * @return inner instance */ public GameRunScript getInnerInstance() { return mouseListener; } /** - * 内部类,用于实现用鼠标在游戏界面上操作的功能 + * Inner class for handling mouse events and game logic * @author Leslie Leung */ private class GameRunScript extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { - Point p = e.getPoint(); //获取所点击位置的那个点 - int y = p.x / Field.FIELD_SIZE; //所获取的点的横坐标 - int x = p.y / Field.FIELD_SIZE; //所获取的点的纵坐标 + Point p = e.getPoint(); + int y = p.x / Field.FIELD_SIZE; + int x = p.y / Field.FIELD_SIZE; - /* 如果单击鼠标左键 */ + // Left click - open field if(e.getButton() == MouseEvent.BUTTON1) { open(x, y); } - /* 如果双击鼠标左键 */ + // Double click - open around if(e.getClickCount() == 2) { openAround(x, y); } - /* 如果单击鼠标右键,标记该域或取消该域的标记 */ + // Right click - mark field if(e.getButton() == MouseEvent.BUTTON3) { mark(x, y); } - } } /** - * 对于所有不是地雷的Field,判断是否全部都已代开 - * @return true,全部都已打开;false,部分或全部都没打开 + * Check if all non-mine fields are opened + * @return true if all non-mine fields are opened, false otherwise */ public boolean isAllOpened() { for(Field field: notMineFields) { @@ -123,123 +127,118 @@ public boolean isAllOpened() { } /** - * 返回一个Field对象 - * @param x 横坐标 - * @param y 纵坐标 - * @return Field对象 + * Get a field by coordinates + * @param x row index + * @param y column index + * @return Field object */ public Field getField(int x, int y) { return fields.get(x + "," + y); } /** - * 返回不是地雷的所有Field - * @param x 某Field的横坐标 - * @param y 某Field的纵坐标 - * @return 不是地雷的所有Field,存放在集合里 + * Get surrounding fields that are not mines + * @param x row index of center field + * @param y column index of center field + * @return list of surrounding non-mine fields */ public List getAround(int x, int y) { List aroundList = new ArrayList(); for(int m = -1; m <= 1; m ++) { for(int n = -1; n <= 1; n ++) { - /* 如果所选中的对象为地雷本身,跳出本次循环 */ + // Skip the center field if(m == 0 && n == 0) { continue; } - /* 先判断是否获取附近的地雷的坐标是否越界,若否,把不是地雷的所有Field放进aroundList里面 */ - if(x + m < COLUMNS && x + m >= 0 && y + n >= 0 && y + n < ROWS) { + // Check boundaries and add valid fields + if(x + m < columns && x + m >= 0 && y + n >= 0 && y + n < rows) { aroundList.add(getField(x + m, y + n)); } - } } return aroundList; - } /** - * 当该Field的地雷值为0时,递归打开其附近的Field - * @param x 横坐标 - * @param y 纵坐标 + * Open a field with recursive flood fill when mineValue is 0 + * @param x row index + * @param y column index */ public void open(int x, int y) { if(isCovered(x, y)) { - /* 如果是该Field是地雷的话,打开全部Field */ + // Hit a mine - game over if(isMine(x, y)) { explode(); - JOptionPane.showMessageDialog(null, "你输了"); + JOptionPane.showMessageDialog(null, "Game Over!"); return; } - setOpened(x, y); //把该Field设置为打开状态 + setOpened(x, y); repaint(); - if(isAllOpened()) {//如果全部已被打开 - JOptionPane.showMessageDialog(null, "恭喜你,你赢了!!!"); + if(isAllOpened()) { + JOptionPane.showMessageDialog(null, "Congratulations! You Win!"); } - /* 当该field的地雷值为0才打开附近的Field */ + // Recursively open surrounding fields if mineValue is 0 if(getMineValue(x, y) == 0) { List aroundList = getAround(x, y); - /* 递归调用打开某Field附近的所有Field */ for(Field field: aroundList) { open(field.getX(), field.getY()); } } - } } /** - * 当在该Field附近的其他域作标记后,用于处理“打开附近Field”的方法 - * @param x 横坐标 - * @param y 纵坐标 + * Open surrounding fields when double-clicking on an opened field + * @param x row index + * @param y column index */ public void openAround(int x, int y) { - if(isOpened(x, y) && getMineValue(x, y) > 0) {//如果该Field已打开并且它附近的地雷值大于0 + if(isOpened(x, y) && getMineValue(x, y) > 0) { List aroundList = getAround(x, y); int mineNum = 0; for(Field field: aroundList) { - /* 如果该Field已被标记,mineNum加1 */ + // Count marked fields as mines if(field.isMarked()) { mineNum ++; } } - /* 当该Field附近的地雷值和mineNum相等时才执行真正的操作 */ + // If marked count matches mine value, open remaining if(getMineValue(x, y) == mineNum) { for(Field field: aroundList) { if(field.isMarked() && !field.isMine()) { - explode(); //如果该Field被标记且该Field不是地雷,马上打开所有Field - JOptionPane.showMessageDialog(null, "你输了"); + // Wrong mark - game over + explode(); + JOptionPane.showMessageDialog(null, "Game Over!"); } else if(!field.isMarked() && !field.isMine()) { - open(field.getX(), field.getY());//当附近的field不是地雷时调用open方法 + open(field.getX(), field.getY()); } } - } } - } /** - * 把某个Field设置为打开状态 - * @param x 横坐标 - * @param y 纵坐标 + * Set a field as opened + * @param x row index + * @param y column index */ public void setOpened(int x, int y) { getField(x, y).setStyle(Field.STYLE_OPENED); } /** - * 根据标记状态设置其为标记或取消标记 - * @param x 横坐标 - * @param y 纵坐标 + * Toggle mark on a field + * @param x row index + * @param y column index */ public void mark(int x, int y) { if(isCovered(x, y)) { @@ -252,88 +251,88 @@ public void mark(int x, int y) { } /** - * 把某个Field设置为被标记 - * @param x 横坐标 - * @param y 纵坐标 + * Set a field as marked + * @param x row index + * @param y column index */ public void setMarked(int x, int y) { getField(x, y).setStyle(Field.STYLE_MARKED); } /** - * 判断一个Field是否被标记 - * @param x 横坐标 - * @param y 纵坐标 - * @return 若被标记,true;否则,false + * Check if a field is marked + * @param x row index + * @param y column index + * @return true if marked, false otherwise */ public boolean isMarked(int x, int y) { return getField(x, y).isMarked(); } /** - * 判断某个Field是否地雷 - * @param x 横坐标 - * @param y 纵坐标 - * @return true,是地雷;false,不是地雷 + * Check if a field is a mine + * @param x row index + * @param y column index + * @return true if mine, false otherwise */ public boolean isMine(int x, int y) { return getField(x, y).isMine(); } /** - * 通过把mineValue值设置为-100表示该Field为地雷 - * @param x 横坐标 - * @param y 纵坐标 + * Set a field as a mine + * @param x row index + * @param y column index */ public void setMine(int x, int y) { getField(x, y).setMine(); } /** - * 判断该Field是否已打开 - * @param x - * @param y - * @return true,已被打开;false,没打开 + * Check if a field is opened + * @param x row index + * @param y column index + * @return true if opened, false otherwise */ public boolean isOpened(int x, int y) { return getField(x, y).isOpened(); } /** - * 获得指定Field的地雷值 - * @param x 横坐标 - * @param y 纵坐标 - * @return 该Field的地雷值 + * Get the mine value of a field + * @param x row index + * @param y column index + * @return mine value */ public int getMineValue(int x, int y) { return getField(x, y).getMineValue(); } /** - * 判断某个Field是否为覆盖 - * @param x 横坐标 - * @param y 纵坐标 - * @return 若为覆盖,true;否则,false + * Check if a field is covered + * @param x row index + * @param y column index + * @return true if covered, false otherwise */ public boolean isCovered(int x, int y) { return getField(x, y).isCovered(); } /** - * 把该Field的样式设置为覆盖 - * @param x 横坐标 - * @param y 纵坐标 + * Set a field as covered + * @param x row index + * @param y column index */ public void setCovered(int x, int y) { getField(x, y).setStyle(Field.STYLE_COVERED); } /** - * 打开全部Field + * Reveal all fields (game over) */ public void explode() { - for(int x = 0; x < COLUMNS; x ++) { - for(int y = 0; y < ROWS; y ++) { + for(int x = 0; x < columns; x ++) { + for(int y = 0; y < rows; y ++) { setOpened(x, y); } } @@ -345,12 +344,10 @@ public void paint(Graphics g) { g.setColor(Color.BLACK); g.fillRect(0, 0, getBounds().width, getBounds().height); - for(int x = 0; x < COLUMNS; x ++) { - for(int y = 0; y < ROWS; y ++) { + for(int x = 0; x < columns; x ++) { + for(int y = 0; y < rows; y ++) { getField(x, y).paintField(g); } } - } - } diff --git a/Mines/src/mines/MinesFrame.java b/Mines/src/mines/MinesFrame.java index d7464e9..904902b 100644 --- a/Mines/src/mines/MinesFrame.java +++ b/Mines/src/mines/MinesFrame.java @@ -1,69 +1,107 @@ package mines; +import java.awt.BorderLayout; +import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; +import javax.swing.JPanel; /** - * 扫雷主框架类 + * Main game frame * @author Leslie Leung */ public class MinesFrame extends JFrame{ - private MinesFields ms; //表示扫雷游戏面板 - private JButton btnStart; //表示“重新开始”按钮 + private MinesFields ms; + private JButton btnRestart; + private JButton btnBack; + private int rows; + private int columns; + private int minesNum; /** - * 构造方法 + * MinesFrame constructor + * @param rows number of rows + * @param columns number of columns + * @param minesNum number of mines */ - public MinesFrame(){ - setSize(500, 500); //设置窗体大小 + public MinesFrame(int rows, int columns, int minesNum){ + this.rows = rows; + this.columns = columns; + this.minesNum = minesNum; + + int width = columns * Field.FIELD_SIZE + 50; + int height = rows * Field.FIELD_SIZE + 100; + + // Ensure window size fits screen + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + if(width > screenSize.width - 100) { + width = screenSize.width - 100; + } + if(height > screenSize.height - 100) { + height = screenSize.height - 100; + } + + setSize(width, height); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setLocationRelativeTo(null); //设置窗体于屏幕中央 - setTitle("Mine"); //设置标题为Mine - setResizable(false); //不允许窗体缩放 - setLayout(new FlowLayout()); //设置布局管理器 - - ms = new MinesFields(); //新建场景类对象 - btnStart = new JButton("重新开始"); //新建按钮 + setLocationRelativeTo(null); + setTitle("Minesweeper - " + rows + "x" + columns); + setResizable(true); + + JPanel topPanel = new JPanel(new FlowLayout()); + + btnRestart = new JButton("Restart"); + btnRestart.addActionListener(new Restart()); + + btnBack = new JButton("Back to Menu"); + btnBack.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + new StartFrame(); + } + }); + + topPanel.add(btnRestart); + topPanel.add(btnBack); + + add(topPanel, BorderLayout.NORTH); - add(btnStart); //把按钮添加到框架中 - add(ms); //把扫雷场景添加到框架中 + ms = new MinesFields(rows, columns, minesNum); + add(ms, BorderLayout.CENTER); - /* 注册鼠标事件 */ + // Register mouse listeners addMouseListener(ms.getInnerInstance()); ms.addMouseListener(ms.getInnerInstance()); - /* 使用匿名内部类的方式监听按钮事件,让游戏重新开始 */ - btnStart.addActionListener(new Restart()); - setVisible(true); } /** - * 内部类,用于实现点击按钮重新开始游戏的功能 + * Inner class for restart button action * @author Leslie Leung */ private class Restart implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - remove(ms); //先移除面板 - ms = new MinesFields(); //再新建 - add(ms); //添加新建的MinesFields对象 + remove(ms); + ms = new MinesFields(rows, columns, minesNum); + add(ms, BorderLayout.CENTER); - /* 注册鼠标事件 */ + // Register mouse listeners addMouseListener(ms.getInnerInstance()); ms.addMouseListener(ms.getInnerInstance()); - setVisible(true); + revalidate(); + repaint(); } } public static void main(String[] args) { - new MinesFrame(); + new StartFrame(); } - } diff --git a/Mines/src/mines/StartFrame.java b/Mines/src/mines/StartFrame.java new file mode 100644 index 0000000..8fbedbe --- /dev/null +++ b/Mines/src/mines/StartFrame.java @@ -0,0 +1,118 @@ +package mines; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; + +/** + * Game start menu frame + * @author Leslie Leung + */ +public class StartFrame extends JFrame { + + // Easy difficulty: 16x16 with 30 mines + private static final int EASY_ROWS = 16; + private static final int EASY_COLUMNS = 16; + private static final int EASY_MINES = 30; + + // Medium difficulty: 20x20 with 60 mines + private static final int MEDIUM_ROWS = 20; + private static final int MEDIUM_COLUMNS = 20; + private static final int MEDIUM_MINES = 60; + + // Hard difficulty: 25x25 with 100 mines + private static final int HARD_ROWS = 25; + private static final int HARD_COLUMNS = 25; + private static final int HARD_MINES = 100; + + /** + * StartFrame constructor + */ + public StartFrame() { + setTitle("Minesweeper"); + setSize(400, 350); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setLocationRelativeTo(null); + setResizable(false); + + JPanel mainPanel = new JPanel(new BorderLayout()); + + // Title label + JLabel titleLabel = new JLabel("Minesweeper", JLabel.CENTER); + titleLabel.setFont(new Font("Arial", Font.BOLD, 36)); + titleLabel.setBorder(new javax.swing.border.EmptyBorder(40, 0, 20, 0)); + mainPanel.add(titleLabel, BorderLayout.NORTH); + + // Difficulty buttons panel + JPanel buttonPanel = new JPanel(new GridBagLayout()); + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.insets = new Insets(10, 80, 10, 80); + + // Easy button + JButton btnEasy = new JButton("Easy (16x16)"); + btnEasy.setFont(new Font("Arial", Font.PLAIN, 16)); + btnEasy.setPreferredSize(new Dimension(200, 45)); + btnEasy.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + startGame(EASY_ROWS, EASY_COLUMNS, EASY_MINES); + } + }); + buttonPanel.add(btnEasy, gbc); + + // Medium button + JButton btnMedium = new JButton("Medium (20x20)"); + btnMedium.setFont(new Font("Arial", Font.PLAIN, 16)); + btnMedium.setPreferredSize(new Dimension(200, 45)); + btnMedium.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + startGame(MEDIUM_ROWS, MEDIUM_COLUMNS, MEDIUM_MINES); + } + }); + buttonPanel.add(btnMedium, gbc); + + // Hard button + JButton btnHard = new JButton("Hard (25x25)"); + btnHard.setFont(new Font("Arial", Font.PLAIN, 16)); + btnHard.setPreferredSize(new Dimension(200, 45)); + btnHard.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + startGame(HARD_ROWS, HARD_COLUMNS, HARD_MINES); + } + }); + buttonPanel.add(btnHard, gbc); + + mainPanel.add(buttonPanel, BorderLayout.CENTER); + + add(mainPanel); + setVisible(true); + } + + /** + * Start the game with specified difficulty + * @param rows number of rows + * @param columns number of columns + * @param minesNum number of mines + */ + private void startGame(int rows, int columns, int minesNum) { + dispose(); + new MinesFrame(rows, columns, minesNum); + } + + public static void main(String[] args) { + new StartFrame(); + } +} diff --git a/Tetris/.project b/Tetris/.project index ddf9a01..914e617 100644 --- a/Tetris/.project +++ b/Tetris/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1776589793075 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Tetris/bin/tetris/Cell.class b/Tetris/bin/tetris/Cell.class deleted file mode 100644 index 9b6b82a..0000000 Binary files a/Tetris/bin/tetris/Cell.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisFrame.class b/Tetris/bin/tetris/TetrisFrame.class deleted file mode 100644 index 321f9f1..0000000 Binary files a/Tetris/bin/tetris/TetrisFrame.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$DropExecution.class b/Tetris/bin/tetris/TetrisPane$DropExecution.class deleted file mode 100644 index 377674d..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$DropExecution.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$IShaped.class b/Tetris/bin/tetris/TetrisPane$IShaped.class deleted file mode 100644 index e5fa4bf..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$IShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$JShaped.class b/Tetris/bin/tetris/TetrisPane$JShaped.class deleted file mode 100644 index 3ab86e2..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$JShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$KeyControl.class b/Tetris/bin/tetris/TetrisPane$KeyControl.class deleted file mode 100644 index a8c5be7..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$KeyControl.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$LShaped.class b/Tetris/bin/tetris/TetrisPane$LShaped.class deleted file mode 100644 index b908e9f..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$LShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$OShaped.class b/Tetris/bin/tetris/TetrisPane$OShaped.class deleted file mode 100644 index d69f0e7..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$OShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$SShaped.class b/Tetris/bin/tetris/TetrisPane$SShaped.class deleted file mode 100644 index 611b505..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$SShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$TShaped.class b/Tetris/bin/tetris/TetrisPane$TShaped.class deleted file mode 100644 index e6d649a..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$TShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane$ZShaped.class b/Tetris/bin/tetris/TetrisPane$ZShaped.class deleted file mode 100644 index 15fe14c..0000000 Binary files a/Tetris/bin/tetris/TetrisPane$ZShaped.class and /dev/null differ diff --git a/Tetris/bin/tetris/TetrisPane.class b/Tetris/bin/tetris/TetrisPane.class deleted file mode 100644 index 545d304..0000000 Binary files a/Tetris/bin/tetris/TetrisPane.class and /dev/null differ diff --git a/Tetris/bin/tetris/Tetromino.class b/Tetris/bin/tetris/Tetromino.class deleted file mode 100644 index 7238b44..0000000 Binary files a/Tetris/bin/tetris/Tetromino.class and /dev/null differ diff --git a/TrainGame/.project b/TrainGame/.project index 0fe010e..335b197 100644 --- a/TrainGame/.project +++ b/TrainGame/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1776589793080 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/TrainGame/bin/traingame/Card.class b/TrainGame/bin/traingame/Card.class deleted file mode 100644 index 01a3084..0000000 Binary files a/TrainGame/bin/traingame/Card.class and /dev/null differ diff --git a/TrainGame/bin/traingame/ImageFactory.class b/TrainGame/bin/traingame/ImageFactory.class deleted file mode 100644 index d3e5573..0000000 Binary files a/TrainGame/bin/traingame/ImageFactory.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGame$DealExecution.class b/TrainGame/bin/traingame/TrainGame$DealExecution.class deleted file mode 100644 index 76944e5..0000000 Binary files a/TrainGame/bin/traingame/TrainGame$DealExecution.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGame$MouseControl.class b/TrainGame/bin/traingame/TrainGame$MouseControl.class deleted file mode 100644 index 717fd8b..0000000 Binary files a/TrainGame/bin/traingame/TrainGame$MouseControl.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGame$PlayExecution$1.class b/TrainGame/bin/traingame/TrainGame$PlayExecution$1.class deleted file mode 100644 index 634f563..0000000 Binary files a/TrainGame/bin/traingame/TrainGame$PlayExecution$1.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGame$PlayExecution.class b/TrainGame/bin/traingame/TrainGame$PlayExecution.class deleted file mode 100644 index e3e795a..0000000 Binary files a/TrainGame/bin/traingame/TrainGame$PlayExecution.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGame.class b/TrainGame/bin/traingame/TrainGame.class deleted file mode 100644 index 2738d99..0000000 Binary files a/TrainGame/bin/traingame/TrainGame.class and /dev/null differ diff --git a/TrainGame/bin/traingame/TrainGameFrame.class b/TrainGame/bin/traingame/TrainGameFrame.class deleted file mode 100644 index 7da5834..0000000 Binary files a/TrainGame/bin/traingame/TrainGameFrame.class and /dev/null differ diff --git a/Worm/.project b/Worm/.project index 60d3c7c..dee7d5c 100644 --- a/Worm/.project +++ b/Worm/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1776589793085 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/Worm/bin/worm/Cell.class b/Worm/bin/worm/Cell.class deleted file mode 100644 index c9993d6..0000000 Binary files a/Worm/bin/worm/Cell.class and /dev/null differ diff --git a/Worm/bin/worm/Worm.class b/Worm/bin/worm/Worm.class deleted file mode 100644 index dac932b..0000000 Binary files a/Worm/bin/worm/Worm.class and /dev/null differ diff --git a/Worm/bin/worm/WormFrame.class b/Worm/bin/worm/WormFrame.class deleted file mode 100644 index 22dcb20..0000000 Binary files a/Worm/bin/worm/WormFrame.class and /dev/null differ diff --git a/Worm/bin/worm/WormStage$KeyControl.class b/Worm/bin/worm/WormStage$KeyControl.class deleted file mode 100644 index 3f8ee60..0000000 Binary files a/Worm/bin/worm/WormStage$KeyControl.class and /dev/null differ diff --git a/Worm/bin/worm/WormStage$Move.class b/Worm/bin/worm/WormStage$Move.class deleted file mode 100644 index 2f9f19b..0000000 Binary files a/Worm/bin/worm/WormStage$Move.class and /dev/null differ diff --git a/Worm/bin/worm/WormStage.class b/Worm/bin/worm/WormStage.class deleted file mode 100644 index 00b066a..0000000 Binary files a/Worm/bin/worm/WormStage.class and /dev/null differ