final 攻击网站的游戏
来源:互联网 发布:农村淘宝运营方案模板 编辑:程序博客网 时间:2024/06/06 00:42
import java.util.*;public class DotComBust{private GameHelper helper=new GameHelper();private ArrayList<DotCom> dotComList=new ArrayList<DotCom>();private int numOfGuesses=0;private void setUpGame(){DotCom one=new DotCom();one.setName("Pets.com");DotCom two=new DotCom();two.setName("eToys.com");DotCom three=new DotCom();three.setName("Go2.com");dotComList.add(one);dotComList.add(two);dotComList.add(three);System.out.println("Your goal is to sink three dot coms.");System.out.println("Pets.com,eToys.com,Go2.com");System.out.println("Try to sink them all in the fewest number of guesses.");for(DotCom dotComToSet:dotComList){ArrayList<String> newLocation=helper.placeDotCom(3);dotComToSet.setLocationCells(newLocation);}}private void startPlaying(){while(!dotComList.isEmpty()){String userGuess=helper.getUserInput("Enter a guess");checkUserGuess(userGuess);}finshGame();}private void checkUserGuess(String userGuess){numOfGuesses++;String result="miss";for(DotCom dotComToTest:dotComList){dotComToTest.checkYourself(userGuess);if(result.equals("hit"))break;if(result.equals("kill")){dotComList.remove(dotComToTest);break;}}System.out.println(result);}private void finshGame(){System.out.println("All Dot Coms are dead!Your stock is now worthless.");if(numOfGuesses<=18){System.out.println("It only took you "+numOfGuesses+" guesses.");System.out.println("You got out before your options sank.");}else{System.out.println("Took you long enough. "+numOfGuesses+" guesses.");System.out.println("Fish are dancing with your options");} }public static void main(String [] args){DotComBust game=new DotComBust();game.setUpGame();game.startPlaying();}}
import java.util.*;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";System.out.println("Ouch!You sunk "+name+" :(");}elseresult="hit";}return result;}}
import java.io.*;import java.util.*;public class GameHelper{private static final String alphabet="abcdefg";private int gridLength=7;private int gridSize=49;private int [] grid=new int[gridSize];private int comCount=0;public String getUserInput(String prompt){String inputLine=null;System.out.print(prompt+" ");try{BufferedReader is=new BufferedReader(new InputStreamReader(System.in));inputLine=is.readLine();if(inputLine.length()==0){return null;}}catch(IOException e){System.out.println("IOException: "+e);}return inputLine.toLowerCase();}public ArrayList<String> placeDotCom(int comSize){ArrayList<String> alphaCells=new ArrayList<String>();String [] alphacoords=new String [comSize];//保存字符串String temp=null;//临时字符串int [] coords=new int[comSize];//现有字符串int attemps=0;//目前测试的字符串boolean success=false;//找到合适的位置吗?int location=0;//目前起始位置comCount++;//现在处理第几个comint incr=1;//水平增量if((comCount%2)==1){incr=gridLength;//垂直增量}while(!success&attemps++<200)//主要搜索循环{location=(int)(Math.random()*gridSize);//随机起点int x=0;//第n个位置success=true;while(success&&x<comSize)if(grid[location]==0){coords[x++]=location;location+=incr;if(location>=gridSize)success=false;if(x>0&&(location%gridLength==0))success=false;}elsesuccess=false;}int x=0;int row=0;int column=0;while(x<comSize){grid[coords[x]]=1;row=(int)(coords[x]/gridLength);column=coords[x]%gridLength;temp=String.valueOf(alphabet.charAt(column));alphaCells.add(temp.concat(Integer.toString(row)));x++;}return alphaCells;}}
0 0
- final 攻击网站的游戏
- 攻击网站的游戏(simple连续的三个数字)
- 攻击网站的游戏(连续的三个数字)含有ArrayList的升级版
- 互联网 网站常见的攻击
- 常见的网站攻击方式
- 常见的网站攻击方式
- 网站攻击类型跨站攻击的解决方案
- 【网站安全】简单的Js脚本攻击sql注入攻击
- 网页游戏的攻击与防御
- 网页游戏的攻击与防御
- MMO游戏技能攻击区域的计算
- 游戏开发的网站
- 关于网站的SYN_RECV攻击的防范措施
- PHP的网站常见的攻击方式
- LoadRunner对小网站的攻击
- 社交网站被目标攻击的人为因素
- 网站防止CC攻击的方法
- 网站防范XXS攻击的关键思考
- SVM 的推导、特点、优缺点、多分类问题及应用
- 如何在QML中使用camera API来拍照
- 多表查询2(8)
- 使用VS2012创建ActiveX控件
- 博文
- final 攻击网站的游戏
- android FileObserver的用法与避坑指南
- Android layout 盲点
- 设计模式——单例模式
- GIT基本使用命令整理
- oracle事务管理(9)
- Atom飞行手册翻译: 2.2 在Atom中移动
- Django 学习 4 表单处理
- 报错,但不影响运行ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2