js+css实现hsl找不同颜色游戏代码

代码语言:html

所属分类:游戏

代码描述:js+css实现hsl找不同颜色游戏代码,找出6个颜色中不一样的颜色。

代码标签: js css hsl 找不同 颜色 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;900&display=swap" rel="stylesheet">
  
  
  
<style>
body {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  margin: 2em 1em;
  
  height: 100%;
  
  font-family: 'Inter', sans-serif;
  text-align: center;
  background-color: hsl(0, 0%, 93%);
}

.container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 2em;
  
  background-color: white;
  padding: 4em;
  border-radius: 20px;
}

#game {
  display: grid;
  grid-auto-flow:column dense;
  grid-template-rows: 110px 110px;
  grid-auto-columns: 110px;
  
  
}

.square {
  width: 100px;
  height: 100px;
  display: inline-block;
  margin: 5px;
  cursor: pointer;
  border-radius: 10px;
  box-sizing: border-box;
  
  background-color: hsl(212, 100%, 63%);
}

.diff {
  background-color: hsl(212, 100%, 40%);
}

h1 {
  font-size: 40px;
  font-weight: 900;
  margin: 0;
}

div, p {
  font-weight: 400;
  font-size: 20px;
}

#score {
  text-align: center;
  line-height: 2;
  padding: 1em 3em;
  border: 1px solid hsl(0, 0%, 93%);
  border-radius: 10px;
}

#try-again {
  padding: 1em 3em;
  background-color: hsl(0, 0%, 93%);
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  display: none;
}

#try-again:hover {
  background-color: hsl(0, 0%, 85%);
  transition: background-color 0.3s ease;
}
</style>


  
  
</head>

<body >
  <div class="container">
  <h1>HSL Color Game</h1>
  <p>Find the block with a different shade or brightness.</p>
  <div id="game"></div>
  <div id="score">Pick a block to play.</div>
  <div id="try-again"></div>
</div>

  
      <script  >
const gameContainer = document.getElementById("game");
let score = 0;
let highScore = 0;

generateSquares();

function generateSquares() {
  gameContainer.innerHTML = "";
  
  const similarHue = Math.floor(Math.random() * 360);
  
  const similarSaturation = Math.floor(Math.random() * 21) + 80;
  const similarLightness = Math.floor(Math.random() * 21) + 40;
  
  const differentSaturation = Math.floor(Math.random() * 21) + 80;
  const differentLightness = Math.floor(Math.random() * 21) + 40;
  
  const squares = [];
  for (let i = 0.........完整代码请登录后点击上方下载按钮下载查看

网友评论0