当前位置:   article > 正文

软件工程—黄金矿工_黄金矿工java代码

黄金矿工java代码

 周二去实验室完善了游戏的详细设计所需的图(附加上传第一版黄金矿工的代码,代码有借鉴)。



  1. package minegame;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.KeyAdapter;
  5. import java.awt.event.KeyEvent;
  6. import java.awt.event.MouseAdapter;
  7. import java.awt.event.MouseEvent;
  8. import java.io.IOException;
  9. public class GoldMiner extends JFrame{
  10. Stage stage;
  11. static boolean tag = true;
  12. // static final double TIME_STEP = 1.0; //单位事件步长
  13. static final double PERIOD = 20.0;
  14. public GoldMiner() throws IOException{
  15. setTitle("Gold Miner");
  16. setSize(800,600);
  17. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18. stage = new Stage();
  19. stage.setFocusable(true);
  20. stage.requestFocusInWindow();
  21. stage.addMouseListener(new MouseAdapter() {
  22. @Override
  23. public void mouseClicked(MouseEvent e) {
  24. super.mouseClicked(e);
  25. int x=e.getX(), y=e.getY();
  26. if(stage.stageState==Stage.StageState.MENU){
  27. if(x>340&&x<490 && y>200 && y<250){
  28. try{
  29. stage.load(0);
  30. stage.start();
  31. }catch (IOException e1){
  32. e1.printStackTrace();
  33. }
  34. }else if(x>340&&x<490&& y>280 && y<330){
  35. //游戏设置
  36. stage.setting();
  37. }else if (x > 340&&x < 490 && y > 360 && y < 410){
  38. stage.openOptions();
  39. }
  40. else if (x > 340 && x < 490 && y > 440 && y < 490){
  41. dispose();
  42. }
  43. }else if(stage.stageState== Stage.StageState.GAME_OVER){
  44. int distance = (x-412)*(x-412)+(y-432)*(y-432);
  45. if (x > 10 && x < 81 && y > 10 && y < 50){
  46. stage.openMenu();
  47. }
  48. if(distance<1024){
  49. try{
  50. stage.load(0);
  51. stage.start();
  52. stage.hook = new Hook(stage.width, 180);
  53. }catch (IOException e1){
  54. e1.printStackTrace();
  55. }
  56. }
  57. }else if (stage.stageState == Stage.StageState.GAME_SETTING){
  58. int distance1 = (x - 365) * (x - 365) + (y - 315) * (y - 315);
  59. int distance2 = (x - 445) * (x - 445) + (y - 315) * (y - 315);
  60. if (x > 10 && x < 81 && y > 10 && y < 50){
  61. stage.openMenu();
  62. }
  63. if (distance1 <= 625){
  64. Stage.setFlag(true);
  65. tag = true;
  66. stage.openMenu();
  67. System.out.println("123");
  68. }
  69. if (distance2 <= 625){
  70. Stage.setFlag(false);
  71. tag = false;
  72. stage.openMenu();
  73. }
  74. }else if (stage.stageState == Stage.StageState.GAME_OPTIONS){
  75. if(x>340&&x<490&& y>280 && y<330){
  76. stage.keyplain();
  77. }else if (x > 340&&x < 490 && y > 360 && y < 410){
  78. stage.aboutGame();
  79. }else if (x > 10 && x < 81 && y > 10 && y < 50){
  80. stage.openMenu();
  81. }
  82. }else if (stage.stageState == Stage.StageState.GAME_MOVE){
  83. if (x > 10 && x < 81 && y > 10 && y < 50){
  84. stage.openOptions();
  85. }
  86. }else if (stage.stageState == Stage.StageState.GAME_EXPLAIN){
  87. if (x > 10 && x < 81 && y > 10 && y < 50){
  88. stage.openOptions();
  89. }
  90. }
  91. }
  92. }
  93. );
  94. stage.addKeyListener(new KeyAdapter() {
  95. @Override
  96. public void keyPressed(KeyEvent e) {
  97. super.keyPressed(e);
  98. switch (e.getKeyCode()) {
  99. case KeyEvent.VK_SPACE:
  100. stage.hook.launch();
  101. break;
  102. case KeyEvent.VK_P:
  103. stage.pause();
  104. break;
  105. case KeyEvent.VK_ESCAPE:
  106. stage.configure();
  107. break;
  108. }
  109. }
  110. });
  111. stage.stageSta
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/127508
推荐阅读
相关标签
  

闽ICP备14008679号