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 ...
随机推荐
- POJ 2396 Budget (有源汇有上下界最大流)
题意:给定一个矩阵的每行的和和每列的和,以及每个格子的限制,让你求出原矩阵. 析:把行看成X,列看成Y,其实就是二分图,然后每个X到每个Y边一条边,然后加一个超级源点和汇点分别向X和Y连边,这样就形成 ...
- UVa 1025 A Spy in the Metro (DP动态规划)
题意:一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你在时间T内时到达n,并且等车时间最短, 也就是尽量多坐车,最后输出最少等待时间. 析:这个挺复杂,首先时间是 ...
- thinkphp5 swoole 执行异步任务
目录结构: 服务器端: <?php /* *author:hdj */ namespace app\Console; use think\console\Command; use think\c ...
- linux下mysql安装和调优
1.yum yum -y install mysql-server mysql 2.RPM安装 http://dev.mysql.com/downloads/ 下载RPM包,请确认服务器版本,我的是红 ...
- swift学习之-- UIAlertVIewController - uiactionsheet
// // ViewController.swift // actionsheet // // Created by su on 15/12/7. // Copyright © 2015年 t ...
- PowerDesigner工具建表步骤
以商场VIP系统中的表为例 先建立管理员用户表 1.双击打开PowerDesigner工具,点File 选择 New Model 打开如下图,选择标红部分,点击OK 2点击选择标红部位Entity ...
- Linux 基础教程 27-ss和ip命令
什么是netstat 在Linux系统中输入 man netstat,显示的结果如下所示: netstat - Print network connections, routing table ...
- 【node错误】/usr/bin/env: node: No such file or directory
背景 安装了node后,执行npm run xxx的命令的时候,报错,提示如下: /usr/bin/env: node: No such file or directory 步骤 1. 什么玩意,执行 ...
- jenkins修改时区
查看jenkins目前的时区 访问http://your-jenkins/systemInfo,查看user.timezone变量的值 默认是纽约时间 修改时区 查https://wiki.jenki ...
- asp.net mvc 上传图片 摘自mvc 高级编程第311页
Image Uploads I am going to complete the SportsStore user experience with something a little more so ...