[java] Harry Potter
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- // Harry Potter Video Game
- // Define variables for player character
- let playerCharacter = {
- name: "Harry Potter",
- house: "Gryffindor",
- health: 100,
- magic: 100,
- spells: ["Expelliarmus", "Stupefy", "Expecto Patronum"],
- wand: {
- wood: "Holly",
- core: "Phoenix Feather",
- length: 11.5
- }
- };
- // Define variables for enemy character
- let enemyCharacter = {
- name: "Voldemort",
- health: 100,
- magic: 100,
- spells: ["Avada Kedavra", "Crucio", "Imperio"]
- };
- // Define variables for teachers
- let teachers = [
- {
- name: "Albus Dumbledore",
- house: "Gryffindor",
- health: 150,
- magic: 200,
- spells: ["Fawkes", "Petrificus Totalus", "Expecto Patronum"],
- wand: {
- wood: "Elder",
- core: "Thestral Tail Hair",
- length: 15
- }
- },
- {
- name: "Severus Snape",
- house: "Slytherin",
- health: 150,
- magic: 200,
- spells: ["Sectumsempra", "Expulso", "Morsmordre"],
- wand: {
- wood: "Yew",
- core: "Dragon Heartstring",
- length: 13
- }
- }
- ];
- // Define variables for students
- let students = [
- {
- name: "Hermione Granger",
- house: "Gryffindor",
- health: 120,
- magic: 150,
- spells: ["Lumos", "Wingardium Leviosa", "Alohomora"],
- wand: {
- wood: "Vine",
- core: "Dragon Heartstring",
- length: 10
- }
- },
- {
- name: "Draco Malfoy",
- house: "Slytherin",
- health: 120,
- magic: 150,
- spells: ["Expelliarmus", "Crucio", "Imperio"],
- wand: {
- wood: "Hawthorn",
- core: "Unicorn Hair",
- length: 12
- }
- }
- ];
- // Define function for player attack
- function playerAttack(spell) {
- let damage = Math.floor(Math.random() * 10) + 1;
- if (spell === "Expelliarmus") {
- damage *= 2;
- enemyCharacter.health -= damage;
- console.log(`${playerCharacter.name} used ${spell} and dealt ${damage} damage!`);
- } else if (spell === "Stupefy") {
- enemyCharacter.health -= damage;
- console.log(`${playerCharacter.name} used ${spell} and dealt ${damage} damage!`);
- } else if (spell === "Expecto Patronum") {
- playerCharacter.magic -= 10;
- console.log(`${playerCharacter.name} used ${spell} and gained 10 magic points!`);
- } else {
- console.log("Invalid spell! Try again.");
- }
- }
- // Define function for enemy attack
- function enemyAttack() {
- let spell = enemyCharacter.spells[Math.floor(Math.random() * enemyCharacter.spells.length)];
- let damage = Math.floor(Math.random() * 10) + 1;
- if (spell === "Avada Kedavra") {
- damage *= 2;
- playerCharacter.health -= damage;
- console.log(`${enemyCharacter.name} used ${spell} and dealt ${damage} damage!`);
- } else if (spell === "Crucio") {
- playerCharacter.health -= damage;
- console.log(`${enemyCharacter.name} used ${spell} and dealt ${damage} damage!`);
- } else if (spell === "Imperio") {
- playerCharacter.magic -= 10;
- console.log(`${enemyCharacter.name} used ${spell} and gained 10 magic points!`);
- } else {
- console.log("Invalid spell! Try again.");
- }
- }
- // Define function for game loop
- function gameLoop() {
- console.log(`${playerCharacter.name} (${playerCharacter.house}) vs ${enemyCharacter.name}`);
- while (playerCharacter.health > 0 && enemyCharacter.health > 0) {
- let playerSpell = playerCharacter.spells[Math.floor(Math.random() * playerCharacter.spells.length)];
- playerAttack(playerSpell);
- enemyAttack();
- console.log(`${playerCharacter.name} health: ${playerCharacter.health}, magic: ${playerCharacter.magic}`);
- console.log(`${enemyCharacter.name} health: ${enemyCharacter.health}, magic: ${enemyCharacter.magic}`);
- }
- if (playerCharacter.health <= 0) {
- console.log(`${enemyCharacter.name} wins!`);
- } else {
- console.log(`${playerCharacter.name} wins!`);
- }
- }
- // Call game loop function
- gameLoop();
Editor
You can edit this paste and save as new: