methods part a alice in ac4on ch 2

Methods (part a) Alice In Ac4on, Ch 2 Slides Credit: - PDF document

CS101 Lecture 21 Methods (part a) Alice In Ac4on, Ch 2 Slides Credit: Joel Adams, Alice in Action With thanks to John Magee for his guidance about these materials Objec4ves Build


  1. CS101 Lecture 21 Methods ¡(part ¡a) ¡ Alice ¡In ¡Ac4on, ¡Ch ¡2 ¡ ¡ ¡ Slides Credit: Joel Adams, Alice in Action With thanks to John Magee for his guidance about these materials Objec4ves ¡ • Build ¡world-­‑level ¡methods ¡to ¡help ¡organize ¡a ¡ story ¡into ¡scenes ¡and ¡shots ¡ • Use ¡dummies ¡to ¡reposi4on ¡the ¡camera ¡for ¡ different ¡points ¡of ¡views ¡within ¡a ¡scene ¡ ¡ • Understand ¡how ¡an ¡object’s ¡ posi%on , ¡ orienta%on , ¡and ¡ point ¡of ¡view ¡ are ¡described, ¡ changed ¡and ¡determined ¡ • Documen4ng ¡your ¡code ¡with ¡comments. ¡ • Understand ¡Flow ¡of ¡Control ¡with ¡methods. ¡ 2 1

  2. Methods ¡ • Methods ¡ ¡ – behavior-­‑producing ¡messages ¡(from ¡the ¡sender’s ¡view) ¡ – behaviors/ac4ons ¡in ¡response ¡to ¡requests, ¡messages ¡ (from ¡the ¡recipient’s ¡view) ¡ – E.g. ¡in ¡world.my_first_method: ¡whiteRabbit.pointat(camera) ¡ ¡ • Conven4on ¡for ¡naming ¡methods ¡ – Name ¡should ¡be ¡a ¡verb ¡or ¡verb ¡phrase ¡ – Name ¡should ¡describe ¡what ¡the ¡method ¡does ¡ • A ¡method ¡is ¡a ¡way ¡to ¡name ¡a ¡block ¡of ¡code. ¡ 3 Methods ¡ • Objects ¡have ¡predefined ¡methods ¡for ¡common ¡tasks ¡ ¡ • Methods ¡may ¡also ¡be ¡created ¡by ¡Alice ¡developers ¡ – Two ¡main ¡reasons ¡for ¡building ¡your ¡own ¡methods ¡ • To ¡provide ¡an ¡object ¡with ¡addi4onal ¡behaviors ¡(last ¡week) ¡ • To ¡organize ¡your ¡story ¡and ¡program ¡into ¡more ¡manageable ¡pieces ¡ (Today) ¡ • Divide ¡and ¡conquer ¡methodology ¡ – Break ¡a ¡big ¡problem ¡into ¡smaller ¡problems ¡ – Solve ¡each ¡of ¡the ¡smaller ¡problems ¡ – Combine ¡the ¡solu4ons ¡of ¡ ¡smaller ¡problems ¡into ¡a ¡solu4on ¡for ¡ the ¡original, ¡big ¡problem ¡ • Hiding ¡complex ¡details ¡with ¡abstrac4on. ¡ ¡ Alice in Action with Java 4 2

  3. World ¡Methods ¡for ¡Scenes ¡and ¡Shots ¡ ¡ • User ¡stories ¡can ¡be ¡divided ¡into ¡scenes ¡and ¡shots ¡ – Scene: ¡segment ¡of ¡a ¡story, ¡usually ¡set ¡in ¡one ¡loca4on ¡ ¡ – Shot: ¡part ¡of ¡a ¡scene, ¡normally ¡from ¡one ¡fixed ¡camera ¡view ¡ • Use ¡mul4ple ¡scenes ¡and ¡shots ¡to ¡create ¡a ¡program ¡that ¡reflects ¡the ¡user ¡ story ¡and ¡ ¡has ¡a ¡modular ¡design ¡ • ¡ ¡ ¡ Two shots of one scene 5 Methods ¡for ¡Scenes ¡ • Example: ¡develop ¡a ¡user ¡story ¡with ¡three ¡scenes ¡ • Crea4ng ¡the ¡first ¡new ¡method ¡ – Select ¡the ¡ world ¡object ¡ – Click ¡the ¡ create new method ¡in ¡the ¡details ¡area ¡ – Enter ¡ playScene1 ¡in ¡the ¡ New Method ¡dialog ¡box ¡ • Check ¡new ¡method ¡by ¡sending ¡ say() ¡to ¡ ground – First ¡test ¡fails ¡because ¡ my_first_method() ¡is ¡ empty ¡ 6 3

  4. Methods for Scenes (continued) Alice in Action with Java 7 Methods for Scenes (continued) Alice in Action with Java 8 4

  5. Methods ¡for ¡Scenes ¡(con4nued) ¡ • How ¡to ¡fix ¡the ¡first ¡bug ¡ – Click ¡on ¡the ¡tab ¡for ¡ my_first_method ¡ ¡ – Drag ¡a ¡ doInOrder ¡ control ¡to ¡the ¡top ¡of ¡the ¡pane ¡ – Click ¡on ¡ world ¡ in ¡the ¡ object ¡tree ¡ – Drag ¡ playScene1() ¡ into ¡the ¡ doInOrder ¡ statement ¡ • Extend ¡technique ¡used ¡to ¡build ¡ playScene1() ¡ ¡ – Add ¡two ¡methods: ¡ playScene2() , playScene3 () – New ¡method ¡sends ¡a ¡ say() ¡message ¡to ¡the ¡ground ¡ – New ¡Methods ¡are ¡called ¡in ¡ my_first_method() Alice in Action with Java 9 Methods for Scenes (continued) Alice in Action with Java 10 5

  6. Methods for Scenes (continued) 11 Methods ¡for ¡Shots ¡ • Example ¡of ¡a ¡scheme ¡using ¡scenes ¡and ¡shots ¡ – Level ¡1: ¡ my_first_method() – Level ¡2: ¡three ¡methods ¡for ¡three ¡scenes ¡ – Level ¡3: ¡four ¡methods ¡for ¡four ¡shots ¡in ¡Scene ¡2 ¡ 12 6

  7. Methods ¡for ¡Shots ¡(con4nued) ¡ • Implemen4ng ¡the ¡scheme ¡ – Test ¡each ¡shot ¡in ¡Scene ¡2 ¡using ¡a ¡ say() ¡method ¡ – Call ¡the ¡four ¡shot ¡methods ¡from ¡ playScene2() – Call ¡three ¡scene ¡methods ¡from ¡ my_first_method() • Structure ¡diagram ¡reflects ¡organiza4on ¡of ¡user ¡ story ¡ • Scene ¡and ¡shot ¡messages ¡are ¡stored ¡in ¡the ¡ world Alice in Action with Java 13 Methods for Shots (continued) Alice in Action with Java 14 7

  8. World ¡and ¡Object ¡Methods ¡ • World ¡method: ¡affects ¡behavior ¡of ¡all ¡objects ¡in ¡ a ¡world ¡ • Object ¡method: ¡defines ¡behavior ¡for ¡a ¡single ¡ object ¡(that ¡may ¡have ¡mul4ple ¡parts) ¡ – examples : flapWings() for ¡dragon, ¡hop() ¡for ¡a ¡ rabbit… ¡ Alice in Action with Java 15 Program ¡Documenta4on ¡ • Standalone ¡readme, ¡manual… ¡ • Comments: ¡explanatory ¡remark ¡ignored ¡by ¡ Alice ¡ – an ¡integral ¡part ¡of ¡code ¡ ¡ – Used ¡to ¡describe ¡what ¡code ¡does ¡at ¡various ¡levels ¡ • the ¡overall ¡program, ¡individual ¡methods, ¡blocks ¡of ¡ statements…. ¡ – Useful ¡for ¡collaborators ¡and ¡developers ¡themselves ¡ – ¡Important ¡part ¡of ¡programming ¡ • ¡Also ¡a ¡component ¡evaluated ¡for ¡your ¡program ¡grades ¡ Alice in Action with Java 16 8

  9. Alice ¡Tip: ¡Using ¡Dummies ¡ • Review ¡ ¡ ¡ – Scenes ¡comprise ¡shots ¡ – Shots ¡are ¡filmed ¡with ¡the ¡camera ¡in ¡a ¡given ¡ posi4on ¡ – Alice ¡places ¡a ¡ camera ¡object ¡in ¡every ¡world ¡ • Two ¡techniques ¡for ¡shi_ing ¡posi4on ¡of ¡camera ¡ – Use ¡set ¡of ¡mo4on-­‑related ¡messages, ¡such ¡as ¡ move () ¡ ¡ – Use ¡an ¡invisible ¡marker ¡called ¡a ¡dummy ¡ 17 Dummies ¡ • Dummy: ¡invisible ¡marker ¡with ¡a ¡point ¡of ¡view ¡ • Dummies ¡are ¡used ¡to ¡change ¡a ¡camera’s ¡posi4on ¡ • Descrip4on ¡of ¡a ¡scene ¡that ¡will ¡use ¡dummies ¡ ¡ – Wizard ¡intervenes ¡to ¡prevent ¡trolls ¡from ¡taking ¡a ¡castle ¡ – Camera ¡changes ¡posi4on ¡for ¡each ¡of ¡three ¡shots ¡ – Story ¡conforms ¡to ¡structure ¡in ¡Figure ¡2-­‑11 ¡(less ¡Shot ¡4) ¡ • Seang ¡up ¡the ¡first ¡shot ¡of ¡Scene ¡2 ¡ ¡ – Add ¡ castle , ¡ wizard , ¡and ¡ trolls ¡to ¡build ¡the ¡scene ¡ ¡ – Click ¡ more controls ¡bubon ¡and ¡then ¡drop ¡a ¡dummy ¡ – Go ¡to ¡object ¡tree ¡and ¡rename ¡dummy ¡ scene2Shot1 18 9

  10. Dummies (continued) 19 Dummies (continued) 20 10

  11. Dummies ¡(con4nued) ¡ • Seang ¡up ¡the ¡second ¡shot ¡of ¡Scene ¡2 ¡ – Using ¡ camera ¡controls, ¡zoom ¡in ¡on ¡the ¡ wizard – Press ¡the ¡ drop ¡ dummy ¡ at camera ¡bubon ¡ – Rename ¡the ¡second ¡dummy, ¡ scene2Shot2 • Seang ¡up ¡the ¡third ¡shot ¡of ¡Scene ¡3 ¡ – First ¡dummy ¡will ¡be ¡reused ¡for ¡this ¡shot ¡ • A_er ¡dummies ¡are ¡inserted ¡they ¡will ¡be ¡ programmed ¡ ¡ 21 Dummies (continued) Alice in Action with Java 22 11

  12. Using ¡ setPointOfView() ¡to ¡ Control ¡the ¡Camera ¡ • obj.setPointOfView(obj2) – Changes ¡the ¡posi4on ¡of ¡ obj ¡ to ¡ obj2 – Example: ¡ camera.setPointOfView(aDummy) • Adding ¡code ¡to ¡the ¡first ¡shot ¡of ¡Scene ¡2 ¡ – Drag ¡a ¡ doInOrder statement ¡to ¡the ¡edi4ng ¡area ¡ – Click ¡on ¡camera ¡object ¡in ¡the ¡object ¡tree ¡ – Drag ¡ setPointOfView() to ¡the ¡edi4ng ¡area ¡ • Select ¡ scene2Shot1 ¡dummy ¡as ¡target ¡and ¡0 ¡ duration – Add ¡ say() ¡statements ¡for ¡each ¡of ¡the ¡trolls ¡ – Add ¡a ¡comment ¡to ¡explain ¡the ¡purpose ¡of ¡the ¡method ¡ Alice in Action with Java 23 Using setPointOfView() to Control the Camera (continued) Alice in Action with Java 24 12

Recommend


More recommend


Explore More Topics

Stay informed with curated content and fresh updates.