攻击战舰游戏示例:
--DotCom.java
package com.test.java;
import java.util.ArrayList;
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";
} else {
result = "hit";
}
}
return result;
}
}
package com.test.java;
import java.io.*;
import java.util.*;
public class GameHelper {
private static final String alphabet = "abcdefg";
private int gridLength = 7;
private int gridSize = 49;

最低0.47元/天 解锁文章
753

被折叠的 条评论
为什么被折叠?



