On Oct 5, 2008, at 10:20 AM, Paul David wrote:
> maybe something here will help i tried to stick to fairly relevent
> code
>
> from chase.h
> . . .
> void initgame();
> char *itoa(int n);
> void printboard();
> void thirdroundtests();
>
> //Globals:
> ifstream ifile;
> ofstream ofile;
> const unsigned int ARRAY_COLUMNS = 11, ARRAY_ROWS = 11;
> char board[ARRAY_ROWS][ARRAY_COLUMNS], character = 'o';
> string names[10], names2[10], new_highscore = "", final_name = "";
> int board2[ARRAY_ROWS][ARRAY_COLUMNS][2], pos[10], elapsedtime = 0,
> restarttime = 0, wintime = 0, wini = 0,
> highscores[10], highscores2[10], numhighscores = 0, place,
> counter_name = 0;
> bool round1comp = false, round2comp = false, gun = false, choice =
> '\0', instructions = false, gameover = false,
> restart = false, win = false, menu = true, game = false,
> show_highscores = false, accepting_input = false, highscore = false,
> prevhigh = false;
> //:Globals
>
> char* itoa (int n)
> {
> int i=0,j;
> char* s;
> char* u;
>
> s= (char*) malloc(17);
> u= (char*) malloc(17);
>
> do{
> s[i++]=(char)( n%10+48 );
> n-=n%10;
> }
> while((n/=10)>0);
> for (j=0;j<i;j++)
> u[i-1-j]=s[j];
>
> u[j]='\0';
> return u;
> }
> . . .
> end chase.h
>
> taken from display()
> . . .
> else if(show_highscores == true)
> {
> int x[10], x1[10], y[10];
> glBegin(GL_LINE_LOOP);
> glVertex2f( 200, 11);
> glVertex2f( 460, 11);
> glVertex2f( 460, 400 );
> glVertex2f( 200, 400 );
> glEnd();
> for(int i = 0, j = 41; i < 10; i++, j += 35)
> {
> y[i] = j;
> }
> for(int i = 0; i < 10; i++)
> {
> renderBitmapString( 205, y[i], 0, GLUT_BITMAP_HELVETICA_18, itoa(i
> +1));
> x[i] = bitmapStringWidth( GLUT_BITMAP_HELVETICA_18, itoa(i+1));
> renderBitmapString( (205 + x[i]), y[i], 0,
> GLUT_BITMAP_HELVETICA_18, ".) ");
> x[i] += bitmapStringWidth( GLUT_BITMAP_HELVETICA_18, ".) ");
> }
> for(int i = 0; i < numhighscores; i++)
> {
> renderBitmapString( 205 + x[i] + 10, y[i], 0,
> GLUT_BITMAP_HELVETICA_18, names[i]);
> x1[i] = bitmapStringWidth( GLUT_BITMAP_HELVETICA_18, names[i]);
> renderBitmapString( 205 + x[i] + x1[i] + 50, y[i], 0,
> GLUT_BITMAP_HELVETICA_18, itoa(highscores[i]));
> }
> if( prevhigh == true)
> {
> button5.set_text(GLUT_BITMAP_HELVETICA_18, "Menu");
> prevhigh = false;
> }
> button5.draw();
> button5.set_text(GLUT_BITMAP_HELVETICA_18, "Back");
> }
> else if(win == true)
> {
> place = numhighscores;
> game = false;
> wini++;
> if(wini == 1)
> {
> wintime = elapsedtime - restarttime;
> }
> renderBitmapString(10 + (639 -
> bitmapStringWidth(GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!") )/2, 200,
> 0, GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!");
> int x = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished
> in");
> renderBitmapString( (639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2, 230, 0,
> GLUT_BITMAP_HELVETICA_18, "You finished in");
> renderBitmapString( ((639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x +
> 10), 230, 0, GLUT_BITMAP_HELVETICA_18, itoa(wintime));
> int x1 = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime));
> renderBitmapString( ((639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x + x1
> + 20), 230, 0, GLUT_BITMAP_HELVETICA_18, "Seconds");
> button6.draw();
> button7.draw();
> button8.draw();
> for(int i = numhighscores; i >= 0; i--)
> {
> if( wintime < highscores[i])
> {
> place--;
> }
> }
> if(place != 10)
> {
> if(numhighscores < 10)
> {
> numhighscores++;
> }
> highscore = true;
> win = false;
> accepting_input = true;
> }
> }
> else if(highscore == true)
> {
> glBegin(GL_LINE_LOOP);
> glVertex2f( 200, 50);
> glVertex2f( 460, 50);
> glVertex2f( 460, 90 );
> glVertex2f( 200, 90 );
> glEnd();
> renderBitmapString(250, 31, 0, GLUT_BITMAP_HELVETICA_18,"New
> Highscore");
> renderBitmapString(210, 119, 0, GLUT_BITMAP_HELVETICA_18,"(type Your
> name and hit return)");
> renderBitmapString(145, 75, 0, GLUT_BITMAP_HELVETICA_18,"Name: ");
> renderBitmapString(210, 75, 0, GLUT_BITMAP_HELVETICA_18,
> new_highscore);
> renderBitmapString(10 + (639 -
> bitmapStringWidth(GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!") )/2, 200,
> 0, GLUT_BITMAP_TIMES_ROMAN_24, "YOU WIN!!!");
> int x = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished
> in");
> renderBitmapString( (639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2, 230, 0,
> GLUT_BITMAP_HELVETICA_18, "You finished in");
> renderBitmapString( ((639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x +
> 10), 230, 0, GLUT_BITMAP_HELVETICA_18, itoa(wintime));
> int x1 = bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime));
> renderBitmapString( ((639 -
> (bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "You finished in") +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, itoa(wintime)) +
> bitmapStringWidth(GLUT_BITMAP_HELVETICA_18, "Seconds") ) )/2 + x + x1
> + 20), 230, 0, GLUT_BITMAP_HELVETICA_18, "Seconds");
> button5.set_text(GLUT_BITMAP_HELVETICA_18,"Menu");
> button5.draw();
> button5.set_text(GLUT_BITMAP_HELVETICA_18,"Back");
> place = place;
> if(accepting_input == false)
> {
> place = place;
> highscores[place] = wintime;
> place = place;
> names[place] = final_name;
> for(int i = (place+1); i < numhighscores; i++)
> {
> highscores[i] = highscores2[i-1];
> names[i] = names2[i-1];
> }
>
> ofile.open("High Scores.txt");
> for(int i = 0; i < numhighscores; i++)
> {
> if(i > 0)
> {
> ofile << endl;
> }
> ofile << highscores[i] << endl;
> ofile << names[i];
>
> }
> ofile.close();
> ifile.open("High Scores.txt");
> string input_string = "";
> numhighscores = 0;
> for(int i = 0; !ifile.eof() && i < 10; i++, numhighscores++)
> {
> getline(ifile, input_string);
> stringstream(input_string) >> highscores[i];
> getline(ifile, names[i]);
> }
> for(int i = 0; i < numhighscores; i++)
> {
> highscores2[i] = highscores[i];
> names2[i] = names[i];
> }
> ifile.close();
> highscore = false;
> show_highscores = true;
> prevhigh = true;
> }
> }
> . . .
> end display()
>
> void keyboard(unsigned char key, int x, int y)
> {
> if(accepting_input == true )
> {
> if(key == 13 || key == 10 || key == '\n' || key == 12 || key == 3)
> {
> final_name = new_highscore;
> accepting_input = false;
> }
> else if( (key == '\b' || key == 127 || key == '\x7f') &&
> counter_name > 0)
> {
> counter_name--;
> new_highscore[counter_name] = '\0';
> }
> else
> {
> new_highscore[counter_name] = key;
> counter_name++;
> }
> }
> }
>
> int main(int argc, char** argv)
> {
> glutInit(&argc, argv);
> srand(time(NULL));
>
> initgame();
>
> ifile.open("High Scores.txt");
> string input_string;
> numhighscores = 0;
> for(int i = 0; !ifile.eof() && i < 10; i++, numhighscores++)
> {
> getline(ifile, input_string);
> stringstream(input_string) >> highscores[i];
> getline(ifile, names[i]);
> }
> for(int i = 0; i < numhighscores; i++)
> {
> highscores2[i] = highscores[i];
> names2[i] = names[i];
> }
> ifile.close();
>
> glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
> glutInitWindowSize(640, 480);
>
> glutCreateWindow("Chase Game");
>
> glMatrixMode (GL_PROJECTION);
> glLoadIdentity();
> glOrtho (0, glutGet( GLUT_WINDOW_WIDTH ),
> glutGet( GLUT_WINDOW_HEIGHT ), 0, 0, 1);
> glMatrixMode (GL_MODELVIEW);
>
> glutKeyboardFunc(keyboard);
> glutSpecialFunc(arrows);
> glutMouseFunc(MouseButton);
> glutPassiveMotionFunc(MousePassiveMotion);
>
> glutDisplayFunc(display);
> glutReshapeFunc(reshape);
> glutIdleFunc(idle);
> glutMainLoop();
> }
>
> On Oct 5, 2008, at 9:57 AM, Tyler Littlefield wrote:
> > Just post the relevant functions.
> > This might also help you clean up code--yahoogroups doesn't accept
> > attachments, or this list doesn't, anyway.
> > You can just section things off in to functions which might help,
> > but also look at what I asked before. "If you turn on all warnings,
> > do you get warnings?"
> >
>
> > When i turn on all warnings i still don't get any complaints from
> > the compiler not a single warning
> >
>
> >
>
> [Non-text portions of this message have been removed]
>
>
>
[Non-text portions of this message have been removed]