当前位置: 首页>>代码示例>>Java>>正文


Java String.split方法代码示例

本文整理汇总了Java中java.lang.String.split方法的典型用法代码示例。如果您正苦于以下问题:Java String.split方法的具体用法?Java String.split怎么用?Java String.split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.String的用法示例。


在下文中一共展示了String.split方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readBoard

import java.lang.String; //导入方法依赖的package包/类
public void readBoard(String in,boolean update){   
    moveSequence = "";
    redTurn = true;
    blueTurn = false;
    try{
        String[] parts;
        boolean newMode = false;
        char[] id = in.toCharArray();
        if(id[0]=='B'){
            int indexOfFirstComma = in.indexOf(",");
            int indexOfFirstSlash = in.indexOf("/");
            birth.clear();
            survive.clear();
            for(int i=1;i<indexOfFirstSlash;i++){
                birth.add(Character.getNumericValue(id[i]));
            }
            for(int i=indexOfFirstSlash+2;i<indexOfFirstComma;i++){
                survive.add(Character.getNumericValue(id[i]));
            }
            parts = in.substring(indexOfFirstComma+1).split(",");
        }else{
            parts = in.split(",");
        }
        if (parts.length < 5) {
            throw new IOException();
        }
 
        WIDTH = HEIGHT = Math.min(Math.max(Integer.parseInt(parts[0]),3),20);
        timeLimit[0]=0;
        timeLimit[1] = Integer.parseInt(parts[1]);
        timeLimit[2]=0;
        timeLimit[3]=0;
        timeBonus = Integer.parseInt(parts[2]);
        int humanNum = Integer.parseInt(parts[3]);
        stringToBoard(parts[4],update);
        /*redDepth = (int)(((humanNum/4)-1)*2);
        blueDepth = (((humanNum%4)-1)*2);
        if(redDepth<0){
            redBot = false;
        }else{
            redBot = true;
        }
        if(blueDepth<0){
            blueBot = false;
        }else{
            redBot = true;
        }*/
        int noSwapsUntil = -1;
        String[] moves = new String[parts.length-5];
        for(int i = 0; i<moves.length; i++){
            moves[i]=parts[i+5];
        } 
        int moveLimit = Integer.MAX_VALUE;
        if(screen==4){
            moveArray = moves;        
            totalMoves = moveArray.length;
            moveNumber = 0;
            saveTiles();
        }else{
            saveTiles();
            for (int t = 0; t < moves.length; t++) { // Go through all the moves.
                makeMove(moves[t]);
            } 
        }
        updateNumbers();
        updateLists();            
        boardStart = getBoard();
    }catch (Exception e) {
        JFrame frame = new JFrame("Error");
        JOptionPane.showMessageDialog(frame, "Illegal game string", "Error", 0);
    }       
}
 
开发者ID:hanss314,项目名称:GOLAD,代码行数:73,代码来源:MyWorld.java

示例2: makeMove

import java.lang.String; //导入方法依赖的package包/类
public void makeMove(String s){
    String[] moveParts = s.split("\\+");
    if (moveParts.length == 3) {
        redTimer.set(Integer.parseInt(moveParts[1])*(long)(0.01f));
        blueTimer.set(Integer.parseInt(moveParts[2])*(long)(0.01f));
    }else{
        redTimer.set(0);
        blueTimer.set(0);
    }
    int moveType = charTable.indexOf(moveParts[0].charAt(moveParts[0].length()-1))-12;
    if (moveType <= 3) {
        
        int x = charTable.indexOf(moveParts[0].charAt(0))-12;
        int y = charTable.indexOf(moveParts[0].charAt(1))-12;
        if(moveType==1){
            if(redTurn){
                allTiles[x][HEIGHT-y-1].setState(1);
            }else if(blueTurn){
                allTiles[x][HEIGHT-y-1].setState(2);
            }
        }else{
            int swapWith = 0;
            allTiles[x][HEIGHT-y-1].setState(0);
        }
        allTiles[x][HEIGHT-y-1].preupdate(allTiles);
        allTiles[x][HEIGHT-y-1].updateNeighbours(allTiles);
    }else if (moveType == 4){
        //moveNumber = 0;
        //totalMoves = 0;
        doTurn();
    }else{
        int endGameCause = moveType-5;
        endGameCause = 2+3*(moveType-5);
        return;
    }
}
 
开发者ID:hanss314,项目名称:GOLAD,代码行数:37,代码来源:MyWorld.java


注:本文中的java.lang.String.split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。