zoukankan      html  css  js  c++  java
  • 我感觉我恰似一个呆逼

      TicTacToe V2.0。

      非要用1-9来输入的结果就是使用二维数组这件事的意义变得非常难找。

      留个遗体,我要改回坐标输入了。

     1 public class Game {
     2     String chessBoard;
     3     String[][] pieces = new String[3][3];
     4     
     5     /** 初始化棋盘样式和棋子数组。*/
     6     Game() {
     7         chessBoard = 
     8                 "--------------   
    " +
     9                 "| %s | %s | %s | 
    " +
    10                 "--------------   
    " +
    11                 "| %s | %s | %s | 
    " +
    12                 "--------------   
    " +
    13                 "| %s | %s | %s | 
    " +
    14                 "--------------   
    ";
    15         
    16         for (int i = 1, j = 0; j < 3; i++, j++)
    17             pieces[0][j] = String.valueOf(i);
    18         for (int i = 4, j = 0; j < 3; i++, j++)
    19             pieces[1][j] = String.valueOf(i);
    20         for (int i = 7, j = 0; j < 3; i++, j++)
    21             pieces[2][j] = String.valueOf(i);
    22     }
    23     
    24     /** 棋子数组降维。*/
    25     String[] pieceList() {
    26         String[] temp = new String[9];
    27         
    28         System.arraycopy(pieces[0], 0, temp, 0, 3);
    29         System.arraycopy(pieces[1], 0, temp, 3, 3);
    30         System.arraycopy(pieces[2], 0, temp, 6, 3);
    31         
    32         //for (int i = 0, j = 0; i < 3; i++, j += 3)
    33                 //    System.arraycopy(pieces[i], 0, temp, j, 3);
    34         
    35         return temp;
    36     }
    37     
    38     /** 列表到棋子数组的反映射。*/
    39     int[] map(int i) {
    40         int[] result = new int[2];
    41         for 
    42     }
    43     
    44     /** 打印棋盘。*/
    45     void printChessBoard() {
    46         System.out.printf(this.chessBoard, (Object[])this.pieceList());
    47     }
    48 }
    Player类也得改
  • 相关阅读:
    Linux日志不记录问题
    Centos下yum安装PHP
    centos yum update kernel
    oh-my-zsh主题
    centos 6.6 使用tomcat6部署solr5.3.1
    Nginx manifest 实现 HTML5 Application Cache
    -bash: /bin/rm: Argument list too long
    linux mysql-5.6.26 安装
    LVM 管理减少swap分区空间增加到根分区
    Linux 使用iftop命令查看服务器流量
  • 原文地址:https://www.cnblogs.com/chihane/p/3448378.html
Copyright © 2011-2022 走看看