Christian Kayl Levi Seth Jared Joe Arthi Keqin Arif He He Mike C Rajeev Andrew T 
Alex Q Jiahao Xing W Siddartha Rerajitha Kevin S Jerry Shen Brandon Andrew Max Yinan 
Chenrui Matthew was in the bathroom 11:28-11:32 Vanessa Jiebo David Sunghyun Alex S 
Zhiwei Haoyang Xinyu Danny Guacamole, Jiawei #ap-l and Inktpot your hosts. 

Debug session: Tomcat manager. 

Final Exam: write the Tetris game 

import java.awt.*; 

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

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

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( "what?!" );                    
               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 javax.swing.*;

public class Tetris implements World {
  public Tetris() {
    super(); 
    this.current = new Tetromino( 20, 50, "tea"); 
  }
  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("what?!")) {
      
    } 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 java.awt.*; 
import java.util.*; 

public class Tetromino extends ArrayList<Block> {
  // private String text = "Welcome to Tetris!"; 
  private int x, y; 
  public Tetromino(int x, int y, String what) {
    this.x = x; 
    this.y = y; 
    if (what.equals("tea")) {
      this.add( new Block( this.x + 5 * 0, this.y + 5 * 1, 5, 5, Color.YELLOW ) ); 
      this.add( new Block( this.x + 5 * 1, this.y + 5 * 1, 5, 5, Color.YELLOW ) ); 
      this.add( new Block( this.x + 5 * 2, this.y + 5 * 1, 5, 5, Color.YELLOW ) ); 
      this.add( new Block( this.x + 5 * 1, this.y + 5 * 0, 5, 5, Color.YELLOW ) );       
    } else {
      
    }
  }
  public void draw(Graphics g) {
    // g.drawString("(" + this.x + ", " + this.y + ")", this.x, this.y); 
    for (Block b : this)
      b.draw(g); 
  }
  public void moveLeft() {
    this.x -= 5;  
    for (Block b : this) b.moveLeft(); 
  }
    public void moveRight() {
    this.x += 5; 
    for (Block b : this) b.moveRight(); 
  }
  public void moveUp() {
    this.y -= 5;  
    for (Block b : this) b.moveUp(); 
  } 
  public void moveDown() {
    this.y += 5;  
    for (Block b : this) b.moveDown(); 
  }
}

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

import java.awt.*; 

public class Block {
  private int x, y, w, h;
  private Color c; 
  public Block(int x, int y, int w, int h, Color c) {
    this.x = x;    
    this.y = y;    
    this.w = w;    
    this.h = h;    
    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 -= 5; } 
  public void moveRight() { this.x += 5; } 
  public void moveUp(   ) { this.y -= 5; } 
  public void moveDown( ) { this.y += 5; } 
}

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

Before lab:

  (a) modify the size of the blocks and make it customizable 

  (b) use that as a step for moving left, right, up, down etc.