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的更多相关文章

  1. 微信小游戏 demo 飞机大战 代码分析 (三)(spirit.js, animation.js)

    微信小游戏 demo 飞机大战 代码分析(三)(spirit.js, animation.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码 ...

  2. 微信小游戏 demo 飞机大战 代码分析 (二)(databus.js)

    微信小游戏 demo 飞机大战 代码分析(二)(databus.js) 微信小游戏 demo 飞机大战 代码分析(一)(main.js) 微信小游戏 demo 飞机大战 代码分析(三)(spirit. ...

  3. 相当牛X的java版星际游戏

    分享一款牛人用java写的经典游戏,目录结构如下: 虽然只能算一个Demo,但是用到了很多Java基础技术和算法: Java2D,双缓冲,A星寻路,粒子系统,动画效果,处理图片,Swing ui ,U ...

  4. 2015-2016-2 《Java程序设计》 游戏化

    2015-2016-2 <Java程序设计> 游戏化 实践「<程序设计教学法--以Java程序设计为例>」中的「游戏化(Gamification)理论」,根据 2015-201 ...

  5. java简易编辑器

    package peng_jun; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swi ...

  6. Ext & Java 上存图片 Demo

    Ext & Java 上存图片 Demo Ext <html> <head> <script id="microloader" type=&q ...

  7. Java 多线程异步处理demo

    java中实现多线程 1)继承Thread,重写里面的run方法 2)实现runnable接口通过源码发现:第一种方法说是继承Tread然后重写run方法,通过查看run方法的源码,发现run方法里面 ...

  8. Java 后端微信支付demo

    Java 后端微信支付demo 一.导入微信SDK 二.在微信商户平台下载证书放在项目的resources目录下的cert文件夹下(cert文件夹需要自己建) 三.实现微信的WXPayConfig接口 ...

  9. 【Visual C++】游戏编程学习笔记之九:回合制游戏demo(剑侠客VS巡游天神)

    本系列文章由@二货梦想家张程 所写,转载请注明出处. 作者:ZeeCoder  微博链接:http://weibo.com/zc463717263 我的邮箱:michealfloyd@126.com ...

随机推荐

  1. setPadding 与 setBackgroundDrawable

    这两个不能同时用,如果同时用,setPadding 将不会起作用,用的是 drawable里面自带的padding

  2. css控制同一个页面的两个表格,一个显示有边框线,而另一个没边框线

    不显示边框的:<table border="0" cellspacing="0"  cellpadding="" ><tr ...

  3. JQuery和JS操作LocalStorage/SessionStorage的方法(转)

    出处:http://blog.csdn.net/djzhao627/article/details/50747628 首先说一下LocalStorage和SessionStorage LocalSto ...

  4. BurpSuite安装和配置

    Burp Suite是什么 Burp Suite 是用于攻击web 应用程序的集成平台.它包含了许多Burp工具,这些不同的burp工具通过协同工作,有效的分享信息,支持以某种工具中的信息为基础供另一 ...

  5. Windows sql语句正则匹配导出数据到本地 The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

    尝试使用 into outfile导出数据的时候出现错误: The MySQL server is running with the --secure-file-priv option so it c ...

  6. 如何用Word发布WordPress博客

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  7. linux每天一小步---mkdir命令详解

    1 命令功能 mkdir命令用于创建单个目录或者多级目录,但前提在于用户对于当前目录有写权限. 2 命令语法 mkdir  [选项]  [目录名] 3 命令参数 -m 在创建目录的同时设定目录权限(而 ...

  8. javascript与java的相互调用,纯java的javascript引擎rhino(转载)

    1.下载Rhino安装包,下载地址:官网http://www.mozilla.org/rhino. 2.rhino环境配置,把解压出来的js.jar文件加入到系统的环境变量classpath 3.在命 ...

  9. Linux Context , Interrupts 和 Context Switching 说明

    一. 进程Context 定义 当一个进程在执行时, CPU的所有寄存器中的值.进程的状态以及堆栈中的内容,比如各个变量和数据,包括所有的寄存器变量.进程打开的文件.内存信息等.这些信息被称为该进程的 ...

  10. 传智播客.NET视频学习课件

    传智播客.NET视频学习课件访问.NET网站了解更多课程详情http://net.itcast.cn(小提示:为什么本书中超链接打不开?)此套课件是伴随 传智播客.net实况教学视频 (小提示:为什么 ...