<!DOCTYPE html>
<html>
  <head>
    <title>ASCII Game</title>
    <style>
      pre {
        font-family: monospace;
      }
    </style>
  </head>
  <body>
    <pre id="game-screen"></pre>

    <script>
      var gameScreen = document.getElementById("game-screen");
      var currentRoom = "start";
      var hasKey = false;

      // Function to display text on the game screen
      function displayText(text) {
        gameScreen.textContent += text + "\n";
      }

      // Function to clear the game screen
      function clearScreen() {
        gameScreen.textContent = "";
      }

      // Start the game
      function startGame() {
        clearScreen();
        displayText("Welcome to the ASCII Game!");
        displayText("You find yourself in a mysterious room.");
        displayText("There are two doors in front of you.");
        displayText("Press 1 or 2 to choose a door.");

        // Event listener to handle user input
        document.addEventListener("keydown", handleInput);
      }

      // Handle user input
      function handleInput(event) {
        var key = event.key.toLowerCase();

        if (currentRoom === "start") {
          if (key === "1") {
            enterHallway();
          } else if (key === "2") {
            enterLibrary();
          } else {
            displayText("Invalid input. Press 1 or 2 to choose a door.");
          }
        } else if (currentRoom === "hallway") {
          if (key === "1") {
            enterDiningRoom();
          } else if (key === "2") {
            enterBedroom();
          } else {
            displayText("Invalid input. Press 1 or 2 to choose a door.");
          }
        } else if (currentRoom === "library") {
          if (key === "1") {
            enterDiningRoom();
          } else if (key === "2") {
            enterBedroom();
          } else {
            displayText("Invalid input. Press 1 or 2 to choose a door.");
          }
        } else if (currentRoom === "dining room") {
          if (key === "1") {
            if (hasKey) {
              enterTreasureRoom();
            } else {
              displayText("The door is locked. You need a key to enter.");
            }
          } else if (key === "2") {
            enterHallway();
          } else {
            displayText("Invalid input. Press 1 or 2 to choose a door.");
          }
        } else if (currentRoom === "bedroom") {
          if (key === "1") {
            enterHallway();
          } else if (key === "2") {
            displayText("You found a key! It might be useful.");
            hasKey = true;
            enterHallway();
          } else {
            displayText("Invalid input. Press 1 or 2 to choose a door.");
          }
        } else if (currentRoom === "treasure room") {
          displayText("Congratulations! You found the treasure and won the game!");
          document.removeEventListener("keydown", handleInput);
        }
      }

      // Enter the hallway
      function enterHallway() {
        clearScreen();
        displayText("You enter a dark hallway.");
        displayText("There are two doors ahead of you.");
        displayText("Press 1 or 2 to choose a door.");
        currentRoom = "hallway";
      }

      // Enter the library
      function