Java简易撞鬼游戏demo
9*9方格内两点随机行走,相遇则停止。
public class 撞鬼 {
public static int length = 9;
public static char[][] matrix = new char[length][length];
public static int firstx = length - length;
public static int firsty = length - length;
public static int secondx = length - 1;
public static int secondy = length - 1;
public static void main(String[] args) {
final int timeInterval = 333;
for(int i=length - length;i<length;i++){
for(int j=length - length;j<length;j++){
matrix[i][j] = '○';
if((i==j&&i==(length - length))||(i==j&&i==(length-1))){
matrix[i][j] = '●';
}
}
}
Runnable runnable = new Runnable() {
public void run() {
while (true) {
try {
for(int i=length - length;i<length;i++){
for(int j=length - length;j<length;j++){
System.out.print(matrix[i][j]);
System.out.print(' ');
}
System.out.println();
}
if(firstx==secondx&&firsty==secondy){
break;
}
changePosition();
Thread.sleep(timeInterval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}
public static void changePosition(){
double randomfirst = Math.random();
double randomsecond = Math.random();
if(randomfirst<0.25){
if(firstx>length - length){
matrix[firstx--][firsty] = '○';
matrix[firstx][firsty] = '●';
}
}else if(randomfirst<0.50){
if(firstx<length - 1){
matrix[firstx++][firsty] = '○';
matrix[firstx][firsty] = '●';
}
}else if(randomfirst<0.75){
if(firsty>length - length){
matrix[firstx][firsty--] = '○';
matrix[firstx][firsty] = '●';
}
}else{
if(firsty<length - 1){
matrix[firstx][firsty++] = '○';
matrix[firstx][firsty] = '●';
}
}
if(randomsecond<0.25){
if(secondx>length - length){
matrix[secondx--][secondy] = '○';
matrix[secondx][secondy] = '●';
}
}else if(randomsecond<0.50){
if(secondx<length - 1){
matrix[secondx++][secondy] = '○';
matrix[secondx][secondy] = '●';
}
}else if(randomsecond<0.75){
if(secondy>length - length){
matrix[secondx][secondy--] = '○';
matrix[secondx][secondy] = '●';
}
}else{
if(secondy<length - 1){
matrix[secondx][secondy++] = '○';
matrix[secondx][secondy] = '●';
}
}
}
}
Java简易撞鬼游戏demo的更多相关文章
- 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)
微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...
- 微信小游戏 demo 飞机大战 代码分析 (二)(databus.js)
微信小游戏 demo 飞机大战 代码分析(二)(databus.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码分析(三)(spirit. ...
- 相当牛X的java版星际游戏
分享一款牛人用java写的经典游戏,目录结构如下: 虽然只能算一个Demo,但是用到了很多Java基础技术和算法: Java2D,双缓冲,A星寻路,粒子系统,动画效果,处理图片,Swing ui ,U ...
- 2015-2016-2 《Java程序设计》 游戏化
2015-2016-2 <Java程序设计> 游戏化 实践「<程序设计教学法--以Java程序设计为例>」中的「游戏化(Gamification)理论」,根据 2015-201 ...
- java简易编辑器
package peng_jun; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swi ...
- Ext & Java 上存图片 Demo
Ext & Java 上存图片 Demo Ext <html> <head> <script id="microloader" type=&q ...
- Java 多线程异步处理demo
java中实现多线程 1)继承Thread,重写里面的run方法 2)实现runnable接口通过源码发现:第一种方法说是继承Tread然后重写run方法,通过查看run方法的源码,发现run方法里面 ...
- Java 后端微信支付demo
Java 后端微信支付demo 一.导入微信SDK 二.在微信商户平台下载证书放在项目的resources目录下的cert文件夹下(cert文件夹需要自己建) 三.实现微信的WXPayConfig接口 ...
- 【Visual C++】游戏编程学习笔记之九:回合制游戏demo(剑侠客VS巡游天神)
本系列文章由@二货梦想家张程 所写,转载请注明出处. 作者:ZeeCoder 微博链接:http://weibo.com/zc463717263 我的邮箱:michealfloyd@126.com ...
随机推荐
- 修复PlatformToolsets丢失问题(为VS2013以上版本安装VC90,VC100编译器)
前段时间测试VS2017的IDE时不小心弄丢了 MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets 下的VC90以及VC100的编译 ...
- centos环境下输入命令不能有中文那么我怎么插入中文数据到数据库
centos环境下输入命令不能有中文那么我怎么插入中文数据到数据库 如下图: 首先查看是否安装了中文语言支持组件 yum grouplist 没有的话安装 yum install Chinese Su ...
- mutex 实现 只允许一个进程
static class Program { [STAThread] static void Main() { bool createdNew=false; Mutex mutex = new Mut ...
- linux平台使用spark-submit以cluster模式提交spark应用到standalone集群
shell脚本如下 sparkHome=/home/spark/spark-2.2.0-bin-hadoop2.7 $sparkHome/bin/spark-submit \ --class stre ...
- HDU2680 Choose the best route 2017-04-12 18:47 28人阅读 评论(0) 收藏
Choose the best route Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Othe ...
- java try catch finally return执行
public static int testBasic(){ int i = 1; try{ i++; System.out.println("try block, i = "+i ...
- tomcat启动时就频繁gc和full gc
一个小业务,流量并不大,功能也很简单,spring framework+mybatis+quartz,一启动就看到gc的频次和full gc的频次非常高: 4.202: [Full GC 4.202: ...
- Http 安全检测
httpsecurityreport.com www.ssllabs.com
- 使用Toolbar + DrawerLayou实现菜单侧滑,改变toolbar左上角图标
侧边栏具体实现可以参照http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0303/2522.html getSupportActio ...
- system.data.oracleclient 需要 8.17 需要oracle客户端问题
1.下载 2.程序引用 Oracle.DataAccess.dll 其他引用放在debug下