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 ...
随机推荐
- dojo和jquery混合使用
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/dojo/1.7 ...
- (最小生成树)Eddy's picture -- hdu -- 1162
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1162 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- WebDriver高级应用——操作Web页面的滚动条
目的: (1)滑动页面的滚动条到页面最下方 (2)滑动页面的滚动条到页面某个元素 (3)滑动页面的滚动条向下移动某个数量的像素 测试的网址: http://www.seleniumhq.org/ 代码 ...
- C# skip 重试执行代码段
var retryTimes = 5; //重试次数 int times = 0; skip: //代码段开始 //处理逻辑 var result=false ; // ...
- SQL Server数据库的基础脚本编程
数据库脚本的基础编程 Go批量处理语句 用于同时处理多条语句 use指定数据库或表 use master --创建数据库 go use Student --创建表(Student)表示数据库 go 创 ...
- WPF显示Gif动画
WPF的Image控件不能很好的支持.gif文件.解决办法有如下2种. 1使用MediaElement <MediaElement Source="file://D:\anim.gif ...
- .Net生成导出Excel
概述 在做.Net web开发的过程中经常需要将查出的数据导成Excel表返给用户,方便用户对数据的处理和汇总.这里我将导出Excel表格的代码做一个总结,这也是我项目中经常用到的,代码简单易懂,使用 ...
- golang plugin的依赖问题
golang plugin的依赖问题 此文中涉及的plugin运行环境为mac 10.14,go版本为1.11 主要是想讨论一下插件依赖的第三方库的问题. 例子是在https://github.com ...
- CentOS6.3上部署Ceph
一.背景知识 搭建ceph的机器分为两种:client和非client(mds.monitor.osd). 配置时client只需要在内核编译时选上ceph就行,而其它三种则还需要编译ceph用户态源 ...
- 黄包车比赛 python学习
将性别进行编码: https://github.com/Bifzivkar/Boutique-Travel-Services-Predict/blob/master/feature/2_feature ...