改进了一下这个游戏的输出及思路,是不是好玩多了??:)
终于看了两天才摸 熟悉,还是有点笨啊。。。
GameHelper.java
import java.io.*; import java.util.*;public class GameHelper {int comCount = 0;public String getUserInput(String prompt) {String inputLine = null;System.out.println(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) {final String alphabet = "abcdefg";int gridLength = 7;int gridSize = 49;int [] grid = new int[gridSize]; ArrayList<String> alphaCells = new ArrayList<String>();String temp = null;int [] coords = new int[comSize];int attempts = 0;boolean success = false;int location = 0;int incr;if (((int) (Math.random() * 2) % 2) == 1) {incr = gridLength;} else {incr = 1;}//System.out.println("incr is: " + incr);while ( !success & attempts++ < 200) {location = (int) (Math.random() * gridSize);//System.out.println("location: " +location);int x = 0;success = true;while (success && x < comSize) {if (grid[location] == 0) {coords[x++] = location;location += incr;//System.out.println("location: " +location);if (location >= gridSize) {success = false;}if (x > 0 && (location % gridLength == 0)) {success = false;}} else {success = false;}//System.out.println("sucess status is :" + success);//System.out.println("x value is :" + x); }}//System.out.print("coords array is :");//for (int item : coords) {// System.out.print(item + " ");//}//System.out.println("");int x = 0;int row = 0;int column = 0;while (x < comSize) {grid[coords[x]] = 1;row = (int) (coords[x] / gridLength);//System.out.println("row value is :" + row);column = (int) (coords[x] % gridLength);temp = String.valueOf(alphabet.charAt(column));//System.out.println("temp value is :" + temp); alphaCells.add(temp.concat(Integer.toString(row)));x++;}//for (String item : alphaCells) {// System.out.print(item + " ");//}return alphaCells;}}
DotCom.java
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 getName() {return name;}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 + " :(");} else {result = "hit";}}return result;}}
DotComBurst.java
import java.util.*;public class DotComBust {private GameHelper helper = new GameHelper();private ArrayList<DotCom> dotComsList = 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");dotComsList.add(one);dotComsList.add(two);dotComsList.add(three);System.out.println("Your goal is to sink three doc coms.");System.out.println("Pets.com, eToys.com, Go2.com");System.out.println("Try to sink them all in the fewsest number of guesses.");for(DotCom dotComToSet : dotComsList) {ArrayList<String> newLocation = helper.placeDotCom(3);dotComToSet.setLocationCells(newLocation);for (String item : newLocation) {System.out.print( item +" ");}System.out.println(dotComToSet.getName());System.out.println();}}private void startPlaying() {while (!dotComsList.isEmpty()) {String userGuess = helper.getUserInput("Enter a guess");checkUserGuess(userGuess);}finishGame();}private void checkUserGuess(String userGuess) {numOfGuesses++;String result = "miss";for (DotCom dotComToTest : dotComsList) {result = dotComToTest.checkYourself(userGuess);if (result.equals("hit")) {break;}if (result.equals("kill")) {dotComsList.remove(dotComToTest);break;}}System.out.println(result);}private void finishGame(){System.out.println("All Dot Coms are dead! Your stock is now worthless.");if (numOfGuesses < 18) {System.out.println("It's 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 you options..");}}public static void main (String[] args) {DotComBust game = new DotComBust();game.setUpGame();game.startPlaying();System.out.println("Finish");}}
改进了一下这个游戏的输出及思路,是不是好玩多了??:)相关推荐
- 课时4:改进我们的小游戏
目录: 一.改进我们的小游戏 二.条件分支 三.while循环 四.引入外援 五.课时04课后习题及答案 ************************** 一.改进我们的小游戏 ********* ...
- 以LOL为起点,谈谈游戏数值设计核心思路
文档在今年三月份我动笔写了一小部分,但当时思路凌乱,行文梗阻,于是丢在一边构思了半年,现在又回过头来慢慢写,希望能写好写完吧,初衷是希望即时萌新也能看懂,但是好像并不能行--本来几个数据就能弄好的东西 ...
- 游戏数值——LOL篇 以LOL为起点-说游戏数值设计核心思路
附 文 文档在今年三月份我动笔写了一小部分,但当时思路凌乱,行文梗阻,于是丢在一边构思了半年,现在又回过头来慢慢写,希望能写好写完吧,初衷是希望即时萌新也能看懂,但是好像并不能行--本来几 ...
- 【Cheat Engine自带小游戏step1的通关思路】
Cheat Engine自带小游戏step1的通关思路 Step1小游戏 多试几次可以发现如下规律:前4次开火敌人会掉血,第5次开火瞬间,敌人就处于恢复状态,无论开火快慢,敌人永远不会死亡. 通关的几 ...
- python tkinter火柴人_用Python实现童年小游戏俄罗斯方块!别说还挺好玩!
原标题:用Python实现童年小游戏俄罗斯方块!别说还挺好玩! 前言 大三上学期的程序设计实训大作业,挑了其中一个我认为最简单的的<图书管理系统>来写.用python写是因为py有自带的G ...
- 安卓手机游戏的识别码设计思路
通常安卓手机用作识别码的有IMEI.MAC.Android ID.但是这几个值在虚拟器上面都是可以改的,有些虚拟器的IMEI值就是空或者都是一样的,特别是到了后面的安卓版本,玩家是可以不允许APP获邓 ...
- Java游戏任务背包系统设计思路
Java游戏任务背包系统设计思路 前言 1.任务系统 1.1 任务的分类 1.2 任务数据的定义 2.道具系统 2.2 道具的数据定义 前言 在游戏开发中,游戏任务系统是必不可少的,因为任务系统是游戏 ...
- 改进Python文字小游戏(4)
前面,我们讲了变量和字符串的一些种类.朋友们,还记得我们之前的那个智障的文字小游戏吗?今天,我们要做的第一件事就是来改进我们的文字小游戏,至于第二件事嘛,先让我卖个关子,众位客官,注意咯! 1)首先, ...
- python实现文字游戏_改进Python文字小游戏(4)
前面,我们讲了变量和字符串的一些种类.朋友们,还记得我们之前的那个智障的文字小游戏吗?今天,我们要做的第一件事就是来改进我们的文字小游戏,至于第二件事嘛,先让我卖个关子,众位客官,注意咯! 1)首先, ...
最新文章
- 熟悉常用的Linux操作
- jsp 验证码以及验证码局部刷新
- Android提醒:Dialog,Toast,Snackbar
- 伯克利电子和计算机工程申请入口
- python基础之语句_P009 python基础之控制语句01
- tr闭包_嵌套函数及闭包
- python中的变量的作用_Python中的变量作用域
- 面对 996,程序员如何利用“碎片时间”涨薪?
- SLS机器学习介绍(05):时间序列预测
- 一个简简单单检测http服务状态的脚本
- #牛客网 2018年牛客多校算法寒假训练营练习比赛(第五场)
- 用java实现飞机大战_java飞机大战实现了什么技术
- pdf factory pro7序列号教你如何打印转换PDF教程
- 怎样在计算机桌面上安装驱动器,驱动安装好了却不知该怎么查看 如何找到驱动安装的位置 - 驱动管家...
- JavaScript基础知识-JS数据类型
- 2.6一个小工具的使用snipaste
- linux 多块网卡 bridge,理解linux虚拟网络设备bridge
- ## Myql的常见命令及语法规范
- 编译程序与解释程序区别
- 工作了这么长时间,是不是非用macbook pro不可呢?