Attendance for today:

Zhichao, Mary-Anne, Daniel, Adrian, Justin S., Kyle N., Kexin, Yinan, 
Artur, Justin B., Neelan, Max, Erik, Yunsheng, JSON, Adam K., Adam J., 
Chris McK, Scott B., Ruifeng, Yi, Hang, Jordan, Alex S., Dylan, Kyle C, 
Austin S. it's good to have you all here we're starting at:

class Point {
  int x, y;
  Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
}

import java.awt.*; 

abstract class Shape {
  Point center;
  Color color; 
  Shape(Point center, Color color) {
    this.center = center; 
    this.color = color; 
  }
  abstract void draw(Graphics g);
  void fall() {
    this.center.y += 2;  
  }
  void moveLeft() {
    this.center.x -= 5;  
  }
  void moveRight() {
    this.center.x += 5;  
  }
}

import java.awt.*; 

class Circle extends Shape {
  int radius; 
  Circle(Point center, int radius, Color color) {
    super(center, color);
    this.radius = radius;
  }
  public void draw(Graphics g) {
    g.setColor(this.color); 
    g.fillOval(this.center.x - this.radius,
               this.center.y - this.radius,
               2 * this.radius, 
               2 * this.radius);   
    g.setColor(Color.BLACK); 
    g.drawOval(this.center.x - this.radius,
               this.center.y - this.radius,
               2 * this.radius, 
               2 * this.radius);   

  }
}

import javax.swing.*; 

class Game extends JFrame {
  Game() {
    World tetris = new World(); 
    this.getContentPane().add( tetris ); 
    this.addKeyListener( tetris ); 
    this.setVisible(true); 
    this.setSize(300, 600); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
  public static void main(String[] args) {
    Game game = new Game(); 
  }
}

import javax.swing.JComponent;
import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.Graphics; 
import java.awt.Color; 

class World extends JComponent implements ActionListener, KeyListener {
  Timer timer; // this starts as null
  Ground ground;
  World() {
    this.timer = new Timer(100, this); 
    this.timer.start(); 
    this.ground = new Ground(); 
  }
  Shape current; // starts as null 
  public void actionPerformed(ActionEvent e) { 
    if (this.current == null) {
      this.current = new Circle( new Point(150, 0), 
                                 10 + (int) (60 * Math.random()), 
                                 new Color( (float) Math.random() , 
                                            (float) Math.random() , 
                                            (float) Math.random() ) 
                               ); 
    } else {
      this.current.fall();  
      if (this.current.center.y == 400) {
        this.ground.add( this.current ); 
        this.current = null; 
      }
    }
    this.repaint(); 
  }
  public void keyPressed(KeyEvent e) { 
    // System.out.println( e ); 
    if (e.getKeyCode() == 32) { // the space 
      this.current = null; 
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { // left arrow non-numpad key
      if (this.current != null) 
        this.current.moveLeft();
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { // right arrow non-numpad key 
      if (this.current != null) 
        this.current.moveRight();
    } 
    this.repaint(); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }
  public void paintComponent( Graphics g ) {
    if (this.current != null) 
      this.current.draw( g ); 
    this.ground.draw(g); 
  }
}


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

class Ground extends ArrayList<Shape> {
  void draw(Graphics g) {
    for (int i = this.size() - 1; i >= 0; i--) {
      this.get(i).draw(g);  
    }
  }
  
}

After much discussion we end up with this:

class Point {
  int x, y;
  Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
  double distanceTo(Point other) {
    int dx = this.x - other.x; 
    int dy = this.y - other.y; 
    return Math.sqrt( dx * dx + dy * dy ); 
  }
}

import java.awt.*; 

abstract class Shape {
  Point center;
  Color color; 
  World world; 
  Shape(Point center, Color color, World world) {
    this.center = center; 
    this.color = color; 
    this.world = world; 
  }
  abstract void draw(Graphics g);
  boolean fall() {
    this.center.y += 2;  
    if (world.ground.validates(this)) { 
      return true;
    } else {
      return false; 
    }
  }
  void moveLeft() {
    this.center.x -= 5;  
  }
  void moveRight() {
    this.center.x += 5;  
  }
  abstract boolean overlaps(Shape other); 
}

import java.awt.*; 

class Circle extends Shape {
  int radius; 
  Circle(Point center, int radius, Color color, World world) {
    super(center, color, world);
    this.radius = radius;
  }
  public void draw(Graphics g) {
    g.setColor(this.color); 
    g.fillOval(this.center.x - this.radius,
               this.center.y - this.radius,
               2 * this.radius, 
               2 * this.radius);   
    g.setColor(Color.BLACK); 
    g.drawOval(this.center.x - this.radius,
               this.center.y - this.radius,
               2 * this.radius, 
               2 * this.radius);   

  }
  boolean overlaps(Shape other) {
    if (other instanceof Circle) {
      Circle max = (Circle)other; 
      if (this.radius + max.radius >= this.center.distanceTo(max.center)) 
        return true;
      else 
        return false;         
    } else {
      return false; 
    }
  }
}

import javax.swing.*; 

class Game extends JFrame {
  Game() {
    World tetris = new World(); 
    this.getContentPane().add( tetris ); 
    this.addKeyListener( tetris ); 
    this.setVisible(true); 
    this.setSize(300, 600); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  }
  public static void main(String[] args) {
    Game game = new Game(); 
  }
}

import javax.swing.JComponent;
import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.Graphics; 
import java.awt.Color; 

class World extends JComponent implements ActionListener, KeyListener {
  Timer timer; // this starts as null
  Ground ground;
  World() {
    this.timer = new Timer(100, this); 
    this.timer.start(); 
    this.ground = new Ground(); 
  }
  Shape current; // starts as null 
  public void actionPerformed(ActionEvent e) { 
    if (this.current == null) {
      this.timer.setDelay(100);
      this.current = new Circle( new Point(150, 0), 
                                 10 + (int) (60 * Math.random()), 
                                 new Color( (float) Math.random() , 
                                            (float) Math.random() , 
                                            (float) Math.random() ),
                                 this
                               ); 
    } else {
      if ( this.current.fall() ) {
        
      } else {   
      // if (this.current.center.y == 400) {
         this.ground.add( this.current ); 
         this.current = null; 
      }
    }
    this.repaint(); 
  }
  public void keyPressed(KeyEvent e) { 
    // System.out.println( e ); 
    if (e.getKeyCode() == 32) { // the space 
      // this.current = null; 
      this.timer.setDelay(10); 
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) { // left arrow non-numpad key
      if (this.current != null) 
        this.current.moveLeft();
    } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { // right arrow non-numpad key 
      if (this.current != null) 
        this.current.moveRight();
    } 
    this.repaint(); 
  }
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }
  public void paintComponent( Graphics g ) {
    if (this.current != null) 
      this.current.draw( g ); 
    this.ground.draw(g); 
  }
}

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

class Ground extends ArrayList<Shape> {
  void draw(Graphics g) {
    for (int i = this.size() - 1; i >= 0; i--) {
      this.get(i).draw(g);  
    }
  }
  boolean validates(Shape shape) {
    int y = shape.center.y; 
    if (y >= 550) return false; 
    for (Shape s : this) {
      if (s.overlaps(shape)) {
        return false;
      }
    }
    return true;    
  }
}

Now we should summarize it, then decide on what we need to do in Stage Two.

Expect e-mail from me soon. 

--