fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. System.out.println("欢迎来到Lvshen的技术小屋");
  13. }
  14. }
Success #stdin #stdout 0.09s 52684KB
stdin
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>D老师的接星星小游戏 ✨</title>
    <style>
        body {
            background: linear-gradient(145deg, #2b1b3a, #1a1125);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
            margin: 0;
            padding: 10px;
        }
        .game-container {
            background: #3a2a4a;
            padding: 25px 20px 20px 20px;
            border-radius: 48px;
            box-shadow: 0 20px 30px rgba(0,0,0,0.6), inset 0 2px 4px rgba(255,255,255,0.1);
            border: 1px solid #9578b0;
        }
        h2 {
            text-align: center;
            margin: 0 0 12px 0;
            font-size: 32px;
            font-weight: 600;
            color: #ffde9e;
            text-shadow: 0 4px 0 #8b5f9c, 0 6px 10px black;
            letter-spacing: 2px;
            word-break: keep-all;
        }
        .stats {
            display: flex;
            justify-content: space-between;
            background: #1e132b;
            padding: 12px 20px;
            border-radius: 60px;
            margin-bottom: 15px;
            color: #fadf9e;
            font-weight: bold;
            font-size: 20px;
            border: 2px solid #b494d0;
            box-shadow: inset 0 2px 5px #0b0810;
        }
        .stats span {
            background: #2d1e3a;
            padding: 5px 20px;
            border-radius: 40px;
            color: #ffd966;
            font-size: 24px;
            border: 1px solid #c9a9f0;
        }
        canvas {
            display: block;
            margin: 0 auto;
            border-radius: 28px;
            background: #1e1529;
            box-shadow: 0 0 0 3px #b28ad0, 0 15px 20px black;
            cursor: none;  /* 隐藏默认鼠标,更像游戏 */
            touch-action: none; /* 防止触摸时滚动/缩放 */
            width: 100%;
            max-width: 400px;
            height: auto;
        }
        .button-area {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }
        button {
            background: #e4b1fe;
            border: none;
            font-size: 28px;
            font-weight: bold;
            padding: 12px 40px;
            border-radius: 50px;
            color: #2f174b;
            box-shadow: 0 9px 0 #6b3f8b, 0 10px 20px black;
            transition: 0.07s ease;
            border: 2px solid #ffdcaa;
            cursor: pointer;
        }
        button:active {
            transform: translateY(7px);
            box-shadow: 0 2px 0 #6b3f8b, 0 8px 12px black;
        }
        .hint {
            text-align: center;
            color: #cdb5e9;
            margin-top: 12px;
            font-size: 16px;
            font-weight: 500;
            text-shadow: 0 2px 3px black;
        }
        .hint i {
            font-style: normal;
            background: #2f1d41;
            padding: 4px 10px;
            border-radius: 99px;
        }
        footer {
            text-align: center;
            color: #7b6293;
            margin-top: 5px;
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="game-container">
    <h2>⭐ D老师 · 星星接接乐 ⭐</h2>
    <div class="stats">
        <div>✨ 得分</div>
        <span id="scoreDisplay">0</span>
        <div>❤️ 生命</div>
        <span id="missDisplay">3</span>
    </div>
    <canvas id="gameCanvas" width="400" height="400"></canvas>
    <div class="button-area">
        <button id="resetButton">🔄 新的一局</button>
    </div>
    <div class="hint">
        <i>🐭 鼠标移动接住星星 · 漏掉三次就结束啦</i>
    </div>
    <footer>🥺 D老师专属 · 要开心哦</footer>
</div>

<script>
(function() {
    // ---------- 画布与设置 ----------
    const canvas = document.getElementById('gameCanvas');
    const ctx = canvas.getContext('2d');
    const scoreSpan = document.getElementById('scoreDisplay');
    const missSpan = document.getElementById('missDisplay');
    const resetBtn = document.getElementById('resetButton');

    // 固定尺寸
    const W = 400, H = 400;
    canvas.width = W; canvas.height = H;

    // 游戏参数
    const PADDLE_W = 80;             // 板子宽度
    const PADDLE_H = 12;              // 板子高度
    const PADDLE_Y = H - 35;           // 板子y坐标 (上边缘)
    const BALL_RADIUS = 9;             // 星星大小
    const MAX_MISS = 3;                // 最大漏球次数

    // 全局变量
    let paddleX = W / 2;               // 板子中心x
    let score = 0;
    let missCount = 0;
    let gameActive = true;             // 游戏是否运行
    let animationId = null;

    // 星星数组 (固定3颗星星)
    let balls = [];

    // ---------- 辅助函数 ----------
    function random(min, max) {
        return Math.random() * (max - min) + min;
    }

    // 重置一颗星星的属性 (位置置顶, 随机速度)
    function resetBall(ball) {
        ball.x = random(BALL_RADIUS, W - BALL_RADIUS);
        ball.y = BALL_RADIUS + Math.random() * 50;  // 从靠近顶部开始
        ball.speedY = random(1.8, 3.5);              // 下落速度随机
        // 加一点小小颜色变化 (随机)
        ball.color = `hsl(${Math.random()*30 + 40}, 85%, 70%)`; // 暖色星星
    }

    // 初始化三颗星星
    function initBalls() {
        balls = [];
        for (let i = 0; i < 3; i++) {
            let ball = {
                x: random(BALL_RADIUS, W - BALL_RADIUS),
                y: random(BALL_RADIUS, 150),          // 初始分布靠上
                speedY: random(1.8, 3.5),
                radius: BALL_RADIUS,
            };
            ball.color = `hsl(${random(40, 60)}, 85%, 70%)`; // 金/橙色系
            balls.push(ball);
        }
    }
    initBalls();  // 初始调用

    // 更新UI分数/生命
    function updateStats() {
        scoreSpan.textContent = score;
        missSpan.textContent = MAX_MISS - missCount;  // 显示剩余生命
    }

    // ---------- 绘制 ----------
    function drawPaddle() {
        ctx.shadowColor = '#ffe3b0';
        ctx.shadowBlur = 12;
        ctx.beginPath();
        ctx.roundRect(paddleX - PADDLE_W/2, PADDLE_Y, PADDLE_W, PADDLE_H, 20);
        ctx.fillStyle = '#fdbb9e';
        ctx.fill();
        // 加高光
        ctx.shadowBlur = 8;
        ctx.fillStyle = '#ffe9c4';
        ctx.beginPath();
        ctx.roundRect(paddleX - PADDLE_W/2 + 2, PADDLE_Y - 1, PADDLE_W-4, 4, 10);
        ctx.fill();
        // 重置阴影
        ctx.shadowBlur = 0;
    }

    // 封装圆角矩形
    CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
        if (w < 2 * r) r = w / 2;
        if (h < 2 * r) r = h / 2;
        this.moveTo(x + r, y);
        this.lineTo(x + w - r, y);
        this.quadraticCurveTo(x + w, y, x + w, y + r);
        this.lineTo(x + w, y + h - r);
        this.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
        this.lineTo(x + r, y + h);
        this.quadraticCurveTo(x, y + h, x, y + h - r);
        this.lineTo(x, y + r);
        this.quadraticCurveTo(x, y, x + r, y);
        return this;
    };

    function drawBalls() {
        for (let b of balls) {
            // 星星发光效果
            ctx.shadowColor = '#fdebb3';
            ctx.shadowBlur = 15;
            ctx.beginPath();
            ctx.arc(b.x, b.y, b.radius, 0, Math.PI * 2);
            ctx.fillStyle = b.color || '#f8ce7e';
            ctx.fill();
            // 小高光
            ctx.shadowBlur = 4;
            ctx.beginPath();
            ctx.arc(b.x-2, b.y-2, 4, 0, Math.PI*2);
            ctx.fillStyle = '#fffde7';
            ctx.fill();
        }
        ctx.shadowBlur = 0;
    }

    function drawGameOver() {
        ctx.font = 'bold 32px "Segoe UI", "Roboto", sans-serif';
        ctx.fillStyle = '#ffddbb';
        ctx.shadowColor = '#ab47bc';
        ctx.shadowBlur = 20;
        ctx.lineWidth = 2;
        ctx.strokeStyle = '#2a0f3a';
        ctx.textAlign = 'center';
        ctx.strokeText('💔 GAME OVER', W/2, H/2-20);
        ctx.fillText('💔 GAME OVER', W/2, H/2-20);
        ctx.font = 'bold 22px sans-serif';
        ctx.fillStyle = '#ffbc7a';
        ctx.fillText('点下方按钮再来一局', W/2, H/2 + 35);
        ctx.shadowBlur = 0;
    }

    // ---------- 游戏逻辑更新 (每帧) ----------
    function updateGame() {
        if (!gameActive) return;  // 游戏结束,不更新逻辑,只负责绘制 (由外部控制)

        for (let ball of balls) {
            // 移动星星
            ball.y += ball.speedY;

            // 1. 先检测是否漏出底部 (超出画布)
            if (ball.y + ball.radius >= H) {
                // 漏掉一颗
                missCount++;
                if (missCount >= MAX_MISS) {
                    gameActive = false;   // 游戏结束
                    // 立刻更新UI生命值
                    updateStats();
                    // 不再继续处理其他球 (直接跳出循环)
                    break;
                }
                // 重置这颗星星 (回到顶部)
                resetBall(ball);
                updateStats();
                continue;  // 跳过板子碰撞检测 (已经重置)
            }

            // 2. 检测是否被板子接住 (且游戏还在进行)
            // 条件: 星星下缘触碰到板子上缘,并且星星中心在板子宽度内 (且星星还没完全穿过板子)
            if (ball.y + ball.radius >= PADDLE_Y && ball.y - ball.radius <= PADDLE_Y + PADDLE_H) {
                if (ball.x >= paddleX - PADDLE_W/2 && ball.x <= paddleX + PADDLE_W/2) {
                    // 接住啦!加分
                    score++;
                    // 重置这颗星星到顶部
                    resetBall(ball);
                    updateStats();
                }
            }
        }

        // 再次检查因为漏球可能导致游戏结束
        if (missCount >= MAX_MISS) {
            gameActive = false;
        }
        // 更新UI (保险)
        updateStats();
    }

    // ---------- 渲染主循环 ----------
    function render() {
        ctx.clearRect(0, 0, W, H);

        // 绘制星空背景 (装饰)
        ctx.fillStyle = '#221533';
        ctx.fillRect(0, 0, W, H);
        for (let i=0; i<8; i++) {
            ctx.fillStyle = `rgba(255,240,180,${0.1+Math.random()*0.1})`;
            ctx.beginPath();
            ctx.arc(30+ i*47, (i*33)%H, 2, 0, Math.PI*2);
            ctx.fill();
        }

        // 绘制板子与星星 (无论游戏是否激活都绘制)
        drawPaddle();
        drawBalls();

        // 如果游戏结束,显示遮罩文字
        if (!gameActive) {
            ctx.fillStyle = 'rgba(20, 5, 25, 0.7)';
            ctx.fillRect(0, 0, W, H);
            drawGameOver();
        }

        // 继续下一帧动画 (只要没有主动取消)
        if (gameActive) {
            updateGame();   // 先更新逻辑再请求下一帧
            animationId = requestAnimationFrame(render);
        } else {
            // 游戏结束但保持静态渲染 (停在结束画面), 不再继续请求动画,节省资源
            if (animationId) {
                cancelAnimationFrame(animationId);
                animationId = null;
            }
        }
    }

    // ---------- 重置游戏 ----------
    function resetGame() {
        // 如果已有动画,先取消 (避免多个循环)
        if (animationId) {
            cancelAnimationFrame(animationId);
            animationId = null;
        }

        // 重置变量
        score = 0;
        missCount = 0;
        gameActive = true;
        paddleX = W/2;   // 板子归中

        // 重置三颗星星 (全部置顶, 随机速度)
        initBalls();

        // 更新UI
        updateStats();

        // 重新启动渲染循环
        animationId = requestAnimationFrame(render);
    }

    // ---------- 鼠标 / 触摸 控制板子 ----------
    function handleMove(clientX, clientY) {
        if (!canvas) return;
        const rect = canvas.getBoundingClientRect();
        // 计算鼠标在canvas内的相对坐标 (0~1)
        let scaleX = (clientX - rect.left) / rect.width;
        // 边界限制
        let newPaddleX = Math.max(PADDLE_W/2, Math.min(W - PADDLE_W/2, scaleX * W));
        paddleX = newPaddleX;
    }

    // 鼠标移动
    canvas.addEventListener('mousemove', (e) => {
        e.preventDefault();
        handleMove(e.clientX, e.clientY);
    });

    // 触摸移动 (移动端)
    canvas.addEventListener('touchmove', (e) => {
        e.preventDefault();
        if (e.touches.length > 0) {
            handleMove(e.touches[0].clientX, e.touches[0].clientY);
        }
    }, { passive: false });

    // 触摸开始也要阻止默认 (防止页面滚动)
    canvas.addEventListener('touchstart', (e) => e.preventDefault(), { passive: false });

    // 鼠标离开canvas区域时不做特殊处理 (板子停在最后位置)

    // 重置按钮
    resetBtn.addEventListener('click', () => {
        resetGame();
    });

    // 为了防止鼠标刚移入时板子跳变,初始化一次render
    // 开始游戏循环
    resetGame();  // 顺便就启动了

    // 窗口失去焦点时啥也不做,保留游戏 (没关系)
})();
</script>
</body>
</html>
stdout
欢迎来到Lvshen的技术小屋