「java项目迷宫」java迷宫游戏的设计报告

博主:adminadmin 2023-03-18 09:35:09 468

本篇文章给大家谈谈java项目迷宫,以及java迷宫游戏的设计报告对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java怎么生成迷宫地图

//作者:zhongZw   

package cn.zhongZw.model;

import java.util.ArrayList;

import java.util.Random;

public class MazeModel {

private int width = 0;

private int height = 0;

private Random rnd = new Random();

public MazeModel() {

this.width = 50; //迷宫宽度

this.height = 50; //迷宫高度

}

public int getWidth() {

return width;

}

public void setWidth(int width) {

this.width = width;

}

public int getHeight() {

return height;

}

public void setHeight(int height) {

this.height = height;

}

public MazeModel(int width, int height) {

super();

this.width = width;

this.height = height;

}

public ArrayList  MazePoint  getMaze() {

ArrayList  MazePoint  maze = new ArrayList  MazePoint  ();

for (int h = 0; h  height; h++) {

for (int w = 0; w  width; w++) {

MazePoint point = new MazePoint(w, h);

maze.add(point);

}

}

return CreateMaze(maze);

}

private ArrayList  MazePoint  CreateMaze(ArrayList  MazePoint  maze) {

int top = 0;

int x = 0;

int y = 0;

ArrayList  MazePoint  team = new ArrayList  MazePoint  ();

team.add(maze.get(x + y * width));

while (top = 0) {

int[] val = new int[] {

-1, -1, -1, -1

};

int times = 0;

boolean flag = false;

MazePoint pt = (MazePoint) team.get(top);

x = pt.getX();

y = pt.getY();

pt.visted = true;

ro1: while (times  4) {

int dir = rnd.nextInt(4);

if (val[dir] == dir)

continue;

else

val[dir] = dir;

switch (dir) {

case 0: // 左边

if ((x - 1) = 0  maze.get(x - 1 + y * width).visted == false) {

maze.get(x + y * width).setLeft();

maze.get(x - 1 + y * width).setRight();

team.add(maze.get(x - 1 + y * width));

top++;

flag = true;

break ro1;

}

break;

case 1: // 右边

if ((x + 1)  width  maze.get(x + 1 + y * width).visted == false) {

maze.get(x + y * width).setRight();

maze.get(x + 1 + y * width).setLeft();

team.add(maze.get(x + 1 + y * width));

top++;

flag = true;

break ro1;

}

break;

case 2: // 上边

if ((y - 1) = 0  maze.get(x + (y - 1) * width).visted == false) {

maze.get(x + y * width).setUp();

maze.get(x + (y - 1) * width).setDown();

team.add(maze.get(x + (y - 1) * width));

top++;

flag = true;

break ro1;

}

break;

case 3: // 下边

if ((y + 1)  height  maze.get(x + (y + 1) * width).visted == false) {

maze.get(x + y * width).setDown();

maze.get(x + (y + 1) * width).setUp();

team.add(maze.get(x + (y + 1) * width));

top++;

flag = true;

break ro1;

}

break;

}

times += 1;

}

if (!flag) {

team.remove(top);

top -= 1;

}

}

return maze;

}

}

迷宫

[java] view plain copy

//作者:zhongZw

//邮箱:zhong317@126.com

package cn.zhongZw.model;

import java.util.*;

import java.lang.*;

public class MazePoint {

private int left = 0;

private int right = 0;

private int up = 0;

private int down = 0;

private int x;

private int y;

public boolean visted;

public MazePoint(int x, int y) {

this.x = x;

this.y = y;

}

public int getLeft() {

return left;

}

public void setLeft() {

this.left = 1;

}

public int getRight() {

return right;

}

public void setRight() {

this.right = 1;

}

public int getUp() {

return up;

}

public void setUp() {

this.up = 1;

}

public int getDown() {

return down;

}

public void setDown() {

this.down = 1;

}

public int getX() {

return x;

}

public void setX(int x) {

this.x = x;

}

public int getY() {

return y;

}

public void setY(int y) {

this.y = y;

}

}

Java课程设计 走迷宫

教学过程是一个程序化的过程也是一个动态的。生成过程,因此,教学过程是。动态的。课程资源,教师在教学过程中充分利用,合。那个课程资源应他,把握好,以下禁。第弟弟的,调查学生的兴趣,第二,确定学生现有的发展基础,第三开展课外时间活动。

急需一java高手帮忙写一迷宫程序

给你代码,你给出的那两个类,不能满足,我的需要,我就没有使用。

你看一下吧。

----------------------------------------

package stackpackage;

import java.io.BufferedReader;

import java.io.FileReader;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Maze {

// 上

private static Point directionTop = new Point(-1, 0);

// 下

private static Point directionBottom = new Point(1, 0);

// 左

private static Point directionLeft = new Point(0, -1);

// 右

private static Point directionRight = new Point(0, 1);

private static Point[] directions = { directionTop, directionRight,

directionBottom, directionLeft };

private static boolean isStop = false;

private static int row = 0;

private static int col = 0;

private static Point startPoint = new Point();

public static void main(String[] args) throws Exception {

FileReader fr = new FileReader("data.txt");

BufferedReader br = new BufferedReader(fr);

int rowIndex = 1;

int[][] maze = null;

while (br.ready()) {

String line = br.readLine();

Scanner sc = new Scanner(line);

if (rowIndex == 1) {

row = sc.nextInt();

col = sc.nextInt();

maze = new int[row][col];

} else {

if (rowIndex row + 2) {

for (int i = 0; i col; i++) {

maze[rowIndex - 2][i] = sc.nextInt();

}

} else {

startPoint.x = sc.nextInt();

startPoint.y = sc.nextInt();

}

}

rowIndex++;

}

ListPoint route = new ArrayListPoint();

route.add(startPoint);

findNext(startPoint);

puzzle(maze, startPoint, route);

System.out.println(route);

}

private static void puzzle(int[][] maze, Point p, ListPoint route) {

if (isStop) {

return;

}

Point[] nextDirections = p.nextDirections;

for (int i = 0; i nextDirections.length; i++) {

if (isStop) {

return;

}

Point direction = nextDirections[i];

Point newP = new Point(p.x + direction.x, p.y + direction.y);

if (newP.isEffective() maze[newP.x][newP.y] == 0

!route.contains(newP)) {

newP.before = p;

findNext(newP);

route.add(newP);

if (isExit(newP)) {

isStop = true;

break;

}

puzzle(maze, newP, route);

}

}

if (isStop) {

return;

}

route.remove(route.size() - 1);

}

private static void findNext(Point p) {

int index = 0;

Point[] nextDirections = new Point[3];

for (int i = 0; i nextDirections.length; i++) {

nextDirections[i] = new Point(0, 0);

}

for (int i = 0; i directions.length; i++) {

Point direction = directions[i];

Point newP = new Point(p.x + direction.x, p.y + direction.y);

if (newP.isEffective() !newP.equals(p.before) newP.x row

newP.y col) {

nextDirections[index++] = direction;

}

}

p.nextDirections = nextDirections;

}

private static boolean isExit(Point p) {

if (startPoint.equals(p)) {

return false;

}

for (int i = 0; i directions.length; i++) {

Point direction = directions[i];

Point newP = new Point(p.x + direction.x, p.y + direction.y);

if (!newP.equals(p.before)

(newP.x = row || newP.y = col || newP.x 0 || newP.y 0)) {

return true;

}

}

return false;

}

}

class Point {

int x = 0;

int y = 0;

Point[] nextDirections = null;

Point before = null;

public Point() {

}

public Point(int x, int y) {

this.x = x;

this.y = y;

}

public String toString() {

return "" + x + "," + y + "";

}

public boolean isEffective() {

return x = 0 y = 0;

}

public boolean equals(Object obj) {

return equals((Point) obj);

}

public boolean equals(Point p) {

if (p == null) {

return false;

}

return this.x == p.x this.y == p.y;

}

}

Java迷宫算法问题(用栈实现)有算法简述

import java.io.File;

import java.io.FileNotFoundException;

import java.util.HashSet;

import java.util.LinkedList;

import java.util.List;

import java.util.Scanner;

public class Test {

public static void main(String[] args) throws FileNotFoundException {

Scanner input = new Scanner(new File("Maze2tong.txt"));

int row = 0;

char[][] Mazemap = new char[12][58];

while (input.hasNext()) {

String line = input.nextLine();

for (int column = 0; column = line.length() - 1; column++) {

char c = line.charAt(column);

Mazemap[row][column] = c;

}

row++;

}

for (int i = 0; i  12; i++) {

for (int j = 0; j  58; j++) {

System.out.print(Mazemap[i][j]);

}

System.out.print("\n");

}

LinkedListTwoTupleInteger, Integer trace = new LinkedListTwoTupleInteger, Integer();

System.out.println(maze(Mazemap, trace));

System.out.println(trace);

}

public static boolean maze(char[][] maze,

ListTwoTupleInteger, Integer trace) {

LinkedListTwoTupleInteger, Integer path = new LinkedListTwoTupleInteger, Integer();

HashSetTwoTupleInteger, Integer traverse = new HashSetTwoTupleInteger, Integer();

for (int i = 0; i  maze.length; i++) {

for (int j = 0; j  maze[i].length; j++) {

if (maze[i][j] == 'S') {

path.add(new TwoTupleInteger, Integer(i, j));

}

}

}

while (!path.isEmpty()) {

TwoTupleInteger, Integer temp = path.pop();

if (traverse.contains(temp)) {

continue;

} else if (maze[temp.first][temp.second] == 'F') {

trace.add(temp);

return true;

} else if (!traverse.contains(temp)) {

if (temp.second + 1  maze[temp.first].length

 maze[temp.first][temp.second + 1] != 'W')

path.add(new TwoTupleInteger, Integer(temp.first,

temp.second + 1));

if (temp.second - 1  0

 maze[temp.first][temp.second - 1] != 'W')

path.add(new TwoTupleInteger, Integer(temp.first,

temp.second - 1));

if (temp.first + 1  maze.length

 maze[temp.first + 1][temp.second] != 'W')

path.add(new TwoTupleInteger, Integer(temp.first + 1,

temp.second));

if (temp.first - 1  0

 maze[temp.first - 1][temp.second] != 'W')

path.add(new TwoTupleInteger, Integer(temp.first - 1,

temp.second));

traverse.add(temp);

trace.add(temp);

}

}

trace.clear();

return false;

}

}

class TwoTupleA, B {

public final A first;

public final B second;

public TwoTuple(A a, B b) {

first = a;

second = b;

}

@Override

public int hashCode() {

return first.hashCode() + second.hashCode();

}

@Override

public boolean equals(Object obj) {

if (!(obj instanceof TwoTuple)) {

}

return obj instanceof TwoTuple  first.equals(((TwoTuple) obj).first)

 second.equals(((TwoTuple) obj).second);

}

public String toString() {

return "(" + first + ", " + second + ")";

}

} // /:-

import java.io.File;

import java.io.FileNotFoundException;

import java.util.LinkedList;

import java.util.Scanner;

class MyPoint

{

    public boolean visited=false;

    public int parentRow=-1;

    public int parentColumn=-1;

    public final char content;

    public int x;

    public int y;

    public MyPoint(char c,int x,int y)

    {

     this.content = c;

     this.x = x;

     this.y = y;

    }

}

public class Maze

{

    public static MyPoint[][] getMazeArray(){

Scanner input = null;

MyPoint[][] mazemap = new MyPoint[12][58];

try {

input = new Scanner(new File("Maze2tong.txt"));

int row = 0;

while (input.hasNext()) {

String line = input.nextLine();

for (int column = 0; column = line.length() - 1; column++) {

char c = line.charAt(column);

MyPoint point = new MyPoint(c,row,column);

mazemap[row][column] = point;

}

row++;

}

input.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

}

return mazemap;

    }

    public static boolean tomRun(MyPoint[][] maze,MyPoint end)

    {

     int x = maze.length;

     int y = maze[0].length;

     LinkedListMyPoint stack=new LinkedListMyPoint();

for (int i = 0; i  maze.length; i++) {

for (int j = 0; j  maze[i].length; j++) {

if (maze[i][j].content == 'S') {

stack.push(maze[i][j]);

maze[i][j].visited=true;

}

}

}

        boolean result=false;

        while(!stack.isEmpty())

        {

            MyPoint t=stack.pop();

           //System.out.println("pop point:"+t.x+" "+t.y+" value:"+maze[t.x][t.y]);

            if(t.content == 'F')

            {

                result=true;

                end.x = t.x;

                end.y = t.y;

                break;

            }

            if(t.x-1  0  maze[t.x-1][t.y].visited==false  maze[t.x-1][t.y].content != 'W')

            {

                stack.push(maze[t.x-1][t.y]);

                maze[t.x-1][t.y].parentRow=t.x;

                maze[t.x-1][t.y].parentColumn=t.y;

                maze[t.x-1][t.y].visited=true;

            }

            if(t.x + 1  x  maze[t.x+1][t.y].visited==false  maze[t.x+1][t.y].content != 'W')

            {

                stack.push(maze[t.x+1][t.y]);

                maze[t.x+1][t.y].parentRow=t.x;

                maze[t.x+1][t.y].parentColumn=t.y;

                maze[t.x+1][t.y].visited=true;

            }

            if(t.y - 1  0  maze[t.x][t.y - 1].visited==false  maze[t.x][t.y-1].content != 'W')

            {

                stack.push(maze[t.x][t.y-1]);

                maze[t.x][t.y-1].parentRow=t.x;

                maze[t.x][t.y-1].parentColumn=t.y;

                maze[t.x][t.y-1].visited=true;

            }

            if( t.y + 1  y  maze[t.x][t.y + 1].visited==false  maze[t.x][t.y+1].content != 'W')

            {

                stack.push(maze[t.x][t.y+1]);

                maze[t.x][t.y+1].parentRow=t.x;

                maze[t.x][t.y+1].parentColumn=t.y;

                maze[t.x][t.y+1].visited=true;

            }

 

        }

        return result;

    }

    public static void show(int x,int y,MyPoint[][] visited)

    {

        if(visited[x][y].parentRow==-1)

        {

            System.out.println("["+x+","+y+"]");

            return;

        }

        show(visited[x][y].parentRow,visited[x][y].parentColumn,visited);

        System.out.println("-"+"["+x+","+y+"]");

    }

    public static void main(String[] args)

    {

     MyPoint[][] maze = getMazeArray();

     MyPoint point = new MyPoint('c',1,1);

        if(tomRun(maze,point))

        {

            System.out.println("逃生路径如下:");

            show(point.x,point.y,maze);

        }

        else

            System.out.println("无法走出迷宫!");

    }

}

WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

WSOOOOOOOOOOOOO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OOOOOOWWWWWWWWWOOOOOWW

WOOWWWWWWWWWWWWWOOWWWWWWWWWWWWWWWWWOOOOOOOWWWWWWWWWWWWOOOW

WOWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWOOOOOOOWWWWWWWWWWWOOW

WOWWWWWWWWWWWWWOOOOOOOOOOOOOOOOOOOOOOOOOOOOWWWWWWWWWWWWOOW

WOOOOOOOOOOOOOOOOWWWWOOOOOOOOWWWWWWWOOOOOOWWWWWWWWWWWWWWFW

WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

java课程设计创意小游戏

① 求Java课程设计—小游戏(含源代码)

//hi./srxboys/item/8ce4743da1adc991c2cf29c4

Tank——坦克大战(简洁版)源代码-------(此文档是自己在韩顺平教程总结而来)

*功能:1.防止敌人的坦克重叠运动

*(决定把判断是否碰撞的函数写到EnemyTank类)

*2.可以分关

*2.1(做一个开始的Panel,它是一个空的)

*2.2开始字体闪烁

*3.可以在玩游戏的时候,暂停和继续

*3.1当用户点击暂停时,子弹的速度和坦克速度设为0,并让坦克的方向

*不要发生变化。

*4.可以记录玩家的成绩

*4.1用文件流的方式(小游戏)[大游戏是用的数据库cs,bs结构,三国]

*4.2单写一个记录类,完成对玩家的记录

*4.3先完成保存共击毁了多少辆敌人坦克的功能

*4.4存盘退出游戏,可以记录当时的敌人的坦克坐标,并可以恢复

*5.java如何操作声音文件

*/

② JAVA课程设计,求个能用eclipse实现小游戏或小程序的源代码。感激不尽

你自己来去下自载吧,这里面都有 //oschina/project/java

③ 用JAVA编写一个小游戏

前天写的猜数字游戏,yongi控制猜测次数,有详细解析,用黑窗口可以直接运行,

我试验过了,没问题

import javax.swing.Icon;

import javax.swing.JOptionPane;

public class CaiShuZi4JOptionPane {

/**

* @param args

*/

public static void main(String[] args) {

Icon icon = null;

boolean bl = false;

int put = 0;

int c = (int) (((Math.random())*100)+1); //获取一个1-100的随机数

System.out.println("你获取的随机数是:"+c); //打印你的随机数字

String str1 = (String) JOptionPane.showInputDialog(null,"请输入你的猜测数字(1-100): ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入"); //第一次输入你的猜测数字

if(str1==null){

JOptionPane.showMessageDialog(null, "你已经取消了本次游戏"); //如果你点取消那么本次游戏结束

}else{

bl = num(str1); //判断是输入的是不是数字或者是整数

if(true==bl){ //如果是数字的话进入与随机数比较的程序

System.out.println("你输入的数字是:"+str1); //打印你输入的数字

put = Integer.valueOf(str1);

for(int i = 4;i 0;i--){ //i是你可以猜测的次数

if(put==c){

JOptionPane.showMessageDialog(null, "恭喜你猜对了,正确答案是:"+c+"。"); //如果你猜对了就直接结束循环

break;

}else if(putc){ //如果输大了就让你再次从新输入

str1 = (String) JOptionPane.showInputDialog(null,"你的输入过大。你还有"+i+"次机会,请重新输入: ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入");

if(str1==null){

JOptionPane.showMessageDialog(null, "你已经取消了本次输入");

break;

}else{

bl =num(str1);

if(true==bl){

put = Integer.valueOf(str1);

}else{

JOptionPane.showMessageDialog(null, "你的输入不正确,请重新输入");

}

}

}else if(putc){ //如果你输小了也让你从新输入

str1 = (String) JOptionPane.showInputDialog(null,"你的输入过小。你还有"+i+"次机会,请重新输入: ","猜数字游戏",JOptionPane.PLAIN_MESSAGE,icon,null,"在这输入");

if(str1==null){

JOptionPane.showMessageDialog(null, "你已经取消了本次输入");

break;

}else{

bl =num(str1);

if(true==bl){

put = Integer.valueOf(str1);

}else{

JOptionPane.showMessageDialog(null, "你的输入不正确,请重新输入");

}

}

}

}

}else if(bl==false){ //这个 是你第一次如果填写的不是数字的话也会结束本次游戏

JOptionPane.showMessageDialog(null, "请您下次按要求填写。本次游戏结束");

}

if(true==bl c!=put){ //如果你i次都没猜对,那么就直接告诉你这个数十什么

JOptionPane.showMessageDialog(null, "很遗憾你没能猜对,这个数字是:"+c+".");

}

}

}

public static boolean num(String value){ //一个静态方法,判断你输入的是不是数字

try {

Integer.parseInt(value);

return true;

} catch (Exception e) {

return false;

}

}

}

④ 用java制作一个小游戏 教学

static Scanner in =new Scanner(System.in);

public static int aaa(){

int c = 0;

while(true){

try {

if(c999c10000){

break;

}else{

// System.out.println("请输入4位整数");

c= in.nextInt();

if(c999c10000){

break;

}else{

System.out.println("输入有误,请重新输入4位整数");

}

}

} catch (Exception e) {

System.out.println("请输入整数");

c= in.nextInt();

}

}

//in.close();

return c;

}

public static void cai(){

//Scanner sa =new Scanner(System.in);

int haoma=(int)(Math.random()*10000);

if(haoma999)

{

haoma = Integer.parseInt(String.valueOf(haoma)+"0");

}

System.out.println(haoma);

System.out.println("请输入一位4位整数");

int aa = 0;

while(true){

aa= aaa();

String pd=String.valueOf(aa);

if(pd.length()!=4){

aa = aaa();

}else{

break;

}

}

while(true){

if(aa==haoma){

System.out.println("你猜对了,可以去买彩票了");

}else{

System.out.println("抱歉 , 你猜错了");

}

System.out.println("是否继续1继续 其他结束");

try {

int ss = in.nextInt();

if(ss==1){

cai();

}else{

break;

}

} catch (Exception e) {

in.close();

break;

}

}

}

public static void main(String[] args) {

System.out.println("欢迎来到猜号小游戏");

cai();

System.out.println("over");

}

⑤ 想做一个java小游戏 谁能给几个创意啊 注意 是创意!!!!! 不是已有的有创意的小游戏

比如有东西扔过来,选择吃掉或者躲开,考反应吧。

⑥ 急求java课程设计,内容可以是小游戏的,如(迷宫,计算器,停车场之恋的),要能运行,谢谢

俄罗斯方块,贪吃蛇。推箱子。

⑦ 求JAVA期末课程设计,要那种开发的小项目软件。可以是像记事本那种,也可以是小游戏那种。

网上搜不到的一般是不可共享的资源,建议去图书馆找本专门针对课程设计的书,里面的资料很丰富,你可以照着做一下,并作功能上适当的增减,这样网上就很难找到了

java项目迷宫的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java迷宫游戏的设计报告、java项目迷宫的信息别忘了在本站进行查找喔。