Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    0
    ReputationRep:
    I got stuck how to write these 4 methods, please guys kindly help me this exercise, I am facing with so many deadlines and I really want to scream.

    I need your help in METHODs MOVEUP MOVEDOWN MOVELEFT and MOVERIGHT.

    I attached the questions and the work I have partially done.
    Attached Files
  1. File Type: zipquestions.zip (285.8 KB, 36 views)
    Offline

    0
    ReputationRep:
    Lets take moveDown() as an example.

    Here is the description of what it should achieve according to your docs
    Attempts to move down in the array by an increment of 1.
    If the new position is outside the array it goes to the topmost point in the 2D array. Note: It is not possible to move onto a water ('W') or mountain ('M') square on the map. This should output a message such as "Cannot go down as there is water in the way." or "Cannot go down as there is mountains in the way."
    So you should be doing something like this.
    Code:
    //Pseudocode for  moveDown
    moveDown()
    {
         //get the current position and store into temp variables.
         int a,b;
         a=x;
         b=y;
         //Decrease the y co-ordinate by one and check to see if we are inside the array's bounds.
         //this assumes a 0 based array. 
         //top_of_array is some constant which defines the length of the array.
         b=b-1;
         if (b<0)
        {
               b=top_of_array;
         }
    
        //check to find out what is on the new square.
        switch(map[x][b])
        {
            case 'E':
                 //fine we can go there, just update the y co-ord and reprint the map
                y=b;
                printMap();
            case 'D'
                 //fine we can go there, just update the y co-ord and reprint the map
                y=b;
                printMap();
            case 'W'
                 //print out an error message saying we cant go there its water
                return ERROR;
            case 'M'
                  //print out an error saying we cant go there its mountain
                return ERROR;
            default 
               // print out an error saying that the land type is unkown.
                return ERROR;
        }
    return SUCCESS;
    }
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by MickyT)
    Lets take moveDown() as an example.

    Here is the description of what it should achieve according to your docs


    So you should be doing something like this.
    Code:
    //Pseudocode for  moveDown
    moveDown()
    {
         //get the current position and store into temp variables.
         int a,b;
         a=x;
         b=y;
         //Decrease the y co-ordinate by one and check to see if we are inside the array's bounds.
         //this assumes a 0 based array. 
         //top_of_array is some constant which defines the length of the array.
         b=b-1;
         if (b<0)
        {
               b=top_of_array;
         }
    
        //check to find out what is on the new square.
        switch(map[x][b])
        {
            case 'E':
                 //fine we can go there, just update the y co-ord and reprint the map
                y=b;
                printMap();
            case 'D'
                 //fine we can go there, just update the y co-ord and reprint the map
                y=b;
                printMap();
            case 'W'
                 //print out an error message saying we cant go there its water
                return ERROR;
            case 'M'
                  //print out an error saying we cant go there its mountain
                return ERROR;
            default 
               // print out an error saying that the land type is unkown.
                return ERROR;
        }
    return SUCCESS;
    }
    Let me try it then tell you later. Please accept my big thanks.
    • Thread Starter
    Offline

    0
    ReputationRep:
    anyone else could help me please ? I am screaming ...tomorrow is deadline
    Offline

    0
    ReputationRep:
    anyone else could help me please ? I am screaming ...tomorrow is deadline
    Maybe if you provided more info on what you don't understand people would be more inclined to help you.

    We're not here to do your homework for you, I posed the above as a framework in the hope that you would addapt it to fit your needs. Not just to copy and paste it without understanding why/how it works.
    Its trivial to use it as a basis for the other functions.


    Come back with specifics and not just "help" and we may be able to do something.
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: December 17, 2010
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Did TEF Bronze Award affect your UCAS choices?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.