diff --git a/FishGame/bin/com/mypro/base/graphics/Bitmap.class b/FishGame/bin/com/mypro/base/graphics/Bitmap.class new file mode 100644 index 0000000..77b0b90 Binary files /dev/null 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 new file mode 100644 index 0000000..9c8af2b Binary files /dev/null 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 new file mode 100644 index 0000000..cf1e9fd Binary files /dev/null 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 new file mode 100644 index 0000000..9a24c50 Binary files /dev/null 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 new file mode 100644 index 0000000..6113e42 Binary files /dev/null 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 new file mode 100644 index 0000000..ed35b4b Binary files /dev/null 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 new file mode 100644 index 0000000..7d57849 Binary files /dev/null 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..d38b373 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 new file mode 100644 index 0000000..ca8cd49 Binary files /dev/null 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 new file mode 100644 index 0000000..562dbd0 Binary files /dev/null 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 new file mode 100644 index 0000000..cc226c7 Binary files /dev/null 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 new file mode 100644 index 0000000..4d42b5a Binary files /dev/null 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 new file mode 100644 index 0000000..cafdce3 Binary files /dev/null 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 new file mode 100644 index 0000000..cac5adf Binary files /dev/null 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 new file mode 100644 index 0000000..0869d05 Binary files /dev/null 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 new file mode 100644 index 0000000..37634ff Binary files /dev/null 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 new file mode 100644 index 0000000..2a3e18e Binary files /dev/null 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 new file mode 100644 index 0000000..aa28dd8 Binary files /dev/null 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 new file mode 100644 index 0000000..2fa501e Binary files /dev/null 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 new file mode 100644 index 0000000..f53df02 Binary files /dev/null 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 new file mode 100644 index 0000000..a0daeb9 Binary files /dev/null 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 new file mode 100644 index 0000000..472f941 Binary files /dev/null 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 new file mode 100644 index 0000000..8147b3e Binary files /dev/null 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 new file mode 100644 index 0000000..87b4125 Binary files /dev/null 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 new file mode 100644 index 0000000..b6c87d0 Binary files /dev/null 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 new file mode 100644 index 0000000..29b4ce3 Binary files /dev/null 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 new file mode 100644 index 0000000..a2679b7 Binary files /dev/null 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 new file mode 100644 index 0000000..ee72d52 Binary files /dev/null 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 new file mode 100644 index 0000000..7f0e173 Binary files /dev/null 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 new file mode 100644 index 0000000..6d56d7e Binary files /dev/null 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 new file mode 100644 index 0000000..96f5f1b Binary files /dev/null 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 new file mode 100644 index 0000000..3219bbe Binary files /dev/null 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 new file mode 100644 index 0000000..6ef0348 Binary files /dev/null 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 new file mode 100644 index 0000000..6f13bc2 Binary files /dev/null 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 new file mode 100644 index 0000000..03f8f79 Binary files /dev/null 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 new file mode 100644 index 0000000..61dd6db Binary files /dev/null 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 new file mode 100644 index 0000000..94408a0 Binary files /dev/null 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 new file mode 100644 index 0000000..da512d0 Binary files /dev/null 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 new file mode 100644 index 0000000..519f080 Binary files /dev/null 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 new file mode 100644 index 0000000..9e9283b Binary files /dev/null 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 new file mode 100644 index 0000000..1b9c1a5 Binary files /dev/null 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 new file mode 100644 index 0000000..4975212 Binary files /dev/null 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 new file mode 100644 index 0000000..ea76bb6 Binary files /dev/null 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 new file mode 100644 index 0000000..ecd3e58 Binary files /dev/null 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 new file mode 100644 index 0000000..ee9b46c Binary files /dev/null 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 new file mode 100644 index 0000000..1085b36 Binary files /dev/null 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 new file mode 100644 index 0000000..e81a727 Binary files /dev/null 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 new file mode 100644 index 0000000..830f835 Binary files /dev/null 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 new file mode 100644 index 0000000..aaebc19 Binary files /dev/null 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 new file mode 100644 index 0000000..fe326f3 Binary files /dev/null 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 new file mode 100644 index 0000000..10f6755 Binary files /dev/null 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 new file mode 100644 index 0000000..750c110 Binary files /dev/null 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 new file mode 100644 index 0000000..e8703f0 Binary files /dev/null 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 new file mode 100644 index 0000000..4a8869a Binary files /dev/null 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 new file mode 100644 index 0000000..a491439 Binary files /dev/null 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 new file mode 100644 index 0000000..5e7cadf Binary files /dev/null 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 new file mode 100644 index 0000000..a1fb181 Binary files /dev/null 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 new file mode 100644 index 0000000..ae8c871 Binary files /dev/null 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 new file mode 100644 index 0000000..1ca38df Binary files /dev/null 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 new file mode 100644 index 0000000..8354262 Binary files /dev/null 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 new file mode 100644 index 0000000..d1827a7 Binary files /dev/null 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 new file mode 100644 index 0000000..1b8d768 Binary files /dev/null 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 new file mode 100644 index 0000000..d572e8d Binary files /dev/null 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 new file mode 100644 index 0000000..d41d0ce Binary files /dev/null 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 new file mode 100644 index 0000000..07178f5 Binary files /dev/null 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 new file mode 100644 index 0000000..d9562f9 Binary files /dev/null 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 new file mode 100644 index 0000000..2f7f9d0 Binary files /dev/null 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 new file mode 100644 index 0000000..deeb060 Binary files /dev/null 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 new file mode 100644 index 0000000..0662904 Binary files /dev/null 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 new file mode 100644 index 0000000..3ce72c4 Binary files /dev/null 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 new file mode 100644 index 0000000..5be8377 Binary files /dev/null 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 new file mode 100644 index 0000000..20519ed Binary files /dev/null and b/FishGame/bin/com/mypro/tools/Tool.class differ diff --git a/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java b/FishGame/src/com/mypro/basecomponet/AwtMainComponet.java index 3329389..985d1fa 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,172 @@ 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 = 30; + private static final int BUTTON_WIDTH = 40; + private static final int BUTTON_HEIGHT = 30; + 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().setScreenHeight(600); + 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.pack(); - pane.action(); - /** - * 创建一个线程来异步初始化游戏内容 - */ + + frame.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + } + + @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); + } + } + }); + + 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(40, 40, 60)); + g.fillRect(0, 0, width, TITLE_BAR_HEIGHT); + + g.setColor(java.awt.Color.WHITE); + g.setFont(new java.awt.Font("Microsoft YaHei", java.awt.Font.BOLD, 14)); + g.drawString("鎹曢奔娓告垙", 10, 20); + + int buttonX = width - BUTTON_WIDTH * 3; + + g.setColor(java.awt.Color.GRAY); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(java.awt.Color.WHITE); + g.drawLine(buttonX + 10, 15, buttonX + BUTTON_WIDTH - 10, 15); + + buttonX += BUTTON_WIDTH; + g.setColor(java.awt.Color.GRAY); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(java.awt.Color.WHITE); + if (isMaximized) { + g.drawRect(buttonX + 12, 10, BUTTON_WIDTH - 24, BUTTON_HEIGHT - 20); + } else { + g.drawRect(buttonX + 10, 8, BUTTON_WIDTH - 20, BUTTON_HEIGHT - 16); + } + + buttonX += BUTTON_WIDTH; + g.setColor(java.awt.Color.RED); + g.fillRect(buttonX, 0, BUTTON_WIDTH, BUTTON_HEIGHT); + g.setColor(java.awt.Color.WHITE); + g.drawLine(buttonX + 12, 10, buttonX + BUTTON_WIDTH - 12, BUTTON_HEIGHT - 10); + g.drawLine(buttonX + BUTTON_WIDTH - 12, 10, buttonX + 12, BUTTON_HEIGHT - 10); } } diff --git a/FishGame/src/com/mypro/mainsurface/MainSurface.java b/FishGame/src/com/mypro/mainsurface/MainSurface.java index ba9e844..0d8f819 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 = 30; + 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锟斤拷锟斤拷锟劫伙拷取图锟斤拷锟斤拷疲锟绞∪ワ拷舜锟絤ap锟叫伙拷取锟斤拷锟斤拷图锟斤拷锟斤拷锟斤拷锟斤拷锟解) - private Paint paint; // 锟斤拷锟斤拷 - private OnDrawThread odt; // 锟斤拷幕锟斤拷锟斤拷锟竭程o拷锟斤拷锟节匡拷锟狡伙拷锟斤拷帧锟斤拷锟斤拷锟斤拷锟斤拷锟皆碉拷锟斤拷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); - } + drawTitleBar(g); + + 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); + } + } } } - /** - * 锟斤拷锟斤拷图锟姐,锟斤拷锟斤拷锟轿拷锟斤拷植锟斤拷锟斤拷锟斤拷直锟斤拷歉锟斤拷锟斤拷锟绞蓖硷拷锟斤拷械锟斤拷锟斤拷莸锟斤拷锟斤拷锟酵硷拷锟斤拷校锟缴撅拷锟斤拷锟斤拷锟酵硷拷锟斤拷械锟皆拷兀锟斤拷锟斤拷踊锟斤拷锟酵硷拷锟斤拷械锟皆拷锟 - * 锟斤拷锟斤拷锟斤拷烁锟斤拷叱锟斤拷锟斤拷锟斤拷锟街わ拷锟斤拷叱锟斤拷虏锟斤拷锟酵硷拷锟侥帮拷全锟斤拷 - * @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; - /** - * 锟斤拷锟斤拷锟斤拷锟斤拷锟酵纪硷拷锟斤拷锟斤拷锟斤拷踊锟斤拷锟缴撅拷锟皆拷兀锟斤拷锟斤拷锟斤拷锟街憋拷硬锟斤拷锟斤拷锟斤拷锟酵硷拷悖拷锟斤拷谴锟斤拷锟节讹拷应锟斤拷锟斤拷时图锟斤拷锟叫o拷锟饺达拷锟斤拷锟狡凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟叫斤拷锟戒化锟斤拷锟斤拷锟捷革拷锟铰碉拷锟斤拷锟斤拷图锟斤拷锟斤拷 - * 锟斤拷证锟斤拷锟竭程诧拷锟斤拷锟斤拷锟斤拷碌陌锟饺拷锟 - */ - //锟斤拷锟斤拷一锟斤拷元锟斤拷 + 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 - * 图锟斤拷锟 图锟斤拷锟斤拷锟饺伙拷锟絠nt锟斤拷锟斤拷锟斤拷实锟斤拷锟斤拷只支锟街碉拷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锟斤拷模锟斤拷徒锟斤拷碌锟酵硷拷锟絀D锟斤拷锟斤拷锟斤拷锟 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); @@ -317,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; @@ -330,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 871c623..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 锟斤拷锟絘ssets锟侥达拷路锟斤拷锟斤拷锟侥硷拷 锟斤拷 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); } } } - /** - * 锟斤拷锟斤拷图片锟斤拷锟斤拷锟斤拷息 - * 锟斤拷锟斤拷锟较革拷锟斤拷顺锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟剿筹拷锟斤拷锟斤拷猓拷锟斤拷锟絰ml锟角憋拷锟斤拷锟矫碉拷顺锟斤拷要锟饺斤拷锟较革拷 - * @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); } - /** - * 锟斤拷锟斤拷锟斤拷幕锟竭达拷锟斤拷锟斤拷图片 - * 锟斤拷锟斤拷锟斤拷要注锟斤拷锟揭伙拷锟斤拷牵锟揭拷锟绞硷拷锟紾amingInfo锟斤拷锟斤拷锟侥伙拷叽纾拷锟轿拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷图片锟斤拷 - * @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,12 +230,7 @@ public Bitmap sacleImageByWidthAndHeight(Bitmap src,int width,int height){ g.drawImage(src.getImage(), trans, null); return new Bitmap(img); } - /** - * 锟斤拷锟绞诧拷锟叫伙拷取图片 - * @param imageName 锟斤拷锟斤拷什锟絘ssets锟斤拷目录锟铰的达拷路锟斤拷锟斤拷图片锟斤拷锟斤拷 - * @return 锟斤拷锟斤拷指锟斤拷锟斤拷图片 - * @throws Exception - */ + public Bitmap getBitmapByAssets(String imageName)throws Exception{ try { File file = new File(imageName); @@ -331,12 +247,7 @@ public Bitmap getBitmapByAssets(String imageName)throws Exception{ throw e; } } - /** - * 锟斤拷锟绞诧拷锟叫伙拷取锟斤拷锟斤拷锟斤拷幕锟竭达拷锟斤拷锟脚猴拷锟酵计 - * @param imageName - * @return - * @throws Exception - */ + public Bitmap getscaleImageByScreenFromAssets(String imageName)throws Exception{ try { return scaleImageByScreen(getBitmapByAssets(imageName)); @@ -346,4 +257,3 @@ public Bitmap getscaleImageByScreenFromAssets(String imageName)throws Exception{ } } - 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; + } }