Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia...

28
Building a Scorekeeper Alice 3 Tricks in Mini Trivia (1/4) By Vicki Zhang Duke University Under the direction of Professor Susan Rodger June 2017 0 à -5à 20à 85

Transcript of Building a Scorekeeper - Duke University · Building a Scorekeeper Alice 3 Tricks in Mini Trivia...

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

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

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

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

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

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

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

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

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

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

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

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
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

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

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

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
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

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

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

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

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
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

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

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

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

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

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

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

Tryitout!

• Runthegameandclickonthehammer,whichcorrespondstoQuestionA.

• CommentsforQuestionsB,CandDarefound,respectively,ininitializeEventListeners,questionC,questionD.