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. // your code goes here
  13. }
  14. }
Success #stdin #stdout 0.07s 54680KB
stdin
pythonimport google.colab.output
import random

# ==========================================
# 1. 障害物よけアクションゲーム(キューブラン)
# ==========================================
google.colab.output.html('''
<div style="text-align: center; font-family: sans-serif; margin-bottom: 40px;">
    <h3>① キューブラン(クリックでジャンプ!)</h3>
    <canvas id="gameCanvas" width="480" height="200" style="border:2px solid #333; background:#f7f7f7;"></canvas>
    <div id="scoreBoard" style="font-size: 20px; margin-top: 10px;">SCORE: 0</div>
    <button id="retryBtn" style="display:none; margin: 10px auto; padding: 5px 15px; font-size:16px;">もう一度プレイ</button>
</div>

<script>
(function() {
    const canvas = document.getElementById("gameCanvas");
    const ctx = canvas.getContext("2d");
    const scoreBoard = document.getElementById("scoreBoard");
    const retryBtn = document.getElementById("retryBtn");

    let player, obstacles, score, gameActive, speed;

    function init() {
        player = { x: 50, y: 150, wy: 0, size: 20, isJumping: false };
        obstacles = [];
        score = 0;
        speed = 4;
        gameActive = true;
        retryBtn.style.display = "none";
        scoreBoard.innerText = "SCORE: 0";
        loop();
    }

    function spawnObstacle() {
        if (!gameActive) return;
        obstacles.push({ x: canvas.width, y: 150, width: 15, height: 20 + Math.random() * 20 });
        setTimeout(spawnObstacle, 1200 + Math.random() * 1000);
    }

    function jump() {
        if (!player.isJumping && gameActive) {
            player.wy = -8;
            player.isJumping = true;
        }
    }

    canvas.addEventListener("click", jump);
    retryBtn.addEventListener("click", init);

    function loop() {
        if (!gameActive) return;
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        ctx.fillStyle = "#666";
        ctx.fillRect(0, 170, canvas.width, 30);

        player.y += player.wy;
        player.wy += 0.4;
        if (player.y >= 150) {
            player.y = 150;
            player.isJumping = false;
        }

        ctx.fillStyle = "#3498db";
        ctx.fillRect(player.x, player.y, player.size, player.size);

        for (let i = obstacles.length - 1; i >= 0; i--) {
            let obs = obstacles[i];
            obs.x -= speed;

            ctx.fillStyle = "#e74c3c";
            ctx.fillRect(obs.x, obs.y, obs.width, obs.height);

            if (player.x < obs.x + obs.width &&
                player.x + player.size > obs.x &&
                player.y < obs.y + obs.height &&
                player.y + player.size > obs.y) {
                gameActive = false;
                ctx.fillStyle = "rgba(0,0,0,0.5)";
                ctx.fillRect(0, 0, canvas.width, canvas.height);
                ctx.fillStyle = "#fff";
                ctx.font = "30px sans-serif";
                ctx.fillText("GAME OVER", 150, 100);
                retryBtn.style.display = "block";
            }

            if (obs.x + obs.width < player.x && !obs.passed) {
                obs.passed = true;
                score += 10;
                scoreBoard.innerText = "SCORE: " + score;
                speed += 0.2;
            }
            if (obs.x < -20) obstacles.splice(i, 1);
        }
        requestAnimationFrame(loop);
    }

    init();
    spawnObstacle();
})();
</script>
''')

# ==========================================
# 2. タイピングスピード測定ゲーム
# ==========================================
google.colab.output.html('''
<div style="text-align: center; font-family: sans-serif; background: #2c3e50; color: white; padding: 20px; border-radius: 10px; width: 400px; margin: 0 auto 40px auto;">
    <h2>② タイピングゲーム</h2>
    <div id="timer" style="font-size: 18px; color: #f1c40f;">残り時間: 20秒</div>
    <div id="wordDisplay" style="font-size: 32px; font-weight: bold; margin: 20px 0; letter-spacing: 2px;">---</div>
    <input type="text" id="typeInput" style="font-size: 20px; padding: 5px; width: 80%; text-align: center;" autocomplete="off" disabled>
    <div id="scoreDisplay" style="margin-top: 15px; font-size: 18px;">スコア: 0</div>
    <button id="startBtn" style="margin-top: 15px; padding: 8px 20px; font-size: 16px; background: #27ae60; color: white; border: none; border-radius: 5px; cursor: pointer;">スタート</button>
</div>

<script>
(function() {
    const words = ["python", "code", "google", "colab", "notebook", "program", "script", "ai", "data", "web", "game", "keyboard"];
    let currentWord = "";
    let score = 0;
    let timeLeft = 20;
    let timerId = null;

    const wordDisplay = document.getElementById("wordDisplay");
    const typeInput = document.getElementById("typeInput");
    const scoreDisplay = document.getElementById("scoreDisplay");
    const timerDisplay = document.getElementById("timer");
    const startBtn = document.getElementById("startBtn");

    function nextWord() {
        currentWord = words[Math.floor(Math.random() * words.length)];
        wordDisplay.innerText = currentWord;
        typeInput.value = "";
    }

    function startGame() {
        score = 0;
        timeLeft = 20;
        scoreDisplay.innerText = "スコア: " + score;
        timerDisplay.innerText = "残り時間: " + timeLeft + "秒";
        typeInput.disabled = false;
        startBtn.style.display = "none";
        nextWord();
        typeInput.focus();
        
        timerId = setInterval(() => {
            timeLeft--;
            timerDisplay.innerText = "残り時間: " + timeLeft + "秒";
            if (timeLeft <= 0) {
                clearInterval(timerId);
                typeInput.disabled = true;
                wordDisplay.innerText = "終了!";
                startBtn.innerText = "もう一度プレイ";
                startBtn.style.display = "inline-block";
            }
        }, 1000);
    }

    typeInput.addEventListener("input", () => {
        if (typeInput.value.trim().toLowerCase() === currentWord) {
            score++;
            scoreDisplay.innerText = "スコア: " + score;
            nextWord();
        }
    });

    startBtn.addEventListener("click", startGame);
})();
</script>
''')

# ==========================================
# 3. 数当てロジックゲーム
# ==========================================
def play_numeric_game():
    print("\n" + "="*40)
    print("③ 【数当てロジックゲーム (3桁)】")
    print("0〜9の異なる3桁の数字を当ててください。")
    print("Eat = 数字も位置も正解 / Bite = 数字は合っているが位置が違う")
    print("="*40 + "\n")
    
    numbers = list(range(10))
    random.shuffle(numbers)
    target = numbers[:3]
    
    turns = 0
    while True:
        turns += 1
        guess_raw = input(f"[{turns手目] 3桁の数字を入力してください: ")
        
        if len(guess_raw) != 3 or not guess_raw.isdigit():
            print("エラー: 3桁の数字を正確を入力してください。")
            continue
            
        guess = [int(char) for char in guess_raw]
        if len(set(guess)) != 3:
            print("エラー: 同じ数字を2回以上使えません。")
            continue
            
        eat = 0
        bite = 0
        for i in range(3):
            if guess[i] == target[i]:
                eat += 1
            elif guess[i] in target:
                bite += 1
                
        print(f"結果: {eat} Eat / {bite} Bite")
        
        if eat == 3:
            print(f"🎉 おめでとうございます! {turns}手目で正解しました!")
            break

play_numeric_game()
stdout
Standard output is empty