Skip to content

Instantly share code, notes, and snippets.

@squallstar
Last active April 21, 2023 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squallstar/488330fc467f74676454bea3888b58dc to your computer and use it in GitHub Desktop.
Save squallstar/488330fc467f74676454bea3888b58dc to your computer and use it in GitHub Desktop.
Novels to JS - ChatGPT JS

Message From You:

summarize romeo and juliet in 10 words

Message From ChatGPT:

Young love, feuding families, tragedy, death.

Message From You:

now 5

Message From ChatGPT:

Forbidden love, family feud, tragic end.

Message From You:

now 2

Message From ChatGPT:

Tragic romance.

Message From You:

just one

Message From ChatGPT:

Tragedy.

Message From You:

now summarize it as a javascript code with no more than 200 characters

Message From ChatGPT:

const romeo = "R";const juliet = "J";if(romeo===juliet){console.log("Tragedy");}else{console.log("Happy Ending!");}

Message From You:

write their story as a javascript module

Message From ChatGPT:

const romeo = {
  name: 'Romeo',
  family: 'Montague',
  age: 17
};
const juliet = {
  name: 'Juliet',
  family: 'Capulet',
  age: 13
};

const meet = () => 'Romeo and Juliet meet and fall in love';

const elope = () => 'The lovers elope in secret';

const tragedy = () => 'The lovers both die tragically';

export { romeo, juliet, meet, elope, tragedy };

Message From You:

make sure the variables and model functions interact with each other

Message From ChatGPT:

const romeo = {
  name: 'Romeo',
  family: 'Montague',
  age: 17,
  lover: null,
  meet(juliet) {
    this.lover = juliet;
    return `${this.name} meets ${juliet.name} and falls in love`;
  },
  elope() {
    if (this.lover && this.family !== this.lover.family) {
      return `${this.name} and ${this.lover.name} elope in secret`;
    } else {
      return 'Unable to elope due to family feud or missing lover';
    }
  },
  tragedy() {
    if (this.lover && this.family !== this.lover.family) {
      return `Tragic ending for ${this.name} and ${this.lover.name}`;
    } else {
      return 'No tragedy since unable to elope or missing lover';
    }
  }
};

const juliet = {
  name: 'Juliet',
  family: 'Capulet',
  age: 13,
  lover: null,
  meet(romeo) {
    this.lover = romeo;
    return `${this.name} meets ${romeo.name} and falls in love`;
  },
  elope() {
    if (this.lover && this.family !== this.lover.family) {
      return `${this.name} and ${this.lover.name} elope in secret`;
    } else {
      return 'Unable to elope due to family feud or missing lover';
    }
  },
  tragedy() {
    if (this.lover && this.family !== this.lover.family) {
      return `Tragic ending for ${this.name} and ${this.lover.name}`;
    } else {
      return 'No tragedy since unable to elope or missing lover';
    }
  }
};

export { romeo, juliet };

Example usage of the above module:

import { romeo, juliet } from './romeo-juliet.js';

console.log(romeo.meet(juliet)); // "Romeo meets Juliet and falls in love"
console.log(juliet.meet(romeo)); // "Juliet meets Romeo and falls in love"
console.log(romeo.elope());      // "Romeo and Juliet elope in secret"
console.log(romeo.tragedy());   // "Tragic ending for Romeo and Juliet"
console.log(juliet.elope());     // "Unable to elope due to family feud or missing lover"
console.log(juliet.tragedy());  // "No tragedy since unable to elope or missing lover"

Message From You:

now do the same for orwell's 1984

Message From ChatGPT:

Sure! Here's a brief summary of George Orwell's "1984" followed by a JavaScript code:

"1984" is a dystopian novel set in a totalitarian society where the government, led by Big Brother, has complete control over every aspect of citizens' lives. The story follows a man named Winston Smith, who secretly rebels against the regime and falls in love with a woman named Julia. However, their rebellious actions lead to tragic consequences.

Here's a JavaScript code that represents the concept of government surveillance and control present in "1984":

const bigBrother = {
  surveillance: true,
  propaganda: true,
  thoughtPolice: true,
  doublethink: true
};

function controlThoughts(thoughts) {
  if (bigBrother.thoughtPolice && bigBrother.doublethink) {
    thoughts = thoughts.replace(/.+/, "");
  }
  return thoughts;
}

This code includes an object called bigBrother, which represents the government's all-encompassing power. It also includes a function called controlThoughts() that demonstrates how the government controls the thoughts of citizens - by removing any that go against the regime.

Message From You:

What about the the Hunger games?

Message From ChatGPT:

Certainly! "The Hunger Games" is a dystopian novel set in the futuristic nation of Panem, where the Capitol holds absolute power over the surrounding 12 districts. The story follows a young girl named Katniss Everdeen, who volunteers to take her younger sister's place in the Hunger Games – a televised event where children from each district must fight to the death. Throughout the story, Katniss becomes a symbol of rebellion against the Capitol, inspiring others to rise up against their oppressors.

Here's a JavaScript code that represents the Hunger Games:

class Tribute {
  constructor(name, district, weapon) {
    this.name = name;
    this.district = district;
    this.weapon = weapon;
    this.alive = true;
    this.sponsor = null;
  }

  attack(target) {
    if (this.weapon === "bow and arrows") {
      target.alive = false;
      console.log(`${this.name} shot ${target.name} with their ${this.weapon}.`);
    } else {
      console.log(`${this.name} tried to attack ${target.name} with a ${this.weapon}, but missed.`);
    }
  }

  receiveSponsor(sponsor) {
    this.sponsor = sponsor;
    console.log(`${sponsor} sponsored ${this.name}.`);
  }
}

const tributes = [
  new Tribute("Katniss Everdeen", 12, "bow and arrows"),
  new Tribute("Peeta Mellark", 12, "knife"),
  new Tribute("Thresh", 11, "sickle"),
  new Tribute("Rue", 11, "slingshot")
];

for (let i = 0; i < tributes.length; i++) {
  console.log(`${tributes[i].name} from District ${tributes[i].district} is ready to fight with their ${tributes[i].weapon}.`);
}

tributes[0].attack(tributes[1]);
tributes[1].attack(tributes[0]);
tributes[2].attack(tributes[1]);
tributes[3].receiveSponsor("Citizens of District 11");

This code creates a Tribute class that has properties for name, district, weapon, alive status, and sponsor. It also includes methods for attacking other tributes and receiving sponsorship. Finally, it creates an array of tributes and simulates some actions that would take place in the Hunger Games, such as attacking other tributes and receiving sponsorships.

Message From You:

can you turn this into a fully fledged game using javascript?

Message From ChatGPT:

I apologize, but I am not entirely sure what you are referring to since you did not provide the context or topic. Could you please clarify your question, and I would be happy to assist you further?

Message From You:

turn the hunger games javascript example into an actual web app game with JS, CS and HTML

Message From ChatGPT:

Sure! Turning the Hunger Games example into a fully fledged web app game with JavaScript, CSS, and HTML would require a significant amount of time and effort since it involves designing and developing a user interface, adding game mechanics and logic, and integrating HTML, CSS, and JavaScript to create an interactive experience.

Here's a high-level overview of the steps involved in creating a web app game based on the Hunger Games example:

  1. Design the user interface: Decide on the layout, color scheme, typography, and visual elements of the game. You'll need to create multiple screens such as the Home screen, Game screen, and End Game screen.

  2. Develop the game mechanics: Determine the rules, actions, and events that occur throughout the game. You'll need to create functions to handle user actions such as selecting the tribute or choosing actions during the games.

  3. Integrate HTML, CSS, and JavaScript: Use HTML to structure the content, CSS to style the elements, and JavaScript to add interactivity and functionality.

  4. Test and refine: Test the game and fix any bugs, usability issues or gameplay imbalances.

Here's an example of a simple HTML and CSS layout that you could use as a starting point:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="style.css">
    <script src="game.js"></script>
  </head>
  <body>
    <div id="home-screen">
      <h1>The Hunger Games</h1>
      <button onclick="startGame()">Start</button>
    </div>
    <div id="game-screen">
      <h2 id="tributes"></h2>
      <button onclick="selectTribute()">Select</button>
      <div id="actions">
        <button onclick="fight()">Fight</button>
        <button onclick="hide()">Hide</button>
        <button onclick="run()">Run</button>
      </div>
    </div>
    <div id="end-screen">
      <h1>Game Over</h1>
      <h2 id="result"></h2>
      <button onclick="restart()">Restart</button>
    </div>
  </body>
</html>

And here's an example of how the game logic could be implemented using JavaScript:

// Define the tributes
var tributes = ['Katniss', 'Peeta', 'Gale', 'Haymitch', 'Effie'];

// Randomly select two tributes to compete
var tribute1 = tributes[Math.floor(Math.random() * tributes.length)];
var tribute2 = tributes[Math.floor(Math.random() * tributes.length)];

// Display the tributes on the game screen
document.getElementById('tributes').innerHTML = tribute1 + ' vs. ' + tribute2;

// Handle user actions
function selectTribute() {
  // Allow the user to select one tribute to perform an action
}

function fight() {
  // Determine the outcome of the fight and update the game state
}

function hide() {
  // Determine the outcome of hiding and update the game state
}

function run() {
  // Determine the outcome of running and update the game state
}

// Track the game state
var gameState = {
  turns: 0,
  tribute1Health: 100,
  tribute2Health: 100,
  tribute1Hunger: 0,
  tribute2Hunger: 0,
  tribute1Hydration: 0,
  tribute2Hydration: 0
};

// Update the game screen based on the current game state
function updateGameState() {
  // Display the current game state on the screen
}

// Start the game
function startGame() {
  // Switch to the game screen and begin the game
}

// End the game and display the results
function endGame(result) {
  // Switch to the end game screen and display the result
}

This is just a starting point to give you an idea of how you could build a Hunger Games web app game. You would need to flesh out the functionality, add the necessary CSS styles, and integrate everything to create a polished and engaging game.


JSFiddle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment