Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-08-06· OpenAIAi2 WildChat-4.8M (AI2)

make a tiny game where i can cook a burger on a stove in js

  1. User

    make a tiny game where i can cook a burger on a stove in js

  2. Assistant

    Creating a simple JavaScript game where you can cook a burger on a stove can be a fun little project. Below is a basic example using HTML, CSS, and JavaScript to accomplish this. This won't involve sophisticated graphics, but it should give you a starting point that you can expand upon:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Cook a Burger Game</title>
        <style>
            #stove {
                width: 200px;
                height: 200px;
                background: #333;
                position: relative;
                margin: 50px auto;
                border-radius: 10px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            }
            #burger {
                width: 100px;
                height: 100px;
                background: brown;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                border-radius: 50%;
            }
            #message {
                text-align: center;
                font-size: 18px;
                margin-top: 20px;
            }
            button {
                display: block;
                margin: 20px auto;
                padding: 10px 20px;
                font-size: 16px;
            }
        </style>
    </head>
    <body>
    
        <div id="stove">
            <div id="burger"></div>
        </div>
        <div id="message">Press "Cook" to start cooking!</div>
        <button id="cookButton">Cook</button>
    
        <script>
            const burger = document.getElementById('burger');
            const message = document.getElementById('message');
            const cookButton = document.getElementById('cookButton');
            let cooking = false;
            let cookTime = 0;
    
            cookButton.addEventListener('click', () => {
                if (!cooking) {
                    cooking = true;
                    cookButton.disabled = true;
                    message.textContent = "Cooking in progress...";
                    const cookInterval = setInterval(() => {
                        cookTime++;
                        if (cookTime === 5) {
                            burger.style.backgroundColor = 'darkbrown';
                            message.textContent = "Burger is perfectly cooked!";
                            clearInterval(cookInterval);
                            cookButton.disabled = false;
                            cooking = false;
                            cookTime = 0;
                        } else if (cookTime > 5) {
                            burger.style.backgroundColor = 'black';
                            message.textContent = "Oh no! The burger is burnt!";
                            clearInterval(cookInterval);
                            cookButton.disabled = false;
                            cooking = false;
                            cookTime = 0;
                        }
                    }, 1000);
                }
            });
        </script>
    
    </body>
    </html>
    

    How it Works:

    1. HTML Structure: This consists of a div representing the stove and another div for the burger. There's also a message area and a button to start cooking.

    2. CSS Styling: Basic styles are provided for the stove, burger, and the UI elements to give them a simple, playable appearance.

    3. JavaScript Logic:

      • An event listener is set on the "Cook" button.
      • When the button is clicked, the cooking process starts.
      • The setInterval function simulates the cooking process, changing the color of the burger as it "cooks."
      • After 5 seconds, the burger is perfectly cooked, and after that, it turns black to signify it is burnt.

    This is a tiny game, but you can expand upon it by adding more interactivity, graphics, or challenges like customizable cooking times or additional ingredients.

  3. User

    make it so after the burger is cooked, a link appears to a portfolio site

  4. Assistant

    Certainly! You can modify the script to include a link to a portfolio site that appears once the burger is perfectly cooked. Below is the revised code with this feature added:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Cook a Burger Game</title>
        <style>
            #stove {
                width: 200px;
                height: 200px;
                background: #333;
                position: relative;
                margin: 50px auto;
                border-radius: 10px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            }
            #burger {
                width: 100px;
                height: 100px;
                background: brown;
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                border-radius: 50%;
            }
            #message {
                text-align: center;
                font-size: 18px;
                margin-top: 20px;
            }
            button {
                display: block;
                margin: 20px auto;
                padding: 10px 20px;
                font-size: 16px;
            }
        </style>
    </head>
    <body>
    
        <div id="stove">
            <div id="burger"></div>
        </div>
        <div id="message">Press "Cook" to start cooking!</div>
        <button id="cookButton">Cook</button>
        <div id="portfolioLink" style="text-align: center; margin-top: 20px;"></div>
    
        <script>
            const burger = document.getElementById('burger');
            const message = document.getElementById('message');
            const cookButton = document.getElementById('cookButton');
            const portfolioLink = document.getElementById('portfolioLink');
            
            let cooking = false;
            let cookTime = 0;
    
            cookButton.addEventListener('click', () => {
                if (!cooking) {
                    cooking = true;
                    cookButton.disabled = true;
                    message.textContent = "Cooking in progress...";
                    portfolioLink.innerHTML = ''; // Clear any previous links
    
                    const cookInterval = setInterval(() => {
                        cookTime++;
                        
                        if (cookTime === 5) {
                            burger.style.backgroundColor = 'darkbrown';
                            message.textContent = "Burger is perfectly cooked!";
                            clearInterval(cookInterval);
                            cookButton.disabled = false;
                            cooking = false;
                            cookTime = 0;
                            
                            // Display the link once the burger is perfectly cooked
                            portfolioLink.innerHTML = `<a href="https://your-portfolio.com" target="_blank">Visit my portfolio</a>`;
                            
                        } else if (cookTime > 5) {
                            burger.style.backgroundColor = 'black';
                            message.textContent = "Oh no! The burger is burnt!";
                            clearInterval(cookInterval);
                            cookButton.disabled = false;
                            cooking = false;
                            cookTime = 0;
                        }
                    }, 1000);
                }
            });
        </script>
    
    </body>
    </html>
    

    Key Changes:

    • Added a new div element with the ID portfolioLink to hold the link.
    • In the JavaScript, once the burger is perfectly cooked, a link to the portfolio (https://your-portfolio.com) is displayed by setting the innerHTML of the portfolioLink element.
    • Make sure to replace https://your-portfolio.com with your actual portfolio URL.

    This enhancement encourages players to interact with the game and gives them a call to action by visiting your portfolio once they've successfully cooked the burger.