15 Cellphone

15 Cellphone - Cell Phone Programming Cell Phone...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Cell Phone Programming Cell Phone Programming When you press the play button it will bring up a virtual cell phone To run the program, press the button under “launch” When you are happy with your program export it as a MIDlet 1 Cell Phone Programming Cell Phone Programming For input, you can use keyCode UP, DOWN, LEFT, RIGHT and FIRE refer to the five navigation buttons or you can use code like if(key == '*') to use the keypad 2 Getting the program on your cell Getting the program on your cell phone is the hard part First, you need a cell phone that supports Java, most don't It's easiest to get the program on your cell phone using a USB cable and your phone's software 3 Inflating Balloon Inflating Balloon Let's say I want to make an animation of a balloon that gets bigger, that is, it "inflates" I'll start by asking what a balloon has and what it does And then I'll write a class that models the object class Balloon { } 4 Inflating Balloon Inflating Balloon Balloon's have a size For each thing it has, we create a variable class Balloon { int size; int } 5 Inflating Balloon Inflating Balloon What balloons do is inflate and show up on the screen For each thing it does, we create a method class Balloon { int size; int void inflate() void { size++; size++; } void show() void { ellipse(150,150,size,size); ellipse(150,150,size,size); } } 6 The Balloon constructor The Balloon constructor Every class should have a special function called a constructor class Balloon { int size; int Balloon() Balloon() { size = 0; size } } void inflate() void { size++; size++; } void show() void { ellipse(150,150,size,size); ellipse(150,150,size,size); } 7 The Balloon constructor The Balloon constructor The constructor must have the same name as the class It doesn't have a return type, not even void It initializes the variables, that is, it sets them equal to their first values Balloon() { size = 0; size } 8 Inflating Balloon Inflating Balloon Once I've written my balloon class, I can use it to build a new Balloon() in my program Balloon bob; void setup() { bob = new Balloon(); bob size(300,300); size(300,300); } 9 Inflating Balloon Inflating Balloon Every time the screen is drawn, I want my Balloon to do it's thing Balloon bob; void setup() { bob = new Balloon(); bob size(300,300); size(300,300); } void draw() { background(0,0,0); background(0,0,0); bob.inflate(); bob.inflate(); bob.show(); bob.show(); } 10 Inflating Balloon Inflating Balloon The complete program looks like this 11 OOP and class OOP and The Pong assignment uses a class to model what Balls and Paddles have and do We use a class to make a "plan" or class to make a "plan" or "blueprint" of the object This is called Object Oriented Programming or just OOP 12 Here's the basic outline of the Here's the basic outline of the Bouncing Ball program Ball bob; //or //or Ball void setup() { //your code //your } void draw() { //your code //your } class Ball { //your code //your } whatever you want to call it here here here 13 An Instance of a class An Creating a class is like making a blueprint for a house It shows what the house will look like when you actually build it Designing a blueprint is different from building a house. It's the same with a class: The Ball class shows 14 what balls will have and do, when some are actually Here's the basic outline of the Here's the basic outline of the Bouncing Ball program Ball bob; //or whatever you want //or Ball void setup() { //other code not shown //other bob = new Ball(); bob } to call it void draw() { //your code here //your } class Ball { //your code here //your } 15 The constructor The constructor bob = new Ball(); Notice the parenthesis, we are actually calling a function, the constructor 16 The constructor The constructor class Ball { int x,y; int boolean up,right; boolean Ball() Ball() { ??? ??? } The constructor initializes the member variables 17 The constructor The constructor class Ball { int x,y; int boolean up,right; boolean Ball() Ball() { x = ??? ??? y = ??? ??? up = ??? ??? right = ??? ??? } 18 new new When you make a new object, it is said to be an instance of its class In Java, you make instances of a class with the word new new Ball(); You can create a variable for a Ball, by declaring it's type and initializing it, much like any variable Ball bob = new Ball(); bob new int num = 5; num 5; 19 The draw function with move, The draw function with move, bounce and display our ball Ball bob; //or whatever you want to call it void setup() { //your code here //your } void draw() { //other code not shown //other bob.move(); bob.move(); bob.bounce(); bob.bounce(); bob.show(); bob.show(); } class Ball { //your code here //your } 20 The dot operator The dot operator Once you have made an instance of a class, you can access its parts with a dot Ball bob; //the declaration //the Ball bob = new Ball(); //the initization //other java code not shown bob.move(); bob.bounce(); bob.show(); 21 Practice Quiz question: Find the output Practice Quiz question: Find the output void setup() { Thingy bob = new Thingy(); Thingy bob.num = 2; bob.num bob.mystery(); bob.mystery(); Thingy barbara = new Thingy(); Thingy barbara.mystery(); barbara.mystery(); println("bob: " + bob.num); println("barbara: " + barbara.num ); println("barbara: } class Thingy { int num; int Thingy() Thingy() { num = 3; num } void mystery() void { num = num *2; num } } 22 Pong Pong 23 Pong Pong 24 Pong Pong For many people, Pong was the first time they used a computer Brought the first computers into people's homes Written by Allan Alcorn (a Lowell grad) for Atari First Pong game was installed in a Sunnyvale bar in September 1972 Two weeks later the machine stopped working—because all the quarters had jammed it Original Paddles had eight segments— different segments gave different angles 25 Allan Alcorn The original arcade Pong game was basically The original arcade Pong game was basically some logic chips hooked up to an actual TV set with an added coin mechanism. 26 Pong was not the first computer Pong was game 10 years before Pong, there was another, much more sophisticated computer game… 27 Spacewar! Spacewar! 28 Spacewar! Spacewar! Written by members of the MIT model railroad club beginning in 1961 They also coined the word "hack" Code was kept in an unlocked drawer—anyone was free to modify it Programmed on the Digital Equipment PDP­1, one of the first computers with a monitor Club members built the world's first joysticks Later modified by Atari (stolen?) to become Asteroids 29 Pong Spin­offs Pong Spin­offs Pong Doubles 1973 30 Pong Spin­offs Pong Spin­offs Dr. Pong 1974 31 Pong Spin­offs Pong Spin­offs Cocktail Pong 1974 32 Pong Spin­offs Pong Spin­offs Puppy Pong 1974 33 Pong Spin­offs Pong Spin­offs Pin Pong 1974 34 Pong Spin­offs Pong Spin­offs Quadra Pong 1974 35 Pong Spin­offs Pong Spin­offs Super Pong 1974 36 Pong Spin­offs Pong Spin­offs Rebound 1974 37 Pong Spin­offs Pong Spin­offs Slime Volleyball 38 Pong Spin­offs Pong Spin­offs Breakout 1976 39 Pong Spin­offs Pong Spin­offs Bomb Bee 1979 40 Pong Spin­offs Pong Spin­offs 3d pong 41 Pong Spin­offs Pong Spin­offs circular pong 42 Pong Spin­offs Pong Spin­offs Warlords 43 Pong Spin­offs Pong Spin­offs Pong Clock­­As Pong randomly plays, the score shown is the time of day 44 Pong Spin­offs Pong Spin­offs Plasma Pong, uses fluid dynamics, so the ball seems to move through a fluid 45 And from these humble And from these humble beginnings… Computer gaming is now a huge industry with revenue over 7 billion dollars in 2005 'Mario' has made twice the revenue of all the 'Star Wars' movies combined Computer Games and entertainment software are the fastest growing area of the computer software industry (which is itself one of the fastest growing areas of the economy) 46 BallMaster BallMaster www.blueteagames.com by Steven Zhao class of 2001 In BallMaster, you guide a flying ball through dangerous adventures. With the aid of your computerized assistant, you fend off a variety of beasts that attack you as you float through the air. Other Games: Cactus Bruce and the Corporate Monkeys, Meeklits and HeliumMan-X 47 Pong Spin­offs Pong Spin­offs and many, many others. . . 48 Practice Quiz Question: Find the output Practice Quiz Question: Find the void setup() { TwoNums bob = new TwoNums(); TwoNums println(bob.mystery1()); println(bob.mystery1()); TwoNums TwoNums jane.d1 jane.d1 jane.n1 jane.n1 jane = new TwoNums(); = bob.d1 * 3; = int(bob.d1); println(jane.mystery1()); println(jane.mystery1()); bob.mystery2(); bob.mystery2(); println("Bob's float is " + bob.d1); } class TwoNums { int n1; int float d1; float TwoNums() TwoNums() { println("Constructing a new one"); println("Constructing n1 = 2; n1 d1 = 1.5; d1 } } int mystery1 () int { return int(n1*d1); return } void mystery2 () void { int nMys = mystery1(); int d1 = nMys + d1; d1 } 49 ...
View Full Document

This note was uploaded on 01/13/2012 for the course CS 12 taught by Professor Ma during the Spring '08 term at UC Davis.

Ask a homework question - tutors are online