2017년 7월 14일 금요일

In Mole Mash, how can I add a second timer to put a limit to the game


I'd like to limit Mole Mash to a specific length of time and then stop the mole movement, clear the screen and show a final score.
I can't figure out how to do this.
Can anyone offer advice/guidance/solution, please?

--
Add a Clock called GameStopper  set to a single shot, 
timed to go off after the proper time.
Do all your game ending stuff in it.

Enable it at game start,
disable at game end (when it fires.)

--
At the age of 75 I've decided to teach myself how to write apps for my smartphone but, after reading your reply, its clear that I don't understand as much as I thought I did!!

I've created GameStopper and set "always fires" and a time interval of 10000 (I think that should be 10 seconds?). Is that what you meant?
The "Game ending stuff" I would like to put in would:
a) stop the mole moving and clear him from the screen
b) display the score in the centre of the screen
c) provide a button to start a new game of Mole Mash

Sadly, I'm pretty much lost at this point.
Thanks ABG for your reply. Can you, or anyone else please, either give me more detailed guidance or tell me where to find it for myself?

--
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

--
The "always fires" switch on a Clock is for repeating events like a metronome.
You want to keep that off.
Use the other switch, that enables (starts and stops) it.

A Notifier is a good way to pop up a message.
Pick the type that comes with an Okay button,
and look for the Notifier block that picks up after the Okay is hit
to start the new game.

Use the PrtSc button to take screen shots of your blocks,
Windows Paint to clip and save them, and attach them as files to your
post for others to see.

--
As suggested by Taifun (thanks) I attach a screen shot of my blocks to date.


--
Sorry, I attached the wrong doc. The correct one is here.


--
The game works, up to a point – the mole moves, the score of hits increments, the score goes back to zero with the reset button, but…..

I want to be able to stop the game after a predetermined time (10 sec, say, for testing). I’m using GameStopper for this.

I think I need to do this inside MoleTimer (which already successfully makes the mole move randomly).

So, what I think I want to do is:

When MoleTimer If GameStopper reached Call StopMole  (which should stop the mole somewhere in the screen) Else Call MoveMole

Later I plan to add a display of the scores (hits and misses) into StopMole.

BUT…. It doesn’t seem to get to StopMole. Presumably GameStopper isn’t working? Or, is the app just not getting to it? Why?
Can I have two timers running at the same time?

It seem to me that there must be some basic concepts that I’m not grasping, but What Are They? 
I’ve tried studying the links ABG gave me but can’t make the leap from those to actually doing the above. 
I’d really, really appreciate two things, please : 
1) specific help with the above and, for future use… 
2)  an “Idiot’s” Guide to using App Inventor 2.

I’ve attached a screen shot of what I’ve done so far.



--
Regarding 2, not for idiots but great for those that want to learn AI2:

We want you to have fun with App Inventor so here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .

Regarding 1,   have you read  Creating Animated Apps        ...it won't solve your clock issue but will help with animation concepts.
However, how long the game lasts?   Several ways to do this ...  one is the second post in this thread  https://groups.google.com/forum/#!searchin/mitappinventortest/count$20down$20timer%7Csort:date/mitappinventortest/nRj9P_m_xvo/GXqVFGOmScMJ   

You set the timer to go off for any time interval you want.  Remember the basic units are ms   (1000 ms = 1 second).

You will need to modify this example as it more complex than you require.   Try some blocks, if you have issues ask again.


Yes, you can have two timers running simultaneously.

--
See attached files for one way to do a single-clock countdown.





--
Nice code ABG!    Another way is shown in    
Magic Counts a simple count down clock or timer AI2 tutorial that uses a slightly different method and you might find it useful somewhere Charlie.

--


댓글 없음:

댓글 쓰기