基于 HTML+CSS+JS 的纸牌记忆游戏,2024年最新逆袭面经分享

先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Python全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。
img
img



既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上Python知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

如果你需要这些资料,可以添加V获取:vip1024c (备注Python)
img

正文

你在

移动了

星级:

<button id="play-again"οnclick=“playAgain()”>

再玩一次 😄

在这里插入图片描述

CSS 部分


现在我们使用一些 CSS 属性来设置记忆纸牌游戏的样式。

一些基本样式

html {

box-sizing: border-box;

}

*,

*::before,

*::after {

box-sizing: inherit;

}

html,

body {

width: 100%;

height: 100%;

margin: 0;

padding: 0;

font-weight:bolder;

}

body {

background: #ffffff;

font-size: 16px;

}

.container {

display: flex;

justify-content: center;

align-items: center;

flex-direction: column;

}

h1 {

font-family: ‘Gloria Hallelujah’, cursive;

}

在这里插入图片描述

纸牌的样式

.deck {

width: 85%;

background: #716F71;

padding: 1rem;

border-radius: 4px;

box-shadow: 8px 9px 26px 0 rgba(46, 61, 73, 0.5);

display: flex;

flex-wrap: wrap;

justify-content: space-around;

align-items: center;

margin: 0 0 3em;

}

.deck .card {

height: 3.7rem;

width: 3.7rem;

margin: 0.2rem 0.2rem;

background: #141214;;

font-size: 0;

color: #ffffff;

border-radius: 5px;

cursor: pointer;

display: flex;

justify-content: center;

align-items: center;

box-shadow: 5px 2px 20px 0 rgba(46, 61, 73, 0.5);

}

.deck .card.open {

transform: rotateY(0);

background: #02b3e4;

cursor: default;

animation-name: flipInY;

-webkit-backface-visibility: visible;

backface-visibility: visible;

animation-duration: .75s;

}

.deck .card.show {

font-size: 33px;

}

.deck .card.match {

cursor: default;

background: #E5F720;

font-size: 33px;

animation-name: rubberBand;

-webkit-backface-visibility: visible;

backface-visibility: visible;

animation-duration: .75s;

}

.deck .card.unmatched {

animation-name: pulse;

-webkit-backface-visibility: visible;

backface-visibility: visible;

animation-duration: .75s;

background: #e2043b;

}

.deck .card.disabled {

pointer-events: none;

opacity: 0.9;

}

在这里插入图片描述

  • animation-duration 属性定义动画完成一个周期需要多少秒或毫秒。这里的.75s表示 0.75 秒。

  • backface-visibility 属性定义当元素背面向屏幕时是否可见。这里的 visible 值使得背面是可见的。

分数面板的样式

.score-panel {

text-align: left;

margin-bottom: 10px;

}

.score-panel .stars {

margin: 0;

padding: 0;

display: inline-block;

margin: 0 5px 0 0;

}

.score-panel .stars li {

list-style: none;

display: inline-block;

}

.score-panel .restart {

float: right;

cursor: pointer;

}

.fa-star {

color: #FFD700;

}

.timer {

display: inline-block;

margin: 0 1rem;

}

在这里插入图片描述

祝贺面板的样式

.overlay {

position: fixed;

top: 0;

bottom: 0;

left: 0;

right: 0;

background: rgba(0, 0, 0, 0.7);

transition: opacity 500ms;

visibility: hidden;

opacity: 0;

}

.overlay:target {

visibility: visible;

opacity: 1;

}

.popup {

margin: 70px auto;

padding: 20px;

background: #ffffff;

border-radius: 5px;

width: 85%;

position: relative;

transition: all 5s ease-in-out;

}

.popup h2 {

margin-top: 0;

color: #333;

font-family: Tahoma, Arial, sans-serif;

}

.popup .close {

position: absolute;

top: 20px;

right: 30px;

transition: all 200ms;

font-size: 30px;

font-weight: bold;

text-decoration: none;

color: #333;

}

.popup .close:hover {

color: #E5F720;

}

.popup .content-1,

.content-2 {

max-height: 30%;

overflow: auto;

text-align: center;

}

.show {

visibility: visible;

opacity: 100;

}

#starRating li {

display: inline-block;

}

#play-again {

background-color: #141214;

padding: 0.7rem 1rem;

font-size: 1.1rem;

display: block;

margin: 0 auto;

width: 50%;

font-family: ‘Gloria Hallelujah’, cursive;

color: #ffffff;

border-radius: 5px;

}

在这里插入图片描述

  • visibility 属性指定一个元素是否是可见的。

动画

/* 卡片打开时的动画 */

@keyframes flipInY {

from {

transform: perspective(400px) rotate3d(0, 1, 0, 90deg);

animation-timing-function: ease-in;

opacity: 0;

}

40% {

transform: perspective(400px) rotate3d(0, 1, 0, -20deg);

animation-timing-function: ease-in;

}

60% {

transform: perspective(400px) rotate3d(0, 1, 0, 10deg);

opacity: 1;

}

80% {

transform: perspective(400px) rotate3d(0, 1, 0, -5deg);

}

to {

transform: perspective(400px);

}

}

在这里插入图片描述

  • animation-timing-function 指定动画将如何完成一个周期,这里的 ease-in 是让动画以低速开始。

/* 卡片匹配时的动画 */

@keyframes rubberBand {

from {

transform: scale3d(1, 1, 1);

}

30% {

transform: scale3d(1.25, 0.75, 1);

}

40% {

transform: scale3d(0.75, 1.25, 1);

}

50% {

transform: scale3d(1.15, 0.85, 1);

}

65% {

transform: scale3d(.95, 1.05, 1);

}

75% {

transform: scale3d(1.05, .95, 1);

}

to {

transform: scale3d(1, 1, 1);

}

}

在这里插入图片描述

/* 卡片不匹配时的动画 */

@keyframes pulse {

from {

transform: scale3d(1, 1, 1);

}

50% {

transform: scale3d(1.2, 1.2, 1.2);

}

to {

transform: scale3d(1, 1, 1);

}

}

在这里插入图片描述

媒体查询

/* 适用于 320px 以下的样式*/

@media (max-width: 320px) {

.deck {

width: 85%;

}

.deck .card {

height: 4.7rem;

width: 4.7rem;

}

}

/* 适用于 768px 以上的样式*/

@media (min-width: 768px) {

.container {

font-size: 22px;

}

.deck {

width: 660px;

height: 680px;

}

.deck .card {

height: 125px;

width: 125px;

}

.popup {

width: 60%;

}

}

在这里插入图片描述

JavaScript 部分


接下来让我们添加 Javascript

首先声明一些我们需要用到的变量:

// 卡片数组包含所有卡片

let card = document.getElementsByClassName(“card”);

let cards = […card];

// 游戏中所有卡片

const deck = document.getElementById(“card-deck”);

// 声明 moves 变量

let moves = 0;

let counter = document.querySelector(“.moves”);

// 声明星形图标的变量

const stars = document.querySelectorAll(“.fa-star”);

// 声明 matchedCard 的变量

let matchedCard = document.getElementsByClassName(“match”);

// 星级列表

let starsList = document.querySelectorAll(“.stars li”);

// 模板中的关闭图标

let closeicon = document.querySelector(“.close”);

// 声明 modal

let modal = document.getElementById(“popup1”)

// 打开卡片的数组

var openedCards = [];

洗牌功能

function shuffle(array) {

var currentIndex = array.length, temporaryValue, randomIndex;

while (currentIndex !== 0) {

randomIndex = Math.floor(Math.random() * currentIndex);

currentIndex -= 1;

temporaryValue = array[currentIndex];

array[currentIndex] = array[randomIndex];

array[randomIndex] = temporaryValue;

}

return array;

};

开始新游戏的功能

// 页面刷新/加载时洗牌

document.body.onload = startGame();

// 开始新游戏的功能

function startGame(){

// 清空 openCards 数组

openedCards = [];

// 洗牌

cards = shuffle(cards);

// 从每张卡片中删除所有现有的类

for (var i = 0; i < cards.length; i++){

deck.innerHTML = “”;

[].forEach.call(cards, function(item) {

deck.appendChild(item);

});

cards[i].classList.remove(“show”, “open”, “match”, “disabled”);

}

// 重置 moves

moves = 0;

counter.innerHTML = moves;

// 重置 rating

for (var i= 0; i < stars.length; i++){

stars[i].style.color = “#FFD700”;

stars[i].style.visibility = “visible”;

}

// 重置 timer

second = 0;

minute = 0;

hour = 0;

var timer = document.querySelector(“.timer”);

timer.innerHTML = “0 分 0 秒”;

clearInterval(interval);

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
img

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
startGame();

// 开始新游戏的功能

function startGame(){

// 清空 openCards 数组

openedCards = [];

// 洗牌

cards = shuffle(cards);

// 从每张卡片中删除所有现有的类

for (var i = 0; i < cards.length; i++){

deck.innerHTML = “”;

[].forEach.call(cards, function(item) {

deck.appendChild(item);

});

cards[i].classList.remove(“show”, “open”, “match”, “disabled”);

}

// 重置 moves

moves = 0;

counter.innerHTML = moves;

// 重置 rating

for (var i= 0; i < stars.length; i++){

stars[i].style.color = “#FFD700”;

stars[i].style.visibility = “visible”;

}

// 重置 timer

second = 0;

minute = 0;

hour = 0;

var timer = document.querySelector(“.timer”);

timer.innerHTML = “0 分 0 秒”;

clearInterval(interval);

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加V获取:vip1024c (备注python)
[外链图片转存中…(img-IltaVCIF-1713539887997)]

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值