• 大小: 8KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: Java
  • 标签: 飞行棋  代码  

资源简介

飞行棋回合中代码.java 博客文章中所用实例代码

资源截图

代码片段和文件信息

    private void roll(){
        roll_num=(int)(Math.random()*6)+1;
        tv_roll_num.setText(Integer.toString(roll_num));
        //info.setText(“玩家:[ “+Value.PlayerName[whosTurn]+“ ]投掷出了\n“+roll_num+“!“);
        //System.out.println(“玩家:[ “+Value.PlayerName[whosTurn]+“ ]投掷出了- “+roll_num+“请移动!“);
        if(chdm.getPlayerType(whosTurn)==Value.LocalHuman){
            if(!canMove())turn_end();//替人类判断是否有子可走
        }
    }
    private boolean canMove() {
        if(roll_num==6){
            info.setText(“玩家:[“+Value.PlayerName[whosTurn]+“]摇出了[ 6 ]\n可选择移动或起飞,并获得一个新的回合“);
            System.out.println(“玩家:[“+Value.PlayerName[whosTurn]+“]可选择移动或起飞,并获得一个新的回合“);
            return true;//显然可以移动或起飞
        }
        boolean flag = false;//是否有飞机起飞
        switch (whosTurn) {
            case Value.red:
                for (int i = 0; i < 4; i++) {
                    if (!red[i].isFlying()) ;
                    else {
                        flag = true;
                        break;
                    }
                }
                break;
            case Value.yellow:
                for (int i = 0; i < 4; i++) {
                    if (!yellow[i].isFlying()) ;
                    else {
                        flag = true;
                        break;
                    }
                }
                break;
            case Value.blue:
                for (int i = 0; i < 4; i++) {
                    if (!blue[i].isFlying()) ;
                    else {
                        flag = true;
                        break;
                    }
                }
                break;
            case Value.green:
                for (int i = 0; i < 4; i++) {
                    if (!green[i].isFlying()) ;
                    else {
                        flag = true;
                        break;
                    }
                }
                break;
        }
        if (!flag) {
            info.setText(“玩家:[“ + Value.PlayerName[whosTurn] + “]\n滚出了:[“ + roll_num + “],但无飞机可动。“);
            System.out.println(“玩家:[“ + Value.PlayerName[whosTurn] + “]滚出了:[“ + roll_num + “],但无飞机可动。“);
            return false;//无6,直接跳过回合,起飞不了又走不了
        }
        //有飞机可飞
        info.setText(“玩家:[ “+Value.PlayerName[whosTurn]+“ ]投掷出了\n“+roll_num+“!“);
        return true;
    }
    private void go(Cheesman c){
        if(roll_num!=0){
            if(roll_num==6){
                if(c==null){
                    System.out.println(“注意:未选中棋子“);//debug
                }
                //滚出六,可继续再移动
                else if(!c.isFlying() && !c.isCompleted()){//起飞
                    c.Fly();
                    myHandler.post(go_mp3_Runable);
                    System.out.println(“注意:起飞成功“);
                }
                else{//移动
                    c.move(roll_num);
                    myHandler.post(go_mp3_Runable);
                    System.out.println(“注意:移动完毕

评论

共有 条评论