自己还是小码畜 仍然有很多很多不懂得地方 所以这个博客只能说是作为一个个人笔记本的形式存在吧 刚好最近在实训Android 就记录一点自己认为有用的小知识吧 如果有幸能够帮助到别人 那是再好不过了 废话不多说吧 小码畜今天要记录的是一个简易版的猜数字游戏
初始(开始)界面
游戏进入界面 时限为30秒 时间到了自动返回退出
好了 上代码吧
工具类:
package Utils; /** * Created by 4820 on 2017/6/6. */ public class AppConstants { private AppConstants(){} //标识返回方 public static final int RESULT_CODE_GAME_WIN = 11; public static final int RESULT_CODE_GAME_FAIL = 12; public static final String EXTRA_KEY_LEVEL="level"; }
实体类:
package Bussiness; import java.util.Random; /** * Created by 4820 on 2017/6/6. */ public class Game { public static final int LEVEL_NOEMAL = 50; public static final int LEVEL_HARD = 100; private int RandomNumber; private Random random; private String Tittle; private static final int REQUEST_CODE_MENU = 10; public String getTittle() { return Tittle; } public Game(int pLevel) { random = new Random(); RandomNumber = random.nextInt(pLevel); Tittle = "请输入0—" + pLevel + "的数字"; } public String guessNumber(int pInputNumber) { if (pInputNumber > RandomNumber) { return "Your number should be smaller!"; } if (pInputNumber < RandomNumber) { return "Your number should be bigger!"; } else { return "You got it!Congratulation!"; } } }
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android