<commit_before>// Design Basic Game Solo Challenge


// This is a solo challenge

// Your mission description:
// Overall mission: Leprechaun collects 5 gold coins to have a full pot of gold
// Goals: collect gold coins, avoid trap
// Characters: leprechaun, gold coins, trap
// Objects: leprechaun(position, health, success, potOfGold, move), gold coins(name, position), trap(position)
// Functions: move for leprechaun, constructor function for coins, display coins

// Pseudocode
// CREATE a function to build a GoldCoin class that takes a name and creates random position coordinates
// SET 10 coin variables to new instances of the GoldCoin class
// SET a goldCoins variable equal to a list of the coins
// CREATE a function to display the coordinates for each coin
// SET a trap variable to random position coordinates
//
// SET a leprechaun variable to have a position of 0 for X & Y, potOfGold to 0, health to true,
// success false, and a move method
// CREATE a move method that takes a direction & number for the amount to move
//   UPDATE the leprechaun's coordinates based on the direction & number
//   DISPLAY the leprechaun's coordinates
//   IF the leprechaun's coordinates are equal to the trap's coordinates
//     UPDATE the leprechaun's health & display "Game Over"
//   ELSE IF the leprechaun's potOfGold is equal to 5
//     UPDATE the leprechaun's success & display "You Win"
//   ELSE iterate through the goldCoins list
//     IF the leprechaun's coordinates are equal to a coin's coordinates
//     DISPLAY "You found a coin"
//     INCREMENT the leprechaun's potOfGold by 1

// Initial Code
// function GoldCoin(coin) {
//   this.coin = coin;
//   this.posX = Math.floor(Math.random()*6 + 1),
//   this.posY = Math.floor(Math.random()*6 + 1)
// }

// var coin1 = new GoldCoin("Coin 1");
// var coin2 = new GoldCoin("Coin 2");
// var coin3 = new GoldCoin("Coin 3");
// var coin4 = new GoldCoin("Coin 4");
// var coin5 = new GoldCoin("Coin 5");
// var coin6 = new GoldCoin("Coin 6");
// var coin7 = new GoldCoin("Coin 7");
// var coin8 = new GoldCoin("Coin 8");
// var coin9 = new GoldCoin("Coin 9");
// var coin10 = new GoldCoin("Coin 10");

// var goldCoins = [ coin1, coin2, coin3, coin4, coin5, coin6, coin7, coin8, coin9, coin10];

// var displayCoins = function () {
//      for (var i = 0; i < goldCoins.length; i++) {
//       console.log(goldCoins[i].coin + "'s position is " + goldCoins[i].posX + "," + goldCoins[i].posY)
//     }
// }

// var trap = {
//   posX: Math.floor(Math.random()*6 + 1),
//   posY: Math.floor(Math.random()*6 + 1)
// };


// var leprechaun = {
//   posX: 0,
//   posY: 0,
//   potOfGold: 0,
//   health: true,
//   success: false,
//   move: function(direction, amount) {
//     if(direction === 'left'){
//       this.posX -= amount;
//     }
//     else if(direction === 'right'){
//       this.posX += amount;
//     }
//     else if(direction === 'up'){
//       this.posY -= amount;
//     }
//     else if(direction === 'down'){
//       this.posY += amount;
//     }

//     console.log("The leprechaun's position is " + this.posX + "," + this.posY);

//     if(this.posX === trap.posX && this.posY === trap.posY){
//       this.health = false;
//       return console.log("You're trapped and hurt. Game Over!");
//     }
//     else if(this.potOfGold === 5){
//       this.success = true;
//       return console.log("You're pot of gold is full, you win!!");
//     }
//     else {
//       for (var i = 0; i < goldCoins.length; i++) {
//         if (this.posX === goldCoins[i].posX && this.posY === goldCoins[i].posY) {
//           console.log("You found a gold coin!");
//           this.potOfGold += 1;
//         }
//       }
//     }

//   }

// };



// Refactored Code
function GoldCoin(coin) {
  this.coin = coin;
  this.posX = Math.floor(Math.random()*6 + 1),
  this.posY = Math.floor(Math.random()*6 + 1)
}

var coin1 = new GoldCoin("Coin 1");
var coin2 = new GoldCoin("Coin 2");
var coin3 = new GoldCoin("Coin 3");
var coin4 = new GoldCoin("Coin 4");
var coin5 = new GoldCoin("Coin 5");
var coin6 = new GoldCoin("Coin 6");
var coin7 = new GoldCoin("Coin 7");
var coin8 = new GoldCoin("Coin 8");
var coin9 = new GoldCoin("Coin 9");
var coin10 = new GoldCoin("Coin 10");

var goldCoins = [ coin1, coin2, coin3, coin4, coin5, coin6, coin7, coin8, coin9, coin10];

var displayCoins = function () {
     for (var i = 0; i < goldCoins.length; i++) {
      console.log(goldCoins[i].coin + "'s position is " + goldCoins[i].posX + "," + goldCoins[i].posY)
    }
}

var trap = {
  posX: Math.floor(Math.random()*6 + 1),
  posY: Math.floor(Math.random()*6 + 1)
};


var leprechaun = {
  posX: 0,
  posY: 0,
  potOfGold: 0,
  health: true,
  success: false,
  move: function(direction, amount) {
    switch(direction){
      case 'left': this.posX -= amount; break;
      case'right': this.posX += amount; break;
      case 'up': this.posY -= amount; break;
      case 'down': this.posY += amount; break;
    }

    console.log("The leprechaun's position is " + this.posX + "," + this.posY);

    if(this.posX === trap.posX && this.posY === trap.posY){
      this.health = false;
      console.log("You're trapped and hurt. Game Over!");
    }

    if(this.potOfGold === 5){
      this.success = true;
      console.log("You're pot of gold is full, you win!!");
    }

    for (var i = 0; i < goldCoins.length; i++) {
      if (this.posX === goldCoins[i].posX && this.posY === goldCoins[i].posY) {
        console.log("You found a gold coin!");
        this.potOfGold += 1;
      }
    }
  }

};


displayCoins();
leprechaun.move('down', 2);
leprechaun.move('right', 2);
leprechaun.move('right', 3);
leprechaun.move('left', 1);
leprechaun.move('down', 3);
leprechaun.move('left', 1);
leprechaun.move('left', 1);
leprechaun.move('up', 1);
leprechaun.move('up', 1);
leprechaun.move('right', 4);
displayCoins();
console.log(leprechaun.potOfGold);
console.log(leprechaun.success);
console.log(leprechaun.health);


// Reflection
/*
What was the most difficult part of this challenge?
Using the correct syntax and semantics was the most difficult part of this challenge.  When I would
test the code I would frequently receive the message 'SyntaxError: Unexpected token' or 'TypeError'.


What did you learn about creating objects and functions that interact with one another?
This challenge helped me to practice creating objects with functions as properties and using the
properties of other objects to update the value's in the object's properties.<commit_msg>Add changes based on feedback<commit_after>// Design Basic Game Solo Challenge


// This is a solo challenge

// Your mission description:
// Overall mission: Leprechaun collects 5 gold coins to have a full pot of gold
// Goals: collect gold coins, avoid trap
// Characters: leprechaun, gold coins, trap
// Objects: leprechaun(position, health, success, potOfGold, move), gold coins(name, position), trap(position)
// Functions: move for leprechaun, constructor function for coins, display coins

// Pseudocode
// CREATE a function to build a GoldCoin class that takes a name and creates random position coordinates
// SET 10 coin variables to new instances of the GoldCoin class
// SET a goldCoins variable equal to a list of the coins
// CREATE a function to display the coordinates for each coin
// SET a trap variable to random position coordinates
//
// SET a leprechaun variable to have a position of 0 for X & Y, potOfGold to 0, health to true,
// success false, and a move method
// CREATE a move method that takes a direction & number for the amount to move
//   UPDATE the leprechaun's coordinates based on the direction & number
//   DISPLAY the leprechaun's coordinates
//   IF the leprechaun's coordinates are equal to the trap's coordinates
//     UPDATE the leprechaun's health & display "Game Over"
//   ELSE IF the leprechaun's potOfGold is equal to 5
//     UPDATE the leprechaun's success & display "You Win"
//   ELSE iterate through the goldCoins list
//     IF the leprechaun's coordinates are equal to a coin's coordinates
//     DISPLAY "You found a coin"
//     INCREMENT the leprechaun's potOfGold by 1

// Initial Code
// function GoldCoin(coin) {
//   this.coin = coin;
//   this.posX = Math.floor(Math.random()*6 + 1),
//   this.posY = Math.floor(Math.random()*6 + 1)
// }

// var coin1 = new GoldCoin("Coin 1");
// var coin2 = new GoldCoin("Coin 2");
// var coin3 = new GoldCoin("Coin 3");
// var coin4 = new GoldCoin("Coin 4");
// var coin5 = new GoldCoin("Coin 5");
// var coin6 = new GoldCoin("Coin 6");
// var coin7 = new GoldCoin("Coin 7");
// var coin8 = new GoldCoin("Coin 8");
// var coin9 = new GoldCoin("Coin 9");
// var coin10 = new GoldCoin("Coin 10");

// var goldCoins = [ coin1, coin2, coin3, coin4, coin5, coin6, coin7, coin8, coin9, coin10];

// var displayCoins = function () {
//      for (var i = 0; i < goldCoins.length; i++) {
//       console.log(goldCoins[i].coin + "'s position is " + goldCoins[i].posX + "," + goldCoins[i].posY)
//     }
// }

// var trap = {
//   posX: Math.floor(Math.random()*6 + 1),
//   posY: Math.floor(Math.random()*6 + 1)
// };


// var leprechaun = {
//   posX: 0,
//   posY: 0,
//   potOfGold: 0,
//   health: true,
//   success: false,
//   move: function(direction, amount) {
//     if(direction === 'left'){
//       this.posX -= amount;
//     }
//     else if(direction === 'right'){
//       this.posX += amount;
//     }
//     else if(direction === 'up'){
//       this.posY -= amount;
//     }
//     else if(direction === 'down'){
//       this.posY += amount;
//     }

//     console.log("The leprechaun's position is " + this.posX + "," + this.posY);

//     if(this.posX === trap.posX && this.posY === trap.posY){
//       this.health = false;
//       return console.log("You're trapped and hurt. Game Over!");
//     }
//     else if(this.potOfGold === 5){
//       this.success = true;
//       return console.log("You're pot of gold is full, you win!!");
//     }
//     else {
//       for (var i = 0; i < goldCoins.length; i++) {
//         if (this.posX === goldCoins[i].posX && this.posY === goldCoins[i].posY) {
//           console.log("You found a gold coin!");
//           this.potOfGold += 1;
//         }
//       }
//     }

//   }

// };



// Refactored Code
function GoldCoin() {
  this.posX = Math.floor(Math.random()*6 + 1),
  this.posY = Math.floor(Math.random()*6 + 1)
}

var goldCoins = [];
var createCoins= function(num) {
  for (var i = 0; i < num; i++) {
    goldCoins.push(new GoldCoin());
  }
  return goldCoins
}

var displayCoins = function () {
     for (var i = 0; i < goldCoins.length; i++) {
      console.log("The coin's position is " + goldCoins[i].posX + "," + goldCoins[i].posY)
    }
}

function Trap() {
  this.posX = Math.floor(Math.random()*6 + 1),
  this.posY = Math.floor(Math.random()*6 + 1)
}
var traps = [];
var createTraps = function(num){
  for (var i = 0; i < num; i++) {
    traps.push(new Trap());
  }
  return traps
}

var leprechaun = {
  posX: 0,
  posY: 0,
  potOfGold: 0,
  health: 100,
  success: false,
  move: function(direction, amount) {
    switch(direction){
      case 'left': this.posX -= amount; break;
      case'right': this.posX += amount; break;
      case 'up': this.posY -= amount; break;
      case 'down': this.posY += amount; break;
    }

    console.log("The leprechaun's position is " + this.posX + "," + this.posY);
    if (this.health > 0) {
      for (var i = 0; i < traps.length; i++) {
        if(this.posX === traps[i].posX && this.posY === traps[i].posY){
          this.health -= 10;
        }
      }
    } else {
      console.log("Game Over!");
    }

    if(this.potOfGold === 5){
      this.success = true;
      console.log("You're pot of gold is full, you win!!");
    }

    for (var i = 0; i < goldCoins.length; i++) {
      if (this.posX === goldCoins[i].posX && this.posY === goldCoins[i].posY) {
        console.log("You found a gold coin!");
        this.potOfGold += 1;
      }
    }
  }

};

createCoins(10);
createTraps(5);
displayCoins();
leprechaun.move('down', 2);
leprechaun.move('right', 2);
leprechaun.move('right', 3);
leprechaun.move('left', 1);
leprechaun.move('down', 3);
leprechaun.move('left', 1);
leprechaun.move('left', 1);
leprechaun.move('up', 1);
leprechaun.move('up', 1);
leprechaun.move('right', 4);
displayCoins();
console.log(leprechaun.potOfGold);
console.log(leprechaun.success);
console.log(leprechaun.health);


// Reflection
/*
What was the most difficult part of this challenge?
Using the correct syntax and semantics was the most difficult part of this challenge.  When I would
test the code I would frequently receive the message 'SyntaxError: Unexpected token' or 'TypeError'.


What did you learn about creating objects and functions that interact with one another?
This challenge helped me to practice creating objects with functions as properties and using the
properties of other objects to update the value's in the object's properties.
{'fraction_non_alphanumeric': 0.15556239421449453, 'fraction_numerical': 0.01577165717802739, 'mean_word_length': 2.86875, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '602697', 'n_tokens_mistral': 4570, 'n_tokens_neox': 4342, 'n_words': 1386}