Breakout 1972 1976 Over 10,000 students Due in week 5 of CS106A - - PowerPoint PPT Presentation

breakout 1972 1976 over 10 000 students due in week 5 of
SMART_READER_LITE
LIVE PREVIEW

Breakout 1972 1976 Over 10,000 students Due in week 5 of CS106A - - PowerPoint PPT Presentation

Breakout 1972 1976 Over 10,000 students Due in week 5 of CS106A Big program. Do it in parts 1 2 3 getCollidingObject 4 GObject collider = getElementAt( x , y ); , , a brick null Pro Tips v Want to wait for a click to start? Use


slide-1
SLIDE 1

Breakout

slide-2
SLIDE 2

1972 1976

slide-3
SLIDE 3
slide-4
SLIDE 4

Over 10,000 students Due in week 5 of CS106A

slide-5
SLIDE 5
slide-6
SLIDE 6

Big program. Do it in parts

1 2 3

slide-7
SLIDE 7

getCollidingObject

4 GObject collider = getElementAt(x, y); null a brick

, ,

slide-8
SLIDE 8
slide-9
SLIDE 9
slide-10
SLIDE 10

Pro Tips

v Want to wait for a click to start? Use waitForClick() v Do not animate in mouse moved! v Use instance var for paddle. v Make sure to test as you go. Program one milestone at a time. v No instance variable for bricks

slide-11
SLIDE 11

How do you know if you hit a brick?

4 GObject collider = getElementAt(x, y); null a brick

, ,

slide-12
SLIDE 12

Aside: Secret to how memory really works

slide-13
SLIDE 13

Who thinks this prints true?

public void run() { int x = 5; int y = 5; println(x == y); }

slide-14
SLIDE 14

Who thinks this prints true?

slide-15
SLIDE 15

Who thinks this prints true?

slide-16
SLIDE 16

Stack Diagrams

run

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; }

slide-17
SLIDE 17

Stack Diagrams

run

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; }

slide-18
SLIDE 18

Stack Diagrams

run toInches feet

5

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; } f

slide-19
SLIDE 19

Stack Diagrams

run toInches feet

5

result

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; } f

60

slide-20
SLIDE 20

Stack Diagrams

run toInches feet

5

result

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; } f

60

s t a c k

slide-21
SLIDE 21

Stack Diagrams

run

public void run() { println(toInches(5)); } private int toInches(int feet){ int result = feet * 12; return result; } f

60

slide-22
SLIDE 22

Aside: Actual Memory

slide-23
SLIDE 23

What is a bucket

feet 5

slide-24
SLIDE 24

What is a bucket

feet

1011100111100011 0011010110010100 * Each bucket or “word” holds 64 bits ** don’t think on the binary level (yet)

slide-25
SLIDE 25

variables have fixed size buckets to store values

slide-26
SLIDE 26

Piech, CS106A, Stanford University

Primitives vs Classes

Primitive Variable Types Class Variable Types int double char boolean GRect GOval Gline Color Class variables (aka objects)

  • 1. Have upper camel case types
  • 2. You can call methods on them
  • 3. Are constructed using new
  • 4. Are stored in a special way
slide-27
SLIDE 27

Piech, CS106A, Stanford University

Primitives vs Classes

Primitive Variable Types Class Variable Types int double char boolean GRect GOval Gline Color Class variables (aka objects)

  • 1. Have upper camel case types
  • 2. You can call methods on them
  • 3. Are constructed using new
  • 4. Are stored in a special way

aka Objects

slide-28
SLIDE 28

Piech, CS106A, Stanford University Key:

How do you share wikipedia articles?

Antelope Canyon Article https://en.wikipedia.org/wiki/Antelope_Canyon

slide-29
SLIDE 29

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack

slide-30
SLIDE 30

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack

slide-31
SLIDE 31

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack

slide-32
SLIDE 32

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack

slide-33
SLIDE 33

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack 42

slide-34
SLIDE 34

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack 42 img

slide-35
SLIDE 35

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run heap stack 42 img 42

slide-36
SLIDE 36

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run img heap stack 42 42

slide-37
SLIDE 37

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run img heap stack 42 42

slide-38
SLIDE 38

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } run img heap stack 42 42

slide-39
SLIDE 39

Piech, CS106A, Stanford University

public void run() { GImage img = new GImage(”mountain.jpg”); add(img, 0, 0); } heap stack 42

slide-40
SLIDE 40

Piech, CS106A, Stanford University

slide-41
SLIDE 41

Piech, CS106A, Stanford University

Who thinks this prints true?

slide-42
SLIDE 42

Piech, CS106A, Stanford University

Who thinks this prints true?

memory.com/18

slide-43
SLIDE 43

Piech, CS106A, Stanford University

Who thinks this prints true?

memory.com/18

slide-44
SLIDE 44

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18

slide-45
SLIDE 45

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18

slide-46
SLIDE 46

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run

slide-47
SLIDE 47

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run

slide-48
SLIDE 48

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run

slide-49
SLIDE 49

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run

slide-50
SLIDE 50

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run second 18

slide-51
SLIDE 51

Piech, CS106A, Stanford University

Who thinks this prints true?

instance vars first memory.com/18 18 run second 18

slide-52
SLIDE 52