游戏效果


类关系如下

不用看sample包和sql包。

BaseObject

package JavaBigJob;import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.Parent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;import java.security.Key;public class BaseObject extends Parent {//为了方便动态绑定,用Property类型//坐标private DoubleProperty xProperty = new SimpleDoubleProperty(0);private DoubleProperty yProperty = new SimpleDoubleProperty(0);//宽,高private DoubleProperty widthProperty = new SimpleDoubleProperty(0);private DoubleProperty heightProperty = new SimpleDoubleProperty(0);private double speed = 1;//初始速度public BaseObject() {//        this.xProperty.bind(super.xProperty());}public double getxProperty() {return xProperty.get();}public DoubleProperty xProperty() {return xProperty;}public void setxProperty(double xProperty) {this.xProperty.set(xProperty);}public double getyProperty() {return yProperty.get();}public DoubleProperty yProperty() {return yProperty;}public void setyProperty(double yProperty) {this.yProperty.set(yProperty);}public double getWidthProperty() {return widthProperty.get();}public DoubleProperty widthPropertyProperty() {return widthProperty;}public void setWidthProperty(double widthProperty) {this.widthProperty.set(widthProperty);}public double getHeightProperty() {return heightProperty.get();}public DoubleProperty heightPropertyProperty() {return heightProperty;}public void setHeightProperty(double heightProperty) {this.heightProperty.set(heightProperty);}public double getSpeed(){return this.speed;}public void setSpeed(double speed){this.speed=speed;}public void moveX(double x){System.out.println(getxProperty()+" "+x);this.setxProperty(getxProperty()+x);System.out.println("moveX");}public void moveY(double y){this.setyProperty(this.getyProperty()+y);}//判断是否发生矩形碰撞public boolean isImpact(BaseObject baseObject){if(getxProperty() + getWidthProperty() > baseObject.getxProperty() && getxProperty() < baseObject.getxProperty() + baseObject.getWidthProperty() && getyProperty() + getHeightProperty() > baseObject.getyProperty() && getyProperty() < baseObject.getyProperty() + baseObject.getHeightProperty()){return true;}return false;}public interface CanMove {//定义一个接口,子类若能移动则需要继承此接口void onKeyBoardPressed(KeyEvent event);void onKeyBoardReleased(KeyEvent event);static void add(){System.out.println("nb");}}}

BaseRectangle

平台类,设置成不可见,导入BaseRectangle到平台集合中。

package JavaBigJob;import javafx.scene.effect.Bloom;
import javafx.scene.effect.BoxBlur;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Rectangle;public class BaseRectangle extends BaseObject {private Rectangle r = null;private BoxBlur boxBlur = null;private Bloom bloom = null;private double width;private double height;public BaseRectangle(double width, double height) {this.width = width;this.height = height;r = new Rectangle();//矩形与该类实例化的对象进行动态绑定r.widthProperty().bindBidirectional(this.widthPropertyProperty());r.heightProperty().bindBidirectional(this.heightPropertyProperty());r.xProperty().bindBidirectional(this.xProperty());r.yProperty().bindBidirectional(this.yProperty());//矩形宽度和长度r.setWidth(width);r.setHeight(height);//动态绑定后把矩形添加this.getChildren().addAll(r);}public BaseRectangle(double width, double height, double Arc1, double Arc2, Color color) {this(width,height);//设置圆角角度r.setArcWidth(Arc1);r.setArcHeight(Arc2);r.setFill(color);//模糊化boxBlur = new BoxBlur();boxBlur.setWidth(5);boxBlur.setHeight(5);//动态化bloom = new Bloom();bloom.setThreshold(50);//上面两种属性与举行绑定r.setEffect(boxBlur);r.setEffect(bloom);}public double getWidth() {return width;}public void setWidth(double width) {this.width = width;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public void setVisible(Boolean b){r.setVisible(b);this.setVisible(b);}//    public void onMouse(MouseEvent event){        if (event.getX() >= this.getWidthProperty()/2 && event.getX() <= GameWindow.WIDTH - this.getWidthProperty()/2 && event.getY()<=Window.HEIGHT) {//            System.out.println(event.getX());
//            System.out.println(event.getY());
//            this.setxProperty(event.getX()/* - this.getWidthProperty()/2*/);
//            this.setyProperty(event.getY()/* - this.getHeightProperty()/2*/);
        }
//    }}

BaseScene

用来加载各种时间线和物体
(时间线:人物跳跃,人物移动,人物下落,人物与平台的碰撞判定。子弹飞行,子弹碰撞。
物体:两个人物,背景,平台)

package JavaBigJob;import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;import java.util.ArrayList;
import java.util.Collections;//场景类,继承了Parent
//加载了 循环时间轴,和各个物体以及场景public class BaseScene extends Parent {public BaseRectangle br;Rectangle rectangleSecen;public ArrayList<BaseRectangle> brArrayList = new ArrayList<BaseRectangle>();static ArrayList<Rectangle> bulletArrayList = new ArrayList<Rectangle>();public static Man man1 =  new Man();;public static Man2 man2 = new Man2();private int width;//场景的宽度长度,用于边界判断。private int height;static Bullet bullet;private ReplaceClothes replaceClothes;KeyFrame keyFrame;//栈帧keyframe,每一帧要执行的事件,执行后通过timeline刷新
//    Timeline timeline;//bg为背景版public Rectangle bg;public ImageView imageView;public BaseScene(int width,int height) {this.width = width;this.height = height;initAll();}public void initBackGround(){imageView = new ImageView(new Image("JavaBigJob/Picture/89.png"));imageView.setFitWidth(1111);imageView.setFitHeight(800);bg = new Rectangle(0,0,GameWindow.WIDTH,GameWindow.HEIGHT);bg.setFill(Color.BLACK);this.getChildren().add(imageView);}public void initBullet(){bullet = new Bullet();getChildren().addAll(bullet);}public void initMan(){man1.setxProperty(700);man1.setyProperty(100);this.getChildren().add(man1);}public void initMan2(){man2.setxProperty(200);man2.setyProperty(100);this.getChildren().add(man2);}public void initReplace(){//加载换装页面,而不是new一个节点;replaceClothes = new ReplaceClothes();}//加载时间轴public void initTimeline(){moveTimeline();Man.dropOutTimeline(brArrayList);
//        Man.jumpTimeline();Man2.dropOutTimeline(brArrayList);//        Man2.jumpTimeline();}//加载临时平台public void initTmpPlat(){//临时平台br = new BaseRectangle(320,5,10,10,Color.YELLOW);br.setxProperty(710);br.setyProperty(525);BaseRectangle br2 = new BaseRectangle(420,5,10,10,Color.BLUE);br2.setxProperty(350);br2.setyProperty(400);BaseRectangle br3 = new BaseRectangle(860,5,10,10,Color.GREEN);br3.setxProperty(135);br3.setyProperty(173);BaseRectangle br4 = new BaseRectangle(875,5,10,10,Color.RED);br4.setxProperty(150);br4.setyProperty(650);BaseRectangle br5 = new BaseRectangle(350,5,10,10,Color.GOLD);br5.setxProperty(85);br5.setyProperty(525);BaseRectangle br6 = new BaseRectangle(350,5,10,10,Color.BLACK);br6.setxProperty(693);br6.setyProperty(525);BaseRectangle br7 = new BaseRectangle(350,5,10,10,Color.GOLD);br7.setxProperty(70);br7.setyProperty(285);BaseRectangle br8 = new BaseRectangle(350,5,10,10,Color.BLACK);br8.setxProperty(705);br8.setyProperty(285);//后续改变下面的方法Collections.addAll(brArrayList,br,br2,br3,br4,br5,br6,br7,br8);
//        brArrayList.add(br);
//        brArrayList.add(br2);this.getChildren().addAll();}public void initAll(){//加载背景this.initBackGround();//临时平台this.initTmpPlat();//加载物体//加载玩家1this.initMan();//加载玩家2this.initMan2();this.initBullet();//换装页面this.initReplace();//把已加载的背景与物体 添加到游戏场景中
//        this.getChildren().addAll(bg,man1,man2);//加载时间线this.initTimeline();}public void moveTimeline(){Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);//无限循环KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//重复执行该方法BaseScene.man1.move();//左右移动and跳跃,坠落BaseScene.man2.move();}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public void loadKeyBoard(){//全局键盘方法//通过按压,抬起标记人物四个方向上是否移动,然后通过时间轴不断刷新来判断标记,进一步执行移动this.getScene().setOnKeyPressed(new EventHandler<KeyEvent>() {@Overridepublic void handle(KeyEvent event) {System.out.println("Pressed");man1.onKeyBoardPressed(event);man2.onKeyBoardPressed(event);bullet.onKeyBoardPressed(event);}});getScene().setOnKeyReleased(new EventHandler<KeyEvent>() {@Overridepublic void handle(KeyEvent event) {System.out.println("Released");man1.onKeyBoardReleased(event);man2.onKeyBoardReleased(event);bullet.onKeyBoardReleased(event);}});}}

Bullet

package JavaBigJob;import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.effect.Bloom;
import javafx.scene.effect.BoxBlur;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;import java.util.*;import static JavaBigJob.BaseScene.*;public class Bullet extends BaseObject implements BaseObject.CanMove{//    private Rectangle r = null;int i=0,j=0;int z=0;boolean dirctionClock=false;boolean dirctionTwoClok=false;boolean isOne = false;static Rectangle[] rectangles = new Rectangle[100];static boolean select = true;static boolean selectTwo = true;boolean Out = false;private BoxBlur boxBlur = null;private Bloom bloom = null;static boolean shoutOpen = false;static boolean shoutOpenTwo = false;private double BulletSpeed;static boolean isShow = false;Rectangle rectangle = null;static Rectangle rectangle1 = null;ArrayList<Bullet> list = new ArrayList<Bullet>();ArrayList<Bullet> list2 = new ArrayList<>();public Bullet() {Rectangle rectangle=new Rectangle();rectangle.setX(man1.gun.getX()+40);rectangle.setY(man1.gun.getY());rectangle.setFill(Color.PINK);rectangle.setWidth(12);rectangle.setHeight(12);this.setxProperty(120);this.setyProperty(120);rectangle.setArcWidth(34);rectangle.setArcHeight(56);BulletSpeed = 3;
//        模糊化boxBlur = new BoxBlur();boxBlur.setWidth(5);boxBlur.setHeight(5);//动态化bloom = new Bloom();bloom.setThreshold(50);//上面两种属性与举行绑定rectangle.setEffect(boxBlur);rectangle.setEffect(bloom);}public Rectangle HandGunBullet(){Rectangle rectangle=new Rectangle();rectangle.setX(man2.hand.getX()+40);rectangle.setY(man2.hand.getY());rectangle.setFill(Color.RED);rectangle.setWidth(12);rectangle.setHeight(12);this.setxProperty(140);this.setyProperty(140);rectangle.setArcWidth(34);rectangle.setArcHeight(56);BulletSpeed = 3;
//        模糊化boxBlur = new BoxBlur();boxBlur.setWidth(6);boxBlur.setHeight(6);//动态化bloom = new Bloom();bloom.setThreshold(55);//上面两种属性与举行绑定rectangle.setEffect(boxBlur);rectangle.setEffect(bloom);return rectangle;}public void RifleGunBullet(){rectangle=new Rectangle();rectangle.setFill(Color.BLUE);rectangle.setWidth(20);rectangle.setHeight(9);rectangle.setX(man1.gun.getX()+40);rectangle.setY(man1.gun.getY());this.setxProperty(140);this.setyProperty(150);rectangle.setArcWidth(20);rectangle.setArcHeight(20);BulletSpeed = 3;
//        模糊化boxBlur = new BoxBlur();boxBlur.setWidth(5);boxBlur.setHeight(5);//动态化bloom = new Bloom();bloom.setThreshold(50);//上面两种属性与举行绑定rectangle.setEffect(boxBlur);rectangle.setEffect(bloom);}public Rectangle snipGunBullet(){Rectangle rectangle=new Rectangle();rectangle.setFill(Color.GOLD);rectangle.setWidth(28);rectangle.setHeight(7);rectangle.setX(man1.gun.getX()+40);rectangle.setY(man1.gun.getY());this.setxProperty(140);this.setyProperty(150);rectangle.setArcWidth(20);rectangle.setArcHeight(20);BulletSpeed = 3;
//        模糊化boxBlur = new BoxBlur();boxBlur.setWidth(5);boxBlur.setHeight(5);//动态化bloom = new Bloom();bloom.setThreshold(50);//上面两种属性与举行绑定rectangle.setEffect(boxBlur);rectangle.setEffect(bloom);return rectangle;}public Rectangle ShotGunBullet(){Rectangle rectangle = new Rectangle();rectangle.setFill(Color.GOLD);rectangle.setWidth(15);rectangle.setHeight(20);rectangle.setX(man2.hand.getX()+40);rectangle.setY(man2.hand.getY());this.setxProperty(140);this.setyProperty(150);rectangle.setArcWidth(1);rectangle.setArcHeight(32);BulletSpeed = 3;
//        模糊化boxBlur = new BoxBlur();boxBlur.setWidth(5);boxBlur.setHeight(5);//动态化bloom = new Bloom();bloom.setThreshold(50);//上面两种属性与举行绑定rectangle.setEffect(boxBlur);rectangle.setEffect(bloom);return rectangle;}public static void MoveLeft(Bullet bullet){if(shoutOpen == true&&isImpacte(man2,bullet)==false){//           rectangle.setX(rectangle.getX()-1);bullet.rectangle.setX(bullet.rectangle.getX()-1);
//            bullet.moveX(-1);}}public static void MoveRight(Bullet bullet){if(shoutOpen == true&&isImpacte(man2,bullet)==false){//            rectangle.setX(rectangle.getX()+1);bullet.rectangle.setX(bullet.rectangle.getX()+1);}}public static void MoveTwoLeft(Bullet bullet){if(shoutOpenTwo == true&&isImpacteTwo(man1,bullet)==false){bullet.rectangle.setX(bullet.rectangle.getX()-1);}}public static void MoveTwoRight(Bullet bullet){if(shoutOpenTwo == true&&isImpacteTwo(man1,bullet)==false){bullet.rectangle.setX(bullet.rectangle.getX()+1);}}public  void shot(Bullet bullet){Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);KeyFrame keyFrame = new KeyFrame(Duration.millis(1), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//if(bullet.select == false /*&&*/ /*bullet.isOne == false*/){man2.moveX(-4);System.out.println("移动了man2!!!!!!!!!!!!!!!");bullet.select = true;}if(bullet.rectangle.getX()< 0 || bullet.rectangle.getX() > 1100 || isImpacte(man2,bullet) == true){getChildren().remove(bullet.rectangle);getChildren().remove(bullet);
//                    timeline.stop();}}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public  void shotTwo(Bullet bullet){Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);KeyFrame keyFrame = new KeyFrame(Duration.millis(0.5), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {if(bullet.selectTwo == false ){man1.moveX(5);System.out.println("!!!!!!!!!!!!!!!移动了man1");bullet.selectTwo = true;}if(bullet.getxProperty() < 0 || bullet.getxProperty() > 1100 || isImpacteTwo(man1,bullet) == true){getChildren().remove(bullet.rectangle);getChildren().remove(bullet);
//                    timeline.stop();}}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public void ShotMove(Bullet bullet){Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {if (bullet.dirctionClock) {MoveLeft(bullet);}elseMoveRight(bullet);}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public void  ShotMoveTwo(Bullet bullet){Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {if(bullet.dirctionTwoClok){MoveTwoLeft(bullet);}
//                else if(isImpacteN(man2,man1)){//                    MoveTwoLeft(bullet);
//                }elseMoveTwoRight(bullet);}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}@Overridepublic void onKeyBoardPressed(KeyEvent event){if(event.getCode()==KeyCode.J){shoutOpen=true;Bullet bullet = new Bullet();list.add(bullet);if(Man.direction==0){list.get(i).dirctionClock = true;}else {list.get(i).dirctionClock = false;}list.get(i).rectangle = bullet.snipGunBullet();shot(list.get(i));ShotMove(list.get(i));getChildren().add(list.get(i).rectangle);list.remove(0);}if(event.getCode()==KeyCode.K){shoutOpenTwo = true;Bullet bullet = new Bullet();list2.add(bullet);if(Man2.direction==0){list2.get(z).dirctionTwoClok = true;}else {list2.get(z).dirctionTwoClok = false;}list2.get(z).rectangle = bullet.HandGunBullet();shotTwo(list2.get(z));ShotMoveTwo(list2.get(z));getChildren().add(list2.get(z).rectangle);list2.remove(0);}}@Overridepublic void onKeyBoardReleased(KeyEvent event) {}public static boolean isImpacte(BaseObject baseObject,Bullet bullet) {if(bullet.rectangle.getX()==baseObject.getxProperty()+Man.width&&bullet.rectangle.getY() >= baseObject.getyProperty()-Man.height/2&&bullet.rectangle.getY()<=baseObject.getyProperty()+Man.height){bullet.select = false;bullet.isOne = true;return true;}return false;}public static boolean isImpacteTwo(BaseObject baseObject,Bullet bullet) {if(bullet.rectangle.getX()==baseObject.getxProperty()-Man.width/2+5&&bullet.rectangle.getY() >= baseObject.getyProperty()-Man.height/2&&bullet.rectangle.getY()<=baseObject.getyProperty()+Man.height){bullet.selectTwo = false;bullet.isOne = true;System.out.println("$$$$$$$$$$$$$$$$$$$$$$$");return true;}return false;}public static boolean isImpacteN(BaseObject baseObject,BaseObject baseObject1) {if(baseObject.getxProperty()>baseObject1.getxProperty()){return true;}return false;}//    @Override
//    public void run() {//
//            Timeline timeline;
//            timeline = new Timeline();
//            timeline.setCycleCount(-1);
//            KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {//                @Override
//                public void handle(ActionEvent actionEvent) {//                    System.out.println("多线程}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}");
//                    if(Man.direction==0){//
//                        MoveLeft(rectangle);
//                    }
//                    else if(Man.direction==1)
//                        MoveRight(rectangle);
//                }
//            });
//            timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧
//            timeline.play();//时间轴循环执行每个栈帧
//        }}

DatabaseUtil

package JavaBigJob;import java.sql.*;public class DataBaseUtil {//2.通过DriverManager获取数据库连接
//    String url = "jdbc:mysql://localhost:3306/label?sever";String url = "jdbc:mysql://localhost:3306/label?severTimezone=GMT%2B8";String driver = "com.mysql.cj.jdbc.Driver";String user = "root";String password = "wenchi0124";Connection conn = null;ResultSet rs = null;Statement statement = null;PreparedStatement ps = null;public DataBaseUtil() {try {conn = DriverManager.getConnection(url,user,password);System.out.println("line success");} catch (SQLException throwables) {throwables.printStackTrace();}}public void close(){try{if(rs != null){rs.close();}if(ps != null){ps.close();}if(statement != null){statement.close();}if(conn != null){conn.close();}}catch (SQLException throwables) {throwables.printStackTrace();}finally {//            this.close();}}public ResultSet queryExecute(String sql) {try {Class.forName(driver);System.out.println("query_success01");statement = conn.createStatement();rs = statement.executeQuery(sql);return rs;}catch (Exception ex){ex.printStackTrace();return null;}finally {//            this.close();}}//重载public ResultSet queryExecute(String sql,String[] paras){try {Class.forName(driver);System.out.println("query_success02");
//            conn = DriverManager.getConnection(url,user,password);ps = conn.prepareStatement(sql);for(int i =0;i < paras.length;i++){ps.setString(i+1,paras[i]);}rs = ps.executeQuery();return rs;}catch (Exception ex){ex.printStackTrace();}finally {//            this.close();}return null;}public boolean updateExecute(String sql,String[] paras){boolean b = true;try {Class.forName(driver);System.out.println("update_success03");
//            conn = DriverManager.getConnection(url,user,password);ps = conn.prepareStatement(sql);for(int i =0;i < paras.length;i++){ps.setString(i+1,paras[i]);}if(ps.executeLargeUpdate() != 1){b = false;}}catch (Exception ex){b = false;ex.printStackTrace();}finally {//            this.close();}return b;}}

GameWindow

package JavaBigJob;import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Stage;public class GameWindow /*extends Application*/ {public static final int WIDTH = 1100;public static final int HEIGHT = 700;GameWindow(){BaseScene bs = new BaseScene(WIDTH,HEIGHT);Scene bsScene = new Scene(bs,WIDTH,HEIGHT);Stage stage = new Stage();stage.setTitle("javaBigWork");stage.setScene(bsScene);//添加bs至scene中,下一步通过bs。getScene返回Scene的实例化对象bs.loadKeyBoard();//因为实例化了scene,加载scene的全局键盘事件stage.show();}
}

login.css

给登录界面加的css样式


#paneId{-fx-background-image: url('Picture/login.png');/*-fx-background-image-opacity: 0.5;*/-fx-background-color: #0155fd;
}#labelLogin {-fx-text-fill: rgba(238, 116, 116, 0.88);-fx-font-size: 10pt;-fx-font-family: "Sans-serif";-fx-font-weight: 500;-fx-font-smoothing-type: inherit;/*-fx-font-weight: bold;*/
}#warn{-fx-text-fill: #30ec9a;-fx-font-family: "Microsoft Yahei";-fx-background-color: gray;-fx-font-weight: bold;-fx-font-size: 10pt;-fx-border-color: #0155fd;
}#btLogin {-fx-text-fill: #2ffd01;-fx-font-family: "Microsoft Yahei";-fx-text-alignment: center;/*-fx-wrap-text: true;*/-fx-cell-size: 30pt;-fx-font-weight: bold;-fx-background-color: linear-gradient(#6169b1, rgba(253, 119, 1, 0.42));-fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );
}#tfLogin {-fx-animated: true;-fx-border-width: 2pt;-fx-border-color: gray;/*-fx-border-radius:10px;*/
}

LoginFrame

package JavaBigJob;import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;import java.sql.ResultSet;
import java.sql.SQLException;public class LoginFrame extends Application{Label nameLabel = new Label("User Name :");Label passwordLabel = new Label("Password  : ");Label lack_information = new Label("用户信息填写不全!");Label Mismatch_information = new Label("用户名或密码不正确");Label user_nonentity = new Label("用户不存在");;Label user_exit = new Label("用户已存在");Label sign_successful = new Label("注册成功!");Label login_successful = new Label("登陆成功!");HBox user = new HBox();HBox password = new HBox();TextField tfUser = new TextField();PasswordField tfPassword = new PasswordField();Button btLogIn = new Button("Log in");Button btSignIn = new Button("Sign in");HBox h3 = new HBox();//装按钮VBox pane = new VBox();@Overridepublic void start(Stage stage) {//cssbtLogIn.setId("btLogin");//设置idbtSignIn.setId("btLogin");nameLabel.setId("labelLogin");passwordLabel.setId("labelLogin");tfUser.setId("tfLogin");tfPassword.setId("tfLogin");lack_information.setId("warn");Mismatch_information.setId("warn");user_nonentity.setId("warn");user_exit.setId("warn");sign_successful.setId("warn");user.getChildren().addAll(nameLabel,tfUser);user.setAlignment(Pos.CENTER);user.setSpacing(20);password.getChildren().addAll(passwordLabel,tfPassword);password.setAlignment(Pos.CENTER);password.setSpacing(20);h3.setAlignment(Pos.CENTER);btLogIn.setAlignment(Pos.BASELINE_RIGHT);btSignIn.setAlignment(Pos.BASELINE_RIGHT);h3.getChildren().addAll(btLogIn,btSignIn);h3.setSpacing(20);pane.setAlignment(Pos.CENTER);pane.setSpacing(20);pane.getChildren().addAll(user,password,h3);Scene scene = new Scene(pane,400,250);pane.setId("paneId");//添加css样式scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());stage.setScene(scene);stage.setTitle("Welcome!");stage.show();btLogIn.setOnAction(e->{if(user_exist()==false){System.out.println("用户不存在");HBox hBox = new HBox();Label label = user_nonentity;ImageView image = new ImageView("JavaBigJob/Picture/No.png");image.setFitWidth(150);image.setFitHeight(120);hBox.setAlignment(Pos.CENTER);hBox.setSpacing(10);hBox.getChildren().addAll(image,label);Scene sub_scene = new Scene(hBox,400,200);sub_scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());Stage stage1 = new Stage();stage1.setScene(sub_scene);stage1.setTitle("ERROR");stage1.show();}else if(detection_information()){if(user_right()){stage.hide();//登陆成功new GameWindow();}}});btSignIn.setOnAction(e->{if(user_exist()){System.out.println("用户已存在");HBox hBox = new HBox();Label label = user_exit;ImageView image = new ImageView("JavaBigJob/Picture/No.png");image.setFitWidth(150);image.setFitHeight(120);hBox.setAlignment(Pos.CENTER);hBox.setSpacing(10);hBox.getChildren().addAll(image,label);Scene sub_scene = new Scene(hBox,400,200);sub_scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());Stage stage1 = new Stage();stage1.setScene(sub_scene);stage1.setTitle("ERROR");stage1.show();}else if(detection_information()){DataBaseUtil db = new DataBaseUtil();String sql = "INSERT INTO user (name,passwd) VALUES (?,?)";db.updateExecute(sql,new String[]{tfUser.getText(),tfPassword.getText()});HBox hBox = new HBox();Label label = sign_successful;ImageView image = new ImageView("JavaBigJob/Picture/yes.png");image.setFitWidth(150);image.setFitHeight(120);hBox.setAlignment(Pos.CENTER);hBox.setSpacing(10);hBox.getChildren().addAll(image,label);Scene sub_scene = new Scene(hBox,400,200);sub_scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());Stage stage1 = new Stage();stage1.setScene(sub_scene);stage1.show();}});}public static void main(String[] args) {DataBaseUtil db = new DataBaseUtil();launch();}public Boolean user_exist(){//判断是否已存在用户DataBaseUtil db = new DataBaseUtil();String sql = "select count(*) from user where name = '"+tfUser.getText()+"'";try {ResultSet rs = db.queryExecute(sql);rs.next();if(rs.getInt(1)==1){return true;}} catch (SQLException throwables) {throwables.printStackTrace();}return false;}public Boolean user_right(){DataBaseUtil db = new DataBaseUtil();String sql = "select count(*) from user where name = ? and passwd = ?";try {ResultSet rs = db.queryExecute(sql,new String[]{tfUser.getText(),tfPassword.getText()});rs.next();if(rs.getInt(1)==1){return true;}} catch (SQLException throwables) {throwables.printStackTrace();}System.out.println("用户名或密码不正确");HBox hBox = new HBox();Label label = Mismatch_information;ImageView image = new ImageView("JavaBigJob/Picture/No.png");image.setFitWidth(150);image.setFitHeight(120);hBox.setAlignment(Pos.CENTER);hBox.setSpacing(10);hBox.getChildren().addAll(image,label);Scene sub_scene = new Scene(hBox,400,200);sub_scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());Stage stage1 = new Stage();stage1.setScene(sub_scene);stage1.setTitle("ERROR");stage1.show();return false;}public Boolean detection_information(){//判断信息是否填写完全if (tfUser.getText().equals("")||tfPassword.getText().equals("")){System.out.println("信息不全!");HBox hBox = new HBox();Label label = lack_information;ImageView image = new ImageView("JavaBigJob/Picture/No.png");image.setFitWidth(150);image.setFitHeight(120);hBox.setAlignment(Pos.CENTER);hBox.setSpacing(10);hBox.getChildren().addAll(image,label);Scene sub_scene = new Scene(hBox,400,200);sub_scene.getStylesheets().add(LoginFrame.class.getResource("login.css").toExternalForm());Stage stage1 = new Stage();stage1.setScene(sub_scene);stage1.setTitle("ERROR");stage1.show();return false;//信息不全}return true;//信息全}}

Man

package JavaBigJob;import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.effect.Effect;
import javafx.scene.effect.PerspectiveTransform;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.util.Duration;import java.util.ArrayList;import static JavaBigJob.BaseScene.man1;public class Man extends BaseObject implements BaseObject.CanMove {static double high = 3;//跳跃时的高度static boolean isOnPlat = false;static int dropSpeed = 1;static int times = 0;static int height = 68;static int width = 42;static boolean jump = false;//是否正在跳跃static boolean down = false;//掉到下一层static boolean PressJump = false;//跳跃(是否正在按压跳跃键)boolean moveLeft = false;
//    boolean moveUp = false;boolean moveRight = false;
//    boolean moveDown = false;static int direction = 0;//0表示人物向左,1表示人物向右//头部不能与this.xProperty直接绑定(头是突出来的,必须改变坐标才能美观),直接绑定无法动态改变头部的相对位置(不能在add方法中添加变量,变量即使改变,也始终为第一次的值)。ImageView body = new ImageView("JavaBigJob/Picture/198.png");ImageView head = new ImageView("JavaBigJob/Picture/229.png");ImageView foot1 = new ImageView("JavaBigJob/Picture/181.png");ImageView foot2 = new ImageView("JavaBigJob/Picture/181.png");ImageView hand = new ImageView("JavaBigJob/Picture/102.png");ImageView gun = new ImageView("JavaBigJob/Picture/456.png");ImageView clothes = new ImageView("JavaBigJob/Picture/198.png");public Man(){//        ReplaceClothes replaceClothes = new ReplaceClothes();
//        Image image = replaceClothes.GetImage();
//        clothes = new ImageView(image);clothes.xProperty().bind(body.xProperty());clothes.yProperty().bind(body.yProperty());clothes.setFitHeight(55);clothes.setFitWidth(35);clothes.scaleXProperty().bind(body.scaleXProperty());body.setScaleX(-1);//设置主角图片以及绑定图片在场景中的位置body.setFitHeight(55);body.setFitWidth(35);body.xProperty().bind(this.xProperty());body.yProperty().bind(this.yProperty());head.setFitWidth(30);head.setFitHeight(32);head.xProperty().bind(this.xProperty().add(-8));head.yProperty().bind(this.yProperty().add(-12));hand.xProperty().bind(this.xProperty().add(-4));hand.yProperty().bind(this.yProperty().add(20));hand.scaleXProperty().bind(body.scaleXProperty());hand.rotateProperty().bind(body.yProperty());head.scaleXProperty().bind(body.scaleXProperty());//绑定翻转head.rotateProperty().bind(body.rotateProperty());//绑定角度foot1.xProperty().bind(this.xProperty());foot1.yProperty().bind(this.yProperty().add(55));foot1.rotateProperty().bind(body.rotateProperty());foot1.scaleXProperty().bind(body.scaleXProperty());foot2.xProperty().bind(this.xProperty().add(15));foot2.yProperty().bind(this.yProperty().add(55));foot2.rotateProperty().bind(body.rotateProperty());foot2.scaleXProperty().bind(body.scaleXProperty());gun.xProperty().bind(hand.xProperty().add(-35));gun.yProperty().bind(hand.yProperty().add(-4));gun.scaleXProperty().bind(hand.scaleXProperty());//添加到MangetChildren().addAll(body,clothes,head,foot1,foot2,hand,gun);}public void onKeyBoardPressed(KeyEvent event){if(event.getCode() == KeyCode.RIGHT){moveRight = true;}if(event.getCode() == KeyCode.LEFT){moveLeft = true;}if(event.getCode() == KeyCode.UP){PressJump = true;System.out.println("按压了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");}if(event.getCode() == KeyCode.DOWN){down = true;}}public void onKeyBoardReleased(KeyEvent event){if(event.getCode() == KeyCode.RIGHT){moveRight = false;}if(event.getCode() == KeyCode.LEFT){moveLeft = false;}if(event.getCode() == KeyCode.UP){PressJump = false;}if(event.getCode() == KeyCode.DOWN){down = false;}}public void move(){if(moveLeft == true){head.xProperty().bind(this.xProperty().add(-7));hand.xProperty().bind(this.xProperty().add(-5));gun.xProperty().bind(this.xProperty().add(-38));this.direction = 0;//向左body.setScaleX(-1);//设置翻转moveX(-this.getSpeed());}if(PressJump == true && jump == false &&isOnPlat == true){//正在按下跳跃&不在跳跃过程中&在平台上,进入if后执行跳跃timeline,this.jumpTimeline();PressJump = false;isOnPlat = false;}if(moveRight == true){head.xProperty().bind(this.xProperty().add(14));hand.xProperty().bind(this.xProperty().add(25));gun.xProperty().bind(this.xProperty().add(23));this.direction = 1;//向右body.setScaleX(1);moveX(this.getSpeed());}if(down == true && isOnPlat==true){moveY(1);down = false;}}public static void dropOutTimeline(ArrayList<BaseRectangle> brArrayList){System.out.println("---------------");Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);//无限循环KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//重复执行该方法
//                System.out.println("--------0-------");
//                    System.out.println("---------1------");if(!Man.jump){if(ObjectCollections.Man1DropJudge(brArrayList)){System.out.println("碰撞到平台了!!!!!!!!!");Man.isOnPlat = true;
//                        dropSpeed = 0;}else{Man.isOnPlat = false;BaseScene.man1.moveY(dropSpeed);System.out.println("在坠落!");}}}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public void jumpTimeline(){jump = true;//isOnPlat = false;Timeline timeline;timeline = new Timeline();timeline.setCycleCount(90);//90System.out.println("&&&&&&&执行了jump_timeline!!!!!");
//        high = 3;//初始高度为3
//        times = 0;KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//重复执行该方法times++;System.out.println("&&&&&&&跳跃了!!!!!!!!!!");man1.moveY(-high);}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧jump = false;}}

Man2

package JavaBigJob;import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.util.Duration;import java.util.ArrayList;import static JavaBigJob.BaseScene.man1;
import static JavaBigJob.BaseScene.man2;public class Man2 extends BaseObject implements BaseObject.CanMove{static double high = 3;//跳跃时的高度static boolean isOnPlat = false;static int dropSpeed = 1;static int height = 68;static int width = 42;static boolean jump = false;//是否正在跳跃static boolean down = false;//掉到下一层static boolean PressJump = false;//跳跃(是否正在按压跳跃键)boolean moveLeft = false;//    boolean moveUp = false;boolean moveRight = false;//    boolean moveDown = false;static int direction = 1;//0表示人物向左,1表示人物向右//头部不能与this.xProperty直接绑定(头是突出来的,必须改变坐标才能美观),直接绑定无法动态改变头部的相对位置(不能在add方法中添加变量,变量即使改变,也始终为第一次的值)。ImageView body = new ImageView("JavaBigJob/Picture/200.png");ImageView head = new ImageView("JavaBigJob/Picture/230.png");ImageView foot1 = new ImageView("JavaBigJob/Picture/182.png");ImageView foot2 = new ImageView("JavaBigJob/Picture/182.png");ImageView hand = new ImageView("JavaBigJob/Picture/104.png");ImageView clothes = new ImageView("JavaBigJob/Picture/200.png");public Man2(){clothes.setFitHeight(55);clothes.setFitWidth(35);//设置主角图片以及绑定图片在场景中的位置body.setFitHeight(55);body.setFitWidth(35);body.xProperty().bind(this.xProperty());body.yProperty().bind(this.yProperty());head.setFitWidth(30);head.setFitHeight(32);head.xProperty().bind(this.xProperty().add(14));head.yProperty().bind(this.yProperty().add(-12));head.scaleXProperty().bind(body.scaleXProperty());//绑定翻转head.rotateProperty().bind(body.rotateProperty());//绑定角度hand.xProperty().bind(this.xProperty().add(25));hand.yProperty().bind(this.yProperty().add(20));hand.scaleXProperty().bind(body.scaleXProperty());hand.rotateProperty().bind(body.yProperty());foot1.xProperty().bind(this.xProperty());foot1.yProperty().bind(this.yProperty().add(55));foot1.rotateProperty().bind(body.rotateProperty());foot1.scaleXProperty().bind(body.scaleXProperty());foot2.xProperty().bind(this.xProperty().add(15));foot2.yProperty().bind(this.yProperty().add(55));foot2.rotateProperty().bind(body.rotateProperty());foot2.scaleXProperty().bind(body.scaleXProperty());clothes.xProperty().bind(body.xProperty());clothes.yProperty().bind(body.yProperty());clothes.scaleXProperty().bind(body.scaleXProperty());//衣服绑定clothes.rotateProperty().bind(body.rotateProperty());//添加到环境getChildren().addAll(body,clothes,head,foot1,foot2,hand);}public void onKeyBoardPressed(KeyEvent event){if(event.getCode() == KeyCode.D){moveRight = true;}if(event.getCode() == KeyCode.A){moveLeft = true;}if(event.getCode() == KeyCode.W){PressJump = true;}if(event.getCode() == KeyCode.S){down = true;}}public void onKeyBoardReleased(KeyEvent event){if(event.getCode() == KeyCode.D){moveRight = false;}if(event.getCode() == KeyCode.A){moveLeft = false;}if(event.getCode() == KeyCode.W){PressJump = false;}if(event.getCode() == KeyCode.S){down = false;}}public void move(){if(moveLeft == true){head.xProperty().bind(this.xProperty().add(-7));hand.xProperty().bind(this.xProperty().add(-5));this.direction = 0;//向左body.setScaleX(-1);//设置翻转moveX(-this.getSpeed());}if(PressJump == true && jump == false &&isOnPlat == true){this.jumpTimeline();PressJump = false;isOnPlat = false;}if(moveRight == true){head.xProperty().bind(this.xProperty().add(14));hand.xProperty().bind(this.xProperty().add(25));this.direction = 1;//向右body.setScaleX(1);moveX(this.getSpeed());}if(down == true && isOnPlat==true){moveY(1);down = false;}}public static void dropOutTimeline(ArrayList<BaseRectangle> brArrayList){System.out.println("---------------");Timeline timeline;timeline = new Timeline();timeline.setCycleCount(-1);//无限循环KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//重复执行该方法
//                System.out.println("--------0-------");
//                    System.out.println("---------1------");if(ObjectCollections.Man2DropJudge(brArrayList)&&!Man2.jump){System.out.println("碰撞到平台了!!!!!!!!!");Man2.isOnPlat = true;
//                        dropSpeed = 0;}else{Man2.isOnPlat = false;BaseScene.man2.moveY(dropSpeed);}}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧}public void jumpTimeline(){jump = true;isOnPlat = false;Timeline timeline;timeline = new Timeline();timeline.setCycleCount(90);//无限循环System.out.println("&&&&&&&执行了jump_timeline!!!!!");high = 3;//初始高度为3KeyFrame keyFrame = new KeyFrame(Duration.millis(4), new EventHandler<ActionEvent>() {@Overridepublic void handle(ActionEvent actionEvent) {//重复执行该方法
//                if(high >= 0.1 ){//                    high -= 0.01;System.out.println("&&&&&&&跳跃了!!!!!!!!!!");man2.moveY(-high);
//                }}});timeline.getKeyFrames().add(keyFrame);//为时间轴添加栈帧timeline.play();//时间轴循环执行每个栈帧jump = false;}}

ObjectCollections

package JavaBigJob;import java.util.ArrayList;
import java.util.List;import static JavaBigJob.BaseScene.man1;
import static JavaBigJob.BaseScene.man2;public class ObjectCollections {public static Boolean Man1DropJudge(ArrayList<BaseRectangle> brArrayList){if(brArrayList==null){System.out.println("平台集合中没有元素");return false;}for(BaseRectangle br: brArrayList){if(man1.getyProperty()+Man.height==br.getyProperty()&&(man1.getxProperty()<=br.getxProperty()+br.getWidth())&&man1.getxProperty()+Man.width>=br.getxProperty()){return true;}
//            System.out.println(man1.getHeightProperty()+" "+man1.getxProperty()+" "+br.getxProperty()+" "+br.getxProperty()+br.getWidth());}return false;}public static Boolean Man2DropJudge(ArrayList<BaseRectangle> brArrayList){if(brArrayList==null){System.out.println("平台集合中没有元素");return false;}for(BaseRectangle br: brArrayList){if(man2.getyProperty()+Man2.height==br.getyProperty()&&(man2.getxProperty()<=br.getxProperty()+br.getWidth())&&man2.getxProperty()+Man2.width>=br.getxProperty()){return true;}
//            System.out.println(man2.getHeightProperty()+" "+man2.getxProperty()+" "+br.getxProperty()+" "+br.getxProperty()+br.getWidth());}return false;}}

ReplaceClothes

package JavaBigJob;import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Border;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;import java.util.ArrayList;public class ReplaceClothes extends Parent {Image image = new Image("JavaBigJob/Picture/207.png");Image HeadImage = new Image("JavaBigJob/Picture/227.png");Image FootImage = new Image("JavaBigJob/Picture/178.png");Image HandImage = new Image("JavaBigJob/Picture/670.png");Image BodyImage = new Image("JavaBigJob/Picture/195.png");Image Man2ClothesImage = new Image("JavaBigJob/Picture/207.png");Image Man2headImage = new Image("JavaBigJob/Picture/230.png");Image Man2footImage = new Image("JavaBigJob/Picture/182.png");Image Man2BodyImage = new Image("JavaBigJob/Picture/200.png");Image Man2HandImage = new Image("JavaBigJob/Picture/104.png");ImageView imageView;ImageView HeadImageView;ImageView FootImageView;ImageView HandImageView;ImageView BodyImageView;ImageView Man2ClothesImageView;ImageView Man2headImageView;ImageView Man2footImageView;ImageView Man2BodyImageView;ImageView Man2HandImageView;int i = 207;int HeadCount = 227;int FootCount = 178;int HandCount = 670;int BodyCount = 195;int Man2ClothesCount = 207;int Man2HeadCount = 227;int Man2FootCount = 178;int Man2HandCount = 670;int Man2BodyCount = 195;public void Photo(){//循环展示衣服图片if(i==225){i=207;}if(i==222){i++;}image = new Image("JavaBigJob/Picture/"+i+".png");imageView = new ImageView(image);i++;}public void Man2Photo(){//循环展示衣服图片if(Man2ClothesCount==225){Man2ClothesCount=207;}if(Man2ClothesCount==222){Man2ClothesCount++;}Man2ClothesImage = new Image("JavaBigJob/Picture/"+Man2ClothesCount+".png");Man2ClothesImageView = new ImageView(Man2ClothesImage);Man2ClothesCount++;}public void BodyPhoto(){if(BodyCount == 206){BodyCount = 195;}BodyImage = new Image("JavaBigJob/Picture/"+BodyCount+".png");BodyImageView = new ImageView(BodyImage);BodyCount++;}public void Man2BodyPhoto(){if(Man2BodyCount == 206){Man2BodyCount = 195;}Man2BodyImage = new Image("JavaBigJob/Picture/"+Man2BodyCount+".png");Man2BodyImageView = new ImageView(Man2BodyImage);Man2BodyCount++;}public void HeadPhoto(){if(HeadCount==238){HeadCount = 227;}HeadImage = new Image("JavaBigJob/Picture/"+HeadCount+".png");HeadImageView = new ImageView(HeadImage);HeadCount++;}public void Man2HeadPhoto(){if(Man2HeadCount==238){Man2HeadCount = 227;}Man2headImage = new Image("JavaBigJob/Picture/"+Man2HeadCount+".png");Man2headImageView = new ImageView(Man2headImage);Man2HeadCount++;}public void FootPhoto(){if(FootCount == 189)FootCount = 178;FootImage = new Image("JavaBigJob/Picture/"+FootCount+".png");FootImageView = new ImageView(FootImage);FootCount++;}public void Man2FootPhoto(){if(Man2FootCount == 189)Man2FootCount = 178;Man2footImage = new Image("JavaBigJob/Picture/"+Man2FootCount+".png");Man2footImageView = new ImageView(Man2footImage);Man2FootCount++;}public void HandPhoto(){if(HandCount == 679){HandCount = 670;}HandImage = new Image("JavaBigJob/Picture/"+HandCount+".png");HandImageView = new ImageView(HandImage);HandCount++;}public void Man2HandPhoto(){if(Man2HandCount == 679){Man2HandCount = 670;}Man2HandImage = new Image("JavaBigJob/Picture/"+Man2HandCount+".png");Man2HandImageView = new ImageView(Man2HandImage);Man2HandCount++;}public ReplaceClothes() {Button btnHat = new Button("更换头部");Button btnBody = new Button("更换身体");Button btnHand = new Button("更换手部");Button btnClothes = new Button("更换衣服");Button btnFoot = new Button("更换脚步");Button btnOk = new Button("确定");Button btnMan2Hat = new Button("更换头部2");Button btnMan2Body = new Button("更换身体2");Button btnMan2Hand = new Button("更换手部2");Button btnMan2Clothes = new Button("更换衣服2");Button btnMan2Foot = new Button("更换脚步2");Button btnMan2Ok = new Button("确定2");//cssGridPane gridPane = new GridPane();gridPane.setPadding(new Insets(0,0,50,0));//与装他的容器的间距gridPane.setAlignment(Pos.CENTER);gridPane.add(btnClothes,3,10);gridPane.add(btnBody,1,10);gridPane.add(btnOk,2,11);gridPane.add(btnHat,0,10);gridPane.add(btnHand,2,10);gridPane.add(btnFoot,4,10);gridPane.add(btnMan2Clothes,3,12);gridPane.add(btnMan2Body,2,12);gridPane.add(btnMan2Ok,2,13);gridPane.add(btnMan2Hat,0,12);gridPane.add(btnMan2Hand,1,12);gridPane.add(btnMan2Foot,4,12);gridPane.setHgap(10);//设置表格单元间的横向间距gridPane.setVgap(20);//设置表格单元间的纵向间距gridPane.setId("gridPane");btnClothes.setOnAction(e->{Photo();//调用方法将imageVIEW赋值gridPane.add(imageView,1,8); //将图片显示到界面上});btnMan2Clothes.setOnAction(e->{Man2Photo();gridPane.add(Man2ClothesImageView,2,8);});btnHand.setOnAction(e->{HandPhoto();gridPane.add(HandImageView,1,6);});btnMan2Hand.setOnAction(e->{Man2HandPhoto();gridPane.add(Man2HandImageView,2,6);});btnHat.setOnAction(e->{HeadPhoto();gridPane.add(HeadImageView,1,4);});btnMan2Hat.setOnAction(e->{Man2HeadPhoto();gridPane.add(Man2headImageView,2,4);});btnFoot.setOnAction(e->{FootPhoto();gridPane.add(FootImageView,1,9);});btnMan2Foot.setOnAction(e->{Man2FootPhoto();gridPane.add(Man2footImageView,2,9);});btnOk.setOnAction(e->{BaseScene.man1.clothes.setImage(image); //更换衣服BaseScene.man1.head.setImage(HeadImage);BaseScene.man1.hand.setImage(HandImage);BaseScene.man1.foot1.setImage(FootImage);BaseScene.man1.foot2.setImage(FootImage);BaseScene.man1.body.setImage(BodyImage);
//            gridPane.add(BaseScene.man1,3,1);});btnMan2Ok.setOnAction(e->{BaseScene.man2.clothes.setImage(Man2ClothesImage); //更换衣服BaseScene.man2.head.setImage(Man2headImage);BaseScene.man2.hand.setImage(Man2HandImage);BaseScene.man2.foot1.setImage(Man2footImage);BaseScene.man2.foot2.setImage(Man2footImage);BaseScene.man2.body.setImage(Man2BodyImage);});btnBody.setOnAction(e->{BodyPhoto();gridPane.add(BodyImageView,1,5);});btnMan2Body.setOnAction(e->{Man2BodyPhoto();gridPane.add(Man2BodyImageView,2,5);});Scene scene = new Scene(gridPane,1000,600);scene.getStylesheets().add(ReplaceClothes.class.getResource("replaceClothes.css").toExternalForm());Stage primaryStage = new Stage();primaryStage.setTitle("换装");primaryStage.setScene(scene);primaryStage.show();}public Image GetImage(){return this.image;}
}

换装页面由于用的是gridpane所以css样式不同于正常的节点,我这边加了没有显示。如果想加的话去看官方文档吧。

这边是jar包。
图片资源想要的话私信发下邮箱,看缘分发。主要是提供代码,提供思路。因为算法实现还蛮难的。
数据库设计如下。

登陆界面流程图就是用powerdesigner画的

要注意的点其实很多,不过注释写的很清楚,多看应该还是可以看懂的。

JAVA游戏 混乱大枪战相关推荐

  1. 小鸡拿着蚯蚓闯关的java游戏,蚯蚓大闯关游戏下载|蚯蚓大闯关安卓版下载 v1.0.0 - 跑跑车安卓网...

    蚯蚓大闯关是一款很赞的益智游戏,作为一只蠕虫,陷入了陷阱里,你需要想尽办法努力的逃脱这里,十分的有趣好玩,不要错过哦. 游戏介绍 一只叫做汤姆的蠕虫想要逃离致命的陷阱,你需要帮助它完成数十个令人惊叹的 ...

  2. java游戏西门大官人_valueOf()方法的使用

    valueOf()方法用于返回给定参数的原生 Number 对象值,参数可以是原生数据类型, String等. 该方法是静态方法.该方法可以接收两个参数一个是字符串,一个是基数. 该方法有以下几种语法 ...

  3. 贪吃蛇大作战代码java,贪吃蛇游戏,贪吃蛇java游戏代码讲解

    贪吃蛇游戏,贪吃蛇java游戏代码讲解 来源:互联网 作者:佚名 时间:2020-06-06 贪吃蛇源代码.txt这世界上除了我谁都没资格陪在你身边. 听着,我允许你喜欢我.除了白头偕老,我们... ...

  4. JAVA抖音潜艇挑战_Android 实现抖音小游戏潜艇大挑战的思路详解

    <潜水艇大挑战>是抖音上的一款小游戏,以面部识别来驱动潜艇通过障碍物,最近特别火爆,相信很多人都玩过. 一时兴起自己用Android自定义View也撸了一个,发现只要有好的创意,不用高深的 ...

  5. 玩java游戏买什么手机好用又便宜_每一款JAVA游戏都是经典,但只有四款游戏,是90%玩家从小玩到大...

    2000年彩屏手机开始流行,诺基亚作为当年世界第一的手机厂商,更是研发出了多款造型酷炫的手机,例如翻盖.推盖以及后来的触屏机,都曾被我们使用过.我还记得当年小的时候,拿着爸爸的手机在上面搜索和下载各种 ...

  6. 帮我写一个java的坦克大作战游戏

    很抱歉,我的能力是生成自然语言的模型,无法直接编写完整的Java游戏.不过,我可以提供一些建议和指导,以帮助您开始编写自己的Java坦克大战游戏. 确定游戏规则和目标:在编写游戏之前,您需要确定游戏的 ...

  7. 有控制雷电武器的java游戏_雷电飞机射击游戏 JAVA

    一.程序概述 1.开发环境 开发程序的工具Eclipse是著名的跨平台的自由集成开发环境.一个开放源代码的.基于Java的课扩展开发平台.就其本身而言,它只是一个框架和一组服务,用与通过插件组件构建开 ...

  8. java游戏服务器必备

    推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 对于一个新手,想接触游戏服务器,一定会有个疑问--使用Java开发服务器需要学习什么? Java语言,由于学习成本低,开发速度快,稳定 ...

  9. Java游戏源码大礼包

    http://blog.csdn.net/cping1982/article/details/7413589 下载地址0(CSDN的,发布后忘添此地址了,麻烦有路过的帮小弟下载一次,否则就快消失||| ...

最新文章

  1. 基于二代和三代测序技术的柚子基因组混合拼装
  2. spring el 三元表达式
  3. poi的autoSizeColumn方法对全角或者说中文支持不好的一个解决办法
  4. 130242014022 蓝宏铮 第2次实验
  5. 将非事务性资源绑定到JTA事务中的几种模式
  6. JPA /休眠刷新策略初学者指南
  7. [Leetcode][第40题][JAVA][数组总和2][回溯][剪枝]
  8. mysql的cpu高定位
  9. 将json字符串转换成html,将JSON HTML字符串转换为HTML
  10. 卑微测试员自述:入职新公司一个月,就让我做自动化测试?!
  11. iOS入门培训还要钱?看博客,看视频都拿下
  12. 数字图像处理之数字图像频率空间
  13. ADB介绍—— 配置ADB环境变量
  14. 信息系统项目管理师快速记忆口诀
  15. Unity 三消游戏学习
  16. C语言程序设计精髓 第13周——原来内存也可以这么玩,我是指针我怕谁 练兵区——编程题
  17. 微信小程序例子——使用icon组件显示常用图标
  18. 高级版的 jvisualvm :Spring Boot Admin 监控 Spring Boot 微服务项目
  19. 今天是我在csdn的1265天
  20. 计算机共享有哪些方式,信息共享的方式有哪些

热门文章

  1. LazyBrush论文笔记(4):问题建模-平滑项与数据项
  2. 锚框之间的IOU理解
  3. 从“领域变迁”的视角,来看钉钉的“退让”与“进取”
  4. excel实现分组合并后居中
  5. 阿里云云计算高级工程师ACP认证(Alibaba Cloud Certified Professional - Cloud Computing)考试大纲
  6. Swift基础(六)解包
  7. 【枚举与countDownLatch的应用】
  8. mysql实现自增字符串_Mysql实现字符串主键自增示例教程-Go语言中文社区
  9. 阿里妈妈佣金转换API接口
  10. 数显电接点压力表与指针电接点压力表的区别