js.js 3.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
var startTime;
var playGames;
var gameTime = 0;
var startText = "";
var score = 0;
$(function() {
    $("body").keypress(function() {
        if (event.keyCode == 119) {
            $(".bottom_top").css("background-color", "gray");
            if ($(".top").text() == "") {
                score += 100;
6
62734f01072d6f2fb9e3f9db 已提交
12
                $(".bottom_center").text("score:" + score);
13 14 15 16 17 18
            }
            setTimeout("clearStyle('119')", 100);
        } else if (event.keyCode == 97) {
            $(".bottom_left").css("background-color", "gray");
            if ($(".left").text() == "") {
                score += 100;
6
62734f01072d6f2fb9e3f9db 已提交
19
                $(".bottom_center").text("score:" + score);
20 21 22 23 24 25
            }
            setTimeout("clearStyle('97')", 100);
        } else if (event.keyCode == 100) {
            $(".bottom_right").css("background-color", "gray");
            if ($(".right").text() == "") {
                score += 100;
6
62734f01072d6f2fb9e3f9db 已提交
26
                $(".bottom_center").text("score:" + score);
27 28 29 30 31 32 33 34 35 36 37 38 39 40
            }
            setTimeout("clearStyle('100')", 100);
        } else if (event.keyCode == 115) {
            $(".bottom_bottom").css("background-color", "gray");
            if ($(".bottom").text() == "") {
                score += 100;
                $(".bottom_center").text("score:" + score);
            }
            setTimeout("clearStyle('115')", 100);
        }
    });
    $(".center").click(function() {
        if ($(".center").text() == "start Game") {
            score = 0;
6
62734f01072d6f2fb9e3f9db 已提交
41
            $(".bottom_center").text("score");
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
            gameTime = 0;
            startText = $(".title").text();
            $(".center").text("out Game");
            startTime = setInterval("playTime()", 1000);
            playGames = setInterval("playGame()", 2200);
        } else {
            clearInterval(startTime);
            clearInterval(playGames);
            $(".center").text("start Game");
            $(".title").text(startText);
        }
    });
});

function playTime() {
    gameTime++;
    var info = startText + gameTime + "s";
    $(".title").text(info);
}

function playGame() {
    var ranTime = (Math.random() * 500) + 500;
    setTimeout("playGo()", ranTime);
}

function playGo() {
    var ranImg = parseInt(Math.random() * 4);
    var ranNum = parseInt((Math.random() * 500) + 500);
    if (ranImg == 0) {
        $(".top").text("");
        setTimeout("clearStar('0')", ranNum);
    } else if (ranImg == 1) {
        $(".left").text("");
        setTimeout("clearStar('1')", ranNum);
    } else if (ranImg == 2) {
        $(".right").text("");
        setTimeout("clearStar('2')", ranNum);
    } else if (ranImg == 3) {
        $(".bottom").text("");
        setTimeout("clearStar('3')", ranNum);
    }
}

function clearStar(num) {
    if (num == 0) {
        $(".top").text("");
    } else if (num == 1) {
        $(".left").text("");
    } else if (num == 2) {
        $(".right").text("");
    } else if (num == 3) {
        $(".bottom").text("");
    }
}

function clearStyle(num) {
    if (num == 119) {
        $(".bottom_top").css("background-color", "lightslategray");
    } else if (num == 97) {
        $(".bottom_left").css("background-color", "lightslategray");
    } else if (num == 100) {
        $(".bottom_right").css("background-color", "lightslategray");
    } else if (num == 115) {
        $(".bottom_bottom").css("background-color", "lightslategray");
    }
}