Turtle Game - Please Help

This is a discussion on Turtle Game - Please Help within the C++ Programming forums, part of the General Programming Boards category; I have to deisgn a game for computer class that is due tommorow and I have been working on for ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    Unhappy Turtle Game - Please Help

    I have to deisgn a game for computer class that is due tommorow and I have been working on for a while and have not yet been able to figure it out so I'm hoping someone here can help me out with my problem.

    I have to write a program that simulates Turtle Graphics (an old computer game). The turtle holds the pen in one of two positions, up or down. When the pen is down, the turtle traces out shapes as it moves; while the turtle is up, the turtle moves about freely without writing anything.

    I have to use a 20x20 array "floor" which is initialized to zeros. The user gets to input commands. It has to keep track of the current position at all times and wether the pen is currently up or down. Assuming that the turtle always starts at position 0,0 with the pen up. The commands work as follows:

    Command:
    1-pen up
    2-pen down
    3-turn right
    4-turn left
    5, # - move forward, and # represents amount of spaces moved.
    6- prints the array
    9-ends data

    Here's what I have in my program so far. I dont know how to have it inout for each space so say if it's going forward 3 spaces with the pen down to input a 1 in each of the spaces and then be able to turn in any direction and continue, etc. Please let me know if you see something wrong with it so far and if you could, can you fill in the command steps 5 and 6, changing what I have now for it too work. If you have any questions on the program and what it's susposed to do please let me know. Here's my program..:


    //turtle.cpp
    //This program uses a double dimension array to draw shapes and lines base on the users input of commands

    #include <iostream.h>

    int func_name();
    int func_game();
    int commands;
    int pen;

    int main(void)

    { char yesorno;
    func_name();
    Again:
    func_game();
    cout<<"Would you like to play again? (y/n)";
    cin>>yesorno;
    cout<<endl<<endl;
    if (yesorno=='y')
    {
    cout<<endl<<endl;
    goto Again;
    }
    else
    cout<<"Thanks for using my program. Please come again sometime soon.";
    cout<<endl<<endl;


    return 0;

    }

    //**************************************************
    //This part of the program just allows the user to enter their name

    int func_name()

    {
    char f_name[20];
    cout<<"Hello, and welcome to my game!";
    cout<<endl;
    cout<<"Please input your first name. ";
    cin>>f_name;
    char l_name[30];
    cout<<"Please input your last name. ";
    cin>>l_name;
    cout<<endl;
    cout<<"Welcome "<<f_name<<" "<<l_name<<" I hope you have fun with my game!";
    cout<<endl<<endl<<endl;


    return 0;
    }

    //**************************************************
    //This is the actual game part of the program that uses the double dimension array

    int func_game()

    { int R, C, I, turtle[20][20], spaces, stop=0, num=0, direction=1;

    cout<<"Instructions: The purpose of the game will use you to input commands to make a ";
    cout<<endl;
    cout<<"picture using * and blank spaces. A list of what the commands do will be above ";
    cout<<endl;
    cout<<"the command space to enter.";
    cout<<endl<<endl;
    cout<<"The commands: ";
    cout<<endl;
    cout<<"1-pen up";
    cout<<endl;
    cout<<"2-pen down";
    cout<<endl;
    cout<<"3-Turn right";
    cout<<endl;
    cout<<"4-Turn left";
    cout<<endl;
    cout<<"5,#-Amount of spaces moved ";
    cout<<endl;
    cout<<"6-Prints game on screen";
    cout<<endl;
    cout<<"9-Ends data ";
    cout<<endl<<endl;
    Default:
    cout<<"Please input your command: ";
    cin>>commands;
    cout<<endl;

    switch (commands)
    {
    case 1: {pen=0;
    commands=0;
    goto Default;
    break;}
    case 2: {pen=1;
    commands=0;
    goto Default;
    break;}
    case 3: {if (direction==4)
    {direction==1;}
    else
    {direction=direction++;}
    commands=0;
    goto Default;
    break;}
    case 4: {if (direction==1)
    {direction==4;}
    else
    {direction=direction--;}
    commands=0;
    goto Default;
    break;}
    case 5: {
    cout<<"How many spaces would you like to move? ";
    cin>>spaces;
    turtle[R][C]=pen;
    cout<<endl<<endl;
    goto Default;
    }
    case 6: {
    for(R=0; R<20;R++)
    {
    for(C=0; C<20; C++)
    {
    cout<<turtle[R][C]<<" ";//you'll see
    }
    cout<<endl;
    }
    cout<<endl<<endl;

    goto Default;


    break;}
    case 9: {return 0;}
    default: {cout<<"You entered a wrong number please type a correct number. ";
    cout<<endl<<endl;
    goto Default;
    break;}
    }



    return 0;

    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    69

    1 thing

    You aren't meant to ask people to do your homework for you.

  3. #3
    Unregistered
    Guest
    chill man,

    at least he did most of the work

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    1. remove all those goto statements

    2. goto 1

    3. comparision and assignment
    case 3: {if (direction==4)
    {direction==1;}

    Should be
    case 3: {if (direction==4)
    {direction=1;}

    You really ought to turn on all your compiler warnings - most would tell you that direction==1; has no effect.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    he isnt asking to do the homework fro him.. just to help him with the errors

    btw wish i could help but im new heh

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    try this,

    when u use cin inside the drawing program to move the cursor or set the pen down, use cin.get this will not force the user to hit enter but will only accept one char(all that u need to be accepted) this would make the program a lot better when u decide to display the current contents and allow the user to work at the same time.

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    9

    thanks..

    First, thanks Salem for the first part of my problem because that seemed to fix that part of the case.

    My teacher gave me an extension so I'm still working on it.

    golfingguy how would I incorporate the cin.get into the input part in case 5. This is my first year in C++ and I have only been dealing with it for 1 semester in school. Again thanx fo everyone's help, and please send more suggestions, because I still have not been able to get it to work, I just dont know how to work the cin.get into my program..

    Again, thanks if you can help..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-07-2010, 11:08 PM
  2. Turtle Graphics, how does it work?
    By freddyvorhees in forum C++ Programming
    Replies: 15
    Last Post: 08-28-2009, 09:57 AM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. C++ Game of Life Program
    By rayrayj52 in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 03:58 PM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

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