JQuery做的一个简单的点灯游戏分享

2020-05-17 06:19:55易采站长站整理

                changeButton(this.id);

                var x = this.id.charAt(2);
                var y = this.id.charAt(3);

                if (x – 1 > 0) {
                    changeButton(‘bt’ + (x – 1) + y);
                }
                if (y – 1 > 0) {
                    changeButton(‘bt’ + x + (y – 1));
                }

                var newX = 1 + parseInt(x);
                if (x + 1 <= maxX) {
                    changeButton(‘bt’ + newX + y);
                }
                var newY = 1 + parseInt(y);
                if (y + 1 <= maxY) {
                    changeButton(‘bt’ + x + newY);
                }

                step++;

                document.getElementById(“step”).innerHTML = step;
            });
        }

        function changeButton(id) {
            var button = document.getElementById(id);

            if (button.className === “darkButton”) {
                button.className = “lightButton”;
            }