JAVA的一个小游戏的编程问题 (第2题)
5-下,8-上,4-左,6-右,0-退出如果按照上面的要求,长度是5,高度是3,那就是:
10000
00000
00000
输入5的话就是:
10000
10000
00000
输入6是:
10000
11000
00000
按这个玩,如果移动旁边没有数字了像:
10000
00000
00000
输入了4,没有数字了,就print left wall.如果右边没数字就print right wall.
像
10000
10000
00000
输入5(下),就变成
10000
20000
00000
像这样应该怎么做
import java.util.Scanner;
public class Grid
{
int maze[][]; // the 2D maze
int width; // width of maze
int height; // height of maze
int hPos; // current horizontal position in maze
int vPos; // current vertical position in maze
/*
* initializes maze using w (width) and h (height)
*/
public Grid(int w, int h)
{
// set the width and height of maze
width=w;
height=h;
// set the starting horizontal & vertical position in maze
hPos=0;
vPos=0;
// create 2D maze of specified size
maze = new int[height][width];
visit(); // visit the current position
}
/*
* increments the current position in maze by one
* then displays the maze (note that if the value
* reaches ten the value should reset back to zero
*/
public void visit()
{
}
/*
* print the maze values out as a 2 dimensional grid
* with width x height dimensions
* eg if the width is 4 and the height is 3 and only the top
* left position has been visited, it should print the following:
*
* 1000
* 0000
* 0000
*/
public void display()
{
//public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc= new Scanner(System.in);
//int width =sc.nextInt();
// int height = sc.nextInt();
int i,j;
for(i=0;i<height;i++)
{
if(i==0)
{
System.out.print("1");
for(j=1;j<width;j++)
{
System.out.print("0");
}
System.out.println();
}
else
{
for(j=0;j<width;j++)
{
System.out.print("0");
}
System.out.println();
}
}
}
/*
* move the current position in maze left by one position
* needs to avoid going through left wall
*/
public void left()
{
}
/*
* move the current position in maze right by one position
* needs to avoid going through right wall
*/
public void right()
{
}
/*
* move the current position in maze up by one position
* needs to avoid going through top wall
*/
public void up()
{
}
/*
* move the current position in maze down by one position
* needs to avoid going through bottom wall
*/
public void down()
{
}
}
谢谢