当前位置: 首页 > article >正文

蓝桥杯18583-俄罗斯方块

蓝桥杯18583-俄罗斯方块

介绍

在俄罗斯方块游戏中,玩家需要操作不同形状的方块,使它们在游戏区域内旋转、移动和下落,以创建完整的水平行。当一行填满方块时,该行将被清除并腾出空间。游戏随着时间的推移变得越来越快,考验玩家的反应速度和空间想象力。

游戏工作室的工程师们在开发俄罗斯方块时,遇到一个 Bug,游戏界面上右侧提示的下一个方块不能正常显示,下面请你来修复这个 Bug。

准备

开始答题前,需要先打开本题的项目代码文件夹,目录结构如下:

├── css
│   └── style.css
└── index.html

其中:

  • index.html 是主页面。
  • css/style.css 是待补充代码的样式文件。

在浏览器中预览 index.html 页面效果显示如下所示:

在这里插入图片描述

目标

请使用 Grid 布局的 grid-template-columnsgrid-template-rows 属性,完善 css/style.css 中的 TODO 代码,实现下面的方块布局:

  • Z 型方块(class=z-shape)元素设置为 2 行 4 列,行高列宽均为 30px。
  • L 型方块(class=l-shape)元素设置为 2 行 3 列,行高列宽均为 30px。

完成后,效果如下:

在这里插入图片描述

规定

  • 请严格按照考试步骤操作,切勿修改考试默认提供项目中的文件名称、文件夹路径、id、class、DOM 结构、css 样式、以及函数名等,以免造成判题无法通过。
  • 本题代码完成之后,考生需将题目对应代码文件夹压缩成 zip 或 rar 格式后上传提交,其他格式为 0 分。例如 01 代码文件夹,应该在此文件夹基础上直接压缩后,为 01.zip01.rar,然后提交压缩包到对应题目。请注意不要给压缩包添加密码。

解题

题目解读

将右侧Next Block样式根据请使用 Grid 布局的 grid-template-columnsgrid-template-rows 属性,在css/style.css 的 TODO 代码中完善。

  • Z 型方块(class=z-shape)元素设置为 2 行 4 列,行高列宽均为 30px。
  • L 型方块(class=l-shape)元素设置为 2 行 3 列,行高列宽均为 30px。
//style.css
.z-shape {
    display: grid;
    /* TODO:待补充代码 */
    grid-template-columns: repeat(4,30px);
    grid-template-rows: repeat(2,30px);
}

.l-shape {
    display: grid;
    /* TODO:待补充代码 */
    grid-template-columns: repeat(3,30px);
    grid-template-rows: repeat(2,30px);
}



/* 以下代码无需修改 */
.cell {
    background-color: #3498db;
    border: 1px solid #2980b9;
    box-sizing: border-box;
}

.l-shape .cell:nth-child(1) {
    background-color: #e74c3c;
    border-color: #c0392b;
}

.l-shape .cell:nth-child(2) {
    background-color: #2ecc71;
    border-color: #27ae60;
}

.l-shape .cell:nth-child(3) {
    background-color: #f1c40f;
    border-color: #f39c12;
}

.l-shape .cell:nth-child(4) {
    background-color: #9b59b6;
    border-color: #8e44ad;
}

.z-shape .cell:nth-child(1),
.z-shape .cell:nth-child(2) {
    background-color: #e67e22;
    border-color: #d35400;
}

.z-shape .cell:nth-child(3),
.z-shape .cell:nth-child(4) {
    background-color: #f39c12;
    border-color: #d35400;
}


.l-shape {
    grid-template-areas:
        "a b c"
        "d e .";
}

.z-shape {
    grid-template-areas:
        "a b c d"
        "e f g h";
}

.z-shape {
    grid-template-areas:
        "a b c d"
        "e f g h";
}

.l-shape .cell:nth-child(1) {
    grid-area: a;
}

.l-shape .cell:nth-child(2) {
    grid-area: b;
}

.l-shape .cell:nth-child(3) {
    grid-area: c;
}

.l-shape .cell:nth-child(4) {
    grid-area: d;
}

.l-shape .cell:nth-child(5) {
    grid-area: e;
}

.z-shape .cell:nth-child(1) {
    grid-area: a;
}

.z-shape .cell:nth-child(2) {
    grid-area: b;
}

.z-shape .cell:nth-child(3) {
    grid-area: g;
}

.z-shape .cell:nth-child(4) {
    grid-area: h;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.tetris-container {
    border: 2px solid #333;
    padding: 20px;
    background: linear-gradient(45deg, #000 25%, transparent 25%),
        linear-gradient(-45deg, #000 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #000 75%),
        linear-gradient(-45deg, transparent 75%, #000 75%);
    background-size: 30px 30px;
    background-color: #000;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
}

.score-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 20px;
}

.score {
    font-weight: bold;
    color: #fff;
    margin-bottom: 10px;
}

.level {
    font-weight: bold;
    color: #fff;
    margin-bottom: 10px;
}

.grid-container {
    position: relative;
    display: grid;
    grid-template-columns: repeat(10, 30px);
    grid-template-rows: repeat(20, 30px);
    border: 2px solid #333;
    width: 300px;
    height: 600px;
    box-sizing: border-box;
    margin-bottom: 20px;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    background-image: linear-gradient(90deg,
            transparent 29px,
            #333 29px,
            #333 30px),
        linear-gradient(0deg, transparent 29px, #333 29px, #333 30px);
    background-size: 30px 30px;
}

.grid-item {
    border: 1px solid #333;
    background-color: transparent;
    width: 30px;
    height: 30px;
    position: absolute;
    bottom: 0;
}

.grid-item.type1 {
    background-color: #ff7f0e;
}

.grid-item.type2 {
    background-color: #1f77b4;
}

.grid-item.type3 {
    background-color: #2ca02c;
}

.grid-item.type4 {
    background-color: #d62728;
}

.grid-item.type5 {
    background-color: #9467bd;
}

.grid-item.type6 {
    background-color: #8c564b;
}

.grid-item.type7 {
    background-color: #e377c2;
}

.next-block {
    text-align: center;
    margin-top: 20px;
    color: #fff;
    width: 120px;
    margin-left: 20px;
}

.next-block .grid-container {
    border: 1px solid #333;
    width: 120px;
    height: 90px;
    border-radius: 5px;
    overflow: hidden;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

grid知识扩展

grid-template-columns: repeat(3, 1fr); 是 CSS Grid 布局中用于定义网格容器列的属性。这个属性通过 repeat 函数重复定义列的大小,使得代码更加简洁和易读。

基本概念

grid-template-columns 属性

用于定义网格容器的列轨道(column tracks)。每个值表示一列的宽度。
repeat 函数:

repeat 函数用于重复定义列或行的大小,减少冗余代码。
语法:repeat(次数, 重复的值)
例如:repeat(3, 1fr) 表示重复定义3次,每次的值为 1fr。

//使用方法
 display: grid;
    /* TODO:待补充代码 */
    grid-template-columns: repeat(4,30px);//四行
    grid-template-rows: repeat(2,30px);//三列

px单位

“px” 单位代表像素(pixel),是网页设计和开发中常用的长度单位之一。它是相对于显示器屏幕分辨率的长度单位,通常被用来描述元素在屏幕上的大小和位置。使用场景

等分列:

当需要将网格容器的宽度等分成多列时,使用 repeat 函数可以方便地定义列的数量和大小。

响应式布局:

结合媒体查询,可以创建响应式网格布局,根据屏幕宽度动态调整列的数量和大小。

动态内容:

当网格项目数量或内容长度不确定时,使用 repeat 函数可以确保项目在容器内均匀分布。
示例:一个动态生成的产品列表页面,每行显示3个产品卡片。
底层原理

网格轨道(Grid Tracks):

网格轨道是网格线之间的空间,表示行或列。
grid-template-columns: repeat(3, 1fr); 定义了3个列轨道,每个轨道的宽度为可用空间的1份。

分数单位(fr):

1fr 表示该列占据可用空间的1份。
如果容器的总宽度为900px,那么每个列的宽度将是300px(900px / 3)。

重复定义:

repeat(3, 1fr) 等同于 1fr 1fr 1fr,但使用 repeat 函数可以减少冗余代码,提高可读性。
epeat 函数可以确保项目在容器内均匀分布。
示例:一个动态生成的产品列表页面,每行显示3个产品卡片。
底层原理

网格轨道(Grid Tracks):

网格轨道是网格线之间的空间,表示行或列。
grid-template-columns: repeat(3, 1fr); 定义了3个列轨道,每个轨道的宽度为可用空间的1份。

分数单位(fr):

1fr 表示该列占据可用空间的1份。
如果容器的总宽度为900px,那么每个列的宽度将是300px(900px / 3)。

重复定义:

repeat(3, 1fr) 等同于 1fr 1fr 1fr,但使用 repeat 函数可以减少冗余代码,提高可读性。


http://www.kler.cn/a/562646.html

相关文章:

  • ChatGPT各模型版本对比分析
  • 【学习笔记】计算机网络(四)
  • 读取罗克韦尔AllenBradley Micro-Logix1400 罗克韦尔 CIP PCCC通信协议
  • 内网综合渗透测试——WinterMute: 1靶场
  • 构建GraphRAG图数据检索知识库搜索图数据(含源代码)
  • 【后端】微服务架构
  • 主从同步延迟过高?阿里云助力优化读写分离数据库
  • 蓝桥杯刷题-dp-线性dp(守望者的逃离,摆花,线段)
  • [回顾]从原型链视角解读Vue底层实现Vue VueCompoent VM VC关系
  • 【R安装包报错】在conda环境下用R语言命令安装R包报错
  • Git 版本控制器:从零入门到实战配置(2025 最新版)
  • 小智机器人CMakeLists编译文件解析
  • 基于SpringBoot的“古城景区管理系统”的设计与实现(源码+数据库+文档+PPT)
  • comfy SDXL_EcomID_ComfyUI 节点地址
  • windows中kafka集群部署示例
  • Orange 开源项目 - 集成百度智能云-千帆大模型
  • Spring boot中的@ConfigurationProperties注解
  • 危化品经营单位安全管理人员的职责及注意事项
  • windows本地升级npm
  • Ranorex 截图功能对UI测试有哪些优势