File size: 3,561 Bytes
d9c0229
 
80693d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad3072
80693d2
 
 
 
9ad3072
 
 
 
 
 
80693d2
 
 
 
 
9ad3072
80693d2
 
 
 
 
 
 
 
 
9ad3072
 
80693d2
 
 
 
 
9ad3072
80693d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ad3072
80693d2
 
 
 
 
9ad3072
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80693d2
 
 
 
 
d9c0229
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<head>
    <title>Dungeons & Dragons</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }
        #output {
            white-space: pre-wrap;
            background-color: #f0f0f0;
            padding: 10px;
            margin-top: 10px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <h1>Dungeons & Dragons: Adventure Awaits</h1>
    <button id="createCharacter">Create Character</button>
    <button id="startAdventure">Start Adventure</button>
    <button id="attack">Attack</button>
    <button id="castSpell">Cast Spell</button>
    <button id="useItem">Use Item</button>
    <div id="output"></div>

    <script>
        let character = {};
        let inventory = ["health potion", "magic potion", "mysterious key"];
        let monsters = [
            { name: "Goblin", health: 30, strength: 5 },
            { name: "Orc", health: 50, strength: 10 },
            { name: "Dragon", health: 100, strength: 20 }
        ];

        document.getElementById("createCharacter").addEventListener("click", createCharacter);
        document.getElementById("startAdventure").addEventListener("click", startAdventure);
        document.getElementById("attack").addEventListener("click", attack);
        document.getElementById("castSpell").addEventListener("click", castSpell);
        document.getElementById("useItem").addEventListener("click", useItem);

        function createCharacter() {
            character = {
                name: "Hero",
                class: "Warrior",
                level: 1,
                health: 100,
                magic: 50,
                strength: 10,
                intelligence: 5,
                inventory: [...inventory]
            };
            display(`Character Created: ${character.name}, the ${character.class}`);
        }

        function startAdventure() {
            const encounters = ["a wild beast", "a mysterious traveler", "a hidden treasure", ...monsters.map(m => `a ${m.name}`)];
            const encounter = encounters[Math.floor(Math.random() * encounters.length)];
            display(`You encounter ${encounter} on your adventure.`);
        }

        function attack() {
            if (!character.name) {
                display("You need to create a character first!");
                return;
            }

            const damage = Math.floor(Math.random() * character.strength);
            display(`You attack dealing ${damage} damage.`);
        }

        function castSpell() {
            if (!character.name) {
                display("You need to create a character first!");
                return;
            }

            const spells = ["Fireball", "Healing Light", "Shadow Strike", "Ice Bolt", "Thunder Wave"];
            const spell = spells[Math.floor(Math.random() * spells.length)];
            display(`You cast ${spell}! It uses 10 magic points.`);
            character.magic -= 10;
        }

        function useItem() {
            if (!character.name) {
                display("You need to create a character first!");
                return;
            }

            if (character.inventory.length === 0) {
                display("Your inventory is empty!");
                return;
            }

            const item = character.inventory.pop();
            display(`You use a ${item}.`);
        }

        function display(message) {
            document.getElementById("output").textContent += message + "\n";
        }
    </script>
</body>
</html>