 // Design Basic Game Solo Challenge

// This is a solo challenge

// Your mission description:
// Overall mission: To Jump up and collect the object
// Goals: Jump from one object to the other one to collect the object.
// Characters: Player One
// Objects: Player(Kid), Two pieces of platform(brick), and an object (Ball)
// Functions: Forward, Up(Jump), Back

// Pseudocode
//Set the Player at an intial position
//There will be another Platform tile near by to jump on to.
//On that platform will be the Ball the Player needs to collect
//If the Player doesnt land on the platform, Player will Fail
//If he lands on the platform and then grabs the ball, then Win!
//

// Initial Code




var player = {
posX: 0,
posY: 0,

move: function(direction) {
  if(direction === 'forward'){
    this.posX +=1;
  }
  else if(direction === 'back'){
    player.posX -=1;
  }


ball.posX = Math.floor(Math.random()*5);

console.log("Player you are getting closer" + " " + (ball.posX) + " " + "Keep trying");

if(player.posX === ball.posX){
console.log("You Win!")}

}
};

var ball = {
posX: Math.floor(Math.random())
};

player.move('forward');



// Refactored Code : added comments for readabilty

//This is our Player
var player = {
posX: 0,
posY: 0,

//This is our moving function (Foward and Front)
move: function(direction) {
  if(direction === 'forward'){
    this.posX +=1;
  }
  else if(direction === 'back'){
    player.posX -=1;
  }

//We have our object ball and then we randomize the location of it.
ball.posX = Math.floor(Math.random()*5);

console.log("Player you are getting closer" + " " + (ball.posX) + " " + "Keep trying");

if(player.posX === ball.posX){
  console.log("You Win!")
  }

}
};

//This is our ball, also randomizes the X positon.
var ball = {
posX: Math.floor(Math.random())
};

//Makes our player move forward.
player.move('forward');







/* Reflection
 1. What was the most difficult part of this challenge?

The hardest part of this challenge for me was how to actually start and make a simplistic game. I wanted to make a platform type game but I didnt know how to make a UI yet so I just made a random event game. The actual writing of the code was not the hard part, but how to make the player move back and using new functions to randomize the movement was hard to figure out.

2. What did you learn about creating objects and functions that interact with one another?

That everything needs to be properly attached together to make it work. If some of the variables are not in the right place that program wont recgonize where to grab that variable from. I had my ball variable inside my player variable and that did not work. I like everything separated out, the readablity of the code seems to be better that way.

3. Did you learn about any new built-in methods you could use in your refactored solution? If so, what were they and how do they work?

For mine, not really I tried to keep my code as simple as possible. I only got rid of some stuff that wasnt being used in my refecatored code.

How can you access and manipulate properties of objects?

The easiest way to manipulate the objects would be to use the dot notation.For example, ball.posX we can change the location of the ball.

*/
@@ -64,1151 +64,432 @@
 ge%0A%0A
-// Your mission description:%0A// Overall mission: To Jump up and collect the object%0A// Goals: Jump from one object to the other one to collect the object.%0A// Characters: Player One%0A// Objects: Player(Kid), Two pieces of platform(brick), and an object (Ball)%0A// Functions: Forward, Up(Jump), Back%0A%0A// Pseudocode%0A//Set the Player at an intial position%0A//There will be another Platform tile near by to jump on to.%0A//On that platform will be the Ball the Player needs to collect%0A//If the P
+%0A%0A// Pseudocode%0A//Set the Player at an intial position%0A//There will be another object called ball at another random position%0A//The p
 layer 
-doesnt land on the platform, Player will Fail%0A//If he lands on the platform and then grabs the ball, then Win!%0A//%0A%0A// Initial Code%0A%0A%0A%0A%0Avar player = %7B%0AposX: 0,%0AposY: 0,%0A%0Amove: function(direction) %7B%0A  if(direction === 'forward')%7B%0A    this.posX +=1;%0A  %7D%0A  else if(direction === 'back')%7B%0A    player.posX -=1;%0A  %7D%0A%0A%0Aball.posX = Math.floor(Math.random()*5);%0A%0Aconsole.log(%22Player you are getting closer%22 + %22 %22 + (ball.posX) + %22 %22 + %22Keep trying%22);%0A%0Aif(player.posX === ball.posX)%7B%0Aconsole.log(%22You Win!%22)%7D%0A%0A%7D%0A%7D;%0A%0Avar ball = %7B%0AposX: Math.floor(Math.random())%0A%7D;%0A%0Aplayer.move('forward');%0A%0A%0A%0A// Refactored Code : added comments for readabilty%0A%0A//This is our Player
+has to find that ball using the back and forward movements%0A//Once the player encounters the ball the games will say you won%0A%0A%0A//Very simple game hard to play when you dont really have any visuals. But I didnt want to make this overly complicated and spend too much time.%0A%0A// Final Code%0A
 %0Avar
@@ -713,117 +713,8 @@
  %7D%0A%0A
-//We have our object ball and then we randomize the location of it.%0Aball.posX = Math.floor(Math.random()*5);%0A
 %0Acon
@@ -772,16 +772,18 @@
 all.posX
+()
 ) + %22 %22 
@@ -785,16 +785,18 @@
  %22 %22 + %22
+, 
 Keep try
@@ -799,16 +799,80 @@
  trying%22
+ + %22 (Players Position %22 + player.posX + %22,%22 + player.posY + %22)%22
 );%0A%0Aif(p
@@ -895,21 +895,25 @@
 all.posX
+()
 )%7B%0A  
+//
 console.
@@ -928,21 +928,50 @@
  Win!%22)%0A
+  alert(%22You found the ball%22)%0A
   %7D%0A
-%0A
 %7D%0A%7D;%0A%0A//
@@ -1037,16 +1037,46 @@
  %7B%0AposX:
+ function(direction)%7B%0A  return
  Math.fl
@@ -1096,12 +1096,18 @@
 om()
+*5
 )%0A%7D
-;
+%0A%0A%7D;%0A
 %0A%0A//
@@ -1135,16 +1135,24 @@
  forward
+ or back
 .%0Aplayer
@@ -1169,16 +1169,39 @@
 ward');%0A
+player.move('back');%0A%0A%0A
 %0A%0A%0A%0A%0A%0A%0A/

add more functionality