Erin, Shikun, Michael, Danielle, Shane, Connor, 
Taylor, Mahamat, Kokhi, Vinayak, Phoebe, Chen, Daniel, 
Kevin, Haleigh, Grant, Minh, Nick Palmer, Nick Palumbo, 
Joe G Topp, Ben B

Let's try to convert the reference implementation of Tetris. 

http://silo.cs.indiana.edu:8346/c212/spr2015/tetris.rkt

The world is 20 rows by 10 columns of 20x20 pixels blocks. 

class Block {
  int x, y; 
  Color c;
  Block(int x, int y, Color c) {
    this.x = x;
    this.y = y;
    this.c = c;  
  } 
  boolean equals(Block other) {
    return this.x == other.x && this.y == other.y; 
  }  
  void move(int dx, int dy) {

  } 
  void rotateCCW(Point center) {

  } 
  void rotateCW(Point center) {
    this.rotateCCW(center); 
    this.rotateCCW(center); 
    this.rotateCCW(center); 
  }
}

class Tetra {
  Point center; 
  BSet blocks; 
  Tetra(Point center, BSet blocks) {
    this.center = center; 
    this.blocks = blocks; 
  }
  void move(int dx, int dy) {
    
  } 
  void rotateCCW() {

  } 
  void rotateCW() { 

  } 
  boolean overlapsBlocks(BSET blocks) {
    
  } 
  void changeColor(Color color) {

  } 
}

class BSet extends ArrayList<Block> {
  boolean contains(Block block) {
    if (this.size() != 0) 
      for (Block b : this) 
        if (b.equals(block))
          return true; 
    return false; 
  }  
  boolean subset(BSet other) {
    if (this.size() != 0) 
      for (Block b : this)
        if (! other.contains(b))
          return false; 
    return true;
  }  
  boolean equals(BSet other) {

  } 
  BSet intersect(BSet other) {
    
  } 
  BSet union(BSet other) {
  
  }
  int count() {
    return this.size(); 
  } 
  int maxY() { } 
  int maxX() { } 
  int minX() { } 
  void move(int dx, int dy) {
    
  }
  void rotateCCW(Point center) {

  } 
  void rotateCW(Point center) {

  }
  void changeColor(Color c) {

  }
  boolean overflow() {
    
  } 
  Bset row(int i) {

  } 
  boolean rowFull(int i) {
    
  }
  void eliminateFullRows() {

  }
}

class World { // class Tetris implements World 
  Tetra falling;
  BSet blocks; 
  World(Tetra tetra, BSet blocks) {
    this.falling = tetra; 
    this.blocks = blocks;
  }
  void touchdown() {

  } 
  void jumpDown() {

  }
  boolean landedOnBlocks() { } 
  boolean landedOnFloor() { }
  boolean landed() { } 
  void nextWorld() { } // this is update    
  ... 
}

Try to finish this for Wednesday. 

Start bottom-up of stage three. 

What's Stage One? A World interface, a BigBang class and a Tetris class (w/ main) 

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

class Tetris implements World {
  public void draw(Graphics g) { System.out.println("World being drawn."); } 
  public void update() { System.out.println("World getting older."); }
  public boolean hasEnded() { return false; } 
  public void keyPressed(KeyEvent e) { System.out.println("Ouch."); } 
  public static void main(String[] args) {
    BigBang game = new BigBang(200, new Tetris()); 
    JFrame frame = new JFrame("Tetris"); 
    frame.getContentPane().add( game ); 
    frame.addKeyListener( game ); 
    frame.setVisible(true); 
    frame.setSize(400, 400); 
    game.start(); 
  }
}

This class the basic Tetris game. 

import java.awt.*; 
import java.awt.event.*; 

interface World {
  public void draw(Graphics g);
  public void update(); 
  public boolean hasEnded();
  public void keyPressed(KeyEvent e); 
}

This interface is part of the general game framework. 

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

class BigBang extends JComponent implements KeyListener, ActionListener {
  Timer timer; 
  World world; 
  BigBang(int delay, World world) {
    timer = new Timer(delay, this); 
    this.world = world;
  } 
  public void start() {
    timer.start();  
  }
  BigBang(World world) {
    this(1000, world);  
  }
  public void paintComponent(Graphics g) {
    world.draw(g);  
  }
  public void actionPerformed(ActionEvent e) {
    world.update(); 
    if (world.hasEnded())
      timer.stop(); 
    this.repaint(); 
  }
  public void keyPressed(KeyEvent e) { 
    world.keyPressed(e); 
  } 
  public void keyTyped(KeyEvent e) { } 
  public void keyReleased(KeyEvent e) { } 
}

--