create account

'Making A Game' - Learning to Code by paulmoon410

View this thread on: hive.blogpeakd.comecency.com
· @paulmoon410 · (edited)
$0.43
'Making A Game' - Learning to Code
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;
}

````
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorpaulmoon410
permlinkmaking-a-game-learning-to
categoryhive-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"]}"
created2024-04-28 23:40:15
last_update2024-04-28 23:43:15
depth0
children5
last_payout2024-05-05 23:40:15
cashout_time1969-12-31 23:59:59
total_payout_value0.220 HBD
curator_payout_value0.214 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,753
author_reputation40,588,970,965,704
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,202,005
net_rshares1,040,893,181,581
author_curate_reward""
vote details (44)
@arc7icwolf ·
I hope someone knows how to help you solve that problem!

Curated by @arc7icwolf.byte for the #LearnToCode Community
properties (22)
authorarc7icwolf
permlinkre-paulmoon410-202451t22414576z
categoryhive-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"}
created2024-05-01 20:41:45
last_update2024-05-01 20:41:45
depth1
children1
last_payout2024-05-08 20:41:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length116
author_reputation503,686,741,861,524
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,284,762
net_rshares0
@paulmoon410 ·
Nobody reached out yet. I'm busy during the week right now anyway. I just finished school and have mountains of paperwork.
properties (22)
authorpaulmoon410
permlinkre-arc7icwolf-202451t173833195z
categoryhive-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"}
created2024-05-01 21:38:33
last_update2024-05-01 21:38:33
depth2
children0
last_payout2024-05-08 21:38:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length122
author_reputation40,588,970,965,704
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,285,933
net_rshares0
@sm-silva ·
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.');
    }
}```
👍  
properties (23)
authorsm-silva
permlinkre-paulmoon410-202451t203356932z
categoryhive-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"}
created2024-05-01 23:33:57
last_update2024-05-01 23:33:57
depth1
children2
last_payout2024-05-08 23:33:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length601
author_reputation1,540,305,234,889
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,287,698
net_rshares0
author_curate_reward""
vote details (1)
@paulmoon410 ·
I'll double check it in a little bit. 
👍  
properties (23)
authorpaulmoon410
permlinkre-sm-silva-202451t193713423z
categoryhive-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"}
created2024-05-01 23:37:12
last_update2024-05-01 23:37:12
depth2
children0
last_payout2024-05-08 23:37:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length38
author_reputation40,588,970,965,704
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,287,736
net_rshares0
author_curate_reward""
vote details (1)
@paulmoon410 ·
I'm about to sit down after dinner and play around with this to see if I can correct my error.
properties (22)
authorpaulmoon410
permlinkre-sm-silva-202457t19232992z
categoryhive-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"}
created2024-05-07 23:02:30
last_update2024-05-07 23:02:30
depth2
children0
last_payout2024-05-14 23:02:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length94
author_reputation40,588,970,965,704
root_title"'Making A Game' - Learning to Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id133,461,826
net_rshares0