Kayl Levi Seth Christian Alex S Vanessa Joe B Arthi Keqin Arif He He Jared Rajeev 
Rerajitha Siddartha Jiebo Xing Yinan Max Jiahao Matt Zhiwei Chenrui Sunghyun Xinyu 
Haoyang A Ray Jerry S David Lee Brandon P Mike C Andrew T Jiawei Alex Q 

import java.awt.*; 

public interface World {
  public boolean hasEnded(); 
  public void draw(Graphics g); 
  public void update(); 
  public void keh(String key); 
}

-------------------------------------------------------------(           )------

import java.awt.*; 
import javax.swing.*;

public class Tetris implements World {
  public Tetris() {
    super(); 
    this.current = new T( 20, 50 ); 
  }
  Tetromino current; 
  public boolean hasEnded() { 

    return false; 
  } 
  public void draw(Graphics g) { 
    this.current.draw(g); 
  }
  private int count;
  public void update() { 
    this.count += 1; 
    System.out.println( count ); 
  }
  public void keh(String key) { 
    if (key.equals("left")) {
      this.current.moveLeft(); 
    } else if (key.equals("right")) {
      this.current.moveRight(); 
    } else if (key.equals("up")) {
      this.current.moveUp();       
    } else if (key.equals("down")) {
      this.current.moveDown(); 
    } else if (key.equals("rotate")) {
      this.current.rotate(); 
    } else {
      
    }
  }
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    a.setSize(200, 500); 
    a.setVisible(true); 
    BigBang b = new BigBang( new Tetris() );
    a.addKeyListener( b ); 
    a.getContentPane().add( b ); 
    b.start(); 
  }
}

-------------------------------------------------------------(           )------

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

public class BigBang extends JComponent
                     implements ActionListener, 
                                KeyListener {
  World world; 
  Timer timer; 
  public BigBang(World w) {
    this.world = w;     
    this.timer = new Timer(1000, this);

  }
  public BigBang(int delay, World w) {
    this.world = w;     
    this.timer = new Timer(delay, this);
     
  }
  public void start() {
    this.timer.start();  
  }
  public void keyPressed(KeyEvent e) { 
    int code = e.getKeyCode(); 
    switch (code) {
      case 37: // left 
               this.world.keh( "left" ); 
               break;
      case 38: // up 
               this.world.keh( "up" ); 
               break;
      case 39: // right
               this.world.keh( "right" ); 
               break;
      case 40: // down 
               this.world.keh( "down" ); 
               break;
      default: // what?!
               this.world.keh( "rotate" );                    
               break; 
    }
    this.repaint(); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }
  public void actionPerformed(ActionEvent e) { 
    this.world.update(); 
    this.repaint(); 
  }
  public void paintComponent(Graphics g) {
    this.world.draw(g);  
  }
}

-------------------------------------------------------------(           )------

import java.awt.*; 
import java.util.*; 

public abstract class Tetromino extends ArrayList<Block> {
  protected int x, y; 
  protected int direction; // will take values 0, 1, 2, 3
  public Tetromino(int x, int y) {
    super(); // since I am in fact an ArrayList of Blocks
    this.x = x; 
    this.y = y; 
  }
  public void draw(Graphics g) {
    for (Block b : this)
      b.draw(g); 
  }
  public void moveLeft() {
    this.x -= Block.SIZE;  
    for (Block b : this) b.moveLeft(); 
  }
    public void moveRight() {
    this.x += Block.SIZE; 
    for (Block b : this) b.moveRight(); 
  }
  public void moveUp() {
    this.y -= Block.SIZE;  
    for (Block b : this) b.moveUp(); 
  } 
  public void moveDown() {
    this.y += Block.SIZE;  
    for (Block b : this) b.moveDown(); 
  }
  public abstract void rotate(); 
}

-------------------------------------------------------------(           )------

import java.awt.*; 

public class T extends Tetromino {
  
  final static int[][][] shape = 
  {
    { { 0, 1, 0 },
      { 1, 1, 1 },
      { 0, 0, 0 }
    }, // index 0 in the shape array 
    { { 0, 1, 0 },
      { 0, 1, 1 },
      { 0, 1, 0 }
    }, // index 0 in the shape array 
    { { 0, 0, 0 },
      { 1, 1, 1 },
      { 0, 1, 0 }
    }, // index 0 in the shape array 
    { { 0, 1, 0 },
      { 1, 1, 0 },
      { 0, 1, 0 }
    }, // index 0 in the shape array 
        
  }; 
  
  public void rotate() {
    this.direction += 1; // reminder a op= b; is the same as a = a op b;  
    this.direction %= 4; 
    // what else 
    this.reset(); 
  }
  
  private void reset() {
    this.clear(); 
    for (int i = 0; i < shape[direction].length; i++) 
      for (int j = 0; j < shape[direction][i].length; j++) 
        if (shape[direction][i][j] == 1)
          this.add( new Block( this.x + Block.SIZE * j, 
                               this.y + Block.SIZE * i, 
                               Color.YELLOW
                             ) 
                  );      
  }
  
  public T(int x, int y) {
    super(x, y); 
    this.reset();             
  }
}

-------------------------------------------------------------(           )------

import java.awt.*; 

public class Block {

  final static int SIZE = 20; 
  
  private int x, y, w, h;
  private Color c; 
  public Block(int x, int y, Color c) {
    this.x = x;    
    this.y = y;    
    this.w = Block.SIZE;    
    this.h = Block.SIZE;    
    this.c = c;    
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillRect(this.x, this.y, this.w, this.h); 
    g.setColor(Color.BLACK); 
    g.drawRect(this.x, this.y, this.w, this.h); 
  }
  public void moveLeft( ) { this.x -= Block.SIZE; } 
  public void moveRight() { this.x += Block.SIZE; } 
  public void moveUp(   ) { this.y -= Block.SIZE; } 
  public void moveDown( ) { this.y += Block.SIZE; } 
}

-------------------------------------------------------------(           )------

So finish this by tomorrow and call it Stage Two. 

We should implement Stage Three tomorrow in class.