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

蓝桥杯 - 简单 - 俄罗斯方块

要求

代码

// index.css

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

.l-shape {
    display: grid;
    /* TODO:待补充代码 */
    grid-template-columns: repeat(3,30px);
    grid-template-rows: 30px 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);
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>俄罗斯方块</title>
    <link rel="stylesheet" href="./css/style.css">
</head>
<body>
    <div class="tetris-container">
        <div class="score-container">
            <div class="score">Score: 123</div>
            <div class="level">Level: 1</div>
        </div>
        <div class="grid-container">
            <div class="grid-item type1" style="left: 0px; bottom: 30px;"></div>
            <div class="grid-item type1" style="left: 0px; bottom: 0;"></div>
            <div class="grid-item type2" style="left: 30px; bottom: 0;"></div>
            <div class="grid-item type3" style="left: 60px; bottom:0;"></div>
            <div class="grid-item type3" style="left: 60px; bottom:30px;"></div>
            <div class="grid-item type4" style="left: 90px; bottom: 0;"></div>
            <div class="grid-item type5" style="left: 120px; bottom: 0;"></div>
            <div class="grid-item type6" style="left: 150px; bottom: 0;"></div>
            <div class="grid-item type2" style="left: 240px; bottom: 30px;"></div>
            <div class="grid-item type2" style="left: 270px; bottom: 30px;"></div>    
            <div class="grid-item type6" style="left: 180px; bottom: 0;"></div>
            <div class="grid-item type6" style="left: 210px; bottom: 0;"></div>
            <div class="grid-item type6" style="left: 240px; bottom: 0;"></div>
            <div class="grid-item type6" style="left: 270px; bottom: 0;"></div>
        </div>
        <div class="next-block">
               Next Block:
            <div class="grid-container">
                <div class="z-shape">
                    <div class="cell"></div>
                    <div class="cell"></div>
                    <div class="cell"></div>
                    <div class="cell"></div>
                  </div>
            </div>
                Next Block:
            <div class="grid-container">
                <div class="l-shape">
                    <div class="cell"></div>
                    <div class="cell"></div>
                    <div class="cell"></div>
                    <div class="cell"></div>
                  </div>
            </div>
        </div>
    </div>
</body>
</html>

 

  • 扩展grid 网格布局;
  • CSS Grid 网格布局教程 - 阮一峰的网络日志
  • 根据题目要求分析,可以利用开发工具查看细节,如具体盒子大小,来确定格子的宽高度等。

相关文章:

  • IDEAPyCharm安装ProxyAI(CodeGPT)插件连接DeepSeek-R1教程
  • 学术小助手智能体
  • rust学习~tokio的io
  • 网络安全技术概述
  • 【安卓】BroadcastReceiver 动态声明为 RECEIVER_NOT_EXPORTED 后无法接收任何 Intent 的问题
  • 结构化方法SASD
  • openGauss数据库使用
  • 谈谈 Node.js 中的文件系统(fs)模块,如何进行文件读写操作?
  • CSS—背景属性与盒子模型(border、padding、margin)
  • 越南SD-WAN跨境组网专线助力制造业访问国内 OA、ERP系统难题
  • Go基于协程池的延迟任务调度器
  • 《Kafka 理解: Broker、Topic 和 Partition》
  • 【leetcode】二分查找专题
  • 打造爆款秘籍:利用ARA数据优化亚马逊广告策略
  • STM32呼吸灯实验手册(TIM定时器)
  • Linux网络 数据链路层
  • StableDiffusion打包 项目迁移 项目分发 1
  • 《深度学习实战》第5集:生成对抗网络(GAN)与图像生成
  • 矩阵系列 题解
  • Spring的@Configuration注解:深入解析与实战指南
  • 无锡专业网站推广/电子网址怎么创建
  • 信息门户网站制作/百度秒收录技术
  • 网页设计师的能力/宁波seo服务推广
  • 怎么在浏览器上面建网站/新站整站优化
  • 拓者设计吧室内效果图轻奢/做seo排名
  • 湘潭seo网站优化/google官方下载