工作日志3——模型代码

人员分工

周志豪:组长,写文档

崔世昂:原型系统的实现

田希宇:进行进阶的测试

张峻杰:管理博客,ppt展示

 

 

代码实现功能点及代码:

  1. 购买棋子

输入BC进入购买页面,输入1-5购买,0刷新,-1退出

                    case "BC":{

                        if(Bought==false) {

                            p1.BuyChess();

                            System.out.println("========已退出购买页面========");

                            Bought=true;

                        }

                        else System.out.println("你已经买过了!");

                        break;

                    }

  1. 购买经验

输入BE购买经验

                    case "BE":{

                        if(p1.Coins<5) {

                            System.out.println("你的钱不够!");

                            break;

                        }

                        else {

                            if(p1.Grade<=10) {

                                System.out.println("========金币-5,经验+4========");

                                p1.Coins-=5;

                                p1.Experience+=4;

                                if(p1.Experience>=p1.LevelUpExperienceOnGrade[p1.Grade]) {

                                    p1.Experience-=p1.LevelUpExperienceOnGrade[p1.Grade];

                                    p1.Grade++;

                                }

                                break;

                            }

                            else {

                                System.out.println("你已经满级了,不需要买经验了!");

                                break;

                            }

                        }

                    }

  1. 卖棋子

输入SC卖棋子

                    case "SC":{

                        p1.SellChess();

                        System.out.println("========已退出卖棋页面========");

                        break;

                    }

4.合成棋子

                    case "CC":{

                        p1.CombineChess();

                        System.out.println("========已退出合棋页面========");

                        break;

                    }

5.下个回合

输入NT进入下个回合

                    case "NT":{

                        System.out.println("========即将开始下一回合========");

                        Next=true;

                        break;

                    }

 

 

 

总共的代码量是475行

 

全部代码:

 

①Chess.java

package Game;

 

 

public class Chess {

    public String Name=new String();

    public String Quality=new String();

    public int Cost;

    public Chess(String name,String quality,int cost) {

        this.Name=name;

        this.Quality=quality;

        this.Cost=cost;

    }

}

 

②PlayerModel.java

package Interface;

 

 

public interface PlayerModel {

 

    public void Init();

    public void BuyChess();

    public void CombineChess();

    public void SellChess();

    public void Update();

}

 

③Player.java

package Game;

 

import Interface.PlayerModel;

import java.util.*;

import java.io.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

 

public class Player implements PlayerModel {

 

       public int Round;

       private int Grade;

       private int Experience;

       private int Coins;

       private int ConstantWinning;

       private int ConstantFailing;

       private int interest=0;

       private String Name;

       public int[] ChessCostOnGrade= {0,1,2,3,3,4,4,4,5,5,5};

       public int[] LevelUpExperienceOnGrade= {1,1,1,2,4,8,16,24,32,40};

       private LinkedList MyChess;

       private LinkedList Library;

       public static void main(String[] args) {

              // TODO Auto-generated method stub

              String Order=new String();

              Scanner in=new Scanner(System.in);

              boolean Bought;

              boolean Next;

              Player p1=new Player();

              p1.Init();

              System.out.println("AutoChess 抽棋模拟");

              System.out.println("=================");

              System.out.println("游戏规则:");

              System.out.println("输入不同的文本来进行操作:\n"

                            + "BC 表示 BuyChess\n"

                            + "BE 表示BuyExperience\n"

                            + "SC 表示 SellChess\n"

                            + "CC 表示 CombineChess\n"

                            + "NT 表示 NextTurn");

              while(true) {

                     p1.Update();

                     Bought=false;

                     Next=false;

                     while(Next==false) {

                            p1.Show();

                            switch(Order=in.next()) {

                                   case "BC":{

                                          if(Bought==false) {

                                                 p1.BuyChess();

                                                 System.out.println("========已退出购买页面========");

                                                 Bought=true;

                                          }

                                          else System.out.println("你已经买过了!");

                                          break;

                                   }

                                   case "BE":{

                                          if(p1.Coins<5) {

                                                 System.out.println("你的钱不够!");

                                                 break;

                                          }

                                          else {

                                                 if(p1.Grade<=10) {

                                                        System.out.println("========金币-5,经验+4========");

                                                        p1.Coins-=5;

                                                        p1.Experience+=4;

                                                        if(p1.Experience>=p1.LevelUpExperienceOnGrade[p1.Grade]) {

                                                               p1.Experience-=p1.LevelUpExperienceOnGrade[p1.Grade];

                                                               p1.Grade++;

                                                        }

                                                        break;

                                                 }

                                                 else {

                                                        System.out.println("你已经满级了,不需要买经验了!");

                                                        break;

                                                 }

                                          }

                                   }

                                   case "SC":{

                                          p1.SellChess();

                                          System.out.println("========已退出卖棋页面========");

                                          break;

                                   }

                                   case "CC":{

                                          p1.CombineChess();

                                          System.out.println("========已退出合棋页面========");

                                          break;

                                   }

                                   case "NT":{

                                          System.out.println("========即将开始下一回合========");

                                          Next=true;

                                          break;

                                   }

                                   default:{

                                          System.out.println("你输错了,请输入正确的指令!");

                                          break;

                                   }

                            }

                     }

              }

       }

 

       @Override

       public void Init() {

              // TODO Auto-generated method stub

              this.Round=0;

              this.Grade=0;

              this.Experience=0;

              this.Coins=100;

              this.ConstantWinning=0;

              this.ConstantFailing=0;

              this.interest=0;

              this.MyChess=new LinkedList();

              this.Library=new LinkedList();

              Scanner in=new Scanner(System.in);

              System.out.println("=================");

              System.out.println("请输入名称:");

              this.Name=in.next();

              for(int i=0;i<9;i++) {

                     this.Library.add(new Chess("潮汐猎人","传说",5));

                     this.Library.add(new Chess("迷团","传说",5));

                     this.Library.add(new Chess("地精工程师","传说",5));

                     this.Library.add(new Chess("巫妖","传说",5));

                     this.Library.add(new Chess("矮人直升机","传说",5));

                     this.Library.add(new Chess("利爪德鲁伊","史诗",4));

                     this.Library.add(new Chess("龙骑士","史诗",4));

                     this.Library.add(new Chess("蛇发女妖","史诗",4));

                     this.Library.add(new Chess("干扰者","史诗",4));

                     this.Library.add(new Chess("炼金术士","史诗",4));

                     this.Library.add(new Chess("圣堂刺客","史诗",4));

                     this.Library.add(new Chess("死灵法师","史诗",4));

                     this.Library.add(new Chess("光之守卫","史诗",4));

                     this.Library.add(new Chess("巨魔战将","史诗",4));

                     this.Library.add(new Chess("海军上将","史诗",4));

                     this.Library.add(new Chess("末日使者","史诗",4));

                     this.Library.add(new Chess("秀逗魔法师","稀有",3));

                     this.Library.add(new Chess("影魔","稀有",3));

                     this.Library.add(new Chess("冥界亚龙","稀有",3));

                     this.Library.add(new Chess("狙击手","稀有",3));

                     this.Library.add(new Chess("鱼人夜行者","稀有",3));

                     this.Library.add(new Chess("沙王","稀有",3));

                     this.Library.add(new Chess("死亡骑士","稀有",3));

                     this.Library.add(new Chess("幻影刺客","稀有",3));

                     this.Library.add(new Chess("风行者","稀有",3));

                     this.Library.add(new Chess("闪电幽魂","稀有",3));

                     this.Library.add(new Chess("全能骑士","稀有",3));

                     this.Library.add(new Chess("剧毒术士","稀有",3));

                     this.Library.add(new Chess("狼人","稀有",3));

                     this.Library.add(new Chess("先知","普通",2));

                     this.Library.add(new Chess("月之骑士","普通",2));

                     this.Library.add(new Chess("树精卫士","普通",2));

                     this.Library.add(new Chess("混沌骑士","普通",2));

                     this.Library.add(new Chess("鱼人守卫","普通",2));

                     this.Library.add(new Chess("巫医","普通",2));

                     this.Library.add(new Chess("精灵龙","普通",2));

                     this.Library.add(new Chess("痛苦女王","普通",2));

                     this.Library.add(new Chess("伐木机","普通",2));

                     this.Library.add(new Chess("剑圣","普通",2));

                     this.Library.add(new Chess("兽王","普通",2));

                     this.Library.add(new Chess("水晶室女","普通",2));

                     this.Library.add(new Chess("敌法师","基础",1));

                     this.Library.add(new Chess("修补匠","基础",1));

                     this.Library.add(new Chess("蝙蝠骑士","基础",1));

                     this.Library.add(new Chess("暗影萨满","基础",1));

                     this.Library.add(new Chess("发条技师","基础",1));

                     this.Library.add(new Chess("赏金猎人","基础",1));

                     this.Library.add(new Chess("卓尔游侠","基础",1));

                     this.Library.add(new Chess("巨牙海民","基础",1));

                     this.Library.add(new Chess("食人魔魔法师","基础",1));

                     this.Library.add(new Chess("魅惑魔女","基础",1));

                     this.Library.add(new Chess("斧王","基础",1));

              }

       }

 

       @Override

       public void CombineChess() {

              // TODO Auto-generated method stub

              int i,index1,index2;

              Chess c;

              System.out.println("========已进入合棋界面========");

              if(this.MyChess.size()<=1) {

                     System.out.println("你没有棋子可以合!");

              }

              else {

                     System.out.println("=================");

                     for(i=0;i

                            c=this.MyChess.get(i);

                            System.out.println(i+1+":"+" "+c.Name+":"+c.Cost);

                     }

                     System.out.println("*****************");

                     System.out.println("请输入要合成的两个棋子的序号,用空格分开");

                     Scanner in=new Scanner(System.in);

                     index1=in.nextInt();

                     index2=in.nextInt();

                     Chess c1,c2;

                     c1=this.MyChess.get(index1-1);

                     c2=this.MyChess.get(index2-1);

                     if(c1.Name!=c2.Name) System.out.println("你输错了!");

                     else {

                            c1.Name+="Plus ";

                            c1.Cost*=2;

                            this.MyChess.remove(index2-1);

                     }

                     this.Show();

              }

       }

      

       @Override

       public void SellChess() {

              // TODO Auto-generated method stub

              int i,place;

              Chess c;

              System.out.println("========已进入卖棋界面========");

              if(this.MyChess.size()==0) {

                     System.out.println("你没有棋子可以卖!");

              }

              else {

                     System.out.println("=================");

                     for(i=0;i

                            c=this.MyChess.get(i);

                            System.out.println(i+1+":"+" "+c.Name+":"+(c.Cost/2));

                     }

                     System.out.println("*****************");

                     System.out.println("请输入要卖的棋子的序号");

                     Scanner in=new Scanner(System.in);

                     place=in.nextInt()-1;

                     this.Coins+=this.MyChess.get(place).Cost/2;

                     this.MyChess.remove(place);

                     this.Show();

              }

       }

      

       @Override

       public void Update() {

              // TODO Auto-generated method stub

              this.Round++;

              System.out.println("========"+"回合 "+this.Round+" 开始了"+"========");

              this.Experience+=1;

              this.Coins+=5;

              this.Coins+=this.interest;

              this.interest=this.Coins/10;

              if(this.Experience>=this.LevelUpExperienceOnGrade[this.Grade]) {

                     this.Experience-=this.LevelUpExperienceOnGrade[this.Grade];

                     this.Grade++;

              }

       }

 

       public void Show() {

              System.out.println("=================");

              System.out.println("名称: "+this.Name);

              System.out.println("回合: "+this.Round);

              System.out.println("等级: "+this.Grade);

              System.out.println("经验: "+this.Experience);

              System.out.println("金币: "+this.Coins);

              System.out.println("连胜: "+this.ConstantWinning);

              System.out.println("连败: "+this.ConstantFailing);

              System.out.println("利息: "+this.interest);

              System.out.println("*****************");

              System.out.println("人口: "+this.Grade);

              System.out.println("棋子如下:");

              for(int i=0;i

                     switch(MyChess.get(i).Quality) {

                            case "基础":{

                                   System.out.println(this.MyChess.get(i).Name+" ★");

                                   break;

                            }

                            case "普通":{

                                   System.out.println(this.MyChess.get(i).Name+" ★★");

                                   break;

                            }

                            case "稀有":{

                                   System.out.println(this.MyChess.get(i).Name+" ★★★");

                                   break;

                            }

                            case "史诗":{

                                   System.out.println(this.MyChess.get(i).Name+" ★★★★");

                                   break;

                            }

                            case "传说":{

                                   System.out.println(this.MyChess.get(i).Name+" ★★★★★");

                                   break;

                            }

                     }

              }

              System.out.println("=================");

       }

 

       @Override

       public void BuyChess() {

              // TODO Auto-generated method stub

              Random rand=new Random();

              Scanner in=new Scanner(System.in);

              String Order=new String();

              int start=this.Library.size();

              int i;

              boolean CanRefresh=true,breakout=false;

              int[] places=new int[5];

              LinkedList SellingChess=new LinkedList();

              Chess c=new Chess("无","无",6);

              while(CanRefresh==true) {

                     System.out.println("========已进入购买界面========");

                     SellingChess.removeAll(SellingChess);

                     for(i=0;i<5;i++) {

                            c=new Chess("无","无",6);

                            while(c.Cost>this.ChessCostOnGrade[this.Grade]) {

                                   places[i]=rand.nextInt(start-i);

                                   c=this.Library.get(places[i]);

                            }

                            SellingChess.add(new Chess(c.Name,c.Quality,c.Cost));

                     }

                     System.out.println("=================");

                     for(i=0;i<5;i++) {

                            c=SellingChess.get(i);

                            System.out.println((i+1)+":"+" "+c.Name+" "+c.Quality+" "+c.Cost);

                     }

                     System.out.println("=================");

                     breakout=false;

                     while(!breakout) {

                            System.out.println("请输入要购买的棋子的序号,不可重复购买同一序号棋子,输入0刷新,输入-1退出");

                            switch(in.nextInt()) {

                                   case -1:{

                                          breakout=true;

                                          CanRefresh=false;

                                          break;

                                   }

                                   case 0:{

                                          if(this.Coins<2) {

                                                 CanRefresh=false;

                                                 breakout=true;

                                                 break;

                                          }

                                          else {

                                                 CanRefresh=true;

                                                 breakout=true;

                                                 this.Coins-=2;

                                                 break;

                                          }

                                   }

                                   case 1:{

                                          if(this.Grade<=this.MyChess.size()) {

                                                 System.out.println("人口已满");

                                                 breakout=true;

                                                 CanRefresh=false;

                                                 break;

                                          }

                                          if(this.Coins>SellingChess.get(0).Cost) {

                                                 this.MyChess.add(SellingChess.get(0));

                                                 this.Coins-=SellingChess.get(0).Cost;

                                                 this.Library.remove(places[0]);

                                                 start--;

                                                 this.Show();

                                                 break;

                                          }

                                          else {

                                                 System.out.println("你买不起!");

                                                 break;

                                          }

                                   }

                                   case 2:{

                                          if(this.Grade<=this.MyChess.size()) {

                                                 System.out.println("人口已满");

                                                 breakout=true;

                                                 CanRefresh=false;

                                                 break;

                                          }

                                          if(this.Coins>SellingChess.get(1).Cost) {

                                                 this.MyChess.add(SellingChess.get(1));

                                                 this.Coins-=SellingChess.get(1).Cost;

                                                 this.Library.remove(places[1]);

                                                 start--;

                                                 this.Show();

                                                 break;

                                          }

                                          else {

                                                 System.out.println("你买不起!");

                                                 break;

                                          }

                                   }

                                   case 3:{

                                          if(this.Grade<=this.MyChess.size()) {

                                                 System.out.println("人口已满");

                                                 breakout=true;

                                                 CanRefresh=false;

                                                 break;

                                          }

                                          if(this.Coins>SellingChess.get(2).Cost) {

                                                 this.MyChess.add(SellingChess.get(2));

                                                 this.Coins-=SellingChess.get(2).Cost;

                                                 this.Library.remove(places[2]);

                                                 start--;

                                                 this.Show();

                                                 break;

                                          }

                                          else {

                                                 System.out.println("你买不起!");

                                                 break;

                                          }

                                   }

                                   case 4:{

                                          if(this.Grade<=this.MyChess.size()) {

                                                 System.out.println("人口已满");

                                                 breakout=true;

                                                 CanRefresh=false;

                                                 break;

                                          }

                                          if(this.Coins>SellingChess.get(3).Cost) {

                                                 this.MyChess.add(SellingChess.get(3));

                                                 this.Coins-=SellingChess.get(3).Cost;

                                                 this.Library.remove(places[3]);

                                                 start--;

                                                 this.Show();

                                                 break;

                                          }

                                          else {

                                                 System.out.println("你买不起!");

                                                 break;

                                          }

                                   }

                                   case 5:{

                                          if(this.Grade<=this.MyChess.size()) {

                                                 System.out.println("人口已满");

                                                 breakout=true;

                                                 CanRefresh=false;

                                                 break;

                                          }

                                          if(this.Coins>SellingChess.get(4).Cost) {

                                                 this.MyChess.add(SellingChess.get(4));

                                                 this.Coins-=SellingChess.get(4).Cost;

                                                 this.Library.remove(places[4]);

                                                 start--;

                                                 this.Show();

                                                 break;

                                          }

                                          else {

                                                 System.out.println("你买不起!");

                                                 break;

                                          }

                                   }

                                   default:{

                                          System.out.println("你输错了!");

                                          break;

                                   }

                            }

                     }

              }    

       }

 

}

进阶项:

1.我们完美模拟了自走棋抽棋的部分,并且为了功能需要添加了金币,经验等多个系统,实现了对自走棋抽棋需求的更加立体的满足。

2.模型操作简便,易上手,可用性较强。简洁明了,能更加明确的体现抽到的棋子和待购区的棋子,充分考虑了用户的使用体验。

3.虽然没有实现图形界面,但是命令行所有的文字提示基本上提供了所有用户需要的信息,因此每次用户抽棋都会给出下一步提示,直观明了。

转载于:https://www.cnblogs.com/Group-5/p/11013188.html

你可能感兴趣的:(工作日志3——模型代码)