javascript石头剪刀布在线小游戏源码

所属分类: 网页特效-抽奖&游戏    2023-12-03 11:16:47

javascript石头剪刀布在线小游戏源码 ie兼容6
 查看演示  登录后下载 温馨提示
登录会员即可享受免费下载
 我要建站

javascript石头剪刀布在线小游戏源码(共3个文件)

    • index.html

使用方法


let uScore = 0;
let cS = 0;
const rock = document.querySelector(".rock");
const scissors = document.querySelector(".scissors");
const paper = document.querySelector(".paper");
const userScore = document.querySelector(".user-score");
const computerScore = document.querySelector(".computer-score");
let statusLeft = document.querySelector(".user-status");
let statusRight = document.querySelector(".computer-status");
let result = document.querySelector(".result-para")


function win(userChoice, computerChoice) {
 uScore ++;
  statusLeft.innerHTML = convertToWord(userChoice);
 statusRight.innerHTML = convertToWord(computerChoice); 
 userScore.innerHTML = uScore;
 result.innerHTML = "你赢了!";
}

function loose(userChoice, computerChoice) {
  cS++;
 statusLeft.innerHTML = convertToWord(computerChoice);
 statusRight.innerHTML = convertToWord(userChoice); 
 computerScore.innerHTML = cS;
 result.innerHTML = "你输了  :-(";
}

function draw(userChoice, computerChoice) {
  result.innerHTML = "wow! 平局了~ ";
}


function getComputerChoice() {
  const choices = ['r','s','p'];
  const choicesRandom = Math.floor(Math.random() * 3);
  return choices[choicesRandom];
}

function game(userChoice) {
  const computerChoice = getComputerChoice();
  switch(userChoice + computerChoice) {
    case 'rs':
    case 'sp':
    case 'pr':
    win(userChoice, computerChoice);
    break;
    case 'ps':
    case 'sr':
    case 'rp':
    loose(userChoice, computerChoice);
    break;
    case 'pp':
    case 'ss':
    case 'rr':
    draw(userChoice, computerChoice);
  } 
}



function main() {
  rock.addEventListener("click", function(){
    game("r");
  })
  scissors.addEventListener("click", function(){
    game("s");
  })
  paper.addEventListener("click", function(){
    game("p");
  })
}

main();
function convertToWord(letter) {
if(letter === "r") return "Rock";
if(letter === "p") return "Paper";
return "Scissors";
}

站长提示:
1. 苦力吧素材官方QQ群:950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励2K币
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服
相关资源 / 抽奖&游戏

jquery数字华容道小游戏代码

一款数字华容道小游戏,简单难玩,核心代码有详细的注释说明,可自定义难度、可扩展。
  抽奖&游戏
 4785  0

jquery有趣的点名游戏抽奖特效代码

很nice的点名抽奖功能,抽中了表演节目,感觉挺好玩的!
  抽奖&游戏
 7876  0

jquery绿色清爽背景html5大转盘抽奖特效代码

兼容手机端访问,中奖后输入手机号码即可领奖。
  抽奖&游戏
 2896  0

原生javascript制作的找茬游戏源码

一款纯js实现的找茬网页小游戏,很像微信中的找茬游戏,在随机出现的方块中找出不同的方块图片,找出方块中不同的图案,随着方块数量增加,难度也是随之增加,最后的图片越来越小。
  抽奖&游戏
 2942  0

评论数(1) 回复有机会获得K币 用户协议

    great0
    2023-12-12 16:53:38
    这个网页游戏好玩,跟我们平时小朋友玩的一样~
    回复
😀
  • 😀
  • 😊
  • 😂
  • 😍
  • 😑
  • 😷
  • 😵
  • 😛
  • 😣
  • 😱
  • 😋
  • 😎
  • 😵
  • 😕
  • 😶
  • 😚
  • 😜
  • 😭
发表评论