赞
踩
周二去实验室完善了游戏的详细设计所需的图(附加上传第一版黄金矿工的代码,代码有借鉴)。
- package minegame;
- import javax.swing.*;
-
- import java.awt.*;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.io.IOException;
- public class GoldMiner extends JFrame{
- Stage stage;
- static boolean tag = true;
- // static final double TIME_STEP = 1.0; //单位事件步长
- static final double PERIOD = 20.0;
-
-
- public GoldMiner() throws IOException{
- setTitle("Gold Miner");
- setSize(800,600);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- stage = new Stage();
- stage.setFocusable(true);
- stage.requestFocusInWindow();
- stage.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- super.mouseClicked(e);
- int x=e.getX(), y=e.getY();
- if(stage.stageState==Stage.StageState.MENU){
-
- if(x>340&&x<490 && y>200 && y<250){
- try{
- stage.load(0);
- stage.start();
- }catch (IOException e1){
- e1.printStackTrace();
- }
- }else if(x>340&&x<490&& y>280 && y<330){
- //游戏设置
- stage.setting();
- }else if (x > 340&&x < 490 && y > 360 && y < 410){
- stage.openOptions();
- }
- else if (x > 340 && x < 490 && y > 440 && y < 490){
- dispose();
- }
- }else if(stage.stageState== Stage.StageState.GAME_OVER){
- int distance = (x-412)*(x-412)+(y-432)*(y-432);
- if (x > 10 && x < 81 && y > 10 && y < 50){
- stage.openMenu();
- }
- if(distance<1024){
- try{
- stage.load(0);
- stage.start();
- stage.hook = new Hook(stage.width, 180);
- }catch (IOException e1){
- e1.printStackTrace();
- }
- }
-
- }else if (stage.stageState == Stage.StageState.GAME_SETTING){
- int distance1 = (x - 365) * (x - 365) + (y - 315) * (y - 315);
- int distance2 = (x - 445) * (x - 445) + (y - 315) * (y - 315);
- if (x > 10 && x < 81 && y > 10 && y < 50){
- stage.openMenu();
- }
- if (distance1 <= 625){
- Stage.setFlag(true);
- tag = true;
- stage.openMenu();
- System.out.println("123");
- }
- if (distance2 <= 625){
- Stage.setFlag(false);
- tag = false;
- stage.openMenu();
- }
- }else if (stage.stageState == Stage.StageState.GAME_OPTIONS){
- if(x>340&&x<490&& y>280 && y<330){
- stage.keyplain();
- }else if (x > 340&&x < 490 && y > 360 && y < 410){
- stage.aboutGame();
- }else if (x > 10 && x < 81 && y > 10 && y < 50){
- stage.openMenu();
- }
- }else if (stage.stageState == Stage.StageState.GAME_MOVE){
- if (x > 10 && x < 81 && y > 10 && y < 50){
- stage.openOptions();
- }
- }else if (stage.stageState == Stage.StageState.GAME_EXPLAIN){
- if (x > 10 && x < 81 && y > 10 && y < 50){
- stage.openOptions();
- }
- }
-
- }
- }
- );
-
-
- stage.addKeyListener(new KeyAdapter() {
- @Override
- public void keyPressed(KeyEvent e) {
- super.keyPressed(e);
- switch (e.getKeyCode()) {
- case KeyEvent.VK_SPACE:
- stage.hook.launch();
- break;
- case KeyEvent.VK_P:
- stage.pause();
- break;
- case KeyEvent.VK_ESCAPE:
- stage.configure();
- break;
- }
- }
- });
-
- stage.stageSta
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。