Left Nav Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Right Nav
Ballot.com

 
     

Left Container Right Container
 

Go Back   Ballot.com » The Political Hotwire » The Hotwire » The Lounge

Reply
 
LinkBack Thread Tools Display Modes
Old 12-18-2007, 01:23 AM   #1
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Tetris Source Code:

Warning:
This code sucks.

Quote:
TITLE:
Project 3 - TETRIS

AUTHOR:
The Bear
12/17/2007

BRIEF DESCRIPTION OF PROGRAM:
A unique version of tetris.

FILES INCLUDED:
- README - this file, tells how to run.
- Project3 - the main class, the program runs from here.
- Pieces - the class that does the physical work
- commenceGame - the class that graphically outputs the game.

KNOWN BUGS:
- There is no collision if the user rotates into a dead block. It is unadvisable to rotate into them.
- Occasionally, it is required to press a button for the game to end.

NOTES:
- There is occasionally a time when if the user presses the down arrow key, they user is able to overwrite some dead block. This is intentional. It is part of this version of tetris.
- I am aware no high score is taken.
- This version of tetris does not bring the floating pieces down. It is designed so that you must work around those
floating pieces.
- Grey blocks represent dead blocks.
- Final score is printed on the command prompt.

CONTROLS:
- Left arrow = move the live piece left.
- Right arrow = move the live piece right.
- Up arrow = rotate the live piece.
- Down arrow = move the live piece down. This cannot be done when you are near other pieces, because speeding into
objects is not good for the health of your person.


HOW TO RUN:
Step 1: Gather all of the files into a single folder.
Step 2: Open a command prompt. If you are using windows, this is done by clicking on start, then run, then typing
cmd into the area given.
Step 3: Find out the address of the folder. If you are using windows, this is done by opening up the folder containing your files.
Step 4: Using the change directory function, or cd, access the particular folder in your command prompt.
For instance, if the folder is in the c drive in documents and settings, access it by typing in the command
line cd c\documents and settings
Step 5: Compile project3 through typing, in the command line javac project3.java . If this returns an error, update the java on your system.
Step 6: Run the program through typing, in the command line, java project3.

SAMPLE OUTPUT:

<game of tetris>
Congratulations, you have scored 41 points, 0 lines, and 0 levels!

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Alt Today
Advertising

Beitrag Sponsored Links

__________________
Tell Your Friends About Ballot.com!
   
Old 12-18-2007, 01:24 AM   #2
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

this is the main class

Quote:
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import java.awt.font.* ;
import java.awt.geom.* ;

public class project3{

public static void main(String[] args)
{

JFrame window = new JFrame();
window.setTitle("Tetris");
commenceGame begin = new commenceGame();
begin.setFocusable(true);
begin.init();
begin.setFocusable(true);
begin.startAnimation();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
window.setFocusable(true);
window.getContentPane().add(begin);
window.pack();
window.setVisible( true );
}}

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:25 AM   #3
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

Quote:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class commenceGame extends JPanel
{
public int lor;

public int x;//starting x location of block

public int y;//starting y location of block

public int width;//width of block

public int height;//height of block

public int board[][];

public int temp_storage_board[][];

public int xBoard;//width of board matrix

public int yBoard;//height of board matrix

public Timer animationTimer;

public int ANIMATION_DELAY;

public int score;

public int level;

public int lines;

Pieces piece1;//the piece that gets modified

Pieces piece2;//the piece that is the result of the modification

public int counter;

public commenceGame()
{
lines = 0;
score = 0;
level = 0;
counter = 0;
xBoard = 12;
yBoard = 22;
width = 40;
height = 40;
x = 5;
y = 0;
board = new int[xBoard][yBoard];
for (int i = 0; i < xBoard; i++)
board[i][0] = -1;
for (int i = 0; i < xBoard; i++)
board[i][yBoard - 1] = -1;
for (int i = 0; i < yBoard; i++)
board[0][i] = -1;
for (int i = 0; i < yBoard; i++)
board[xBoard - 1][i] = -1;
//this is the board where pieces appear
temp_storage_board = new int[xBoard][yBoard];//this is the main board
piece1 = new Pieces(board);
piece1.makeNewShape(board);
ANIMATION_DELAY = 500;

}

public void init()
{

JButton panel = new beginGame();
add(panel);
}

public class beginGame extends JButton
{
public beginGame()
{
addKeyListener(new KeyHandler());
setFocusable(true);
setPreferredSize(new Dimension(480, 880));
setBackground(Color.white);
}

public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;


temp_storage_board = board;
for (int i = 0; i < xBoard; i++)
{
for (int j = 0; j < yBoard; j++)
{
if (temp_storage_board[i][j] == 1)
drawCross(g2, i, j);
else if (temp_storage_board[i][j] == 2)
drawLeftL(g2, i, j);
else if (temp_storage_board[i][j] == 3)
drawRightL(g2, i, j);
else if (temp_storage_board[i][j] == 4)
drawLeftS(g2, i, j);
else if (temp_storage_board[i][j] == 5)
drawRightS(g2, i, j);
else if (temp_storage_board[i][j] == 6)
drawSquare(g2, i, j);
else if (temp_storage_board[i][j] == 7)
drawTetris(g2, i, j);
else if (temp_storage_board[i][j] == -1)
drawDeadSquare(g2, i, j);
else if (temp_storage_board[i][j] == -2)
drawDeaderSquare(g2, i, j);
}
}
}

public void drawCross(Graphics2D g2, int x, int y)
{
// piece1.makeCross(board, true);
g2.setColor(Color.red);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 2)

public void drawLeftL(Graphics2D g2, int x, int y)
{
// piece1.makeLeftL(board, true);
g2.setColor(Color.red);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 3)

public void drawRightL(Graphics2D g2, int x, int y)
{
// piece1.makeRightL(board, true);
g2.setColor(Color.cyan);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 4)
public void drawLeftS(Graphics2D g2, int x, int y)
{
// piece1.makeLeftS(board, true);
g2.setColor(Color.orange);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 5)
public void drawRightS(Graphics2D g2, int x, int y)
{
// piece1.makeRightS(board, true);
g2.setColor(Color.yellow);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 6)
public void drawSquare(Graphics2D g2, int x, int y)
{
// piece1.makeSquare(board, true);
g2.setColor(Color.blue);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

//else if (board[i][x] == 7)
public void drawTetris(Graphics2D g2, int x, int y)
{
// piece1.makeTetris(board, true);
g2.setColor(Color.green);
g2.fillRect(x * width, y * height, width, height);
g2.setColor(Color.black);
g2.drawRect(x * width, y * height, width, height);
}

// else if (board[i][x] == 0)
public void drawBlankSquare(Graphics2D g2, int x, int y)
{
// piece1.makeBlankSquare(board, true);
g2.setColor(Color.white);
g2.fillRect(x * width, y * height, width, height);
}

//else if (board[i][x] == -1)
public void drawDeadSquare(Graphics2D g2, int x, int y)
{
// piece1.makeDeadSquare(board, true);
g2.setColor(Color.gray);
g2.fillRect(x * width, y * height, width, height);
}
public void drawDeaderSquare(Graphics2D g2, int x, int y)
{
// piece1.makeDeadSquare(board, true);
g2.setColor(Color.black);
g2.fillRect(x * width, y * height, width, height);
}
}

public void startAnimation()
{
if (animationTimer == null)
{
animationTimer = new Timer(ANIMATION_DELAY, new TimerHandler());
animationTimer.start();
}
else
{
if (!animationTimer.isRunning())
animationTimer.restart();
}
}

public void stopAnimation()
{
animationTimer.stop();
}


}
this is commenceGame part 1

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:26 AM   #4
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

Quote:
public class TimerHandler implements ActionListener
{
public void actionPerformed(ActionEvent actionEvent)
{

if (!piece1.checkIfDown(board))
{
piece1.moveDown(board);
piece1.update(board, 4);
}
else{
piece1 = new Pieces(board);
piece1.update(board, 4);
}
//System.out.println(piece1.checkIfCleared(board));

if(piece1.checkIfCleared(board) == 0)
{}
else if(piece1.checkIfCleared(board) == 1)
{
System.out.println("clear 1");
score += 10;
lines += 1;
if(lines%10 == 0)
{
level++;
ANIMATION_DELAY -= 10;
}
}
else if(piece1.checkIfCleared(board) == 2)
{
System.out.println("clear 2");
score += 25;
lines += 2;
if(lines%10 == 0)
{
level++;
ANIMATION_DELAY -= 10;
}
}
else if(piece1.checkIfCleared(board) == 3)
{
System.out.println("clear 3");
score += 50;
lines += 1;
if(lines%10 == 0)
{
level++;
ANIMATION_DELAY -= 10;
}
}
else if(piece1.checkIfCleared(board) == 3)
{
System.out.println("TETRIS!");
score += 100;
lines += 1;
if(lines%10 == 0)
{
level++;
ANIMATION_DELAY -= 10;
}
}


piece1.cleanOutBoard(board);
if(piece1.checkIfGameOver(board))
{
piece1.killScreen(board);
animationTimer.stop();

System.out.print("Congratulations, you have scored " + score + " points,");
System.out.print(" " + lines + " lines, ");
System.out.println(" and " + level + " levels!");


}
score++;
repaint();
}
}



public class KeyHandler implements KeyListener
{
public void keyPressed(KeyEvent event)
{
// System.out.println("key pressed");
switch (event.getKeyCode())
{
case KeyEvent.VK_LEFT:
lor = 1;
if(piece1.ableToMoveLeft(board)) piece1.moveXLeft(board);
board = piece1.update(board, lor);
//x -= size;
break;
case KeyEvent.VK_RIGHT:
lor = 2;
if(piece1.ableToMoveRight(board)) piece1.moveXRight(board);
board = piece1.update(board, lor);
// x += size;
break;
case KeyEvent.VK_UP:
lor = 3;
board = piece1.update(board, lor);
break;
case KeyEvent.VK_DOWN:
lor = 2;
if(piece1.ableToMoveDown(board)) piece1.moveDown(board);
board = piece1.update(board, lor);
// x += size;
break;

}
repaint();
}

public void keyReleased(KeyEvent event)
{
}

public void keyTyped(KeyEvent event)
{
}

}
this is commenceGame part II

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:26 AM   #5
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

Quote:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Pieces
{
public int x;

public int what_was_called;

public int y;

public int cross[][] = { { 1, 1, 1 }, { 0, 1, 0 } };

private int leftL[][] = { { 2, 2, 2 }, { 2, 0, 0 } };

private int rightL[][] = { { 3, 0, 0 }, { 3, 3, 3 } };

private int leftS[][] = { { 0, 4, 4 }, { 4, 4, 0 } };

private int rightS[][] = { { 5, 5, 0 }, { 0, 5, 5 } };

private int square[][] = { { 6, 6 }, { 6, 6 } };

private int tetris[][] = { { 7, 7, 7, 7 } };

private int blankSquare[][] = { { 0 } };

public int position;

public int startPlaceY;

public int startPlaceX;

public int shape;

public int replacement_board[][];


public Pieces(int board[][])
{

position = 0;
x = 0;
y = 1;
startPlaceX = 5;
startPlaceY = 1;
shape = (int) (Math.random() * 7);
replacement_board = new int[20][10];
}
public int[][] makeNewShape(int[][] temp2_board)
{
return temp2_board;
}

public void moveDown(int[][] board)
{
// System.out.println(startPlaceX);
// System.out.println(startPlaceY);
startPlaceY++;

}

public void moveXLeft(int[][] temp)
{
startPlaceX--;
}

public void moveXRight(int[][] temp)
{
startPlaceX++;
}

public int[][] update(int [][] temp2, int lor)
{
what_was_called = shape;
// System.out.println("rotate called");
// System.out.println("shape number = " + shape);
// System.out.println("Position = " +position);
// shape = 1;

if(lor== 3) position = (position+1) %4;
try{
switch(shape)
{

//when cross was called
case(0): switch(position)
{
case(0): return modify_cross_d(temp2);
case(1): return modify_cross_l(temp2);
case(2): return modify_cross_u(temp2);
case(3): return modify_cross_r(temp2);
}
case(1): switch(position)
{
case(0): return modify_left_Ll(temp2);
case(1): return modify_left_Lu(temp2);
case(2): return modify_left_Lr(temp2);
case(3): return modify_left_Ld(temp2);
}
case(2): switch(position)
{
case(0): return modify_right_Ll(temp2);
case(1): return modify_right_Lu(temp2);
case(2): return modify_right_Lr(temp2);
case(3): return modify_right_Ld(temp2);
}
case(3): switch(position)
{
case(0): return modify_left_S1(temp2);
case(1): return modify_left_S2(temp2);
case(2): return modify_left_S1(temp2);
case(3): return modify_left_S2(temp2);
}
case(4): switch(position)
{
case(0): return modify_right_S1(temp2);
case(1): return modify_right_S2(temp2);
case(2): return modify_right_S1(temp2);
case(3): return modify_right_S2(temp2);
}
case(5): switch(position)
{
case(0): return modify_square(temp2);
case(1): return modify_square(temp2);
case(2): return modify_square(temp2);
case(3): return modify_square(temp2);
}
case(6): switch(position)
{
case(0): return modify_tetris_h(temp2);
case(1): return modify_tetris_v(temp2);
case(2): return modify_tetris_h(temp2);
case(3): return modify_tetris_v(temp2);
}
}
}
catch(ArrayIndexOutOfBoundsException e)
{}

return temp2;

}
public int[][] modify_cross_d(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY + 1] = 1;
temp[startPlaceX][startPlaceY + 2] = 1;
temp[startPlaceX + 1][startPlaceY + 1] = 1;
temp[startPlaceX - 1][startPlaceY + 1] = 1;
return temp;
}

public int[][] modify_cross_l(int temp[][])
{

for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX - 1][startPlaceY + 1] = 1;
temp[startPlaceX][startPlaceY] = 1;
temp[startPlaceX][startPlaceY + 1] = 1;
temp[startPlaceX][startPlaceY + 2] = 1;
return temp;
}
public int[][] modify_cross_u(int temp[][])
{

for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 1;
temp[startPlaceX - 1][startPlaceY + 1] = 1;
temp[startPlaceX][startPlaceY + 1] = 1;
temp[startPlaceX + 1][startPlaceY + 1] = 1;
return temp;
}

public int[][] modify_cross_r(int temp[][])
{

for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 1;
temp[startPlaceX][startPlaceY + 1] = 1;
temp[startPlaceX][startPlaceY + 2] = 1;
temp[startPlaceX + 1][startPlaceY + 1] = 1;
return temp;
}

public int[][] modify_left_Ll(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}


temp[startPlaceX][startPlaceY] = 2;
temp[startPlaceX][startPlaceY - 1] = 2;
temp[startPlaceX - 1][startPlaceY] = 2;
temp[startPlaceX - 2][startPlaceY] = 2;
return temp;
}

public int[][] modify_left_Lu(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}


temp[startPlaceX][startPlaceY] = 2;
temp[startPlaceX][startPlaceY - 1] = 2;
temp[startPlaceX][startPlaceY - 2] = 2;
temp[startPlaceX + 1][startPlaceY] = 2;
return temp;
}

public int[][] modify_left_Lr(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
this is Piece part I

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:27 AM   #6
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

Quote:
temp[startPlaceX][startPlaceY] = 2;
temp[startPlaceX + 1][startPlaceY] = 2;
temp[startPlaceX + 2][startPlaceY] = 2;
temp[startPlaceX][startPlaceY + 1] = 2;
return temp;
}

public int[][] modify_left_Ld(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}


temp[startPlaceX - 1][startPlaceY] = 2;
temp[startPlaceX][startPlaceY] = 2;
temp[startPlaceX][startPlaceY + 1] = 2;
temp[startPlaceX][startPlaceY + 2] = 2;
return temp;
}

public int[][] modify_right_Ll(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 3;
temp[startPlaceX - 1][startPlaceY] = 3;
temp[startPlaceX - 2][startPlaceY] = 3;
temp[startPlaceX][startPlaceY + 1] = 3;
return temp;
}

public int[][] modify_right_Lu(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY - 2] = 3;
temp[startPlaceX][startPlaceY - 1] = 3;
temp[startPlaceX][startPlaceY] = 3;
temp[startPlaceX - 1][startPlaceY] = 3;
return temp;
}

public int[][] modify_right_Lr(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY - 1] = 3;
temp[startPlaceX][startPlaceY] = 3;
temp[startPlaceX + 1][startPlaceY] = 3;
temp[startPlaceX + 2][startPlaceY] = 3;
return temp;
}

public int[][] modify_right_Ld(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 3;
temp[startPlaceX + 1][startPlaceY] = 3;
temp[startPlaceX][startPlaceY + 1] = 3;
temp[startPlaceX][startPlaceY + 2] = 3;
return temp;
}

public int[][] modify_left_S1(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 4;
temp[startPlaceX - 1][startPlaceY] = 4;
temp[startPlaceX][startPlaceY -1] = 4;
temp[startPlaceX+1][startPlaceY -1] = 4;
return temp;
}


public int[][] modify_left_S2(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 4;
temp[startPlaceX - 1][startPlaceY] = 4;
temp[startPlaceX-1][startPlaceY - 1] = 4;
temp[startPlaceX][startPlaceY + 1] = 4;
return temp;
}

public int[][] modify_right_S1(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 5;
temp[startPlaceX + 1][startPlaceY] = 5;
temp[startPlaceX][startPlaceY - 1] = 5;
temp[startPlaceX-1][startPlaceY -1] = 5;
return temp;
}

public int[][] modify_right_S2(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 5;
temp[startPlaceX][startPlaceY-1] = 5;
temp[startPlaceX-1][startPlaceY] = 5;
temp[startPlaceX-1][startPlaceY + 1] = 5;
return temp;
}

public int[][] modify_square(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 6;
temp[startPlaceX][startPlaceY-1] = 6;
temp[startPlaceX-1][startPlaceY-1] = 6;
temp[startPlaceX-1][startPlaceY] = 6;
return temp;
}


public int[][] modify_tetris_v(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 7;
temp[startPlaceX][startPlaceY - 1] = 7;
temp[startPlaceX][startPlaceY - 2] = 7;
temp[startPlaceX][startPlaceY - 3] = 7;
return temp;
}

public int[][] modify_tetris_h(int temp[][])
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != -1)
temp[i][j] = 0;
}
}
temp[startPlaceX][startPlaceY] = 7;
temp[startPlaceX + 1][startPlaceY] = 7;
temp[startPlaceX + 2][startPlaceY] = 7;
temp[startPlaceX + 3][startPlaceY] = 7;
return temp;
}

public boolean checkIfDown(int[][] temp)
{

for (int i = 1; i < temp.length - 1; i++)
{
for (int j = 1; j < temp[i].length - 1; j++)
{
if (temp[i][j] != 0 && temp[i][j] != -1 && temp[i][j + 1] == -1)
{
killLiving(temp);
return true;
}
}
}
// System.out.println("Something doesn't need to be killed");
return false;
}

public boolean ableToMoveLeft(int [][]temp)
{
for (int i = 1; i < temp.length - 1; i++)
{
for (int j = 1; j < temp[i].length - 1; j++)
{
if (temp[i][j] != 0 && temp[i][j] != -1 && temp[i-1][j] == -1)
{
return false;
}
}
}
return true;
}

public boolean ableToMoveRight(int [][]temp)
{
for (int i = 1; i < temp.length - 1; i++)
{
for (int j = 1; j < temp[i].length - 1; j++)
{
if (temp[i][j] != 0 && temp[i][j] != -1 && temp[i+1][j] == -1)
{
return false;
}
}
}
return true;
}


public boolean ableToMoveDown(int [][]temp)
{
for (int i = 1; i < temp.length - 1; i++)
{
for (int j = 1; j < temp[i].length - 1; j++)
{
if (temp[i][j] != 0 && temp[i][j] != -1 && temp[i][j+1] == 0 && temp[i][j+2] != -1)
{
return true;
}
}
}
return false;
}



this is pieces part II.

the README is the first post.
Read it.

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:28 AM   #7
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

Quote:
public void killLiving(int[][] temp)
{
for (int i = 0; i < temp.length; i++)
{
for (int j = 0; j < temp[0].length; j++)
{
if (temp[i][j] != 0)
{
temp[i][j] = -1;
}
}
}
}

public int checkIfCleared(int[][]temp)
{
// System.out.println("Check if cleared called");
// System.out.println("The height is = " + temp[0].length);
// System.out.println("The width is = " + temp.length);
// System.out.println("Scanner from 1 to " + (temp[0].length-1));
//from 1-20
int lines_cleared = 0;
int counter = 0;
int tracker = 0;

boolean checker = true;
int j = 1;
for (int i = 1; i < temp[0].length-1; i++)
{
counter = 0;
// System.out.println("i = " + i);

for(j = 1;j<temp.length-1;j++)
{
tracker = i;
// System.out.println("tracker = " + tracker);//20
// System.out.println("temp.length-1 = " + (temp.length-1));

if(temp[j][tracker] == -1)
{
counter ++;
if(counter == 10)
{
for(int h = 1;h<temp.length-1;h++)
{
temp[h][tracker] = -2;
lines_cleared++;
}

}
}
}

}
return lines_cleared;

}
/*
public void bringDownRest(int [][]temp)
{
for (int i = 1; i < temp.length-1; i++)
{
for(int j = 1;j<temp[0].length-1;j++)
{
temp[j][i] = temp[j][i-1];
}
}
}*/

public void cleanOutBoard(int[][]temp)
{
for (int i = 1; i < temp.length-1; i++)
{
for(int j = 1;j<temp[0].length-1;j++)
{
if(temp[i][j]== -2)
{
temp[i][j] = 0;
}
}
}
}

public boolean checkIfGameOver(int[][]temp)
{
for (int i = 1; i < temp.length-1; i++)
{
for(int j = 1;j<temp[0].length-1;j++)
{
if(temp[i][j] == -1 && j<2)
{
return true;
}
}
}

return false;
}

public void killScreen(int [][] temp)
{
for (int i = 0; i < temp.length; i++)
{
for(int j = 0;j<temp[0].length;j++)
{
temp[i][j] = -2;
}
}
}


}
this is pieces part III.
pieces is big

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 01:29 AM   #8
The_Bear
Do you know where my Papi is?
 
The_Bear's Avatar
 
Join Date: Jan 2007
Location: thanks for the help on the paper! go to labor/employment section to read it
Age: 5
Posts: 3,877
The_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of lightThe_Bear is a glorious beacon of light
Default Re: Tetris Source Code:

by the way, sorry about the crappy formatting, it went wrong putting it on PH.

The ignorant ask "what is my effect on the world?"
The enlightened ask "What does the world know about itself?"

The Bear

I am The Bear
The Bear
The_Bear is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 12-18-2007, 12:19 PM   #9
TenGig
Question, what is it that everybody has, and some pirates and theives try to take....
 
TenGig's Avatar
 
Join Date: Mar 2007
Location: Googling Kanada. Did you mean Canada?
Age: 25
Posts: 5,143
TenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to beholdTenGig is a splendid one to behold
Default Re: Tetris Source Code:

So it works at least?