码迷,mamicode.com
首页 > Web开发 > 详细

简单版攻击网站设计!

时间:2016-09-24 20:28:04      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

 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 block
13             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 }

 

简单版攻击网站设计!

标签:

原文地址:http://www.cnblogs.com/xwzp/p/5903930.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!