<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>石头剪子布动画特效</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
font-family: 'Arial', sans-serif;
overflow: hidden;
}
.game-container {
position: relative;
width: 100%;
max-width: 800px;
text-align: center;
z-index: 10;
}
h1 {
color: white;
font-size: 3em;
text-shadow: 0 2px 10px rgba(0,0,0,0.3);
margin-bottom: 30px;
}
.choices {
display: flex;
justify-content: center;
gap: 30px;
margin-bottom: 40px;
}
.choice {
width: 120px;
height: 120px;
border-radius: 50%;
background: rgba(255,255,255,0.9);
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
position: relative;
overflow: hidden;
}
.choice:hover {
transform: translateY(-10px);
box-shadow: 0 15px 25px rgba(0,0,0,0.3);
}
.choice::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: linear-gradient(
to bottom right,
rgba(255,255,255,0.3),
rgba(255,255,255,0)
);
transform: rotate(45deg);
animation: shine 3s infinite;
}
@keyframes shine {
0% { left: -50%; top: -50%; }
100% { left: 150%; top: 150%; }
}
.choice i {
font-size: 60px;
color: #333;
}
.result {
margin-top: 30px;
font-size: 1.5em;
color: white;
min-height: 50px;
text-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.vs {
font-size: 2em;
color: white;
margin: 0 20px;
text-shadow: 0 2px 5px rgba(0,0,0,0.3);
}
.players {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 30px;
}
.player, .computer {
width: 150px;
height: 150px;
border-radius: 50%;
background: rgba(255,255,255,0.9);
display: flex;
justify-content: center;
align-items: center;
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
.player i, .computer i {
font-size: 80px;
color: #333;
}
.computer {
animation: computerThinking 2s infinite;
}
@keyframes computerThinking {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.score {
display: flex;
justify-content: center;
gap: 50px;
margin-bottom: 30px;
color: white;
font-size: 1.2em;
}
.link {
margin-top: 40px;
}
.link a {
color: white;
text-decoration: none;
font-size: 1.2em;
padding: 12px 25px;
border: 2px solid white;
border-radius: 30px;
background: rgba(255,255,255,0.1);
transition: all 0.3s;
}
.link a:hover {
background: rgba(255,255,255,0.3);
box-shadow: 0 0 15px rgba(255,255,255,0.5);
}
.confetti {
position: absolute;
width: 10px;
height: 10px;
background: #f00;
border-radius: 50%;
animation: fall 5s linear infinite;
z-index: 1;
}
@keyframes fall {
0% {
transform: translateY(-100vh) rotate(0deg);
opacity: 1;
}
100% {
transform: translateY(100vh) rotate(360deg);
opacity: 0;
}
}
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
</head>
<body>
<div class="game-container">
<h1>石头剪子布</h1>
<div class="score">
<div>玩家: <span id="player-score">0</span></div>
<div>电脑: <span id="computer-score">0</span></div>
</div>
<div class="players">
<div class="player">
<i id="player-choice" class="fas fa-question"></i>
</div>
<div class="vs">VS</div>
<div class="computer">
<i id="computer-choice" class="fas fa-question"></i>
</div>
</div>
<div class="result" id="result">请选择你的出拳</div>
<div class="choices">
<div class="choice" data-choice="rock">
<i class="fas fa-hand-rock"></i>
</div>
<div class="choice" data-choice="paper">
<i class="fas fa-hand-paper"></i>
</div>
<div class="choice" data-choice="scissors">
<i class="fas fa-hand-scissors"></i>
</div>
</div>
<div class="link">
<a href="http://gonglve.100haofu.com" target="_blank">查看游戏攻略</a>
</div>
</div>
<script>
// 游戏变量
let playerScore = 0;
let computerScore = 0;
const choices = ['rock', 'paper', 'scissors'];
const choiceIcons = {
rock: 'fas fa-hand-rock',
paper: 'fas fa-hand-paper',
scissors: 'fas fa-hand-scissors'
};
// 获取DOM元素
const playerChoiceEl = document.getElementById('player-choice');
const computerChoiceEl = document.getElementById('computer-choice');
const resultEl = document.getElementById('result');
const playerScoreEl = document.getElementById('player-score');
const computerScoreEl = document.getElementById('computer-score');
const choiceButtons = document.querySelectorAll('.choice');
// 电脑随机选择
function computerPlay() {
const randomIndex = Math.floor(Math.random() * choices.length);
return choices[randomIndex];
}
// 判断胜负
function playRound(playerSelection, computerSelection) {
if (playerSelection === computerSelection) {
return 'draw';
}
if (
(playerSelection === 'rock' && computerSelection === 'scissors') ||
(playerSelection === 'paper' && computerSelection === 'rock') ||
(playerSelection === 'scissors' && computerSelection === 'paper')
) {
return 'win';
} else {
return 'lose';
}
}
// 更新界面
function updateDisplay(playerChoice, computerChoice, result) {
playerChoiceEl.className = choiceIcons[playerChoice];
computerChoiceEl.className = choiceIcons[computerChoice];
// 添加动画类
playerChoiceEl.parentElement.classList.add('pulse');
computerChoiceEl.parentElement.classList.add('pulse');
// 移除动画类
setTimeout(() => {
playerChoiceEl.parentElement.classList.remove('pulse');
computerChoiceEl.parentElement.classList.remove('pulse');
}, 500);
// 显示结果
switch(result) {
case 'win':
resultEl.textContent = '你赢了!';
resultEl.style.color = '#4CAF50';
playerScore++;
createConfetti();
break;
case 'lose':
resultEl.textContent = '你输了!';
resultEl.style.color = '#F44336';
computerScore++;
break;
case 'draw':
resultEl.textContent = '平局!';
resultEl.styleColor = '#FFC107';
break;
}
// 更新分数
playerScoreEl.textContent = playerScore;
computerScoreEl.textContent = computerScore;
}
// 创建彩色纸屑效果
function createConfetti() {
const colors = ['#f00', '#0f0', '#00f', '#ff0', '#f0f', '#0ff'];
for (let i = 0; i < 50; i++) {
const confetti = document.createElement('div');
confetti.className = 'confetti';
confetti.style.left = Math.random() * 100 + 'vw';
confetti.style.background = colors[Math.floor(Math.random() * colors.length)];
confetti.style.animationDuration = (Math.random() * 3 + 2) + 's';
confetti.style.animationDelay = Math.random() * 2 + 's';
document.body.appendChild(confetti);
// 移除元素
setTimeout(() => {
confetti.remove();
}, 5000);
}
}
// 添加点击事件
choiceButtons.forEach(button => {
button.addEventListener('click', () => {
const playerChoice = button.dataset.choice;
const computerChoice = computerPlay();
const result = playRound(playerChoice, computerChoice);
updateDisplay(playerChoice, computerChoice, result);
});
});
// 添加键盘事件
document.addEventListener('keydown', (e) => {
let playerChoice;
if (e.key === 'r') {
playerChoice = 'rock';
} else if (e.key === 'p') {
playerChoice = 'paper';
} else if (e.key === 's') {
playerChoice = 'scissors';
} else {
return;
}
const computerChoice = computerPlay();
const result = playRound(playerChoice, computerChoice);
updateDisplay(playerChoice, computerChoice, result);
// 高亮显示选择的按钮
choiceButtons.forEach(button => {
button.style.transform = button.dataset.choice === playerChoice ?
'translateY(-10px) scale(1.1)' :
'translateY(0) scale(1)';
setTimeout(() => {
button.style.transform = 'translateY(0) scale(1)';
}, 300);
});
});
</script>
</body>
</html>
2076

被折叠的 条评论
为什么被折叠?



