<file_sep>class Sensor {
    constructor( ship, map ) {
        this.map = map;
        this.ship = ship;
        this.level = 1;            
        this.ScanCP = 2;
    }
    
    use () {
        this.ship.supplies -= 2;        // consume 2% of supplies
        
    }

    getInfo () {
     
    }
    
    upgrade () {
        if ( this.level == 1 && this.ship.credit > 100 ) {
            this.ship.credit -= 100;
            this.level = 2;
            this.ScanCP = 5;
        }
    }
}

// the sensors needed to be commented out as the game would not start with this code
/*
function Sensors(ship,sensors_tpye, gameMap)

{
	shipSupplies = shipSupplies-2;

	len sensorText = document.getElementById("sensor_message").textContext

	sensorText = null;

	if(sensors_type == 1)  <!-- basic -->

	{

		var i;

		var j;

		for(obj in  gameMap){

			for(i=ship.x-2;i<ship.x+2;i++){

				for(j=ship.y-2;j<ship.y+2;j++){

					if(i==gameMap[obj].x && j==gameMap[obj].y){

						sensorText += gameMap[obj].name;

					}

					else

						break;

				}

			}

		}



	}

	else if(sensors_tpye == 2)// <!-- enhanced -->

	{

		var i;

		var j;

		for(obj in gameMap){

			for(i=ship.x-5;i<ship.x+5;i++){

				for(j=ship.y-5;j<ship.y+5;j++){

					if(i==ship.x-5 && j==ship.y+4)

						continue;

					if(i==ship.x-5 &&j==ship.y+5)

						continue;

					if(i==ship.x-5 &&j==ship.y-4)

						continue;

					if(i==ship.x-5 &&j==ship.y-5)

						continue;

					if(i==ship.x+5 && j==ship.y+4)

						continue;

					if(i==ship.x+5 &&j==ship.y+5)

						continue;

					if(i==ship.x+5 &&j==ship.y-4)

						continue;

					if(i==ship.x+5 &&j==ship.y-5)

						continue;

					if(i==ship.x-4 &&j==ship.y+5)

						continue;

					if(i==ship.x-4 &&j==ship.y-5)

						continue;

					if(i==ship.x+4 &&j==ship.y+5)

						continue;

					if(i==ship.x+4 &&j==ship.y-5)

						continue;



					if(i==gameMap[obj].x && j==gameMap[obj].y){

						sensorText += gameMap[obj].name;

					}

					else 

						break;

				}

			}

		}		

	}

}
*/
<file_sep>//<!-- SH-6 Sensors High-->
//<!-- I want to see what located at nearby Celectial Points,so I Know where things are -->

//<!-- IN PROGRESS>
function Sensors2(Ship, Celestial_Map)
{
    let sensorText = document.getElementById("sensor_message").textContent;
    sensorText = null;
    for(obj in Celestial_Map)
    {
        if (distance(Ship, Celestial_Map[obj]) < 100)
        {
            sensorText += Celestial_Map[obj].name;
        }
    }
}

<<<<<<< HEAD
=======
<!-- IN PROGRESS -->
>>>>>>> 7277d5ede67621faa91b0c48f40a1fa4d30c287f

function distance(obj1, obj2)
{
    let dist_sq = Math.abs(obj1.x - obj2.x) + Math.abs(obj1.y - obj2.y);
    return Math.sqrt(dist_sq);
}
function Sensors(currX,currY,supplies, sensors_tpye, Celestial_Map)
{
	alert("you deploys sensors for current cp");
<<<<<<< HEAD
	supplies = supplies-2;
	if(sensors_type == 1)//  <!-- basic -->
=======
	supplies = supplies-2；
	if(sensors_type == 1)  <!-- basic -->
>>>>>>> 7277d5ede67621faa91b0c48f40a1fa4d30c287f
	{
		var i;
		var j;
		for(i=currX-2;i<currX+2;i++){
			for(j=currY-2;j<currY+2;j++){
				if(i==celestialX && j==celestialY){
					//check if (celestialX,celestialY) in Celestial_map
					//add all new (celestialX,celestialY) in Celestial Map
					//display current CP
				}
				else
					break;
			}
		}

	}

	else if(sensors_tpye == 2)// <!-- enhanced -->
	{
		var i;
		var j;
		for(i=currX-5;i<currX+5;i++){
			for(j=currY-5;j<currY+5;j++){
				if(i==currX-5 && j==currY+4)
					continue;
				if(i==currX-5 &&j==currY+5)
					continue;
				if(i==currX-5 &&j==currY-4)
					continue;
				if(i==currX-5 &&j==currY-5)
					continue;
				if(i==currX+5 && j==currY+4)
					continue;
				if(i==currX+5 &&j==currY+5)
					continue;
				if(i==currX+5 &&j==currY-4)
					continue;
				if(i==currX+5 &&j==currY-5)
					continue;
				if(i==currX-4 &&j==currY+5)
					continue;
				if(i==currX-4 &&j==currY-5)
					continue;
				if(i==currX+4 &&j==currY+5)
					continue;
				if(i==currX+4 &&j==currY-5)
					continue;

				if(i==celestialX && j==celestialY){

					//check if (celestialX,celestialY) in Celestial_map
					//add all new (celestialX,celestialY) in Celestial Map
					//display current CP
				}
				else 
					break;
			}
		}		
	}
}

//how to get all celestialX,celestialY form map   (read file??)
//how to check if in celestial map and add to the Celestial map

//consider different direction
//every direction search 5 ,like a circle
<file_sep>// saves the player's name
const nameInput = document.querySelector('#playerName');

// MAIN VARIABLES; (globals, in a sense)
window.gameData = {
    mapsize: 128,
    celeron: null,
    xeon: null,
    ryzen: null,
    eniac: null,
    badMax: new Array(2),
    recipe: new Array(2),
    abFreighter: [],
    asteroid: [],
    meteorShower: [],
    asteroidRandom: true,
    meteorRandom: true,
    freighterRandom: true,
    stationRandom: true,
    gaze: { length: 0 },
    msgs: [],
    savedGamed: false,
    shipX: 0,
    shipY: 0,
    shipEnergy: 1000,
    shipSupplies: 100,
    shipCredit: 1000,
    shipEngineLv: 1,
    shipDamaged: false,
    shipNormalPlay: true,
    randomWormhole: false,
};

// when the window intially opens, this is what happens
window.onload = function() {
    // populate the map
    populateSavedGameList();

    // start the game
    let setupPage = document.querySelectorAll('.setup-game')[0];

    // initializes default settings
    document.querySelectorAll('.game-start-btn')[0].onclick = function() {
        initGame();
        setupPage.attributes.class.value += ' hide';
    };

    // initializes map and ship from previous game if the previous game exists
    document.querySelectorAll('.game-cont-btn')[0].onclick = function() {
        if (contGame()) {
            setupPage.attributes.class.value += ' hide';
        }
    };
};

// initializes the game
function initGame () {
    if (window.gameData != undefined) {
        window.gameMap = new GameMap(window.gameData.mapsize);
        window.oldSpice = new Ship(
            window.gameData.shipX,
            window.gameData.shipY,
            window.gameData.shipEnergy,
            window.gameData.shipSupplies,
            window.gameData.shipCredit,
            window.gameData.shipEngineLv,
            window.gameData.shipDamaged,
            window.gameData.shipNormalPlay
        );

    } else { // default settings
        window.gameMap = new GameMap(128);
        window.oldSpice = new Ship(0, 0, 1000, 100, 1000, 1, false, true);
    }

    // setup + save game
    gameSetSave();

    // update screen data
    updateHeading();
    updateLevels();
    
    PopulateMap(window.gameMap);

    // render map
    window.gameMap.renderMap(window.oldSpice.x, window.oldSpice.y);


    ctrecipe.tickObjects.push(function() { HitObj(window.oldSpice.x, window.oldSpice.y); } );
    ctrecipe.tick();
}

// continues a saved game; Sprint 2
function contGame () {
   
}

// set up the game; save the game; could be discarded; Sprint 2
function gameSetSave () {

}

// add planet locations to the left panel on the main game playing page
function gazePopulate ( obj, objX, objY, isToSave ) {
   
}

// add planet locations to the saved game; adds to the list which is to 
// be displayed on the left panel on the main game playing page
function populateSavedGaze ( gaze ) {
    
}

// save the message board; used to save alerts for the game to be played
// at a later time
function saveMessageBoard(newMessage) {
    let msgIndex = window.gameData.msgs.length;
    window.gameData.msgs[msgIndex] = newMessage;
}

// populates message board; shows the alerts that are generated
function populateMessageBoard(savedMessages) {
    for (const msg of savedMessages)
        addMessage(msg);
}

// shows saved games on the main menu screen
function populateSavedGameList () {

}

// update the player name input box when a past game has been selected
function updatePlayerNameField ( selectedGamed ) {
   
}
<file_sep>/* Add items to the map */

function PopulateMap(gameMap) {
    // to be reimplemented
    
    generateCeleron(gameMap);
    generateXeon(gameMap);
    generateRyzen(gameMap);
    generateEniac(gameMap);
 
    // load objects; asteroid, stations, freighters, other celestial objects
    
    // * ASTEROID *
    if (window.gameData.asteroidRandom) {
        for(let i = 0; i < 10; ++i) {
            let objCoordx = Math.ceil(Math.random() * (gameMap.size));
            let objCoordy = Math.ceil(Math.random() * (gameMap.size));
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy);
        }
    } else {
        for(let coords of window.gameData.asteroids) {
            let objCoordx = coords[0];
            let objCoordy = coords[1];
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy);
        }
    }

    // * METEOR SHOWERS *
    if(window.gameData.meteorRandom) {
        for(let i = 0; i < 10; ++i) {
            let objCoordx = Math.ceil(Math.random() * (gameMap.size));
            let objCoordy = Math.ceil(Math.random() * (gameMap.size));
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy); 
        }
    } else {
        for(let coords of window.gameData.meteors) {
            let objCoordx = coords[0];
            let objCoordy = coords[1];
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy);
        }
    }
    
    // * FREIGHTERS *
    if (window.gameData.freighterRandom) {
        for(let i = 0; i < 10; ++i) {
            let objCoordx = Math.ceil(Math.random() * (gameMap.size));
            let objCoordy = Math.ceil(Math.random() * (gameMap.size));
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy);
        }
    } else {
        for(let coords of window.gameData.freighters) {
            let objCoordx = coords[0];
            let objCoordy = coords[1];
            generateCelestialObjects(gameMap, 4, objCoordx, objCoordy);
        }
    }

    // * STATIONS *
    if (window.gameData.stationRandom) {
        for(let i = 0; i < 10; ++i) {
            let objCoordx = Math.ceil(Math.random() * (gameMap.size));
            let objCoordy = Math.ceil(Math.random() * (gameMap.size));
            generateCelestialObjects(gameMap, (i % 4), objCoordx, objCoordy);
        }
    } else {
        for(let coords of window.gameData.stations) {
            let objCoordx = coords[0];
            let objCoordy = coords[1];
            let stationType = Math.floor(Math.random() * 4);
            generateCelestialObjects(gameMap, stationType, objCoordx, objCoordy);
        }
    }
    
}

/* populates a saved map with the state it was left in */
function PopulateSavedMap ( gameMap, savedMap ) {

}

/* generates celestial objects */
function generateCelestialObjects ( gameMap, type, celestX, celestY ) {
 switch ( type ) {
        case 0:
            mapObj = new SpaceStation( [new MuskTesla( 100, 1000 ), new RepairDepot, new MiniMart()] );
            break;

        case 1:
            mapObj = new SpaceStation( [new MuskTesla( 100, 1000 ), new RepairDepot()] );
            break;

        case 2:
            mapObj = new SpaceStation( [new MuskTesla( 100, 1000 ), new MiniMart()] );
            break;

        case 3:
            mapObj = new SpaceStation( [new MuskTesla( 100, 1000 )] );
            break;

        case 4:
            mapObj = new Asteroid();
            break;

        case 5:
            mapObj = new AbFreighter();
            break;

        case 6:
            mapObj = new MeteorShower();
            break;  
}

/* save the current state of the game */
function updateLogs ( gameMap, mapObj, objCoordX, objCoordY ) {
    console.log( 'Placed ' + mapObj.objType + " at position: " + objCoordX + ' ' + objCoordY );
    gameMap.add( mapObj, objCoordX, objCoordY );
    saveMap( gameData, mapObj, objCoordX, objCoordY );
}

// * CELERON *
// generate celeron at a random x and y position, call the
// generateCeleronAtLocation function to actually place Celeron 
// on the map
function generateCeleron( gameMap ) {
    let randomCelX = Math.ceil(Math.random() * (gameMap.size));
    let randomCelY = Math.ceil(Math.random() * (gameMap.size));
    generateCeleronAtLocation(gameMap, randomCelX, randomCelY);
}

// places Celeron on the map
function generateCeleronAtLocation(gameMap, celeronCoordX, celeronCoordY) {
    // if the location has nothing, add Celeron to the map
    mapObj = new Celeron();
    if (gameData.celeronX || gameData.celeronX === 0)
        celeronCoordX = gameData.celeronX;
    if (gameData.celeronY || gameData.celeronY === 0)
        celeronCoordY = gameData.celeronY;
    mapObj.x = celeronCoordX;
    mapObj.y = celeronCoordY;
    updateLogs(gameMap, mapObj, celeronCoordX, celeronCoordY);
    gazePopulate(mapObj, celeronCoordX, celeronCoordY);
}

// * ENIAC *
// generate eniac at a random x and y position, call the
// generateEniacAtLocation function to actually place eniac 
// on the map
function generateEniac ( gameMap ) {
    generateEniacAtLocation(gameMap, 0, 0);
}

// places Eniac on the map
function generateEniacAtLocation(gameMap, eniacCoordX, eniacCoordY) {
    mapObj = new Eniac();
    mapObj.x = eniacCoordX;
    mapObj.y = eniacCoordY;
    updateLogs( gameMap, mapObj, eniacCoordX, eniacCoordY );
}

// * XEON *
// generate xeon at a random x and y position, call the
// generateXeonAtLocation function to actually place Xeon 
// on the map
function generateXeon(gameMap) {
    let randomXeonX = Math.ceil(Math.random() * (gameMap.size));
    let randomXeonY = Math.ceil(Math.random() * (gameMap.size));
    generateXeonAtLocation(gameMap, randomXeonX, randomXeonY)
}

// places Xeon on the map
function generateXeonAtLocation(gameMap, xeonCoordX, xeonCoordY) {
    mapObj = new Xeon();
    if ( gameData.xeonX || gameData.xeonX === 0 )
        xeonCoordX = gameData.xeonX;
    if ( gameData.xeonY || gameData.xeonY === 0 )
        xeonCoordY = gameData.xeonY;
    mapObj.x = xeonCoordX;
    mapObj.y = xeonCoordY;
    updateLogs(gameMap, mapObj, xeonCoordX, xeonCoordY);
    gazePopulate(mapObj, xeonCoordX, xeonCoordY);
}

// * RYZEN *
// generate ryzen at a random x and y position, call the
// generateRyzenAtLocation function to actually place Ryzen 
// on the map
function generateRyzen ( gameMap ) {
    let randomRyzenX = Math.ceil(Math.random() * (gameMap.size));
    let randomRyzenY = Math.ceil(Math.random() * (gameMap.size));
    generateRyzenAtLocation(gameMap, randomRyzenX, randomRyzenY)
}

// places Ryzen on the map
function generateRyzenAtLocation(gameMap, ryzenCoordX, ryzenCoordY) {
    mapObj = new Ryzen();
    if(gameData.ryzenX || gameData.ryzenX === 0)
        ryzenCoordX = gameData.ryzenX;
    if(gameData.ryzenY || gameData.ryzenY === 0)
        ryzenCoordY = gameData.ryzenY;
    mapObj.x = ryzenCoordX;
    mapObj.y = ryzenCoordY;
    updateLogs(gameMap, mapObj, ryzenCoordX, ryzenCoordY);
    gazePopulate(mapObj, ryzenCoordX, ryzenCoordY);
}
<file_sep>/* sees if OldSpice encounters any objects */
// could potentially be discarded
var HitObj = function(x_coord, y_coord) {
   
}
<file_sep>/* admin page */
<file_sep>function saveMap(gameData, mapObj, objX, objY){
    
}

function saveShip(gameData, oldSpice){
   
}
<file_sep><!-- SH-10 Encountering an Abandoned Freighter  Low  -->
<!-- Storys: As a player, I want to encounter an abandoned
        Freighter drifting in space so I can take on additional supplies and energy  -->

function Freighter(energy,supplies)
{
	energy = energy + 10;
	supplies = supplies + 10;
	return {a1:energy,b1:supplies};
}

<!-- call fucntion -->
//var obj = Freighter(energy,supplies)
//energy = obj.a1;
//supplies = obj.b1;
//energy and supplies is global variable<file_sep>/* Information for the objects that the game has */

// MAP OBJECT
function MapObject(type, radius) {
  this.objType = type; 
  this.radius = radius; 
  this.isHidden = false; 
}

MapObject.prototype.Collide = function() {
  console.log("collision noted"); 
}

// ASTEROID
function Asteroid() {

}

Asteroid.prototype = new MapObject('Asteroid', 0); 

Asteroid.prototype.DamageShip = function() {
  alert("OldSpice bare missed an asteroid! Damage occurred!"); 
  oldSpice.isDamaged = true; 
}

Asteroid.prototype.DestroyShip = function() {
  oldSpice.energy = 0; 
  ctrecipe.GameOver("OldSpice hit an asteroid! You blew up!");
}

Asteroid.prototype.Collide = function() {
  MapObejct.prototype.Collide.call(this); 
  let eventDecider = Math.random(); 
  if(eventDecider < 0.9) {
    this.DamageShip(); 
  }
  else {
    this.DestroyShip(); 
  }
}

// METEOR SHOWER
function MeteorShower() {

}

MeteorShower.prototype = new MapObject("MeteorShower", 0);

MeteorShower.prototype.Collide = function() {
    MapObject.prototype.Collide.call(this);
    alert("You flew into a meteor shower and OldSpice is damaged!");
    oldSpice.isDamaged = true;
}

// ABANDONED FREIGHTER
function AbFreighter() { 

}

AbFreighter.prototype = new MapObject("AbFreighter", 0);

AbFreighter.prototype.Loot = function() {
    let maxEnergy = 1000;
    let maxSupply = 100;
    let retEnergy;
    let retSupply;

    let roll = Math.random();
    if (roll < 0.75) {
        retEnergy = 0.1 * maxEnergy;
        retSupply = 0.1 * maxSupply;
    }
    else if (roll < 0.90) {
        retEnergy = 0.5 * maxEnergy;
        retSupply = 0.5 * maxSupply;
    }
    else {
        retEnergy = maxEnergy;
        retSupply = maxSupply;
    }
    return [retEnergy, retSupply];
}

AbFreighter.prototype.Collide = function() {
    MapObject.prototype.Collide.call(this);
    let loot = this.Loot();
    lootEnergy = parseInt(loot[0]);
    lootSupply = parseInt(loot[1]);
    
    alert("You came across an abandoned freighter and collected " + lootEnergy + " energy and " + lootSupply + " supply from the remains!" );

    oldSpice.energy += lootEnergy;
    if (oldSpice.supplies + lootSupply <= 100)
        oldSpice.supplies += lootSupply;
    else
        oldSpice.supplies = 100;

    updateLevels(); // display new supply and energy gained from the freighter
    gameMap.remove(oldSpice.x, oldSpice.y); // remove the freighter from the map since it was already used
}

// WORMHOLE
function WormHole() {

}

WormHole.prototype = new MapObject("Wormhole", 0); 

WormHole.prototype.Collide = function() {
  MapObject.prototype.Collide.call(this); 
  alert("You hit a wormhole!"); 
  
  if(ctrecipe.WormholeFixed) {
    oldSpice.x = ctrecipe.WormholeX;
    oldSpice.y = ctrecipe.WormholeY;
  }
  // relocate after falling into a wormhole
  else {
    xrand = Math.ceil(Math.random() * (gameMap.size - 2)); 
    yrand = Math.ceil(Math.random() * (gameMap.size - 2)); 
    oldSpice.x = xrand; 
    oldSpice.y = yrand; 
  }
}

// PLANET
function Planet(name, x, y) {
    this.name = name;
    this.x = x;
    this.y = y;
}

Planet.prototype = new MapObject('Planet', 1);

Planet.prototype.Collide = function() {

}

Planet.prototype.EnterOrbit = function() {
   
}

// ENIAC
function Eniac () { 

};

Eniac.prototype = new Planet('Eniac', -1, -1);

Eniac.prototype.Collide = function() {
    MapObject.prototype.Collide.call(this);
    if(oldSpice.recipe) {
        ctrecipe.GameWinner("You got the KokaKola Recipe!" );
    }
    else {
        this.EnterOrbit();
    }
}

// CELERON
function Celeron() { 

};

Celeron.prototype = new Planet('Celeron', -1, -1);

Celeron.prototype.Collide = function() {
    alert("Collided with Celeron!");
    MapObject.prototype.Collide.call(this);
    this.EnterOrbit();
}

// RYZEN
function Ryzen() { 

};

Ryzen.prototype = new Planet('Ryzen', -1, -1);

Ryzen.prototype.Collide = function() {
    alert("Collided with Ryzen!");
    MapObject.prototype.Collide.call(this);
    this.EnterOrbit();
}

// XEON
function Xeon() { 

};

Xeon.prototype = new Planet('Xeon', -1, -1);

Xeon.prototype.Collide = function() {
    alert("Collided with Xeon");
    MapObject.prototype.Collide.call(this);
    this.EnterOrbit();
}

// BAD MAX
function BadMax () { }

BadMax.prototype = new MapObject("BadMax", 0);
BadMax.prototype.isHidden = true;

BadMax.prototype.Collide = function () {
    MapObject.prototype.Collide.call(this);
    let eventDecider = Math.random();
    // you escape
    if (eventDecider < 0.5) {
        this.Escape();
    }
    // you steal
    else if (eventDecider < 0.8) {
        this.Steal();
    }
    // your ship is destroyed
    else {
        this.DestroyShip();
    }
    //reposition badmax after encounter with OldSpice and delete previous BadMax from the map
    gameMap.remove( oldSpice.x, oldSpice.y ); // remove this BadMax from the map
    generateBadMax( gameMap ); //add a new badmax to the map
}

BadMax.prototype.Steal = function() {
    alert("BadMax has boarded your ship and stolen half your supplies and all your credits!");
    oldSpice.supplies /= 2;
    oldSpice.credit = 0;
}

BadMax.prototype.DestroyShip = function() {
    ctrecipe.GameOver("BadMax and his henchmen blasted your ship!");
}

BadMax.prototype.Escape = function() {
    alert("You come across BadMax but successfuly lose him and his henchmen!");
}

// RECIPE
function KokaKolaRecipe() { 

}

KokaKolaRecipe.prototype = new MapObject("Recipe", 0);
KokaKolaRecipe.prototype.isHidden = true;

KokaKolaRecipe.prototype.Collide = function() {
    MapObject.prototype.Collide.call(this);
    oldSpice.recipe = true;
    alert("You got the KokaKola recipe! Return to Eniac!");
    gameMap.remove(oldSpice.x, oldSpice.y); // remove the recipe from the map because user has obtained it
}

// GAME OF CHANCE VAR
var playGameOfChance;

// SPACE STATION
function SpaceStation ( attachedStations ) {
   
}

SpaceStation.prototype = new MapObject( "Station", 0 );

SpaceStation.prototype.Collide = function () {
   
}

function CheckBalance ( price ) {
   
}

function gameOfChance () {
   
}

// WINNINGS 
function PlayGameOfChance () {
   
}

// MUSKTESTA
function MuskTesla ( energyQuantity, energyPrice ) {
   
}

MuskTesla.prototype.MenuPrompt = function () {
  
}

MuskTesla.prototype.Purchase = function () {
   
}

// MINI MART
function MiniMart () {
   
}

MiniMart.prototype.MenuPrompt = function () {
   
}

MiniMart.prototype.Purchase = function () {
   
}

// REPAIR DEPOT
function RepairDepot () {
   
}

RepairDepot.prototype.MenuPrompt = function () {
  
}

RepairDepot.prototype.Purchase = function () {
  
} 
