Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery游戏人机对抗需要一个重置按钮_Javascript_Jquery_Css - Fatal编程技术网

Javascript Jquery游戏人机对抗需要一个重置按钮

Javascript Jquery游戏人机对抗需要一个重置按钮,javascript,jquery,css,Javascript,Jquery,Css,在这里,我得到了一个完全有效的游戏,但缺少以下内容: 模拟游戏(计算机对计算机) 重新启动游戏=未完成 我是否需要模拟点击。。。也许是电脑定时器对电脑? 我需要能够将游戏重置为每场游戏完成后页面加载时的状态吗 任何帮助都将不胜感激:-) var模块={ init:函数(){ 这个.gameSetup(); }, 游戏设置:函数(){ var pedra=“img/rock.png”; var papel=“img/paper.png”; var tesoura=“img/scissors

在这里,我得到了一个完全有效的游戏,但缺少以下内容:

  • 模拟游戏(计算机对计算机)
  • 重新启动游戏=未完成
我是否需要模拟点击。。。也许是电脑定时器对电脑? 我需要能够将游戏重置为每场游戏完成后页面加载时的状态吗 任何帮助都将不胜感激:-)

var模块={
init:函数(){
这个.gameSetup();
},
游戏设置:函数(){
var pedra=“img/rock.png”;
var papel=“img/paper.png”;
var tesoura=“img/scissors.png”;
var用户选择;
var i=3;
风险价值选择;
$(“.button”)。打开(“单击”,启动);
功能启动(e){
$(“.button”)。关闭(“单击”);
userChoice=e.target.id;
console.info(用户选择);
compChoice();
$(“.score”).hide();
$('.lose').removeClass('lose');
倒计时();
};
函数compChoice(){
computerChoice=Math.random();
如果(计算机选择<0.34){
computerChoice=“rock”;
}如果有的话(电脑选择部){
显示:表格单元格;
宽度:50%;
}
章节.内容>部门img{
最大宽度:60%;
高度:自动;
}
第三节控制{
位置:绝对位置;
排名:0;
宽度:100%;
}
第1节控制h1{
颜色:黑色;
边缘底部:150px;
字号:80px;
文本转换:大写;
位置:绝对位置;
文本对齐:居中;
宽度:100%;
}
节。控件h1.lose{
颜色:红色;
}
.按钮{
保证金:自动;
寡妇:100%;
显示:表格;
填充顶部:130px;
}
钮扣{
高度:140像素;
宽度:140px;
边界:0;
保证金:0;
大纲:无;
光标:指针;
-webkit过渡:所有0.35秒都可以轻松过渡;
-moz过渡:所有0.35秒都会变慢;
-o型过渡:所有0.35秒均缓解;
过渡:所有0.35秒都放松;
位置:相对位置;
背景大小:100%;
/*文本缩进:-999em*/
显示:表格单元格;
盒影:2×2×4×222;
边界半径:50%;
位置:相对位置;
溢出:隐藏;
-webkit转换:translatez(0);
-moz变换:translatez(0);
-ms变换:translatez(0);
-o变换:translatez(0);
变换:translatez(0);
左边距:15px;
}
按钮:之前{
内容:“;
位置:绝对位置;
z指数:-1;
排名:0;
左:0;
高度:140像素;
宽度:140px;
}
按钮:之后{
内容:“;
位置:绝对位置;
z指数:0;
排名:0;
左:0;
高度:140像素;
宽度:140px;
}
巴顿。洛克:之后{
背景:url(../images/rock.png)0 0无重复;
背景大小:100%;
}
按钮。纸张:之后{
背景:url(../images/paper.png)0 0 0无重复;
背景大小:100%;
}
纽扣。剪刀:之后{
背景:url(../images/scissor.png)0 0无重复;
背景大小:100%;
}
按钮:悬停{
-webkit转换:规模(1.05);
-mz变换:比例(1.05);
-ms变换:标度(1.05);
转换:标度(1.05);
}
按钮:第一个孩子{
左边距:0:
}
#石头向右,布向右,剪刀向右,石头向左,布向左,剪刀向左{
显示:无;
}

人
机器人
摇滚乐
纸张
剪

我做对了吗?你问如何重置计时器? 尝试在启动函数中将计数器(代码中称为i的变量)设置为其初始值(本例中为3)。这将重置计时器。
我没有看到任何处理计算机与计算机游戏的代码…

您可以更改现有的计算机选择以返回值,而不是更新全局/模块级变量:

    function compChoice() {
        computerChoice = Math.random();
        if (computerChoice < 0.34) return "rock";
        if (computerChoice <= 0.67) return "paper";
        return "scissors";
    };
计时器还有一些其他问题,但以上是针对计算机与计算机的

  • 修复计时器问题
  • if(i==0){
    结果();
    i=3;
    }

  • 要重新启动游戏,只需重新加载页面
    location.reload();

  • 要进行计算机与计算机的对比,您可以添加另一个按钮并在其上放置一个事件

  • vare={};e.target=Math.floor(Math.random()*3)+1;
    
    $(“.button2”)。在(“单击”,启动(e));

    可能是这样的

    JS小提琴:

    var模块={
    init:函数(){
    这个.gameSetup();
    },
    游戏设置:函数(){
    var pedra=“img/rock.png”;
    var papel=“img/paper.png”;
    var tesoura=“img/scissors.png”;
    var用户选择;
    var i=3;
    风险价值选择;
    $(“游戏”)。关闭(“点击”)。打开(“点击”,重置);
    $(“.button”).off(“click”).on(“click”,启动);
    函数演示(e){
    $(“#纸张”).addClass(“hoverSimulate”).trigger(“click”);
    }
    函数启动(e){
    $(.result”).text(“”;i=3;$(.score”).hide();
    }
    功能复位(e){
    if($(e.target).hasClass(“开始”)){
    $(“#重置”).toggleClass(“演示开始”).val(“开始”);
    start();
    }
    其他的
    {
    演示();
    }
    }
    功能启动(e){
    $(“.button”)。关闭(“单击”);
    userChoice=e.target.id;
    console.info(用户选择);
    compChoice();
    $(“.score”).hide();
    $('.lose').removeClass('lose');
    倒计时();
    };
    函数compChoice(){
    computerChoice=Math.random();
    如果(计算机选择<0.34){
    computerChoice=“rock”;
    
    }否则如果(computerChoice Cool jsfiddle:)请包含正确的链接血腥的pc!!!!抱歉@devqon您有机会看到它吗?不是su
    function computerVcomputer() {
        var comp1 = compChoice();
        $("#" + comp1").click();
    }
    
    var module = {
    init: function () {
        this.gameSetup();
    
    },
    
    gameSetup: function () {
    
        var pedra = "img/rock.png";
        var papel = "img/paper.png";
        var tesoura = "img/scissors.png";
    
        var userChoice;
        var i = 3;
        var computerChoice;
    
        $("#game").off("click").on("click", reset);
        $(".button").off("click").on("click", startup);
           function demo(e) {                                      
    $("#paper").addClass("hoverSimulate").trigger("click");
        }
    
    
          function start(e) {                                   
       $(".result").text("");i=3;$(".score").hide();
     }
           function reset(e) {
                if($(e.target).hasClass("start")){
                $("#reset").toggleClass("demo start").val("Start");
                      start();
    
                }
                else
                {
                    demo();
                }
    
        }
        function startup(e) {
            $(".button").off("click");
    
            userChoice = e.target.id;
    
            console.info(userChoice);
    
            compChoice();
    
            $(".score").hide();
            $('.lose').removeClass('lose');
    
    
            countDown();
    
        };
    
        function compChoice() {
            computerChoice = Math.random();
            if (computerChoice < 0.34) {
                computerChoice = "rock";
            } else if (computerChoice <= 0.67) {
                computerChoice = "paper";
            } else {
                computerChoice = "scissors";
            }
        };
    
        function countDown() {
            count();
        };
    
        function count() {
            $(".result").text(i);
            if (i === 0) {
                results();
            } else {
                i--;
                setTimeout(count, 400);
            }
        };
    
        function comparar(choice1, choice2) {
            if (choice1 == choice2) {
                $(".result").text("Tie!");
            } else if (
            (choice1 == "rock" && choice2 == "scissors") || (choice1 == "scissors" && choice2 == "paper") || (choice1 == "paper" && choice2 == "rock")) {
                $(".result").text("You win!");
            } else {
                $(".result").text("You lose!").addClass('lose');
            }
            $("#game").toggleClass("demo start").val("Start");
        };
    
        function results() {
            $(".fist").hide();
            $(".score.left." + userChoice).show();
            $(".score.right." + computerChoice).show();
    
            comparar(userChoice, computerChoice);
    
            $(".button").on("click", startup);
        };
    
    }
    
    };
    
    
    $(document).ready(function () {
        module.init();
    });