阅读背景:

[Java]-第四天-攻击战舰游戏

来源:互联网 

攻击战舰游戏示例:


--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.t



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: