Today and tomorrow in lab: two dimensional structures. 

There will be a box in OnCourse entitled Wednesday Afternoon Exercise. 

Place your code the one you created in lab in it for attendance.

You should write down a story describing the game. 

All the nouns are classes that you have to define. 

All the verbs are methods, static or not. 

I believe that there will a Game. 

The Game will be in touch with the User. 

(The User will be provided.)

The Game by the way could be a JFrame. 

There are Shapes. Who will be in charge of them? 

Where do the Shapes live? Maybe the Game creates them? 

I would like to make my game more general. 

What kind of games do I have in mind? 

How about games with keyboard input? 

My plan: 

  Game is an object that is created by the user. 
  Game is responding to user pressing keys. 
  Game creates a World that has time. 
  The World is in charge of creating Shapes. 
  Every so often the current Shape is moving down a bit (like leaves in Autumn). 
  If it can't move down any more (how do I determine that? ... maybe it will hit
the Ground) it becomes part of it (the Ground) and a new Shape is generated at the 
top and starts falling down. If I can't generate a new Shape it's the end of the
world and of the Game too. 

I will start implementing this. 

http://docs.oracle.com/javase/8/docs/api/javax/swing/Timer.html

http://docs.oracle.com/javase/8/docs/api/javax/swing/Timer.html#Timer-int-java.awt.event.ActionListener-

Here's my Game, general and such, creating a specific World (of Tetris). 

import javax.swing.*; 

class Game extends JFrame {
  World world; 
  Game() {
    this.setSize(200, 500); 
    this.setVisible(true); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
    this.world = new World(1000, new Announcer());   
    this.world.start(); 
  }
  public static void main(String[] args) {
    Game game = new Game();  
  }
}

How can the user interact with the Game. 

We need to add a KeyListener. 

Here's the world, we tried to make it the time itself: 

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

class World extends Timer {
  Ground ground; 
  World(int delay, ActionListener announcer) {
    super(delay, announcer); // because of constructor chaining
    this.ground = new Ground();     
    
  }
  
}

Unfortunately we had to deal with constructor chaining. 

So we didn't to talk about Shapes either. 

class Shape {
  
}

Part of the reason was that the world was invisible. 

Here's the ground, and we can stuff lots of Shapes in it, in order: 

import java.util.*; 

class Ground extends ArrayList<Shape> {
  
}

Here's the part without which we don't have a timer: 

import java.awt.event.*; 

class Announcer implements ActionListener {
  int count = 0; 
  public void actionPerformed(ActionEvent e) {
    this.count += 1; 
    System.out.println("Time is passing... " + count);  
  }
}

So what do we do next: 

(a) I believe that the story is still consistent

(b) I think the World needs to have a Timer instead of being one

(c) I think the World needs to be visible

I will make the World a JComponent 

I therefore think the World will look like this:


class World extends JComponent implements ActionListener {
  Timer timer;
  World() {
    this.timer = new Timer(1000, this); 
  }   
  public void actionPerformed(ActionEvent e) {
    ... 
  }
  ... 
}

  (d) the Shapes should be visible 

      Shapes are created and managed by the World. 

So this was Stage One. 

Actually Stage One is not finished. 

I should finish Stage One when what I have seems like it's Tetris.

My Stage Two will be done when the game is almost all there. 

My Stage Three will wrap it up and tie all the loose ends.

So this is the basic run down. 

I will have to finish the first stage tonight. 

--