Several of my students want to make memory or matching games where the player sees a number of face-down "cards," flips over two of them, and attempts to find a match.
I'm pretty new to App Inventor and AI2 myself, so I made a prototype in AI2 and would appreciate your feedback about how I can revise my prototype to become as clear and simple as possible so that I can use it to guide my students. They are in Grade 7.
A screenshot of my code is attached. I used buttons as cards. A question mark in the button text represents the card being face down, and other text represents the card being face up.
Specifically, the most obvious area for improvement I see is that my prototype's code requires me to program each button separately. This creates room for bugs and goes against the principle of DRY ("don't repeat yourself").
This discussion and this discussion make it look like there's no built-in way to clone something or to use classes and inheritance to set the properties of buttons as desired, but this discussion gives me hope that I might be able to use coding language along the lines of "for all buttons on the screen, set the flipped-over text of the first two buttons to 'cat' (or something from a list) and the flipped-over text of the next two buttons to 'dog,' etc., to create matching button pairs that the player could find.
Is there indeed a way to make the code simpler for each button? In the final version, I would of course remove the commentary in places where it points out redundancy.
Are there also other ways to make the code simpler so that it would be easier for a Grade 7 student to understand?
--
A while ago I made a tic-tac-toe game implementation in AI2 and a bit longer ago a memory implementation in JavaScript.
Unfortunately there is no generic event handling possible in AI2, the best you can do is to make a procedure, which is called from the button.Clicked event which has as input an index number, pointing to the right button in a list which you made at initialization.
Here is a link to a pdf which shows the blocks http://www.squaringthecircles.com/AI2/tictactoe.pdf for my tic-tac-toe game. It is in Dutch, but it has not much text. It uses ImageSprites instead of buttons, but the principle is the same.
I can also send you the .aia if you wish. If you attach yours I will help you out.
--
Yes, there are ways to make your programming simpler.
In your lists, you can create the lists from a csv file. If you are matching images, the list items should be names of images stored in your Media perhaps (cat.png, cat2.png, dog.png, dog.png), if text, then the words should suffice. list from csv row text where the text is cat.png, cat2.png, dog.png, dog2.png or something similar.
Yes, you can use the Any component blocks (on the Block screen). If you name your buttons 1 , 2, 3 etc. you might simplify use of these components.
Instead of using buttons, you might use a Canvas with sprites for the matching elements. Here is 36 buttons but on a Canvas About the amount of BUTTONs they are not really buttons...the code will give you an idea how to do this. Use this in conjunction with image sprites representing your guessing tiles.
You will need to shuffle your lists and unless you want the same 'game' to repeat itself, will need to establish a random procedure that will select ALL items and distribute them randomly but will have to make sure that it only picks a random image once. This can be done in code OR by structuring how you design your lists. For instance, if you only have ONE cat image, your code is going to be complicated, but simplified if you have cat1 and cat2 which might be a copy of the identical image with a different name, chosen so that they do not need to be converted in other steps. To that end, naming images 1,2,3,4, etc might make sense.
Here are two links where others made 'matching' games ...they may give you additional ideas. These are AI Classic projects so be aware, look at the logic, not the blocks:
Some of these ideas may help you. What you need to do is to experiment first using a simple project where you learn to work with the Advanced blocks. As separate projects, consider programming the pieces of your game. When you are satisfied with your algorithms, put them together.
Be aware, what you are attempting to program is NOT simple; it is going to require a lot of logic to get to work smoothly.
What have you tried w.r.t. the advanced blocks?
--
this example might help
--
댓글 없음:
댓글 쓰기