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

要求

代码

// 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>

 

猜你喜欢

转载自blog.csdn.net/2302_81312344/article/details/145852705
今日推荐