need help for a programming exercice

This is a discussion on need help for a programming exercice within the C# Programming forums, part of the General Programming Boards category; Hello, I am a first year programming student and I got problem solving an exercice I would be glad if ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    3

    need help for a programming exercice

    Hello,

    I am a first year programming student and I got problem solving an exercice I would be glad if you could help me.

    Write a program, Tut6_2.cs where robby walks around the perimeter of room 8
    , avoiding blue obstacles. In room 8, the obstacles are all one square wide (again), but of varied length.



    Your solution should use while loops to negotiate these obstacles







    Code:
    namespace CE0721a {
      classtut6_2 {
        publicvoid run() {
    // make objects
    
          Robot robby = new Robot();
          Room room = new Room(8);
          Picture picture = new Picture(room, robby);
    
           robby.right();
           picture.draw();
    
          while (true) {
            if (robby.ahead_is_colour(room, "white")) {
              robby.move();
              picture.draw();
              if (robby.ahead_is_colour(room, "blue")) {
                robby.left();
                picture.draw();
              }
              if (robby.ahead_is_colour(room, "black")) {
                robby.left();
                picture.draw();
              }
            }
          }
        }
      }
    }
    I attached a picture of the room 8.The problem I encounter is when the robot go up the obstacle I don t know how he can check at his right.


    Thank you in advance for your help
    best regards
    Thibault[ATTACH]11093
    [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]
    Attached Images Attached Images  
    Last edited by Salem; 11-12-2011 at 02:14 AM. Reason: remove pointless tags

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    I'm guessing your location is just tracked in some X,Y coordinate...why not just check map[x + 1,y]? Need more information before we can help you with this. How's the map stored? How's the robot's location stored?
    If you understand what you're doing, you're not learning anything.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,752
    Just so you know, next time you should paste "text" and not "html" into the code tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    Woah, for one, you have an infinite loop. Yes you might want it to repeat but you should always have an easy exit option other than the three finger salute.

    Next you should modify the routine to take into account the direction of movement just taken. Always think backwards.
    He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

    The fool wonders, the wise man asks. - Benjamin Disraeli

    There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by thibault0613 View Post
    The problem I encounter is when the robot go up the obstacle I don t know how he can check at his right.
    Unless I am missing something in translation here, his "right" depends on what way he is facing.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help for my programming exercice
    By thibault0613 in forum C# Programming
    Replies: 5
    Last Post: 11-09-2011, 01:52 PM
  2. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  3. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 11:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21