官术网_书友最值得收藏!

Adding game logic to the matching game

Let's now imagine holding a real deck in our hand and setting up the matching game.

We would first shuffle the cards in our hands and then we would put each card on the table with the back facing up. For an easier gameplay, we align the cards into a 4 x 3 array. Now, the game is set up and we are going to play it.

We pick up one card and flip it to make it face up. We pick another one and face it upwards. Afterwards, we have two possible actions. We take away the two cards if they have the same pattern. Otherwise, we put them back facing down, as if we had not touched them. The game continues until we pair all of the cards.

The code flow will be much clearer after we have this step-by-step scenario in our mind. Actually, the code in this example is exactly the same as the procedure we play with a real deck. We just need to replace the human language into the JavaScript code.

主站蜘蛛池模板: 惠安县| SHOW| 东阿县| 荔波县| 伊川县| 当涂县| 阿克苏市| 英超| 苍山县| 富源县| 油尖旺区| 和顺县| 黄骅市| 浙江省| 桐柏县| 贡觉县| 江山市| 井研县| 通海县| 湘西| 天等县| 阿巴嘎旗| 交口县| 河津市| 辛集市| 富宁县| 阳朔县| 博湖县| 南华县| 即墨市| 西城区| 弥勒县| 原阳县| 方正县| 襄汾县| 凯里市| 洛宁县| 宁晋县| 荆门市| 阳新县| 教育|