User Tools

Site Tools


pigadventure2

Sure! Here is a simple version of a game called Pig Adventure 2 that you can use as a starting point. You can modify and expand on this code to create your own version of the game.

// initialize game variables
var gameOver = false;
var score = 0;
var currentLocation = "farm";
 
// game loop
while (!gameOver) {
  // display current location and available actions
  console.log("You are currently at the " + currentLocation + ".");
  console.log("What would you like to do?");
  console.log("1. Explore the farm");
  console.log("2. Visit the market");
  console.log("3. Go to the forest");
 
  // get player action
  var action = prompt("Enter the number of the action you want to take:");
 
  // handle player action
  if (action === "1") {
    // explore the farm
    console.log("You explore the farm and find a pig. You adopt the pig and name it Porky.");
    score += 10;
  } else if (action === "2") {
    // visit the market
    console.log("You visit the market and buy some food for Porky. Your score increases by 5.");
    score += 5;
  } else if (action === "3") {
    // go to the forest
    console.log("You and Porky go for a walk in the forest. You come across a treasure chest and open it to find a golden coin. Your score increases by 20.");
    score += 20;
  } else {
    // invalid action
    console.log("Invalid action. Please try again.");
  }
 
  // check if game should continue
  if (score >= 50) {
    gameOver = true;
    console.log("Congratulations! You have won the game with a score of " + score + ".");
  }
}

In this game, the player starts on a farm and can choose to explore the farm, visit the market, or go to the forest. Each action increases the player's score by a certain amount. The game ends when the player's score reaches 50 or more.

I hope this helps as a starting point for your own version of Pig Adventure 2. Let me know if you have any other questions.

pigadventure2.txt · Last modified: 2022/12/07 04:04 by multitapmugen