⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 board.java

📁 大富翁游戏monopoli
💻 JAVA
字号:
import java.io.*;import java.util.*;import java.util.regex.*;public class Board {  private Allotment[] board;  private String filename; // private Hashtable<LotColors, int[]> _sets = new Hashtable<LotColors, int[3]>();  // contiene i lotti per colore // private Hashtable<LotColors, Integer> _owns = new Hashtable<LotColors, Integer>(); // un lotto appartiene allo stesso player?  private int _go, _jail, _goto;  private Board() {}  public Board(String fn) throws IOException, FileNotFoundException {    this.filename = fn;    reload();  }  public int getGo() {return _go;}  public int getJail() {return _jail;}  public String toString() {    String aux = "";    for (Allotment a : board) aux += a;    return aux;  }    public void setBoard(String cfn) {    board = new Allotment[40];    int i = 0;    Pattern p = Pattern.compile("([CRL123HTG J>])([a-zA-Z0-9 `'!]+)\\$([ycprvobg]?)");    Matcher m = p.matcher(cfn);    while (m.find()) {       //System.out.println(m.group(1).charAt(0));      switch (m.group(1).charAt(0)) {        case 'C': board[i++] = new Company(m.group(2)); break;        case 'R': board[i++] = new RailwayStation(m.group(2)); break;        case 'L': board[i++] = new Lot(m.group(2),LotColors.toColor(m.group(3).charAt(0))); break;        case '1': board[i++] = new LotWithAHouse(m.group(2),LotColors.toColor(m.group(3).charAt(0))); break;        case '2': board[i++] = new LotWithTwoHouses(m.group(2),LotColors.toColor(m.group(3).charAt(0))); break;        case '3': board[i++] = new LotWithThreeHouses(m.group(2),LotColors.toColor(m.group(3).charAt(0))); break;        case 'H': board[i++] = new LotWithAnHotel(m.group(2),LotColors.toColor(m.group(3).charAt(0))); break;        case 'T': board[i++] = new Tax(m.group(2)); break;        case 'G': _go=i; board[i++] = new Go(m.group(2)); break;        case ' ': board[i++] = new FreeLot(m.group(2)); break;        case 'J': _jail=i; board[i++] = new Jail(m.group(2)); break;        case '>': _goto=i; board[i++] = new GoToJail(m.group(2)); break;      }    }  }   public void setEstate(int[] estate, int owner) {    for(int e : estate) {      board[e-1].setOwner(owner);    }  }  public String getBoard() {return this.toString();}  public void write() throws IOException {    PrintWriter out = new PrintWriter(new FileWriter(filename, true));    out.println(this.toString());    out.close();    }  public void reload() throws IOException, FileNotFoundException {    BufferedReader in = new BufferedReader(new FileReader(filename));    String tmp_line, line = in.readLine();    tmp_line = line;    while(line != null) {      tmp_line = line;      line = in.readLine();    }    in.close();    setBoard(tmp_line);    }   public Object clone() throws CloneNotSupportedException {    Board Dolly = new Board();    try { Dolly.setBoard(""+this); } catch(Exception e) {}    return Dolly;    }  public void backup(String fn) throws IOException, CloneNotSupportedException {      Board copied = (Board)this.clone();      copied.filename = fn;      PrintWriter out = new PrintWriter(new FileWriter(fn));      out.write("");      out.close();      copied.write();  }  public Allotment getAllotment(int i) {return board[i];}  public void setAllotment(int i, Allotment a) {board[i]=a;}  public String getFilename() {return filename;}  public void setFilename(String fn) {filename = fn;}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -