📄 lmimaze.java
字号:
x = in.read(player, idx, 4 - idx);
if(x == -1)
{
break;
}
idx += x;
}
//
// Close the connection to the server.
//
connection.disconnect();
//
// Get the graphics context to use for drawing this maze
// data.
//
if(buffer == 0)
{
g = backg2;
}
else
{
g = backg1;
}
//
// Loop through the rows of the maze.
//
idx = 0;
for(y = 0; y < 470; y += 5)
{
//
// Loop through the columns of the maze.
//
for(x = 0; x < 635; x += 5)
{
//
// See if there is a wall at this point in the
// maze.
//
if(maze[idx] == 0)
{
//
// Clear this part of the image.
//
g.setColor(Color.black);
g.fillRect(x, y, 5, 5);
}
else
{
//
// There is a wall, so see if it connects to a
// wall segment above it.
//
if((maze[idx] & 1) == 1)
{
//
// Draw the top row of this wall segment
// based on a wall segment being above it.
//
g.setColor(Color.darkGray);
g.drawLine(x, y, x, y);
g.setColor(Color.white);
g.drawLine(x + 1, y, x + 3, y);
g.setColor(Color.lightGray);
g.drawLine(x + 4, y, x + 4, y);
}
else
{
//
// Draw the top row of this wall segment
// based on there not being a wall segment
// above it.
//
g.setColor(Color.darkGray);
g.drawLine(x, y, x + 4, y);
}
//
// See if this wall segment connects to a wall
// segment below it.
//
if((maze[idx] & 2) == 2)
{
//
// Draw the bottom row of this wall segment
// based on a wall segment being below it.
//
g.setColor(Color.darkGray);
g.drawLine(x, y + 4, x, y + 4);
g.setColor(Color.white);
g.drawLine(x + 1, y + 4, x + 3, y + 4);
g.setColor(Color.lightGray);
g.drawLine(x + 4, y + 4, x + 4, y + 4);
}
else
{
//
// Draw the bottom row of this wall segment
// based on there not being a wall segment
// below it.
//
g.setColor(Color.lightGray);
g.drawLine(x, y + 4, x + 4, y + 4);
}
//
// See if this wall segment connects to a wall
// segment to its right.
//
if((maze[idx] & 4) == 4)
{
//
// The right column should be white.
//
g.setColor(Color.white);
}
else
{
//
// The right column should be light gray.
//
g.setColor(Color.lightGray);
}
//
// Draw the right column of this wall segment
// based on the color chosen above.
//
g.drawLine(x + 4, y + 1, x + 4, y + 3);
//
// See if this wall segment connects to a wall
// segment to its left.
//
if((maze[idx] & 8) == 8)
{
//
// The left column should be white.
//
g.setColor(Color.white);
}
else
{
//
// The left column should be dark gray.
//
g.setColor(Color.darkGray);
}
//
// Draw the left colunn of this wall segment
// based on the color chosen above.
//
g.drawLine(x, y + 1, x, y + 3);
//
// Draw the interior of the wall segment.
//
g.setColor(Color.white);
g.fillRect(x + 1, y + 1, 3, 3);
}
//
// Go to the next byte of the maze data.
//
idx++;
}
}
//
// Set the drawing color to red.
//
g.setColor(Color.red);
//
// Loop through the monsters.
//
for(idx = 0; idx < 400; idx += 4)
{
//
// Get the position of this monster.
//
x = ((monster[idx] & 0xff) +
((monster[idx + 1] & 0xff) * 256));
y = ((monster[idx + 2] & 0xff) +
((monster[idx + 3] & 0xff) * 256));
//
// See if this monster exists.
//
if((x != 0) || (y != 0))
{
//
// Translate the monster position from the full
// maze coordinate to the image coordinate.
//
x = (x * 5) / 12;
y = (y * 5) / 12;
//
// Draw this monster on the image.
//
g.fillRect(x + 1, y, 2, 4);
g.fillRect(x, y + 1, 4, 2);
}
}
//
// Set the drawing color to green.
//
g.setColor(Color.green);
//
// Get the position of the player.
//
x = (player[0] & 0xff) + ((player[1] & 0xff) * 256);
y = (player[2] & 0xff) + ((player[3] & 0xff) * 256);
//
// See if the player is located in the maze.
//
if((x != 0) || (y != 0))
{
//
// Translate the player position from the full maze
// coordinates to the image coordinates.
//
x = (x * 5) / 12;
y = (y * 5) / 12;
//
// Draw the player on the image.
//
g.fillRect(x + 1, y, 2, 4);
g.fillRect(x, y + 1, 4, 2);
}
//
// Indicate that the newly drawn image should be displayed.
//
buffer ^= 1;
//
// Request a refresh of the window.
//
repaint();
//
// Clear the refresh now flag.
//
refreshOne = 0;
}
catch(Exception e)
{
}
}
}
catch(InterruptedException e)
{
}
}
//*************************************************************************
//
// Updates the window.
//
//*************************************************************************
public void update(Graphics g)
{
//
// See which image should be displayed.
//
if(buffer == 0)
{
//
// Draw the first image to the window.
//
g.drawImage(backbuffer1, 2, 2, this);
}
else
{
//
// Draw the second iamge to the window.
//
g.drawImage(backbuffer2, 2, 2, this);
}
}
//*************************************************************************
//
// Handles window update requests.
//
//*************************************************************************
public void paint(Graphics g)
{
//
// Update the window.
//
update(g);
}
//*************************************************************************
//
// Changes the state of the auto refresh variable. Called from JavaScript.
//
//*************************************************************************
public void autoRefresh(int state)
{
//
// Save the state of the refresh variable.
//
refresh = state;
//
// Synhronously notify the background thread.
//
synchronized(this)
{
notify();
}
}
//*************************************************************************
//
// Requests a refresh of the maze. Called from JavaScript.
//
//*************************************************************************
public void refreshNow()
{
//
// Set the single refresh variable.
//
refreshOne = 1;
//
// Synchronously notify the background thread.
//
synchronized(this)
{
notify();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -