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

📄 board2tex.java

📁 大富翁游戏monopoli
💻 JAVA
字号:
import java.io.*;import java.util.*;import java.util.regex.*;public class Board2TeX {  private String filename;  private int x, y;  public Board2TeX(String fn) throws IOException, FileNotFoundException {    this.filename = fn;    this.x = this.y = 0;  }  public String load() throws IOException, FileNotFoundException {    BufferedReader in = new BufferedReader(new FileReader(filename+".txt"));    String tmp_line, line = in.readLine();    tmp_line = line;    while(line != null) {      tmp_line = line;      line = in.readLine();    }    in.close();    return tmp_line;    }  public String toString() {    int i=1;    String aux = "\\documentclass[10pt,xcolor=svgnames]{beamer}\n\\nofiles\n\\usepackage{tikz}\n\\usepackage[active,tightpage]{preview}\n\\PreviewEnvironment{tikzpicture}\n\\hypersetup{pdfpagemode = {None}}\n\\renewcommand{\\ttdefault}{cmtt}\n\\newcommand{\\verytiny}[1]{{\\fontfamily{ptm}\\fontsize{3pt}{5pt}\\selectfont #1}}\n\n\\begin{document}\n\\begin{frame}\n\\begin{tikzpicture}\n";      Pattern p = Pattern.compile("([CRL123HTG J>])([a-zA-Z0-9 `'!]+)\\$([ycprvobg]?)");    Matcher m;    try {       m = p.matcher(this.load());    } catch(Exception e) {e.printStackTrace(); m = null;}    while (m.find()) {       switch (m.group(1).charAt(0)) {        case 'C':        case 'R':         case 'T':         case 'G':         case ' ':         case 'J':         case '>': aux = aux +"  \\draw[black] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\verytiny{"+i+"}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\verytiny{"+m.group(2)+"}}};\n"; i++; break;        case 'L': aux = aux +"  \\draw[black, fill="+this.color(m.group(3).charAt(0))+"] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+i+"}}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+m.group(2)+"}}}};\n"; i++; break;        case '1': aux = aux +"  \\draw[black, fill="+this.color(m.group(3).charAt(0))+"] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+i+"}}}};\n  \\node at ("+(x+.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{1}}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+m.group(2)+"}}}};\n"; i++; break;        case '2': aux = aux +"  \\draw[black, fill="+this.color(m.group(3).charAt(0))+"] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+i+"}}}};\n  \\node at ("+(x+.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{2}}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+m.group(2)+"}}}};\n"; i++; break;        case '3': aux = aux +"  \\draw[black, fill="+this.color(m.group(3).charAt(0))+"] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+i+"}}}};\n  \\node at ("+(x+.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{3}}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+m.group(2)+"}}}};\n"; i++; break;        case 'H': aux = aux +"  \\draw[black, fill="+this.color(m.group(3).charAt(0))+"] ("+x+"cm,"+y+"cm) rectangle +(1cm,-1cm) node ("+i+"){};\n  \\node at ("+(x+1-.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+i+"}}}};\n  \\node at ("+(x+.07)+"cm,"+(y-.07)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{H}}}};\n  \\node at ("+(x+.5)+"cm,"+(y-.5)+"cm) {\\textbf{\\textcolor{white}{\\verytiny{"+m.group(2)+"}}}};\n"; i++; break;      }      if (y == 0) {         if (x < 10) x++;         else y--;      } else      if (x == 10) {        if (y>-10) y--;        else x--;      } else      if (y == -10) {         if (x > 0) x--;         else y++;      } else y++;    }    try {      BufferedReader in;      String line;      int n, z;      for(int j : new int[]{1, 2, 3, 5}) {              //System.out.println("### j: "+j);        in = new BufferedReader(new FileReader(filename+j+".txt"));        line = in.readLine(); // contiene i lanci dei dadi mn1...nm        line = in.readLine(); // contiene le propriet脿 m n1 n2 ..nm              //System.out.println("### line: "+line);        StringTokenizer st = new StringTokenizer(line," ");        n = new Integer(st.nextToken()).intValue();              //System.out.println("### n: "+n);        for (int k = 1; k<=n; k++) {           z = new Integer(st.nextToken()).intValue();              //System.out.println("### k: "+k+" z: "+z);           aux = aux + "  \\node[above=1.5pt,left=-3pt] at ("+z+") {\\textbf{\\textcolor{black}{\\verytiny{"+j+"}}}};\n";        }         in.close();      }    } catch(Exception e) {e.printStackTrace();}    aux = aux + "  \\end{tikzpicture}\n\\end{frame}\n\\end{document}";    return aux;  }   private String color(char c) {     switch (c) {       case 'c': return "DodgerBlue";       case 'y': return "Gold";       case 'p': return "Violet";       case 'r': return "Red!80!black";       case 'v': return "Purple";       case 'o': return "Orange";       case 'b': return "Sienna";       case 'g': return "Green";       default: return "";     }  }  public static void main(String[] argv)  throws IOException, FileNotFoundException {    Board2TeX b = new Board2TeX(argv[0]);    System.out.println(b);  }}

⌨️ 快捷键说明

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