Mingming L, Abigail F, Alex N, Carlie B, Tyler R, Peyton R, Jonah W, Jake P, 
Sam Madden, Nick H, Brent H, Hongjian J, Clint S, Kyle E, Shayan K, Wenhao W, 
Akash S, Tyler D, Kevin Jiawei Z, Vjatcheslav K, Alex T, Sam Maginot, Sha Li, 
Tim M, Raja R, Yaxin T, Jeremy deF, Ben L, Alan R, Steven R, Joe P, Likang X,
Liyuan H, Daniel, 

Project Stage One: equivalent to Lab last week

The framework is composed of an interface and a class: 

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); 
}

The class is the engine: 

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) { } 
}

How do you implement a game? 

class Tetris implements World {
  Tetris() {

  }
  public void draw(Graphics g) { } 
  public void update() { } 
  public boolean hasEnded() { } 
  public void keyPressed(KeyEvent e) { } 
  public static void main() {
    BigBang game = new BigBang(200, new Tetris( ));
    JFrame frame = new JFrame("Stage One"); 
    frame.setVisible(true); 
    frame.setSize(400, 400); 
    frame.getContentPane().add( game );
    game.start(); 
  } 
}

This is what you should turn in for Stage One?

What do we do for Stage Two? 

I propose that we convert the reference implementation to Java. 

It seems like the block size should be 20 pixels. 

The board width should 10 columns (blocks). 

The height of the board should be 20 rows (blocks). 

I realize now that we never did discuss 2-dimensional arrays. 

The board in rows and columns of block spaces is such an array. 

Block[][] board = new Block[20][10]; // 20 rows of 10 columns each

What is x, what is y? 

board[i][j] represents row (i+1) and column (j+1) 

It appears that i is a y and j is an x. 

Let's move on. 

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) { // dx likely dColumns and dy likely dRows
    this.x += dx; 
    this.y += dy; 
  } 
  void rotateCCW(Point center) {
    this.x = center.x + center.y - this.y; 
    this.y = center.y + this.x - center.x;
  } 
  void CW(Point center) {
    this.rotateCCW(); 
    this.rotateCCW(); 
    this.rotateCCW(); 
  } 
}

class Tetra {
  Point center; 
  BSet blocks; 
  Tetra(Point c, BSet b) {
    this.center = c;
    this.blocks = b;
  } 
}

class BSet extends ArrayList<Block> { // how about HashMap<Block> ?
  boolean contains(Block b) {
    if (this.size() != 0) 
      for (Block block : this) 
        if (block.equals(b)) 
          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) {
    return this.subset(other) && other.subset(this); 
  } 
  BSet intersect(BSet other) {

  }
  BSet union(BSet other) {

  }
  BSet count() {
    return this.size(); 
  } 
  int maxY() { } 
  int minX() { } 
  int maxX() { } 
  void move(int dx, int dy) { } 
  void rotateCCW(Point center) { } 
  void rotateCW(Point center) { } 
  void changeColor(Color color) {

  } 
  boolean overflow() { } 
  ...
}

...

class World { // This is actually Tetris 
  Tetra current; 
  BSet blocks; 



So for Wed try to finish this and show something (Block, BSet etc.)