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. 基于Web Service的客户端框架搭建二:数据转换层(FCL)

    引言 要使用WebService来分离客户端与服务端,必定要使用约定好两者之间的数据契约.Json数据以其完全独立于语言的优势,成为开发者的首选.C# JavaScriptSerializer为Jso ...

  2. SpringBoot里的一些注解

    Spring不仅可以通过xml配置获取*.properties,还可以通过@Value注解的方式来获取,将properties配置文件中的属性值注入到java成员变量. 如果不想每次都写private ...

  3. Windows 访问 Oracle

    开发环境 vs2010 安装ODTwithODAC1120320_32bit.zip Win2003 64 位 1.不使用EF需要安装ODAC112021Xcopy_x64.zip开发环境中的Orac ...

  4. 同时安装2个版本的python

    使用pip 当Python2和Python3同时存在于windows上时,它们对应的pip都叫pip.exe,所以不能够直接使用 pip install 命令来安装软件包.而是要使用启动器py.exe ...

  5. vc 使窗口置顶 在最前面

    bool SetWindowTop(CWnd* pWnd){ if(!pWnd) {   return false; } if(pWnd->GetExStyle()&WS_EX_TOPM ...

  6. SqlLocalDB 的一些常用命令行

    Once installed, you can interact with SqlLocalDb using the command line. The following will tell you ...

  7. 如何查看非自己提交的请求的结果 - 深入浅出Oracle EBS之杂项技术荟萃

    如何查看非自己提交的请求的结果定位要找的请求SQL举例:SELECT req.request_id,       fcp.user_concurrent_program_name,       usr ...

  8. Asp.NetCore MVC Web 应用

    Asp.NetCore MVC 与 普通的MVC 基本一致, 只是代码结构稍有改动 一.创建项目 1. 2. 3. 项目结构 二. 构建数据模型 1. Startup类中配置EF Core MySql ...

  9. TortoiseSVN本地版本控制管理

    TortoiseSVN 是 Subversion 版本控制系统的一个免费开源客户端.下载地址:https://tortoisesvn.net/downloads.html. 安装好TortoiseSV ...

  10. Win 8下Rime输入法无法同步的临时解决方法

    意外发现了Rime输入法(OS X上叫鼠须管'Squirrel',windows上叫小狼毫'Weasel',linux上叫中州韵'ibus-rime',连名字都起的这么牛逼),真是神器啊,流畅的速度, ...