一.團隊介紹
成員姓名 | 任務分配 | 團隊成員課程設計博客鏈接 |
---|---|---|
嚴威(組長) | 飛行棋功能的實現,人機功能實現,棋子和骰子的所有操作等 | https://www.cnblogs.com/putianliuzhong/p/12174353.html |
張偉龍 | 數據庫連接,數據庫賬戶匹配及相關操作,道具實現等 | https://www.cnblogs.com/zwl-/p/12174236.html |
周秋斌 | 登錄頁面GUI,游戲過程GUI實現,素材收集,背景音樂等 | https://www.cnblogs.com/zhouqb/p/12174221.html |
二.項目git地址
三.項目git提交記錄截圖
四.前期調查
五.項目功能架構圖、主要功能流程圖
六.包結構圖與主要UML類圖
七.運行結果
登錄界面:
游戲過程中:
踩到不同顏色棋子:
踩到前:
踩到后:
踩到龍卷風道具:
踩到炸彈道具:
踩到再搖一次骰子道具:
踩到前進6格道具:
當飛機到達終點時候效果圖:
當游戲結束時候的彈窗:
八.關鍵代碼
package model;
import java.awt.*;
import java.util.ArrayList;
import static java.lang.Thread.*;
import static model.ChessPane.*;
/**
* 棋子的移動實現
* @author yw
* @date 2020.1.6
*/
public class Move {
private DiceData dice;
private ChessData chess;
/**
* 要走的棋子編號
*/
private int chessNum;
/**
* 對哪個玩家的棋子就行操作
*/
private int playerTurn;
/**
* 判斷棋子是否已經執行
*/
private boolean flag = false;
/**
* 棋子下一步移動的步數
*/
private int nextPositionNum = 0;
/**
* 骰子點數
*/
private int moveStep = 0;
private ArrayList<Point> chessPoint = new ArrayList<>();
private Prop prop;
public Move(int chessNum, DiceData dice, ChessData chess, Prop prop) {
/**
* 產生6個隨機地點、功能的道具,並設置每動十次棋子才更新道具的頻率
*/
this.dice=dice;
this.chess = chess;
this.prop = prop;
this.chessNum = chessNum;
this.playerTurn = dice.getThisPlayerTurn();
this.moveStep = dice.getThisNum();
findMoveWay();
/**
* 判斷移動完之后是否踩到了道具
* 根據踩到道具的種類而完成相應功能
*/
eatProp();
//道具結束
}
/**
* 移動和起飛的步數
*/
private void findMoveWay(){
// 起飛的操作
for (int i = 0; i < 4; i++) {
// 棋子的位置在家
if (homePosition[playerTurn][i].equals(chess.getButtonsPosition(chessNum))) {
// 起飛狀態設為true
chess.changeStatus(chessNum, true);
chess.changePosition(chessNum, road[playerTurn][0]);
chess.getChessButton(chessNum).changeBound(road[playerTurn][0]);
flag = true;
}
}
if (!flag) {
for (int i = 0; i < roadLength; i++) {
if (road[playerTurn][i].equals(chess.getButtonsPosition(chessNum))) {
nextPositionNum = 2 * roadLength - i - moveStep - 2;
//到終點
if(i+moveStep==roadLength-1){
move(this.chessNum,road[playerTurn][roadLength-1]);
move(this.chessNum,homePosition[this.chessNum/4][this.chessNum%4]);
chess.getChessButton(this.chessNum).setEndImage(playerTurn);
chess.setAChessEndStatus(this.chessNum,true);
chess.changeStatus(chessNum,false);
if(chess.isPlayerEnd(playerTurn)){
chess.setAPlayerEndStatus(playerTurn,true);
dice.addEndComps(playerTurn);
}
} else if (i + moveStep > roadLength - 1) {
// 到終點彈回
for (int k = i; k < roadLength; k++) {
move(this.chessNum, road[playerTurn][k]);
}
for (int k = roadLength - 1; k >= nextPositionNum; k--) {
move(this.chessNum, road[playerTurn][k]);
}
} else {
// 輔助記錄移動到哪里
int k;
nextPositionNum = i + moveStep;
for (k = i; k <= nextPositionNum; k++) {
move(this.chessNum, road[playerTurn][k]);
}
killOtherChess(road[playerTurn][nextPositionNum]);
// 是否可以飛
for (int j = 0; j < flyPositionNum; j++) {
if (road[playerTurn][nextPositionNum].equals
(flyPosition[playerTurn][j])) {
nextPositionNum += 4;
break;
}
}
//移動操作
for (k = k - 1; k <= nextPositionNum; k++) {
move(this.chessNum, road[playerTurn][k]);
}
killOtherChess(road[playerTurn][nextPositionNum]);
// 是否可以超遠飛
if (road[playerTurn][nextPositionNum].equals
(specialFlyPosition[playerTurn])) {
nextPositionNum += 12;
}
move(this.chessNum, road[playerTurn][nextPositionNum]);
killOtherChess(road[playerTurn][nextPositionNum]);
}
break;
}
}
}
}
/**
* 控制移動
* @param chessNum
* @param point
*/
private void move(int chessNum, Point point) {
int i = chess.getButtonsPosition(chessNum).x;
int j = chess.getButtonsPosition(chessNum).y;
int x = point.x - i;
int y = point.y - j;
int dx = 1;
int dy = 1;
if (x != 0) {
dx = Math.abs(x) / x;
}
if (y != 0) {
dy = Math.abs(y) / y;
}
for (; i != point.x && j != point.y; i += dx, j += dy) {
chess.getChessButton(chessNum).changeBound(new Point(i, j));
try {
sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (i != point.x) {
for (; i != point.x; i += dx) {
chess.getChessButton(chessNum).changeBound(new Point(i, j));
try {
sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
for (; j != point.y; j += dy) {
chess.getChessButton(chessNum).changeBound(new Point(i, j));
try {
sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
chess.getChessButton(chessNum).changeBound(point);
chess.changePosition(chessNum, point);
}
/**
* 踩死同一位置上的其它棋子
* @param point
*/
private void killOtherChess(Point point) {
for (int i = 0; i < chess.getCompNum() * 4; i++) {
// 是不同顏色的棋子
if (i / 4 != playerTurn) {
if (chess.getButtonsPosition(i).equals(point)) {
move(i, homePosition[i / 4][i % 4]);
chess.changeStatus(i,false);
}
}
}
}
/**
* 判斷移動完之后是否踩到了道具
* 根據踩到道具的種類而完成相應功能
*/
private void eatProp(){
if(prop.collision(chess.getButtonsPosition(chessNum))) {
Point P;
switch (prop.getPoint(chess.getButtonsPosition(chessNum))) {
case 0: {
System.out.println("踩到龍卷風,隨機跳");
P = prop.windFunction(dice.getThisPlayerTurn(), chessPoint);
move(chessNum, P);
killOtherChess(P);
break;
}
case 1: {
System.out.println("踩到加油站,再搖一次骰子");
Prop.setAgain(true);
break;
}
case 2: {
System.out.println("踩到炸彈,退后兩格");
P = prop.minusTwoFunction(dice.getThisPlayerTurn(), chess.getButtonsPosition(chessNum));
move(chessNum, P);
killOtherChess(P);
break;
}
default: {
System.out.println("踩到六骰子,前進六格");
P = prop.sixPane(dice.getThisPlayerTurn(), chess.getButtonsPosition(chessNum));
move(chessNum, P);
killOtherChess(P);
break;
}
}
}
}
}
此代碼主要功能是進行棋子的移動和走到相應位置產生的效果,如到終點飛回起點並不能再次起飛,前進幾格等操作,還有吃到道具產生相應操作的實現,並實現界面上棋子的移動效果。
九.項目代碼掃描結果及改正
修正前:
修正后:
再修正后:
最后修正:
十.項目總結
不足:沒有實現聯網互相對戰的功能,缺少人機的算法,導致人機行動比較的單一。
展望:可以將道具的界面進行優化,棋子的移動進行重新設計。
總結:
這次課程設計參與小組共同完成的編寫代碼、實現功能模塊。歷時兩個星期終於在大家的一起努力下順利完成了。過程辛苦是不可避免,但收獲還是令人感到尤其的欣慰。在這次的課程設計中不僅檢驗了我們所學習的知識,也培養大家的實踐能力,學會了遇到一個問題,如何去尋找思路,如何去解決問題,最終完成整個事情。在設計過程中,與同學分工設計,和同學們相互探討,相互學習,相互監督。學會了合作,學會了寬容,學會了理解。課程設計是我們專業課程知識綜合應用的實踐訓練,是我們邁向社會,從事職業工作前一個必不少的過程。實驗過程中,也十分感謝實驗指導老師鄭如濱,謝書童老師的指點與教導。這次課程設計不僅是對這學期所學知識的一種綜合檢驗,而且也是對自己動手能力的一種提高;增強了自己實踐能力。通過這次課程設計使我明白了自己知識還比較欠缺,只是學習書本知識還是遠遠不夠的,自己不會的東西還有太多,學習需要自己長期的積累,在以后的學習、工作中都應該不斷的學習,將課本的理論知識與生活中的實踐知識相結合,不斷提高自己文化知識和實踐能力。總的來說,這次課設對我們的起到的作用的很大的,每個人都深刻了解到java模塊的重要作用,對自己以后的方向規划也是起到很大的作用。