标签:
游戏介绍,我们把网站命名为DotCom,将它放在一个横列中的3个格子里,玩家输入位置来猜测网站被存放的位置,猜中为hit,如果三个格子都猜中为kill,没有猜中为miss。
在简简版中我们把这些都固定。
1 public class SimpleDotCom { 2 int[] locationCells; 3 int numOfHits = 0; 4 5 public void setLocationCells(int[] locs){ 6 int guess = Integer.parseInt(StringGuess); 7 String result = "miss"; 8 for (int cell : locationCells) { 9 if (guess == cell) { 10 result = "hit"; 11 numOfHits++; 12 break; 13 } 14 } 15 if(numOfHits ==locationCells.length){ 16 result = "kill"; 17 } 18 System.out.println(result); 19 return result; 20 } 21 }
public class SimpleDotComTestDrive{ public static void main (String [] args){ SimpleDocCom dot = new SimpleDotCom(); int[] locations = {2,3,4}; dot.setLocationCells(locations); String uerGuess = "2"; String result = dot.checkYourself(userGuess); } }
标签:
原文地址:http://www.cnblogs.com/xwzp/p/5900401.html