I'm having trouble figuring out why I can't move on the map. If anyone has any input on what I need to correct, please help me. I've tried chat GPT but it doesn't help much. If you want in on it, I welcome whatever help may be out there to help me code this in my spare time. If you want to check out the link it is at www.geocities.ws/paulmoon410/game under the folder 'From Scratch' Please take it easy on me. This is the index.html ````html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Moon - Text-Based D&D Game</title> <style> body { font-family: Arial, sans-serif; } </style> </head> <body> <div id="gameOutput"></div> <script> // Function to display menu options function displayMenu() { const menu = ` <h2>Welcome to Moon!</h2> <ul> <li><a href="#" onclick="startNewGame()">New Game</a></li> <li><a href="#" onclick="loadGame()">Load Game</a></li> <li><a href="#" onclick="showOptions()">Options</a></li> <li><a href="#" onclick="exitGame()">Exit</a></li> </ul> `; document.getElementById('gameOutput').innerHTML = menu; } // Function to start a new game function startNewGame() { // Redirect to moongame.html window.location.href = 'moongame.html'; } // Function to load a saved game function loadGame() { // Add code to load a saved game console.log('Loading game...'); } // Function to show options function showOptions() { // Add code to show game options console.log('Showing options...'); } // Function to exit the game function exitGame() { // Add code to exit the game console.log('Exiting game...'); } // Display menu options when the page loads displayMenu(); </script> </body> </html> ```` <br> Then this is the moongame.html <br> ````html <div id="gameContainer"> <!-- The content will be dynamically updated by JavaScript --> <h1>Welcome to the Town Center</h1> <p>You find yourself in the bustling town center of Moon. What would you like to do?</p> <ul> <li><a href="#" onclick="exploreTown('north')">Go North</a></li> <li><a href="#" onclick="exploreTown('east')">Go East</a></li> <li><a href="#" onclick="exploreTown('south')">Go South</a></li> <li><a href="#" onclick="exploreTown('west')">Go West</a></li> </ul> </div> <!-- Link the JavaScript files --> <script src="map.js"></script> <script src="character.js"></script> <script src="enpc.js"></script> </html> ```` <h2>This is maps.js and where I'm really working right now.</h2> ````javascript // map.js // Define the game map const gameMap = generateMap(100, 100, 10000, 10000); // Function to generate a game map with varying population density function generateMap(centerX, centerY, width, height) { const map = {}; // Define population density based on distance from the center const maxDistance = Math.sqrt(Math.pow(width / 2, 2) + Math.pow(height / 2, 2)); // Generate locations for (let x = 0; x < width; x++) { for (let y = 0; y < height; y++) { const distanceToCenter = Math.sqrt(Math.pow(x - centerX, 2) + Math.pow(y - centerY, 2)); const populationDensity = 1 - (distanceToCenter / maxDistance); // Population density decreases as distance from center increases if (Math.random() < populationDensity) { // Location is populated map[`${x}_${y}`] = { description: `You are at (${x}, ${y}). It is a populated area.`, locations: generateAdjacentLocations(x, y, width, height) }; } } } return map; } // Function to generate adjacent locations for a given coordinate function generateAdjacentLocations(x, y, width, height) { const locations = {}; if (x > 0) locations.west = `${x - 1}_${y}`; if (x < width - 1) locations.east = `${x + 1}_${y}`; if (y > 0) locations.north = `${x}_${y - 1}`; if (y < height - 1) locations.south = `${x}_${y + 1}`; return locations; } // Function to explore a location and navigate the world function exploreTown(x, y) { const currentLocation = `${x}_${y}`; // Current location coordinates if (gameMap[currentLocation]) { // Location exists displayLocation(currentLocation); } else { console.log('Invalid location.'); } } // Function to display the description of a location function displayLocation(location) { const description = gameMap[location].description; document.getElementById('gameContainer').innerHTML = ` <h1>Location: ${location}</h1> <p>${description}</p> <p>What would you like to do?</p> <ul> ${generateNavigationLinks(location)} </ul> `; } // Function to generate navigation links for adjacent locations function generateNavigationLinks(location) { const adjacentLocations = gameMap[location].locations; let links = ''; for (const direction in adjacentLocations) { links += `<li><a href="#" onclick="exploreTown(${adjacentLocations[direction].split('_')[0]}, ${adjacentLocations[direction].split('_')[1]})">Go ${direction.charAt(0).toUpperCase() + direction.slice(1)}</a></li>`; } return links; } ````
author | paulmoon410 |
---|---|
permlink | making-a-game-learning-to |
category | hive-188262 |
json_metadata | "{"app":"ecency/3.1.1-vision","description":"Making a game, stuck on some code.","format":"markdown+html","image":[],"tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"]}" |
created | 2024-04-28 23:40:15 |
last_update | 2024-04-28 23:43:15 |
depth | 0 |
children | 5 |
last_payout | 2024-05-05 23:40:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.220 HBD |
curator_payout_value | 0.214 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 5,753 |
author_reputation | 40,588,970,965,704 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,202,005 |
net_rshares | 1,040,893,181,581 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
chrisaiki | 0 | 264,364,822,256 | 100% | ||
phusionphil | 0 | 10,880,274,433 | 95% | ||
freebornsociety | 0 | 2,930,793,221 | 5.93% | ||
joeyarnoldvn | 0 | 468,458,104 | 1.47% | ||
pixresteemer | 0 | 50,252,787,862 | 12% | ||
isnochys | 0 | 10,188,564,210 | 5% | ||
dejan.vuckovic | 0 | 12,421,656,155 | 15% | ||
steveconnor | 0 | 89,063,672,361 | 50% | ||
chireerocks | 0 | 1,254,654,675 | 50% | ||
michelmake | 0 | 48,416,382,950 | 25% | ||
yintercept | 0 | 202,134,030,406 | 100% | ||
masoom | 0 | 2,673,101,410 | 50% | ||
steemvpn | 0 | 27,423,534,269 | 95% | ||
mind.force | 0 | 7,477,442,298 | 25% | ||
amico.sports | 0 | 21,588,889,463 | 50% | ||
chris-uk | 0 | 22,359,706,427 | 50% | ||
hive-127039 | 0 | 473,799,036 | 25% | ||
zelegations | 0 | 10,216,796,009 | 95% | ||
timhorton | 0 | 9,909,320,669 | 95% | ||
cerberus-dji | 0 | 2,296,104,215 | 95% | ||
hivecannabis | 0 | 3,686,631,226 | 42% | ||
hive-data | 0 | 57,491,651,436 | 10% | ||
hive-vpn | 0 | 2,069,329,899 | 95% | ||
hivehabits | 0 | 75,070,682 | 100% | ||
sodomlv | 0 | 2,571,501,972 | 50% | ||
holovision.stem | 0 | 1,397,237,778 | 50% | ||
marshmellowman | 0 | 9,858,943,254 | 55% | ||
ingi1976 | 0 | 8,954,246,865 | 50% | ||
arc7icwolf | 0 | 36,799,962,887 | 50% | ||
churchoftheway | 0 | 2,777,720,753 | 100% | ||
svanbo | 0 | 16,580,013,968 | 15% | ||
singerice | 0 | 0 | 100% | ||
waivio.welcome | 0 | 717,898,059 | 1.42% | ||
mmoonn | 0 | 1,571,953,561 | 100% | ||
dr-animation | 0 | 1,472,034,071 | 100% | ||
strava2hive | 0 | 17,916,452,691 | 100% | ||
giorgakis | 0 | 2,873,646,618 | 50% | ||
peakecoin | 0 | 1,126,983,833 | 100% | ||
mviews | 0 | 75,296,298,034 | 100% | ||
learn2code | 0 | 860,813,565 | 50% | ||
lolz.byte | 0 | 0 | 100% | ||
arc7icwolf.byte | 0 | 0 | 100% | ||
bbarelyseal | 0 | 0 | 100% | ||
peakecoin.bnb | 0 | 0 | 100% |
I hope someone knows how to help you solve that problem! Curated by @arc7icwolf.byte for the #LearnToCode Community
author | arc7icwolf |
---|---|
permlink | re-paulmoon410-202451t22414576z |
category | hive-188262 |
json_metadata | {"tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"],"app":"ecency/3.1.1-vision","format":"markdown+html"} |
created | 2024-05-01 20:41:45 |
last_update | 2024-05-01 20:41:45 |
depth | 1 |
children | 1 |
last_payout | 2024-05-08 20:41:45 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 116 |
author_reputation | 503,686,741,861,524 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,284,762 |
net_rshares | 0 |
Nobody reached out yet. I'm busy during the week right now anyway. I just finished school and have mountains of paperwork.
author | paulmoon410 |
---|---|
permlink | re-arc7icwolf-202451t173833195z |
category | hive-188262 |
json_metadata | {"type":"comment","tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"],"app":"ecency/3.0.46-mobile","format":"markdown+html"} |
created | 2024-05-01 21:38:33 |
last_update | 2024-05-01 21:38:33 |
depth | 2 |
children | 0 |
last_payout | 2024-05-08 21:38:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 122 |
author_reputation | 40,588,970,965,704 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,285,933 |
net_rshares | 0 |
The error must be around here, I think. ``` <li><a href="#" onclick="exploreTown('north')">Go North</a>li> <li><a href="#" onclick="exploreTown('east')">Go East</a>li> <li><a href="#" onclick="exploreTown('south')">Go South</a>li> <li><a href="#" onclick="exploreTown('west')">Go West</a>li> ``` ``` function exploreTown(x, y) { const currentLocation = `${x}_${y}`; // Current location coordinates if (gameMap[currentLocation]) { // Location exists displayLocation(currentLocation); } else { console.log('Invalid location.'); } }```
author | sm-silva |
---|---|
permlink | re-paulmoon410-202451t203356932z |
category | hive-188262 |
json_metadata | {"tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"],"app":"ecency/3.1.1-vision","format":"markdown+html"} |
created | 2024-05-01 23:33:57 |
last_update | 2024-05-01 23:33:57 |
depth | 1 |
children | 2 |
last_payout | 2024-05-08 23:33:57 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 601 |
author_reputation | 1,540,305,234,889 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,287,698 |
net_rshares | 0 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
arc7icwolf.byte | 0 | 0 | 40% |
I'll double check it in a little bit.
author | paulmoon410 |
---|---|
permlink | re-sm-silva-202451t193713423z |
category | hive-188262 |
json_metadata | {"type":"comment","tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"],"app":"ecency/3.0.46-mobile","format":"markdown+html"} |
created | 2024-05-01 23:37:12 |
last_update | 2024-05-01 23:37:12 |
depth | 2 |
children | 0 |
last_payout | 2024-05-08 23:37:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 38 |
author_reputation | 40,588,970,965,704 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,287,736 |
net_rshares | 0 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
arc7icwolf.byte | 0 | 0 | 10% |
I'm about to sit down after dinner and play around with this to see if I can correct my error.
author | paulmoon410 |
---|---|
permlink | re-sm-silva-202457t19232992z |
category | hive-188262 |
json_metadata | {"tags":["hive-188262","neoxian","pimp","thgaming","blockchaingaming","hivehustlers","palnet","waivio","ctp","lassecash","archon"],"app":"ecency/3.2.0-vision","format":"markdown+html"} |
created | 2024-05-07 23:02:30 |
last_update | 2024-05-07 23:02:30 |
depth | 2 |
children | 0 |
last_payout | 2024-05-14 23:02:30 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 94 |
author_reputation | 40,588,970,965,704 |
root_title | "'Making A Game' - Learning to Code" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 133,461,826 |
net_rshares | 0 |