资源简介
用Java做的骑士游历小游戏,需要的可以下载下来看看学学!
代码片段和文件信息
package gao;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
public class KnightsTour extends Japplet {
public static int access[][] = {
{23444432}
{34666643}
{46888864}
{46888864}
{46888864}
{46888864}
{34666643}
{23444432}};
public static int accessbak[][] = arrayCopy ( access ) ;
// the value indicate the No.value moving
int countMoving = -1 ;
int tourXpos [] = new int [ 64 ];
int tourYpos [] = new int [ 64 ];
private int recordXpos [][];
private int recordYpos [][];
private int recordCount = - 1 ;
private int startx ;
private int starty ;
private boolean success = false;
MyPanel myPanel ;
public void tour ( int xpos int ypos ){
// int xy;
countMoving ++ ;
//all the 64 squares has been touch return
if (countMoving == 63 )
{
tourXpos [ countMoving ] = xpos ;
tourYpos [ countMoving ] = ypos ;
// if ( ( ( Math.abs( xpos -startx ) == 1) & ( Math.abs ( ypos - starty ) ==2 ) ) |
// ( ( Math.abs( xpos -startx ) == 2) & ( Math.abs ( ypos - starty ) ==1 ) ) )
success = true ;
countMoving -- ;
return ;
}
AccessibleSquares nextSquare = new AccessibleSquares( xpos ypos );
while (nextSquare.hasMoreAccessible())
{
// do moving
nextSquare.domoving();
//record this moving
tourXpos [ countMoving ] = xpos ;
tourYpos [ countMoving ] = ypos ;
// try the next moving
nextSquare.nextAccessible();
tour ( nextSquare.getXpos() nextSquare.getYpos() );
//all the 64 squares has been touch return
if ( success )
{
countMoving -- ;
return ;
}
//this moving try is a faillure pick it up from the chess board
nextSquare.undomoving();
}// end of while
countMoving -- ;
}//end of tour method
public static int[] arrayCopy ( int array1[] )
{
int[]array2 = new int [array1.length];
for ( int row = 0 ; row < array1.length ; row ++ )
{
array2 [ row ] = array1 [ row ] ;
};
return array2;
}
public static int[][] arrayCopy ( int array1[][] )
{
int[][] array2 = new int [array1.length][array1[0].length];
for ( int row = 0 ; row < array1.length ; row ++ )
{
for ( int column = 0 ; column < array1[0].length ; column ++ )
{
array2 [ row ][ column ] = array1 [ row ][ column ];
};
};
return array2;
}
public void initialArray ( int chessBoard[][] )
{
for ( int row = 0 ; row < 8 ; row ++ )
{
for ( int column = 0 ; column < 8 ; column ++ )
{
chessBoard [ row ][ column ] = 0 ;
};
};
}
/* public static void main( String args[] ) {
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
...D.H. 0 2003-04-27 15:43 案例一
.....H. 970 2004-04-27 13:46 案例一\bknight.jpg
.....H. 749 2004-04-27 13:46 案例一\black.jpg
.....H. 4155 2004-04-27 13:46 案例一\knighttour.jpx
..A..H. 2008 2009-10-14 14:28 案例一\knighttour.jpx.local
.....H. 1886 2004-04-27 13:46 案例一\knighttour.jpx.local~
.....H. 0 2004-04-27 13:46 案例一\knighttour.jpx~
.....H. 761 2004-04-27 13:46 案例一\white.jpg
.....H. 959 2004-04-27 13:46 案例一\wknight.jpg
...D.H. 0 2003-04-27 15:43 案例一\src
...D.H. 0 2003-04-27 15:43 案例一\src\gao
.....H. 11515 2004-04-27 13:46 案例一\src\gao\KnightsTour.java
.....H. 6377 2004-04-27 13:46 案例一\src\gao\KnightsTour.java~1~
.....H. 970 2004-04-27 13:46 案例一\src\gao\bknight.jpg
.....H. 749 2004-04-27 13:46 案例一\src\gao\black.jpg
.....H. 761 2004-04-27 13:46 案例一\src\gao\white.jpg
.....H. 959 2004-04-27 13:46 案例一\src\gao\wknight.jpg
...D.H. 0 2003-04-27 15:43 案例一\classes
...D.H. 0 2003-04-27 15:43 案例一\classes\package cache
..A..H. 2992 2009-10-14 14:27 案例一\classes\package cache\gao.dep2
...D.H. 0 2003-04-27 15:43 案例一\classes\gao
..A..H. 2596 2009-10-14 14:27 案例一\classes\gao\AccessibleSquares.class
..A..H. 711 2009-10-14 14:27 案例一\classes\gao\KnightsTour$1.class
..A..H. 1049 2009-10-14 14:27 案例一\classes\gao\KnightsTour$2.class
..A..H. 4101 2009-10-14 14:27 案例一\classes\gao\KnightsTour.class
..A..H. 2593 2009-10-14 14:27 案例一\classes\gao\MyPanel.class
.....H. 970 2004-04-27 13:46 案例一\classes\gao\bknight.jpg
.....H. 749 2004-04-27 13:46 案例一\classes\gao\black.jpg
.....H. 761 2004-04-27 13:46 案例一\classes\gao\white.jpg
.....H. 959 2004-04-27 13:46 案例一\classes\gao\wknight.jpg
............此处省略18个文件信息
- 上一篇:jxl.jar
- 下一篇:java龟兔赛跑源代码
相关资源
- java龟兔赛跑源代码
- java_十进制数转换为二进制八进制十六
- 用贝叶斯分类器实现垃圾邮件分类器
- javaweb之jsp+servlet实现简单的学生管理
- java联网版五子棋源代码
- sql server 2000 java驱动包
- java 具有图形界面的最短路径问题的求
- java实现哈密顿路径,递归和非递归两
- java仿QQ() 最新版
- mysql-connector-java-5.1.37-bin jar包
- java解析Pcap文件获取五元组可执行
- Java程序设计清华大学出版社-习题参考
- 决策树算法(Java实现)
- mysql-connector-java-5.1.46.jar
- java版QQ聊天室源代码
- Java加密与解密的艺术.rar 完整源代码
- RSA与AES混合加密算法的实现java版
- Java web 大作业
- 电子文档查重系统
- Java EE互联网轻量级框架整合开发 SS
- java简单版飞鸽传书
- java 路由分组转发仿真
- TF*IDFjava实现
- java源码分水岭算法
- java实现的sift全部代码
- java实现的R树
- JAVAEE图书管理系统
- java 简单购物车
- JAVA学生教师信息录入小系统
- servlet jar包
评论
共有 条评论