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

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.

主站蜘蛛池模板: 湾仔区| 永福县| 奎屯市| 马山县| 枝江市| 句容市| 大洼县| 政和县| 南投县| 神农架林区| 郓城县| 安西县| 洪湖市| 盐山县| 宁乡县| 开阳县| 林口县| 化州市| 邵阳市| 托克逊县| 武冈市| 米泉市| 论坛| 屏南县| 宜州市| 富源县| 和硕县| 乐东| 无锡市| 福建省| 江川县| 海阳市| 辉县市| 天台县| 自治县| 尼木县| 湘乡市| 寿宁县| 赞皇县| 左云县| 温泉县|