团队课程设计博客-飞行棋

一.团队介绍

成员姓名 任务分配 团队成员课程设计博客链接
严威(组长) 飞行棋功能的实现,人机功能实现,棋子和骰子的所有操作等 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地址

https://gitee.com/ywww1/java

三.项目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模块的重要作用,对自己以后的方向规划也是起到很大的作用。

posted @ 2020-01-10 02:50  ywww  阅读(1184)  评论(2编辑  收藏  举报