?? russioncube.txt
字號:
if (colour != BoardArray[i][row]) colour = 0;
}
if (i == 99) continue;
j = row++;
while (--j > 0)
{
i = -1;
while (i++ < 9)
BoardArray[i][j + 1] = BoardArray[i][j];
}
score += ((colour == 0) ? 100 : 1000);
getParent().action(new Event(this, score, null), this);
forceredraw = true;
repaint();
}
}
public void pause()
{ // What happens when you click the button.
if (GameOver) return;
Paused = !Paused;
forceredraw = true; // Force complete repaint.
repaint();
}
public void newGame()
{ // What happens when you click the button.
int x, y;
if (boardinitialized)
{
for (x = 0; x < 10; x++)
for (y = 0; y < 27; y++)
BoardArray[x][y] = 0;
LastX = LastY = LastAngle = -1;
GameOver = Paused = kludgeflag = false;
delay = 500;
forceredraw = true;
}
CurrentBlockColour = NextBlockColour = score = 0;
getParent().action(new Event(this, score, null), this);
repaint();
}
public void moveRight()
{ // What happens when you click the button.
int i = -1;
if (boardinitialized && !Paused)
{
while (i++ < 3)
if (CurrentBlockX + 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0] > 9||
BoardArray[CurrentBlockX + 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0]][CurrentBlockY + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1]] != 0)
return;
CurrentBlockX++;
dopaint();
}
}
public void moveLeft()
{ // What happens when you click the button.
int i = -1;
if (boardinitialized && !Paused)
{
while (i++ < 3)
if (CurrentBlockX - 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0] < 0||
BoardArray[CurrentBlockX - 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0]][CurrentBlockY + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1]] != 0)
return;
CurrentBlockX--;
dopaint();
}
}
public void rotateClockwise()
{ // What happens when you click the button.
int i, NewBlockAngle;
if (boardinitialized && !Paused)
{
NewBlockAngle = CurrentBlockAngle + 1;
if (NewBlockAngle == 4) NewBlockAngle = 0;
i = -1;
while (i++ < 3)
if (CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0] > 9||
CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0] < 0||
CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1] >= 27||
CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1] < 0||
BoardArray[CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0]][CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1]] != 0)
return;
CurrentBlockAngle = NewBlockAngle;
dopaint();
}
}
public void rotateAntiClockwise()
{ // What happens when you click the button.
int i, NewBlockAngle;
if (boardinitialized && !Paused)
{
NewBlockAngle = CurrentBlockAngle - 1;
if (NewBlockAngle == -1) NewBlockAngle = 3;
i = -1;
while (i++ < 3)
if (CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0] > 9||
CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0] < 0||
CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1] >= 27||
CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1] < 0||
BoardArray[CurrentBlockX + BlockInfo[CurrentBlockShape][NewBlockAngle][i][0]][CurrentBlockY + BlockInfo[CurrentBlockShape][NewBlockAngle][i][1]] != 0)
return;
CurrentBlockAngle = NewBlockAngle;
dopaint();
}
}
public void drop()
{ // What happens when you click the drop button.
int i;
if (boardinitialized && !Paused)
{
while (true)
{
i = -1;
while (i++ < 3)
if (CurrentBlockY + 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1] >= 27||
BoardArray[CurrentBlockX + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0]][CurrentBlockY + 1 + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1]] != 0)
{
dopaint();
return;
}
CurrentBlockY++;
score += 1;
}
}
}
public void update(Graphics g)
{ // Background is *not* blanked on entry to update. (As opposed to paint)
int x, y, i;
if (!boardinitialized)
{ // Can't do this in init(). Java bug or feature?
boardinitialized = true;
BoardArray = new int[10][27];
Colours = new Color[7];
for (x = 0; x < 10; x++)
for (y = 0; y < 27; y++)
BoardArray[x][y] = 0;
Colours[0] = new Color(0, 0, 0);
Colours[1] = new Color(200, 0, 0);
Colours[2] = new Color(0, 200, 0);
Colours[3] = new Color(0, 0, 200);
Colours[4] = new Color(200, 200, 0);
Colours[5] = new Color(200, 0, 200);
Colours[6] = new Color(0, 200, 200);
LastX = LastY = LastAngle = -1;
kludgeflag = forceredraw = false;
}
if (kludgeflag && !forceredraw)
{ // See Notes.
kludgeflag = false;
realdopaint(g);
return;
}
kludgeflag = forceredraw = false;
// g.setColor(new Color(0, 0, 0)); blank backgroud
g.setColor(new Color(0, 0, 0)); // white backgroud
g.fillRect(0, 0, 120, 324); // Blank background.
if (Paused)
{ // Display messages if appropriate.
String Over = "Game Over!", Pause = "Game Paused";
g.setColor(new Color(255, 255, 255));
g.drawString(GameOver ? Over : Pause,
60 - (getGraphics().getFontMetrics().stringWidth(GameOver ? Over : Pause) / 2), 20);
if (!GameOver) return;
}
for (x = 0; x < 10; x++)
for (y = 0; y < 27; y++)
{ // Redraw static pieces
if (BoardArray[x][y] != 0)
{
g.setColor(Colours[BoardArray[x][y]]);
g.fill3DRect(x * 12, y * 12, 12, 12, true);
}
}
if (CurrentBlockColour != 0)
{ // Redraw Current Blocks
g.setColor(Colours[CurrentBlockColour]);
i = -1;
while (i++ < 3)
g.fill3DRect((CurrentBlockX + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0]) * 12, (CurrentBlockY + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1]) * 12, 12, 12, true);
}
g.dispose();
}
public void dopaint()
{ // Calls realdopaint via repaint/update to get a valid Graphics handle. See Notes.
kludgeflag = true;
repaint();
}
public void realdopaint(Graphics g)
{ // Erases blocks from previous position and redraws them in their new position.
int x, y, i;
g.setColor(new Color(0, 0, 0));
if (LastX != -1)
{
g.setColor(Colours[0]);
i = -1;
while (i++ < 3)
g.fill3DRect((LastX + BlockInfo[CurrentBlockShape][LastAngle][i][0]) * 12, (LastY + BlockInfo[CurrentBlockShape][LastAngle][i][1]) * 12, 12, 12, true);
}
if (CurrentBlockColour != 0)
{
LastX = CurrentBlockX;
LastY = CurrentBlockY;
LastAngle = CurrentBlockAngle;
g.setColor(Colours[CurrentBlockColour]);
i = -1;
while (i++ < 3)
g.fill3DRect((CurrentBlockX + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][0]) * 12, (CurrentBlockY + BlockInfo[CurrentBlockShape][CurrentBlockAngle][i][1]) * 12, 12, 12, true);
}
g.dispose();
}
public Color getPieceColour()
{
return(Colours[NextBlockColour]);
}
public int getPieceX(int i)
{
return(BlockInfo[NextBlockShape][NextBlockAngle][i][0]);
}
public int getPieceY(int i)
{
return(BlockInfo[NextBlockShape][NextBlockAngle][i][1]);
}
void makeNewPiece()
{
NextBlockColour = (int) (Math.random() * 6) + 1;
if (NextBlockColour == 7) NextBlockColour = 1;
NextBlockX = (int) (Math.random() * 4) + 3;
if (NextBlockX == 8) NextBlockX = 0;
NextBlockY = 1;
NextBlockShape = (int) (Math.random() * 7);
if (NextBlockShape == 7) NextBlockShape = 0;
NextBlockAngle = (int) (Math.random() * 4);
if (NextBlockAngle == 4) NextBlockAngle = 0;
getParent().action(new Event(this, -1, null), this);
}
}
class Icon extends Panel
{ // Could add 3D click effect here.
int iconnumber = 0;
Image icon;
public Icon(Image image, int num)
{
icon = image;
iconnumber = num;
}
public void paint(Graphics g)
{
if (icon != null)
g.drawImage(icon, 0, 0, this);
}
public int getNumber()
{
return iconnumber;
}
public boolean mouseDown(Event evt, int x, int y)
{
getParent().action(evt, this);
return true;
}
}
class Picture extends Panel
{
Image icon;
public Picture(Image image)
{
icon = image;
}
public void paint(Graphics g)
{
if (icon != null)
g.drawImage(icon, 0, 0, this);
}
}
class DisplayPiece extends Panel
{
Board board;
public DisplayPiece(Board b)
{
board = b;
}
public void paint(Graphics g)
{
g.setColor(new Color(128, 128, 128));
g.fill3DRect(0, 0, 68, 68, true);
int i = -1;
if (board instanceof Board)
while (i++ < 3)
{
g.setColor(board.getPieceColour());
g.fill3DRect(28 + board.getPieceX(i) * 12,
28 + board.getPieceY(i) * 12, 12, 12, true);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -