首页 > 代码库 > 简单版攻击网站设计!
简单版攻击网站设计!
1 import java.io.*; 2 3 public class GameHelper { 4 public String getUserInput(String prompt){ 5 String inputLine = null; 6 System.out.println(prompt + " "); 7 try { 8 BufferedReader is = new BufferedReader(new InputStreamReader(System.in)); 9 inputLine = is.readLine();10 if(inputLine.length() == 0) return null;11 } catch (IOException e) {12 // TODO Auto-generated catch block13 System.out.println("IoException: "+e);14 }15 return inputLine;16 }17 18 }
1 public class SimpleDotCom { 2 int[] locationCells; 3 int numOfHits = 0; 4 5 public void setLocationCells(int[] locs) { 6 locationCells = locs; 7 } 8 9 public String checkYourself(String stringGuess){10 int guess = Integer.parseInt(stringGuess);11 String result = "miss";12 for (int cell : locationCells){13 if (guess == cell){14 result = "hit";15 numOfHits++;16 break;17 }18 }19 if(numOfHits == locationCells.length){20 result = "kill";21 }22 System.out.println(result);23 return result;24 25 }26 27 }
1 public class SimpleDotComGame { 2 3 public static void main(String[] args) { 4 int numOfGuesses = 0; 5 GameHelper helper = new GameHelper(); 6 7 SimpleDotCom theDotCom = new SimpleDotCom(); 8 int randomNum = (int)(Math.random() * 5); 9 10 int[] location = {randomNum,randomNum+1,randomNum+2};11 theDotCom.setLocationCells(location);12 boolean isAlive = true;13 14 while(isAlive == true) {15 String guess = helper.getUserInput("enter a number");16 String result = theDotCom.checkYourself(guess);17 numOfGuesses++;18 if(result.equals("kill")) {19 isAlive = false;20 System.out.println("You took"+numOfGuesses+"guesses");21 }22 }23 24 }25 26 }
简单版攻击网站设计!
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。