building a scorekeeper - duke university · building a scorekeeper alice 3 tricks in mini trivia...
TRANSCRIPT
![Page 1: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/1.jpg)
BuildingaScorekeeperAlice3TricksinMiniTrivia (1/4)
ByVickiZhangDukeUniversity
UnderthedirectionofProfessorSusanRodger
June2017
0à -5à 20à 85
![Page 2: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/2.jpg)
AbouttheMiniTriviaChallengeMiniTriviaisafour-questiongamecreatedbyVickiZhang.Theauthorexplainsfourusefultopicsinvolvedinseparatetutorials:1. scorekeeper2. askinguserforananswer3. billboard4. multi-layeredobject
clicking
Thistutorialexplainshowtobuildascorekeeper.StartbydownloadingMini Trivia_Challenge 1 Scorekeeper_Start
![Page 3: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/3.jpg)
Togetstarted >>FindandcreateanewTextModel.
Setname toscore,andinitialvalue to0.
![Page 4: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/4.jpg)
Dragthetextontoaclearspot(shownonnextpage)usingtheDefault handlestyle.
Resizeitby- changingthedatadirectly- orusingtheResize handlestyle.
![Page 5: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/5.jpg)
Tweakittoroughlythissizeandlocation.
Colorcouldbechanged,ifsoinclined:----------------------------Whensatisfied,clickon
![Page 6: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/6.jpg)
OnenewProperty forScore
•Goal:Createapropertyusedtostorethevalueofcurrentscore•Purpose:Toaccessthevalueeasily•How:Addnewproperty for TextModel• Valuetype:wholenumber• Name:currentScore• Initializer:0
![Page 7: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/7.jpg)
NotethatweareenablingALLtextmodelsthispropertyandtheproceduresthatwewillcreate.
![Page 8: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/8.jpg)
AfteryouaddedthecurrentScore property,Aliceautomaticallycreatesaprocedure(setCurrentScore)andafunction(getCurrentScore).Wewillusethemsoon.
currentScore isapropertyoftheTextModel,andusedaparameterofthisprocedure
![Page 9: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/9.jpg)
ThreenewProcedures forScore
1. setScore
2. addScore(#)
3. reduceScore(#)
Notes💡 :• addScore(5) will add 5 to the score,andreduceScore(10) will subtract 10from the score.• The # sign in the procedure is aplaceholder demanding an input.Consider: If addScore did not havethis input, Alice would not know howmuch to add.Thisiscalledaparameter.
![Page 10: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/10.jpg)
SetScore
• AddTextModel ProcedureandnameitsetScore
• Thisprocedureiscreatedforthepurposeofsettingthecontentofdisplay
![Page 11: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/11.jpg)
DraginthesetValue procedure>>Select“customTextString”>>Press“Ok”directly.Theresultisshownbelow.Thenclickthetinytriangleontherightandselect
“”+???>>wholenumber>>currentScore
SetScore
![Page 12: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/12.jpg)
![Page 13: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/13.jpg)
SetScoreCompleted
![Page 14: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/14.jpg)
AddScore
• CreateasecondProcedurefortheTextModel• NameitaddScore• Addaparameterforthisprocedure• **sothatAliceknowshowmuch to add**• NametheparameterhowMuch
>>
![Page 15: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/15.jpg)
AddScore
•DraginthesetCurrentScore procedureandselectcurrentScore astheparameterinthedropdownmenu.•WewanttoaddtothecurrentScore byhowMuch• Theresultingformulashouldbe:
setCurrentScore to(currentScore +howMuch)• Processshownonnextpage.
![Page 16: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/16.jpg)
![Page 17: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/17.jpg)
AddScoreCompleted
ThepointofaddScore istoupdatethevalueofcurrentScore andupdatethescoredisplayedonthescreenbycallingsetScore.
![Page 18: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/18.jpg)
ReduceScore
• ThisismerelyanumericallyflippedversionofaddScore.• Tryityourselffirst!• Step-by-stepguideonthenextslide.
![Page 19: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/19.jpg)
ReduceScore
• CreateasecondProcedurefortheTextModel• NameitreduceScore• Addaparameterforthisprocedure• **sothatAliceknowshowmuch to reduce**• NametheparameterhowMuch
>>
![Page 20: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/20.jpg)
ReduceScore
•DraginthesetCurrentScore procedureandselectcurrentScore astheparameterinthedropdownmenu.•WewanttosubtracthowMuch fromthecurrentScore• Theresultingformulashouldbe:
setCurrentScore to(currentScore-howMuch)• Processshownonnextpage.
![Page 21: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/21.jpg)
![Page 22: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/22.jpg)
ReduceScoreCompleted
ThepointofreduceScore istoupdatethevalueofcurrentScore andupdatethescoredisplayedonthescreenbycallingsetScore.
![Page 23: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/23.jpg)
ScorekeeperCompleted!
• Nowwejusthavetoplugintheprocedurestoappropriateplacesinthegame.• YouwillhavecommentsinQuestionA,QuestionC,QuestionD,andinitializeEventListenersforguidance.
![Page 24: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/24.jpg)
Example:QuestionA
Step1:Gotoscene andyoushouldfindthesceneprocedures.
SelectquestionA procedure.
![Page 25: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/25.jpg)
Example:QuestionA
Step2:SelectonthelefttoolbarTextModel—this.score,whichisthevisualizedformofourscorekeeper
![Page 26: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/26.jpg)
Example:QuestionA•WecannowseeallproceduresofTextModel ontheleft,includingtheoneswecreated.• DraginaddScore intothedoTogether box,eitherbeloworabovethecomment.• Selectcustomwholenumberandtypein10.
![Page 27: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/27.jpg)
Example:QuestionA• Similarly,dragreduceScore in.Makesureyouplaceitatthesamelevelofthecomment,i.e.under“else”andoutsideofdotogether.• Selectcustomwholenumberandtypein5.
![Page 28: Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger](https://reader036.vdocuments.mx/reader036/viewer/2022081607/5edbc0a5ad6a402d66661ffc/html5/thumbnails/28.jpg)
Tryitout!
• Runthegameandclickonthehammer,whichcorrespondstoQuestionA.
• CommentsforQuestionsB,CandDarefound,respectively,ininitializeEventListeners,questionC,questionD.