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 54684KB
stdin
<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Minecraft Clone</title>
  <style>
    body { margin: 0; overflow: hidden; font-family: sans-serif; }
    #crosshair {
      position: absolute; top: 50%; left: 50%;
      width: 16px; height: 16px; margin: -8px 0 0 -8px;
      color: white; font-size: 20px; text-align: center; line-height: 16px;
      pointer-events: none; text-shadow: 1px 1px 2px black;
    }
    #ui {
      position: absolute; top: 10px; left: 10px;
      background: rgba(0, 0, 0, 0.6); color: white;
      padding: 12px; border-radius: 6px; font-size: 14px; line-height: 1.6;
    }
    #blocker {
      position: absolute; width: 100%; height: 100%;
      background: rgba(0, 0, 0, 0.5); display: flex;
      align-items: center; justify-content: center; color: white;
      font-size: 24px; cursor: pointer; z-index: 10;
    }
  </style>
</head>
<body>
  <div id="blocker">CLICK TO PLAY</div>
  <div id="crosshair">+</div>
  <div id="ui">
    <b>操作方法</b><br>
    ・移動: W A S D / ジャンプ: Space<br>
    ・破壊: 左クリック / 設置: 右クリック<br>
    ・ブロック: 1(草) 2(土) 3(石) 4(木)<br>
    ・選択中: <span id="selected-block" style="color:#7cfc00; font-weight:bold;">草</span>
  </div>

  <script type="importmap">
    {
      "imports": {
        "three": "https://u...content-available-to-author-only...g.com",
        "three/addons/": "https://u...content-available-to-author-only...g.com"
      }
    }
  </script>

  <script type="module">
    import * as THREE from 'three';
    import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x87ceeb);
    scene.fog = new THREE.Fog(0x87ceeb, 10, 50);

    const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
    camera.position.set(0, 5, 10);

    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(window.innerWidth, window.innerHeight);
    document.body.appendChild(renderer.domElement);

    const ambientLight = new THREE.AmbientLight(0xffffff, 0.7);
    scene.add(ambientLight);
    const dirLight = new THREE.DirectionalLight(0xffffff, 0.8);
    dirLight.position.set(10, 20, 10);
    scene.add(dirLight);

    const materials = {
      1: new THREE.MeshLambertMaterial({ color: 0x55aa55 }),
      2: new THREE.MeshLambertMaterial({ color: 0x8b5a2b }),
      3: new THREE.MeshLambertMaterial({ color: 0x808080 }),
      4: new THREE.MeshLambertMaterial({ color: 0xc19a6b })
    };
    const blockNames = { 1: "草", 2: "土", 3: "石", 4: "木" };
    let currentBlockType = 1;

    const boxGeo = new THREE.BoxGeometry(1, 1, 1);
    const edgesGeo = new THREE.EdgesGeometry(boxGeo);
    const lineMat = new THREE.LineBasicMaterial({ color: 0x000000, transparent: true, opacity: 0.2 });
    const blocks = [];

    function addBlock(x, y, z, type) {
      const mesh = new THREE.Mesh(boxGeo, materials[type]);
      mesh.position.set(x, y, z);
      mesh.add(new THREE.LineSegments(edgesGeo, lineMat));
      scene.add(mesh);
      blocks.push(mesh);
    }

    for (let x = -10; x < 10; x++) {
      for (let z = -10; z < 10; z++) {
        addBlock(x, 0, z, 1);
        addBlock(x, -1, z, 2);
        if (Math.random() > 0.85) addBlock(x, 1, z, 1);
      }
    }

    const controls = new PointerLockControls(camera, document.body);
    const blocker = document.getElementById('blocker');
    blocker.addEventListener('click', () => controls.lock());
    controls.addEventListener('lock', () => blocker.style.display = 'none');
    controls.addEventListener('unlock', () => blocker.style.display = 'flex');

    const move = { forward: false, backward: false, left: false, right: false };
    let velocityY = 0;
    let canJump = false;

    document.addEventListener('keydown', (e) => {
      switch (e.code) {
        case 'KeyW': move.forward = true; break;
        case 'KeyS': move.backward = true; break;
        case 'KeyA': move.left = true; break;
        case 'KeyD': move.right = true; break;
        case 'Space': if (canJump) { velocityY = 8; canJump = false; } break;
        case 'Digit1': case 'Digit2': case 'Digit3': case 'Digit4':
          currentBlockType = Number(e.key);
          document.getElementById('selected-block').innerText = blockNames[currentBlockType];
          break;
      }
    });

    document.addEventListener('keyup', (e) => {
      switch (e.code) {
        case 'KeyW': move.forward = false; break;
        case 'KeyS': move.backward = false; break;
        case 'KeyA': move.left = false; break;
        case 'KeyD': move.right = false; break;
      }
    });

    const raycaster = new THREE.Raycaster();
    raycaster.far = 8;

    window.addEventListener('mousedown', (e) => {
      if (!controls.isLocked) return;
      raycaster.setFromCamera(new THREE.Vector2(0, 0), camera);
      const intersects = raycaster.intersectObjects(blocks);
      if (intersects.length > 0) {
        const hit = intersects[0];
        if (e.button === 0) {
          scene.remove(hit.object);
          blocks.splice(blocks.indexOf(hit.object), 1);
        } else if (e.button === 2) {
          const pos = hit.object.position.clone().add(hit.face.normal);
          addBlock(pos.x, pos.y, pos.z, currentBlockType);
        }
      }
    });

    window.addEventListener('contextmenu', (e) => e.preventDefault());
    window.addEventListener('resize', () => {
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();
      renderer.setSize(window.innerWidth, window.innerHeight);
    });

    let prevTime = performance.now();
    function animate() {
      requestAnimationFrame(animate);
      const time = performance.now();
      const delta = (time - prevTime) / 1000;
      prevTime = time;

      if (controls.isLocked) {
        const speed = 6.0 * delta;
        if (move.forward) controls.moveForward(speed);
        if (move.backward) controls.moveForward(-speed);
        if (move.left) controls.moveRight(-speed);
        if (move.right) controls.moveRight(speed);

        velocityY -= 20.0 * delta;
        camera.position.y += velocityY * delta;
        if (camera.position.y < 2.5) {
          velocityY = 0;
          camera.position.y = 2.5;
          canJump = true;
        }
      }
      renderer.render(scene, camera);
    }
    animate();
  </script>
</body>
</html>
stdout
Standard output is empty