欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

Javafx實(shí)現(xiàn)國(guó)際象棋游戲

本文實(shí)例為大家分享了Javafx實(shí)現(xiàn)國(guó)際象棋游戲的具體代碼,供大家參考,具體內(nèi)容如下

目前創(chuàng)新互聯(lián)建站已為成百上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計(jì)、慶云網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。

基本規(guī)則

  • 棋子馬設(shè)計(jì)“日”的移動(dòng)方式
  • 兵設(shè)計(jì)只能向前直走,每次只能走一格。但走第一步時(shí),可以走一格或兩格的移動(dòng)方式
  • 請(qǐng)為后設(shè)計(jì)橫、直、斜都可以走,步數(shù)不受限制,但不能越子的移動(dòng)方式。
  • 車只能橫向或者豎向行走
  • 國(guó)王是在以自己為中心的九宮格內(nèi)行走
  • 騎士只能走對(duì)角線

項(xiàng)目目錄結(jié)構(gòu)

Javafx實(shí)現(xiàn)國(guó)際象棋游戲

UML類圖關(guān)系

以騎士為例

Javafx實(shí)現(xiàn)國(guó)際象棋游戲

實(shí)現(xiàn)基本功能

  • 吃子
  • 不能越子
  • 游戲結(jié)束提示
  • 基本移動(dòng)策略
  • 背景音樂(lè)

效果

Javafx實(shí)現(xiàn)國(guó)際象棋游戲

控制器

PressedAction

package com.Exercise3;

import com.Exercise3.Controller.PressedAction;
import com.Exercise3.Controller.ReleaseAction;
import com.Exercise3.Controller.ResetAction;
import com.Exercise3.view.ChessBoard;
import com.Exercise3.view.ChessPane;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;

import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

public class Test extends Application {

 public static void main(String[] args) {
 launch(args);
 }

 @Override
 public void start(Stage primaryStage) {

 String MEDIA_URL = "file:/E:/IdeaProjects/Experiment/src/com/Exercise3/music/BackgroundMusic.mp3";
 ChessBoard chessBoard = ChessBoard.getInstance(100,40,40);

 //添加媒體資源

 Media media = new Media(MEDIA_URL);
 MediaPlayer mediaPlayer = new MediaPlayer(media);
 mediaPlayer.setAutoPlay(true);
 mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
 mediaPlayer.play();


 ChessPane pane = new ChessPane(chessBoard);
 pane.setOnMousePressed(new PressedAction(pane,mediaPlayer));

 pane.setOnMouseReleased(new ReleaseAction(pane));

 BorderPane borderPane = new BorderPane();
 borderPane.setCenter(pane);
 HBox hBox = new HBox();
 hBox.setAlignment(Pos.TOP_CENTER);

 Button button = new Button("悔棋");
 button.setOnAction(new ResetAction(pane));

 hBox.getChildren().add(button);
 borderPane.setBottom(hBox);
 Scene scene = new Scene(borderPane,900,900);
 primaryStage.setScene(scene);
 primaryStage.setTitle("國(guó)際象棋");
 primaryStage.show();

 }
}

ReleasedAction

package com.Exercise3.Controller;

import com.Exercise3.entity.Piece.ChessPiece;
import com.Exercise3.entity.PieceType;
import com.Exercise3.view.ChessBoard;
import com.Exercise3.view.ChessPane;
import javafx.event.EventHandler;
import javafx.scene.control.Alert;
import javafx.scene.input.MouseEvent;

import java.util.Stack;

public class ReleaseAction implements EventHandler<MouseEvent> {
 private ChessPane chessPane;
 static Stack<ChessPiece> stack = new Stack<>();

 public ReleaseAction(ChessPane chessPane) {
 this.chessPane = chessPane;
 }

 @Override
 public void handle(MouseEvent e) {
 chessPane.drawBoard();
 ChessBoard chessBoard = chessPane.getChessBoard();
 int x = (int) ((e.getX() - chessBoard.getStartX()) / (chessBoard.getCellLength()));
 int y = (int) ((e.getY() - chessBoard.getStartY()) / (chessBoard.getCellLength()));

 for (ChessPiece o : chessPane.getChessPieces()) {
 if (o.isSelected()) {

 System.out.println(o.isSelected()+" "+o.getRow()+" "+o.getCol());
 if (chessBoard.getCurrSide()==o.getSide()){
  if(o.getMoveStrategy().move(x, y,chessPane.getChessPieces())){
  o.setSelected(false);
  if(judgeGame(x,y)){
  printTip(o.getSide());
  }
  eatPiece(x,y);
  stack.push((ChessPiece) o.clone());
  o.setCol(x);
  o.setRow(y);

  chessBoard.changeSide();
  }

 }

 break;
 }

 }

 chessPane.drawPiece();
 }

 public void eatPiece(int x,int y){
 chessPane.getChessPieces().removeIf(e->{
 if(e.getCol()==x&&e.getRow()==y){
 stack.push(e);
 return true;
 }
 return false;
 });
 }

 public boolean judgeGame(int x,int y){
 for(ChessPiece e:chessPane.getChessPieces()){
 if(e.getCol()==x&&e.getRow()==y&&(
  e.getType()== PieceType.KINGBLACK||e.getType()==PieceType.KINGWHITE))
 return true;
 }

 return false;
 }

 public void printTip(char side){
 Alert alert = new Alert(Alert.AlertType.INFORMATION);
 alert.setContentText((side=='B'?"黑":"白")+"方取得勝利");
 alert.setTitle("游戲結(jié)束");
 alert.showAndWait();
 }


}

ResetAction

package com.Exercise3.Controller;

import com.Exercise3.entity.Piece.ChessPiece;
import com.Exercise3.view.ChessPane;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;


import java.util.Stack;

public class ResetAction implements EventHandler<ActionEvent>{
 private ChessPane chessPane;
 public ResetAction(ChessPane chessPane) {
 this.chessPane = chessPane;
 }

 @Override
 public void handle(ActionEvent e) {
 Stack<ChessPiece> stack = ReleaseAction.stack;
 if(!stack.empty()){
 chessPane.getChessPieces().removeIf(o->o.equals(stack.peek()));//去除原來(lái)的棋子
 chessPane.getChessPieces().add(stack.pop());//將以前壓入堆棧的棋子重新加入

 chessPane.drawBoard();
 chessPane.drawPiece();
 }
 }
}

實(shí)體

棋子

ChessPiece

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.CarStrategy;

public class Car extends ChessPiece {
 public Car(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new CarStrategy(getCol(),getRow()));
 }
}

Car

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.CarStrategy;

public class Car extends ChessPiece {
 public Car(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new CarStrategy(getCol(),getRow()));
 }
}

Horse

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.HorseStategy;

public class Horse extends ChessPiece{
 public Horse(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new HorseStategy(getCol(),getRow()));
 }
}

King

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.KingStrategy;

public class King extends ChessPiece {
 public King(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new KingStrategy(getCol(),getRow()));
 }
}

Knight

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.KnightStrategy;

public class Knight extends ChessPiece {
 public Knight(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new KnightStrategy(getCol(),getRow()));
 }
}

Queen

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.QueenStrategy;

public class Queen extends ChessPiece {
 public Queen(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new QueenStrategy(getCol(),getRow()));
 }
}

Soldier

package com.Exercise3.entity.Piece;

import com.Exercise3.entity.PieceType;
import com.Exercise3.entity.Strategy.SoldierStategy;

public class Soldier extends ChessPiece{
 public Soldier(PieceType type, int row, int col) {
 super(type, row, col);
 setMoveStrategy(new SoldierStategy(getCol(),getRow(),getSide()));
 }

}

移動(dòng)策略

MoveStategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.Set;

public interface MoveStrategy {
 boolean move(int x, int y, Set<ChessPiece> chessPieces);
}

CarStrategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Set;

public class CarStrategy implements MoveStrategy {
 private int curX;
 private int curY;

 public CarStrategy() {
 }

 public CarStrategy(int curX, int curY) {
 this.curX = curX;
 this.curY = curY;
 }

 public boolean move(int x, int y, Set<ChessPiece> chessPieces) {
 if(x!=curX&&y!=curY)
 return false;
 if(isOverPiece(Math.min(curX,x),Math.min(curY,y),
 Math.max(curX,x),Math.max(curY,y),chessPieces))
 return false;
 curX = x;
 curY = y;
 return true;
 }

 public static boolean isOverPiece(int stX,int stY,int edX,int edY,Set<ChessPiece> chessPieces){
 for(ChessPiece e:chessPieces)
 if((e.getRow()>stY&&e.getRow()<edY)&&e.getCol()==stX||
  (e.getCol()>stX&&e.getCol()<edX&&e.getRow()==stY))
 return true;
 return false;
 }


 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

HorseStrategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Set;

public class HorseStategy implements MoveStrategy{
 private int curX;
 private int curY;

 public HorseStategy(int curX, int curY) {
 this.curX = curX;
 this.curY = curY;
 }


 @Override
 public boolean move(int x, int y, Set<ChessPiece> chessPieces) {
 if((Math.abs(curX-x)==1&&Math.abs(curY-y)==2)||
 (Math.abs(curX-x)==2&&Math.abs(curY-y)==1)){
 curX = x;
 curY = y;
 return true;
 }
 return false;
 }

 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

KingStrategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Set;

public class KingStrategy implements MoveStrategy {
 private int curX;
 private int curY;

 public KingStrategy(int curX, int cuY) {
 this.curX = curX;
 this.curY = cuY;
 }

 @Override
 public boolean move(int x, int y, Set<ChessPiece> chessPieces) {
 if(Math.abs(curX-x)<=1&&Math.abs(curY-y)<=1){
 curX = x;
 curY = y;
 return true;
 }

 return false;
 }

 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

KnightStrage

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class KnightStrategy implements MoveStrategy {
 private int curX;
 private int curY;

 public KnightStrategy(int curX, int curY) {
 this.curX = curX;
 this.curY = curY;
 }

 @Override
 public boolean move(int x, int y, Set<ChessPiece> chessPieces) {
 if(Math.abs(x-curX)==Math.abs(y-curY)){
 if(isOverPiece(Math.min(curX,x),Math.min(curY,y),
  Math.max(curX,x),Math.max(curY,y),chessPieces))
 return false;
 curX=x;
 curY=y;
 return true;
 }
 return false;
 }

 public static boolean isOverPiece(int stX,int stY,int edX,int edY,Set<ChessPiece> chessPieces){
 for(ChessPiece e:chessPieces){
 if(e.getCol()-stX==edX-e.getCol()&&edY-e.getRow()==e.getRow()-stY){
 System.out.println(e.isSelected()+" "+e.getRow()+" "+e.getCol());
 return true;
 }
 }

 return false;
 }
 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

QueeStrategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Set;


public class QueenStrategy implements MoveStrategy{
 private int curX;
 private int curY;

 public QueenStrategy(int curX, int curY) {
 this.curX = curX;
 this.curY = curY;
 }

 @Override
 public boolean move (int x, int y, Set<ChessPiece> chessPieces) {
 if(Math.abs(x-curX)==Math.abs(y-curY)||!(x!=curX&&y!=curY)){
 if(isOverPiece(Math.min(curX,x),Math.min(curY,y),
  Math.max(curX,x),Math.max(curY,y),chessPieces))
 return false;
 curX = x;
 curY = y;
 return true;
 }
 return false;
 }

 public boolean isOverPiece (int stX,int stY,int edX,int edY,Set<ChessPiece> chessPieces) {
 for(ChessPiece e:chessPieces){
 if(e.getRow()!=stY&&e.getCol()!=stX){
 return KnightStrategy.isOverPiece(stX,stY,edX,edY,chessPieces);
 }
 else{
 return CarStrategy.isOverPiece(stX,stY,edX,edY,chessPieces);
 }
 }
 return false;
 }


 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

SoldierStrategy

package com.Exercise3.entity.Strategy;

import com.Exercise3.entity.Piece.ChessPiece;

import java.util.List;
import java.util.Set;

public class SoldierStategy implements MoveStrategy{
 private int curX;
 private int curY;
 private char side;
 private boolean firstMove = true;

 public SoldierStategy(int curX, int curY,char side) {
 this.curX = curX;
 this.curY = curY;
 this.side = side;
 }


 @Override
 public boolean move(int x, int y, Set<ChessPiece> chessPieces) {
 //直線移動(dòng)
 if(curY==y){
 switch (side){
 case 'B': {
  if(isFirstMove()&&(x==curX+1||curX+2==x)){
  setFirstMove(false);
  curY = y;
  curX = x;
  return true;
  }
  else if(!isFirstMove()&&curX+1==x){
  curY = y;
  curX = x;
  return true;
  }
  break;
 }

 case 'W':{
  if(isFirstMove()&&(x==curX-1||x==curX-2)){
  setFirstMove(false);
  curY = y;
  curX = x;
  return true;
  }
  else if(!isFirstMove()&&curX-1==x){
  curY = y;
  curX = x;
  return true;
  }
  break;
 }
 }
 }

 //吃子移動(dòng)
 for(ChessPiece e:chessPieces){
 if(Math.abs(e.getRow()-curY)==1){
 if(e.getCol()-curX==1&&e.getSide()=='W'||
 curX-e.getCol()==1&&e.getSide()=='B'){
  curY = y;
  curX = x;
  return true;
 }

 }
 }

 return false;
 }



 public boolean isFirstMove() {
 return firstMove;
 }

 public void setFirstMove(boolean firstMove) {
 this.firstMove = firstMove;
 }

 public int getCurX() {
 return curX;
 }

 public void setCurX(int curX) {
 this.curX = curX;
 }

 public int getCurY() {
 return curY;
 }

 public void setCurY(int curY) {
 this.curY = curY;
 }
}

棋子類型

package com.Exercise3.entity;

public enum PieceType {
 KINGBLACK("KingBlack","com/Exercise3/img/KingBlack.jpg"),
 QUEENBLACK("QueenBlack","com/Exercise3/img/QueenBlack.jpg"),
 CARBLACK("CarBlack","com/Exercise3/img/CarBlack.jpg"),
 HORSEBLACK("HorseBlack","com/Exercise3/img/HorseBlack.jpg"),
 SOLDIERBLACK("SoldierBlack","com/Exercise3/img/SoldierBlack.jpg"),
 KNIGHTBLACK("KnightBlack","com/Exercise3/img/KnightBlack.jpg"),

 KINGWHITE("KingWhite","com/Exercise3/img/KingWhite.jpg"),
 QUEENWHITE("QueenWhite","com/Exercise3/img/QueenWhite.jpg"),
 CARWHITE("CarWhite","com/Exercise3/img/CarWhite.jpg"),
 HORSEWHITE("HorseWhite","com/Exercise3/img/HorseWhite.jpg"),
 SOLDIERWHITE("SoldierWhite","com/Exercise3/img/SoldierWhite.jpg"),
 KNIGHTWHITE("KnightWhite","com/Exercise3/img/KnightWhite.jpg");


 private String desc;
 private PieceType(String desc,String url ){
 this.desc = desc;
 this.url = url;
 }

 private String url;

 public String getDesc(){
 return desc;
 }

 public String getUrl() {
 return url;
 }
}

視圖

package com.Exercise3.view;

public class ChessBoard {
 static ChessBoard chessBoard = null;
 private int row;
 private int col;
 private double cellLength;
 private double startX;
 private double startY;
 private char currSide;

 private ChessBoard(double cellLength, double startX, double startY) {
 this.row = 8;
 this.col = 8;
 this.cellLength = cellLength;
 this.startX = startX;
 this.startY = startY;
 this.currSide = 'B';
 }

 public static ChessBoard getInstance(double cellLength, double startX, double startY){
 if(chessBoard == null)
 return new ChessBoard(cellLength,startX,startY);
 return chessBoard;
 }

 public ChessBoard getInstance(){
 return chessBoard;
 }

 public int getCol() {
 return col;
 }


 public int getRow() {
 return row;
 }

 public double getCellLength() {
 return cellLength;
 }

 public void changeSide(){
 currSide=(currSide=='B'?'W':'B');
 }

 public void setCellLength(double cellLength) {
 this.cellLength = cellLength;
 }

 public double getStartX() {
 return startX;
 }

 public void setStartX(double startX) {
 this.startX = startX;
 }

 public double getStartY() {
 return startY;
 }

 public void setStartY(double startY) {
 this.startY = startY;
 }

 public char getCurrSide() {
 return currSide;
 }
}
package com.Exercise3.view;

import com.Exercise3.entity.Piece.*;
import com.Exercise3.entity.PieceType;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.*;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;

import java.util.*;

public class ChessPane extends Pane {
 private Set<ChessPiece> chessPieces;
 private ChessBoard chessBoard;
 private Canvas canvas;
 private GraphicsContext gc;

 public ChessPane(ChessBoard chessBoard) {
 this.chessBoard = chessBoard;
 setChessPiece();
 canvas = new Canvas(900,900);
 gc = canvas.getGraphicsContext2D();
 draw();
 }


 public void draw(){
 drawBoard();
 drawPiece();
 getChildren().add(canvas);
 }


 public void drawBoard(){
 gc.clearRect(0,0,900,900);
 double x = chessBoard.getStartX();
 double y = chessBoard.getStartY();
 double cell = chessBoard.getCellLength();


 boolean flag = false;
 for(int i=0;i<chessBoard.getRow();i++){
 flag = !flag;
 for(int j=0;j<chessBoard.getCol();j++){
 gc.setFill(flag? Color.valueOf("#EDEDED"):Color.valueOf("CDC5BF"));
 gc.fillRect(x+j*cell,y+i*cell,cell,cell);
 flag = !flag;
 }
 }


 gc.setStroke(Color.GRAY);
 gc.strokeRect(x,y,cell*chessBoard.getCol(),cell*chessBoard.getRow());

 }

 public void drawPiece(){
 double cell = chessBoard.getCellLength();
 chessPieces.forEach( e->{
 if(e.isSelected()){
 gc.setFill(Color.valueOf("#6495ED"));
 gc.fillRect(chessBoard.getStartX()+e.getCol()*cell,
  chessBoard.getStartY()+e.getRow()*cell,
  cell,cell);
 }

 Image image = new Image(e.getType().getUrl());
 gc.drawImage(image,
  chessBoard.getStartX()+10 + e.getCol() * cell,
  chessBoard.getStartY()+10 + e.getRow() * cell,
  cell-20, cell-20);
 });
 }


 //加入棋子
 public void setChessPiece() {
 chessPieces = new HashSet<>();
 chessPieces.add(new Car(PieceType.CARBLACK,0,0));
 chessPieces.add(new Horse(PieceType.HORSEBLACK,1,0));
 chessPieces.add(new Knight(PieceType.KNIGHTBLACK,2,0));
 chessPieces.add(new King(PieceType.KINGBLACK,3,0));
 chessPieces.add(new Queen(PieceType.QUEENBLACK,4,0));
 chessPieces.add(new Knight(PieceType.KNIGHTBLACK,5,0));
 chessPieces.add(new Horse(PieceType.HORSEBLACK,6,0));
 chessPieces.add(new Car(PieceType.CARBLACK,7,0));
 for(int i=0;i<8;i++){
 chessPieces.add(new Soldier(PieceType.SOLDIERBLACK,i,1));
 }


 chessPieces.add(new Car(PieceType.CARWHITE,0,7));
 chessPieces.add(new Horse(PieceType.HORSEWHITE,1,7));
 chessPieces.add(new Knight(PieceType.KNIGHTWHITE,2,7));
 chessPieces.add(new King(PieceType.KINGWHITE,3,7));
 chessPieces.add(new Queen(PieceType.QUEENWHITE,4,7));
 chessPieces.add(new Knight(PieceType.KNIGHTWHITE,5,7));
 chessPieces.add(new Horse(PieceType.HORSEWHITE,6,7));
 chessPieces.add(new Car(PieceType.CARWHITE,7,7));
 for(int i=0;i<8;i++){
 chessPieces.add(new Soldier(PieceType.SOLDIERWHITE,i,6));
 }
 }

 public ChessBoard getChessBoard() {
 return chessBoard;
 }

 public void setChessBoard(ChessBoard chessBoard) {
 this.chessBoard = chessBoard;
 }

 public Set<ChessPiece> getChessPieces() {
 return chessPieces;
 }

 public void setChessPieces(Set<ChessPiece> chessPieces) {
 this.chessPieces = chessPieces;
 }

 public Canvas getCanvas() {
 return canvas;
 }

 public void setCanvas(Canvas canvas) {
 this.canvas = canvas;
 }

 public GraphicsContext getGc() {
 return gc;
 }

 public void setGc(GraphicsContext gc) {
 this.gc = gc;
 }
}

測(cè)試

package com.Exercise3;

import com.Exercise3.Controller.PressedAction;
import com.Exercise3.Controller.ReleaseAction;
import com.Exercise3.Controller.ResetAction;
import com.Exercise3.view.ChessBoard;
import com.Exercise3.view.ChessPane;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;

import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

public class Test extends Application {

 public static void main(String[] args) {
 launch(args);
 }

 @Override
 public void start(Stage primaryStage) {

 String MEDIA_URL = "file:/E:/IdeaProjects/Experiment/src/com/Exercise3/music/BackgroundMusic.mp3";
 ChessBoard chessBoard = ChessBoard.getInstance(100,40,40);

 //添加媒體資源

 Media media = new Media(MEDIA_URL);
 MediaPlayer mediaPlayer = new MediaPlayer(media);
 mediaPlayer.setAutoPlay(true);
 mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
 mediaPlayer.play();


 ChessPane pane = new ChessPane(chessBoard);
 pane.setOnMousePressed(new PressedAction(pane,mediaPlayer));

 pane.setOnMouseReleased(new ReleaseAction(pane));

 BorderPane borderPane = new BorderPane();
 borderPane.setCenter(pane);
 HBox hBox = new HBox();
 hBox.setAlignment(Pos.TOP_CENTER);

 Button button = new Button("悔棋");
 button.setOnAction(new ResetAction(pane));

 hBox.getChildren().add(button);
 borderPane.setBottom(hBox);
 Scene scene = new Scene(borderPane,900,900);
 primaryStage.setScene(scene);
 primaryStage.setTitle("國(guó)際象棋");
 primaryStage.show();

 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

分享文章:Javafx實(shí)現(xiàn)國(guó)際象棋游戲
轉(zhuǎn)載來(lái)于:http://aaarwkj.com/article46/jesheg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)網(wǎng)站營(yíng)銷、營(yíng)銷型網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站收錄微信小程序

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作
97色伦97色伦国产在线| 成年人免费在线观看毛片| 日韩欧美 高清一区| 日韩欧美亚洲精品中文字幕αv| 日本成人精品二区在线观看| jk黑丝白丝国产精品| 日本激情诱惑免费在线播放| av免费在线观看网页| 国偷蜜桃av一区二区三区| 欧美亚洲五月婷婷激情| 蜜臀视频网站在线观看| 日本高清不卡在线一区二区| 亚洲美腿丝袜综合在线| 亚洲成人影院中文字幕| 亚洲一区二区三区色偷偷| 开裆丝袜高跟啪啪高潮av| 午夜体内射精免费视频| 国产精品一品二区三区在线观看| 人妻少妇被猛烈进入中出视频| 日本道二区视频中文字幕| 欧美日韩国产精品高清| 欧美久久久久综合一区| 亚洲成人福利免费网站| 久久精品久久黄色片看看| 国产剧情av网址观看免费| 国内精品免费视频不卡| 日韩一二卡在线观看视频| 亚洲一区欧美日韩91| 国产精品国语对白av处女| 夫妻性生活黄色录像视频| 亚洲人妻激情一区二区| 欧美欧美欧美欧美在线| 久久精品国产亚洲av热老太| 国产麻豆剧传媒国产av| 日本久久在线观看视频| 九九久久亚洲av成人乱片| 91精品午夜在线观看| 精品av一区二区在线| 天堂在线精品亚洲综合网| 日本黄色av一区二区| 91狠狠综合久久精品|