Leland RemsonKristen HanshawMATH 152-202Plot Gamerestart:with(Maplets[Tools]):with(Maplets[Elements]):with(plots):StartEngine();lightorange:="#FFB300":great :=[
" Very Niiiiiiice!",
" Awesome. You're unstoppable. ",
" You got it! ",
" Way to go.",
" Awesome! ",
" Excellent! "
]:randgreat:=rand(1..nops(great)):bad := [
" Not quite, it's a little off. ",
" Ummmm.....no",
" Really close. You'll get it next time. ",
" Nice try, but your guess is wrong. ",
" So, that was just practice. ",
" Negative",
" Better luck next time. ",
" This one's pretty tough",
" Ask Dr. Yasskin for help, he's good!",
" Oh man, you were so close. "
]:randbad:=rand(1..nops(bad)):rand9:=rand(1..9):First:=true:new_problem:=proc()
global x0, y0, currentplot, First;
x0:=rand9();
y0:=rand9();
currentplot:=plot(0, x=0..10, y=0..10, labels=["",""], tickmarks=[11,11]);
Set(P1=display(currentplot), Dist="", xinput="", yinput="");
Set(reply="", reply(background)=white);
First:=false;
end proc:fn_eval:=proc()
global x0, y0, currentplot, First;
local userx, usery, N;
if First then
return;
end if;
if Get(xinput)="" or Get(yinput)="" then
return
end if;
userx:=Get(xinput::posint);
usery:=Get(yinput::posint);
N:=abs(userx-x0)+abs(usery-y0);
Set(Dist=N);
currentplot:=currentplot,textplot([userx,usery,N]);
Set(P1=display(currentplot));
if N=0 then
Set(reply=great[randgreat()],
reply(background)=green, reply(foreground)=black);
else
Set(reply=bad[randbad()],
reply(background)=red, reply(foreground)=white);
end if;
end proc:show_answer:=proc()
global x0, y0, currentplot;
if First then
return;
end if;
Set(xinput=x0);
Set(yinput=y0);
Set(Dist=0);
currentplot:=currentplot,textplot([x0,y0,0]);
Set(P1=display(currentplot));
Set(reply="Sorry, maybe you'll get it next time.",
reply(background)=lightorange, reply(foreground)=black);
end proc:PlotGame:=Maplet(onstartup=RunWindow(MAIN),
Window[MAIN]('title'="Plot Game", defaultbutton=BEnter,
[ valign=none, inset=0, spacing=0,
[ halign=none,
"Hit New Point to Start:",
Button[BtnNewProblem]("New Point", Evaluate(function="new_problem"),
background=magenta),
HorizontalGlue(),
Button("Quit", Shutdown(), background=pink)
],
[ halign=none, inset=0, spacing=0,
[ border=true,
caption="Guess the hidden point whose value is zero!",
[ halign=none,
"Enter a point and press Enter.",
HorizontalGlue()
],
[ halign=none,
HorizontalGlue(),
"x = ", TextField['xinput']('width'=3, background=turquoise),
HorizontalGlue(),
"y = ", TextField['yinput']('width'=3, background=turquoise),
HorizontalGlue()
],
[ halign=none,
Button[BEnter]("Enter", Evaluate(function="fn_eval"), background= lightorange)
],
[ halign=none,
"Get this number to be zero:",
TextField[Dist](width=3, 'editable'='false', background=white),
HorizontalGlue()
],
[ TextField[reply]('width'=30, 'editable'='false', background= white)
],
[ halign=none,
Button("Show Answer", Evaluate(function="show_answer"), background= lightorange)
]
],
[ border=true,
caption="Plot",
Plotter[P1](width=300, height=300)
]
],
[ halign=none,
"Idea: Gregory Berkolaika",
HorizontalGlue(),
"Programmers: Leland Remson & Kristen Hanshaw",
HorizontalGlue(),
"@ copyright P. Yasskin 2007"
]
]
)):Maplets[Display](PlotGame);LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYkdGJzYjLUkjbWlHRiQ2JVEhRicvJSdpdGFsaWNHUSV0cnVlRicvJSxtYXRodmFyaWFudEdRJ2l0YWxpY0Yn