CS223 Assignment 7

Build a Billiards App

Guidelines:
  1. The Billiards Game includes the cueBall and six other billiard balls.
  2. Code the game to include accurate 2-dimensional collisions and friction.
  3. Provide pockets along the wall of the table.
  4. Once a billard ball hits one of the pockets, it should be eliminated from the game.
The code segment shown below may be used in your document class.



            package {
                import flash.display.*;
                import flash.events.*;
                
                
                public class Controller extends MovieClip { 
                    //GAME ELEMENTS
                    private const NBALLS:Number = 7;	//THERE ARE SEVEN BALLS IN THE GAME
                    private var ballList = [];
                    private var cueBall: Ball;
            
                    
                    //CLASS CONSTRUCTOR:  
                    public function Controller() { 
                        //TASK 1: ADD BILLIARD BALLS AND POCKETS
                        init();
                        
                        //TASK 2:ADD A STICK
                        
                        
                        //TASK 3: REGISTER EVENT LISTENERS
                        
                    }
                
                    public function init(){
                        
                        //TASK 1:ADD A BILLIARD BALLS AND SET PROPERTIES
                        cueBall = new Ball(630, 331);
                        cueBall.setColor(255, 255, 255);
                        addChild(cueBall);
                        ballList.push(cueBall);
                        
                        var yellowB : Ball = new Ball(350, 300);
                        yellowB.setColor(255, 206, 0);
                        addChild(yellowB);
                        ballList.push(yellowB);
                        
                        var redB : Ball = new Ball(350, 330);
                        redB.setColor(255, 0, 0);
                        addChild(redB);
                        ballList.push(redB);
                        
                        var pinkB : Ball = new Ball(350, 360);
                        pinkB.setColor(214, 0, 218);
                        addChild(pinkB);
                        ballList.push(pinkB);
                        
                        var greenB : Ball = new Ball(377, 315);
                        greenB.setColor(0, 162, 0);
                        addChild(greenB);
                        ballList.push(greenB);
                        
                        var blueB : Ball = new Ball(377, 345);
                        blueB.setColor(0, 73, 255);
                        addChild(blueB);
                        ballList.push(blueB);
                        
                        var blackB : Ball = new Ball(402, 331);
                        addChild(blackB);
                        blackB.setColor(5, 5, 5);
                        ballList.push(blackB);
            
                    }
                }
            }