- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的石头剪刀布游戏。 http://jsfiddle.net/Renay/hL3j5hm6/6/
<html> </html>
如何添加动画,在给出结果之前,图像上下弹跳时有 3,2,1 倒计时。我尝试过添加各种功能,但似乎没有任何效果。我不太确定如何为图像添加运动以及它在我的脚本中的位置。
步骤:
斜体的步骤是我遇到的问题。
我知道 CSS 并不理想,但我会在功能正常后修复它。
非常感谢任何形式的帮助。谢谢
最佳答案
嗯,这就是我想出来的。
<div id='computerSide'>
<h1> Computer </h1>
<img src="http://s22.postimg.org/sv6ieobip/rock1.png" id="rockOne" height="130" width="130" class='compFist' />
<div id="you"></div>
</div>
<div id='playerSide'>
<h1> You </h1>
<img src="http://s28.postimg.org/syouexkjx/rock2.png" id="rockOne" height="130" width="130" class='compFist' />
<div id="comp"></div>
</div>
<div id="countDown"></div>
<div id='instructions'>
<h2> Choose your weapon! </h2>
</div>
<div id="container">
<div id='buttons'>
<input type='button' value='Rock' id='rockB' class='button1' />
<input type='button' value='Paper' id='paperB' class='button1' />
<input type='button' value='Scissors' id='scissorsB' class='button1' />
<input type='button' value='Replay' id='replayButton' />
</div>
</div>
<div id="yourResult"></div>
<div id="compResult"></div>
var rockButton = document.getElementById('rockB');
var paperButton = document.getElementById('paperB');
var scissorsButton = document.getElementById('scissorsB');
var replayButton = document.getElementById('replayButton');
var result = document.getElementById('yourResult');
var cresult = document.getElementById('compResult');
var num = document.getElementById('countDown');
var you = document.getElementById('you');
var comp = document.getElementById('comp');
var win = 'You Won!<br />';
var lose = 'You Lost!<br />';
var tie = 'Tie!<br />';
var r = 'Rock!';
var p = 'Paper!';
var s = 'Scissors!';
var compChoice;
function randChoice() {
var shuffle = Math.random();
if (shuffle <= 0.34) {
return 'rock';
} else if (shuffle <= 0.67) {
return 'paper';
} else {
return 'scissors';
}
}
function main(w, one, two, three, four, five, six) {
you.innerHTML = '';
comp.innerHTML = '';
result.innerHTML = '';
cresult.innerHTML = '';
num.innerHTML = "3";
$('img').animate({'top': '20px'}, "fast");
$('img').animate({'top': '0px'}, function() {
num.innerHTML = "2";
});
$('img').animate({'top': '20px'}, "fast");
$('img').animate({'top': '0px'}, function() {
num.innerHTML = "1";
});
$('img').animate({'top': '20px'}, "fast");
$('img').animate({'top': '0px'}, function() {
num.innerHTML = "";
you.innerHTML = w;
compChoice = randChoice();
if (compChoice == 'rock') {
comp.innerHTML = r;
result.innerHTML = one;
cresult.innerHTML = two;
} else if (compChoice == 'paper') {
comp.innerHTML = p;
result.innerHTML = three;
cresult.innerHTML = four;
} else {
comp.innerHTML = s;
result.innerHTML = five;
cresult.innerHTML = six;
}
});
}
rockButton.addEventListener('click', function () {
main(r, tie, tie, lose, win, win, lose);
});
paperButton.addEventListener('click', function () {
main(p, win, lose, tie, tie, lose, win);
});
scissorsButton.addEventListener('click', function () {
main(s, lose, win, win, lose, tie, tie);
});
replayButton.addEventListener('click', function () {
location.reload();
});
#container {
position: absolute;
width: 100%;
height: 60px;
text-align: center;
margin: 0 auto;
}
#buttons {
width: 400px;
margin: 0 auto;
}
#playerSide {
float:left;
margin: 0 0 0 0;
}
#computerSide {
float:right;
margin: 0 0 0 0;
}
#instructions {
padding: 0 0 0 40%;
}
.button1 {
position: relative;
top: 200px;
margin: auto;
display:inline-block;
text-align: center;
color: black;
}
input[type=button] {
background-color:#FFFACD;
border-radius: 20px;
width:6em;
height:2em;
font-size: 20px;
}
.compWeapon {
margin: 20% 0 0 45%;
font-size: 30px;
}
#replayButton {
background-color: #FFD700;
margin:auto;
position: relative;
top: 220px;
color: black;
}
#yourResult {
float: left;
position: absolute;
bottom: 20%;
left: 20%;
font-size: 20px;
}
#compResult {
float: right;
position: absolute;
bottom: 20%;
right: 15%;
font-size: 20px;
}
#yourResult, #compResult {
display: inline-block;
}
img {
position: relative;
}
#countDown {
width: 40px;
height: 20px;
position: absolute;
top: 33%;
left: 50%;
color: red;
font-size: 30px;
}
#you {
position: absolute;
width: 20px;
height: 20px;
top: 53%;
left: 4%;
font-size: 25px;
}
#comp {
position: absolute;
width: 20px;
height: 20px;
top: 53%;
right: 10%;
font-size: 25px;
}
关于javascript - 石头、剪刀、布游戏动画。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26570484/
所以,我正在用 Python 制作这款游戏。问题是,在剪刀、布和石头中可以有不同的组合,例如..石头和布、石头和剪刀等等。那么,如果不执行大量 elif 语句,我将如何做到这一点。 import
我是 javascript 新手,正在开发一个简单的石头、剪刀、布、蜥蜴、斯波克游戏。我想让用户从 5 张图像中进行选择,而不是在提示中填写。有谁知道我该怎么做?警报和确认消息最终也应该是 或类似的内
我正在制作一个小剪刀石头布游戏,我以为我已经完美地计划了一切,但由于某种原因,当你尝试玩时什么也没有发生。 基本上,有三张图像,一 block 石头、一张纸和一些剪刀,然后你单击一个。使用我输入的代码
我试图学习python并以此开始,当我尝试运行它时,我一直收到语法错误。光标跳到def start部分的close结束处。我不确定语法错误来自哪里,因为我用语音标记了所有打印件 #! python3
我有点困惑如何创建一个字段,其中将显示您获胜或平局的次数。喜欢: | Wins: | 234 | | Looses:| 234 | | Draws: | 434 | 意思是,如果我和新闻报纸赢得了答
如何让玩家玩随机数量的比赛,然后以全部分数结束游戏? 我正在尝试做一个循环,让玩家玩多场比赛,并在最后询问是否还想玩。 public class RockPaperScissors { pub
每当我运行它时,似乎继续玩的循环都有效,但是每当 computerChoose 执行 randomGenerator 时,游戏结果都不会正确输出。请帮忙。我是java新手,我们只打算使用3种方法——指
我的石头剪刀布游戏遇到问题。当我玩游戏时,它会将胜利或失败记录为胜利和失败。我试图让它记录一场胜利和一场失败,并且不会为胜利和失败添加分数。有什么建议吗? import java.io.*; publ
我正在制作石头剪刀布游戏。 下面的代码可以工作,但是缺少两个关键的东西,我真的很想知道如何实现它: 如果出现平局,玩家必须能够重新选择。所以必须执行break语句,但是需要什么才能返回到while循环
显然是在学习java。我能够让游戏正常运行。但我需要这样做,以便如果用户放置 R/P/S 以外的东西,那么它默认为 Rock。我不需要循环。如果我放石头的话,游戏就完美了。如果我放置 RPS 以外的任
#RoShamBo import random count=0 while count -2: compnum=random.randint(0,2) usernum=int(inpu
我用Python做了一个石头、剪刀、布的游戏。如果用户输入"is",我如何让游戏重复进行?当用户输入除了石头、布或剪刀之外的任何内容时,我的代码似乎进入永无休止的循环 此外,我正在尝试了解何时何地应该
我还在和我叔叔一起学习 C,我在尝试编译我们一起编写的玩剪刀石头布的程序时遇到了另一个麻烦。我在该程序上还有更多工作要做,但我什至无法让大部分内容正常工作。 我使用 Make 命令从编译器收到的错误
这是我的石头剪刀布游戏。 http://jsfiddle.net/Renay/hL3j5hm6/6/ 如何添加动画,在给出结果之前,图像上下弹跳时有 3,2,1 倒计时。我尝试过添加各种功
我的类(class)本周将举行机器人竞赛,我们应该让我们的机器人战胜其他人的机器人。比赛项目为石头、布、剪刀、炸药、水气球。炸药胜过一切,除了水气球,而水气球只胜过炸药。老师写了竞技场,还有其他一些机
我正在使用 Python 创建一个非常简单的石头剪刀布游戏,但无法解决这个问题。每次我在命令提示符中输入答案时,它都会输出消息“无效输入,请重试!”,这就是我告诉它在存在无效输入时执行的操作。但是,我
我遇到了一个问题,选择根本没有更新。我已经列出了每次选择后应显示最后结果和当前分数的位置。分数运行良好,但选择根本没有更新。谢谢。 Dynamic Web Squirtle,
我的图片和消息正在更改为显示获胜、失败、平局,但我的 javascript 增量似乎不起作用,因为我的分数没有改变。请帮忙:) Rock, Paper, Scissors Rock
我正在用 C# 制作石头、剪刀、布游戏,目前在有人输入非 R、S 或 P 的输入时尝试显示消息时遇到问题。例如,我正在尝试获取默认值在 switch 语句中工作,但我没有运气。这就是我目前所拥有的。如
我希望代码获取用户在输入字段中输入的值并将其传递给变量 userChoice。我不知道为什么这段代码不起作用,唯一的学习方法就是问你们。 HTML: Choose your destiny !
我是一名优秀的程序员,十分优秀!