The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Text based game help, I need to change the directional keys in my game to incorporate matric
fratochips
post May 3 2015, 09:42 PM
Post #1





Group: Members
Posts: 1
Joined: 3-May 15
Member No.: 22,555



Hi this is my first post on this forum and I am really having trouble understanding this school project I'm working on. The professor wants us to use matrices for the navigational functions in our game, but I can't seem to find anywhere on the internet of someone attempting the same code as myself. I am currently using switch cases to go from location to location, but he wants us to change it for the finalized version of our project. Here is a sample of my code.
CODE

//function for directional buttons
function northb() {
    var message = " ";
    switch(charLoc){
        case "HomeB":
            fWaterfall();
            break;
        case "FWaterfall":
            jWaterfall();
            break;
        case "ECave":
            homeb();
            break;
        case "DCave":
            eCave();
            break;
        case "Lake":
            house();
            break;
        default:
            error();
    }
}
function southb()
{    
    var message = " ";
    switch(charLoc)
    {
        case "HomeB":
            eCave();
            break;
        case "ECave":
            dCave();
            break;
        case "JWaterfall":
            fWaterfall();
            break;
        case "FWaterfall":
            homeb();
            break;
        case "House":
            lake();
            break;
        default:
            error();
    }
}
function eastb()
{    
    var message = " ";
    switch(charLoc)
    {
        case "HomeB":
            bear();
            break;
        case "House":
            street();
            break;
        case "Bear":
            lake();
            break;
        case "Cliff":
            homeb();
            break;
        case "RCave":
            dCave();
            break;
        default:
            error();
    }
}
function westb()
{
    var message = " ";
    switch(charLoc)
    {
        case "HomeB":
            cliff();
            break;
        case "Bear":
            homeb();
            break;
        case "DCave":
            rCave();
            break;
        case "Street":
            house();
            break;
        case "Lake":
            bear();
            break;
        default:
            error();
    }
}

These are his exact words as to what he wants us to do:
QUOTE

Redo your navigation one final time, this time with a matrix; no more if-else, no
more switch-case. Write a function that takes the current location and direction
moved as parameters and returns the new location (or the same location if that
was an invalid move). Use that function to run all player navigation through the
game.

If anyone can decipher what he is trying to say I would gladly appreciate any help.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 4 2015, 07:05 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE

Redo your navigation one final time, this time with a matrix; no more if-else, no
more switch-case. Write a function that takes the current location and direction
moved as parameters and returns the new location (or the same location if that
was an invalid move). Use that function to run all player navigation through the
game.

My guess is that he wants you to use a single function that passes data as parameters/arguments, rather than using lots of separate functions for each location.

I don't know any javascript term called "matrix". The closest thing that comes to mind is multidimensional arrays, but then I guess he should have said so. unsure.gif

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 4 2015, 11:42 AM
Post #3


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



As I understand it there are no multidirectional multidimensional arrays in JS but you can work around it by building arrays of arrays. Here's a thread where that's discussed and you can find a lot more.

This is all a little above my head so FWIW.
http://stackoverflow.com/questions/966225/...y-in-javascript
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post May 4 2015, 12:54 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,656
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ May 4 2015, 06:42 PM) *

As I understand it there are no multidirectional arrays in JS

That would have complicated things. tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post May 4 2015, 01:58 PM
Post #5


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



Whatever. tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 23rd April 2024 - 11:59 PM