dotcom.java

来自「HeadFirstCode系列图书里的源代码」· Java 代码 · 共 38 行

JAVA
38
字号
// Tiger version

import java.util.*;

public class DotCom {

   private ArrayList<String> locationCells;  
   private String name;

   public void setLocationCells(ArrayList<String> loc) {
      locationCells = loc;
   }

      public void setName(String n) {
      name = n;
  }

   public String checkYourself(String userInput) { 
      String result = "miss";
      int index = locationCells.indexOf(userInput);      
      if (index >= 0) {                              
          locationCells.remove(index);
         
         if (locationCells.isEmpty()) {
             result = "kill";
             System.out.println("Ouch! You sunk " + name + "  : ( ");
         } else {
             result = "hit";
         }  // close if                       
      } // close if            
       return result;

   } // close method
} // close class
            
     
   
   

⌨️ 快捷键说明

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