js实现一个推冰块过关PINK ICE游戏代码

代码语言:html

所属分类:游戏

代码描述:js实现一个推冰块过关PINK ICE游戏代码,使用键盘方向键或点击方向来移动粉红色的冰块到右侧绿色区域即可过关。

代码标签: js 冰块 过关 PINK ICE 游戏 代码

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

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

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


  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Archivo+Black&display=swap");
html {
  font-size: 3vh;
}
@media (orientation: portrait) {
  html {
    font-size: 2.9vw;
  }
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  color: #fff;
  background-color: #000038;
  overflow: hidden;
  font-family: "Archivo Black", sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
}

.level {
  position: absolute;
  top: 0.75rem;
  left: 1rem;
}
@media (min-height: 500px), (orientation: portrait) {
  .level {
    top: 0.5rem;
  }
}

.refresh,
.fullscreen {
  position: absolute;
  padding: 0.2rem 0.6rem;
  border: 1px solid #fff;
  font-weight: 500;
  background-color: #000038;
  cursor: pointer;
  text-transform: uppercase;
}
.refresh:hover,
.fullscreen:hover {
  color: #000038;
  background-color: #fff;
}
@media (min-height: 500px), (orientation: portrait) {
  .refresh,
.fullscreen {
    font-size: 1rem;
  }
}

.refresh {
  top: 0.5rem;
  right: 1rem;
}

.fullscreen {
  top: 0.5rem;
  left: 4rem;
}

.controls {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  height: 100%;
}
.controls__arrow {
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.controls__arrow:after {
  content: "";
  width: 0;
  height: 0;
  margin: 1rem;
  opacity: 0.3;
}
.controls__arrow--top, .controls__arrow--bottom {
  width: 100%;
  height: 40vh;
}
.controls__arrow--left, .controls__arrow--right {
  flex-direction: column;
  width: 50%;
  height: 20vh;
}
.controls__arrow--top, .controls__arrow--left {
  align-items: flex-start;
}
.controls__arrow--bottom, .controls__arrow--right {
  align-items: flex-end;
}
.controls__arrow--top:after {
  border-left: 1rem solid transparent;
  border-right: 1rem solid transparent;
  border-bottom: 1rem solid #fff;
}
.controls__arrow--left:after {
  border-top: 1rem solid transparent;
  border-right: 1rem solid #fff;
  border-bottom: 1rem solid transparent;
}
.controls__arrow--right:after {
  border-top: 1rem solid transparent;
  border-left: 1rem solid #fff;
  border-bottom: 1rem solid transparent;
}
.controls__arrow--bottom:after {
  border-left: 1rem solid transparent;
  border-right: 1rem solid transparent;
  border-top: 1rem solid #fff;
}

.timer {
  position: absolute;
  top: 55%;
  font-size: 3rem;
}

.title-screen {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 56, 0.8);
}
.title-screen--hidden {
  display: none;
}
.title-screen__title {
  position: relative;
  font-size: 12vw;
  color: #fff;
}
.title-screen__word {
  color: #eb80b1;
}
.title-screen__button {
  position: relative;
  border: 1px solid #fff;
  color: #fff;
  padding: 0.3rem 0.6rem;
  background-color: transparent;
  font-size: 3vw;
  font-family: "Archivo Black", sans-serif;
  text-transform: uppercase;
  cursor: pointer;
}
.title-screen__button:hover {
  color: #000038;
  background-color: #fff;
}
@media (orientation: portrait) {
  .title-screen__title {
    font-size: 18vw;
  }
  .title-screen__button {
    font-size: 4.5vw;
  }
}

.game {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  width: 29.03rem;
}
.game--tutorial:before {
  position: absolute;
  bottom: -4rem;
  content: "Use arrow keys (recommended) or click the arrows to play";
  color: #fff;
  font-size: 1.2rem;
  font-weight: 500;
  text-align: center;
  text-transform: uppercase;
}
@media (max-width: 767px) {
  .game--tutorial:before {
    display: none;
  }
}
.game--win:after, .game--lose:after, .game--final-win:after {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  color: #fff;
  background-color: rgba(0, 0, 56, 0.5);
  font-size: 2rem;
  text-transform: uppercase;
}
.game--win:after {
  content: "You win! Next level";
}
.game--lose:after {
  content: "You lose! Try again!";
}
.game--final-win:after {
  content: "Game completed!";
}
.game__player {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  background-color: #eb80b1;
  top: calc(var(--positionTop) * var(--cell));
  left: calc(var(--positionLeft) * var(--cell));
  transition-property: top, left;
  transition-duration: 0.2s;
  transition-timing-function: ease;
}
@media (max-width: 767px) {
  .game__player {
    transition-duration: 0.1s;
  }
}
.game__cell {
  width: var(--cell);
  height: var(--cell);
  background-color: #fff;
}
.game__cell--rock {
  background: #000038;
}
.game__cell--lava {
  background: linear-gradient(45deg, orange, #ff7d66 150%);
}
.game__cell--stop {
  position: relative;
  background: linear-gradient(45deg, #78d6c6 -50%, #fff 100%);
}
.game__cell--end {
  background: #80c0a1;
}
</style>


</head>

<body >
  <div id="game" class="game"></div>
<div id="controls" class="controls">
  <div id="top" class="controls__arrow controls__arrow--top"></div>
  <div id="left" class="controls__arrow controls__arrow--left"></div>
  <div id="right" class="controls__arrow controls__arrow--right"></div>
  <div id="bottom" class="controls__arrow controls__arrow--bottom"></div>
</div>
<div id="level-text" class="level">0</div>
<div id="refresh" class="refresh">Restart level</div>
<div id="timer" class="timer"></div>
<div id="title-screen" class="title-screen">
  <div class="title-screen__title">PINK <span class="title-screen__word">ICE</span></div>
  <button id="title-screen-button" class="title-screen__button">Play</button>
</div>
<div id="fullscreen" class="fullscreen">Fullscreen</div>
  
      <script  >
const game = document.getElementById("game");
const levelText = document.getElementById("level-text");
const refresh = document.getElementById("refresh");
const fullscreen = document.getElementById("fullscreen");
const topArrow = document.getElementById("top");
const leftArrow = document.getElementById("left");
const rightArrow = document.getElementById("right");
const bottomArrow = document.getElementById("bottom");
const timer = document.getElementById("timer");
const titleScreenButton = document.getElementById("title-screen-button");

const player = document.createElement("div");
player.classList.add("game__player");

let level = 0;
let width = 29;
const puzzles = [
["ox---", "---xe"],
["ox---", "---xe", "--xxx"],
["o--xx", "x--xe", "--x--", "-----", "-----"],
["e-xx-", "x--xx", "--xo-", &.........完整代码请登录后点击上方下载按钮下载查看

网友评论0