Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Rock
Paper
Scissors
Lizard
Spock
css
html { background-color: #eceeef; min-height: 100%; } html * { outline: 0; } section { height: 120px; width: 600px; position: absolute; top: 50%; left: 50%; background-color: #fff; padding: 10px; margin-top: -100px; margin-left: -210px; border-radius: 6px; box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08); } section button { background: 0; border: 0; height: 120px; width: 20%; float: left; } section button .fa { font-size: 80px; display: block; margin-bottom: 20px; } section button.win { color: #15a015; } section button.loss { color: #ff1515; } section button.tie { color: #1515ff; } section .result { position: absolute; text-align: center; font-size: 28px; height: 40px; color: #fff; top: -40px; right: 0; left: 0; } section .result .animated { -webkit-animation-duration: 1.7s; animation-duration: 1.7s; } aside { box-shadow: rgba(0, 0, 0, 0.2) 0 2px 4px; background-color: #e9eaed; padding-top: 50px; padding-bottom: 50px; position: fixed; width: 200px; bottom: 0; left: 0; top: 0; } aside .legend { position: fixed; top: 0; left: 0; right: 0; width: 200px; background-color: #fff; height: 50px; border-top: 1px solid rgba(0, 0, 0, 0.1); } aside .legend .me, aside .legend .cpu { height: 40px; line-height: 40px; font-size: 14px; width: 50%; float: left; text-align: center; padding: 0.3rem 0; } aside .history-item { height: 40px; font-size: 24px; line-height: 40px; border-bottom: 1px solid rgba(0, 0, 0, 0.1); } aside .history-item.win { background-color: rgba(0, 150, 0, 0.1); } aside .history-item.loss { background-color: rgba(150, 0, 0, 0.1); } aside .history-item.tie { background-color: rgba(0, 0, 150, 0.1); } aside .history-item .fa { text-align: center; width: 50%; } aside .scoreboard { position: fixed; bottom: 0; left: 0; right: 0; width: 200px; background-color: #fff; height: 50px; border-top: 1px solid rgba(0, 0, 0, 0.1); } aside .scoreboard .win, aside .scoreboard .loss, aside .scoreboard .tie, aside .scoreboard .move { height: 40px; line-height: 20px; font-size: 11px; width: 25%; float: left; text-align: center; padding: 0.3rem 0; }
JavaScript
$(document).ready(function(e) { var $rps = false; // Default to true var $options; var $message; var $winCount = 0; var $lossCount = 0; var $tieCount = 0; var $moveCount = 0; var $history = {}; if ($rps == true) { $options = ['rock', 'paper', 'scissors']; } else { $options = ['rock', 'paper', 'scissors', 'lizard', 'spock']; } $('button').click(function(e) { var $this = $(this); var $selection = $this.data('play'); var $play = play($selection); $('button').removeClass(); $this.addClass($play); $('.result').empty().html('
' + $message + '
'); }); function play($selection) { var $winners = { rock: ['scissors', 'lizard'], paper: ['rock', 'spock'], scissors: ['paper', 'lizard'], lizard: ['spock', 'paper'], spock: ['rock', 'scissors'] } var $cpuPlays = randomPlay($options); // console.log('CPU: ' + $cpuPlays, 'Player: ' + $selection); if ($selection === $cpuPlays) { $message = 'tied with ' + $selection; $moveCount++; $tieCount++; recordScore('tie', $selection, $cpuPlays); return 'tie'; } // Check if player won if($winners[$cpuPlays].indexOf($selection) == -1) { $message = $selection + ' beat ' + $cpuPlays; $moveCount++; $winCount++; recordScore('win', $selection, $cpuPlays); return 'win'; } // Check if CPU won if($winners[$selection].indexOf($cpuPlays) == -1) { $message = $selection + ' lost against ' + $cpuPlays; $moveCount++; $lossCount++; recordScore('loss', $selection, $cpuPlays); return 'loss'; } return 'none'; } function randomPlay($arr) { return $arr[Math.floor(Math.random() * $arr.length)]; } function recordScore($type, $player, $cpu) { $('aside').prepend('
'); $('.scoreboard .win span').text($winCount); $('.scoreboard .tie span').text($tieCount); $('.scoreboard .loss span').text($lossCount); $('.scoreboard .move span').text($moveCount); } });
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>剪刀,石, 布游戏-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号