-2

im probalby beiing anoying like this.. but can somone help me ..
im a real beginer at this.. the point is i rly need help :D
its like this

mmm i need to make a hangman game
half of the code is done..

and it seams i cant draw the body in the code.. and cant difine it ..
ignore the parths that are not needed.. can somone tell me how to finish the code ??
the point is that i have to make a hangman game

here is the code..

//ovie linii se neophodni za da moze da se koristi STL strukturata vo C++ narecena mapa
//programot treba da se kompajlira na toj nacin sto vo VS2005 ili ponovi ke se poddesat slednive parametri
//Desen klik so gluvceto na Imeto na proektot vo SolutionExplorer (panelot koj obicno e levo ili desno)
//Vo novo otvoreniot pop-up prozor izberete Configuration Properties - > C/C++ -> CodeGeneration -> Enable c++ exceptions = NO
#pragma warning(disable:4786)
#include <map>
using namespace std ;

//Osnovni i neophodni include fajlovi za korektna rabota na programot

#include <windows.h> 
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>   


#include <glut.h> //glut file za windows operacii
                     // toj isto taka vklucuva gl.h i glu.h
#include<iostream>
#include<string>

//informacija za eksternata slika koja ke se koristi kako pozadina (nebo so zvezdi i zemjata)
//pritoa vo ednata struktura se izdvojuvaat informaciite od hederot za slikata a vo drugata struktura samite bitovi
//slikata e BMP 24 bitna
BITMAPINFO *bginfo; // Bitmap information
GLubyte *bgpixels; // Actual pixel data



#pragma region Operacii so sliki

extern GLubyte * ReadBitmap(const char *filename,BITMAPINFO **info);  
extern int SaveBitmap(const char *filename, BITMAPINFO *info,GLubyte    *bits); 
extern GLubyte * ReadBitmapFromScreen(BITMAPINFO **info);

/* read bitmap information. Returns the final bitmap pixel values */
GLubyte *                         
ReadBitmap(const char *filename, 
             BITMAPINFO **info)    
{
  FILE             *fp;          /* Open file pointer */
  GLubyte          *pixels;        /* Bitmap pixel bits */
  int              imgsize;      /* Size of bitmap image*/
  int              infosize;     /* Size of header information */
  BITMAPFILEHEADER header;       /* File header */


  // Try opening the file; use "rb" mode to read a binary file. 
  if ((fp = fopen(filename, "rb")) == NULL)
    return (NULL);

  // Read the file header
  if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1)
  {
  // Couldn't read the file header 
      fclose(fp);
    return (NULL);
  }

  if (header.bfType != 'MB')    /* 'MB' set to 'B' Check for BM reversed... */
  {
  // Not a bitmap file
    fclose(fp);
    return (NULL);
  }

  infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
  if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
  {
    fclose(fp);
    return (NULL);
  }

  if (fread(*info, 1, infosize, fp) < infosize)
  {
    free(*info);
    fclose(fp);
    return (NULL);
  }

  /* Now that we have all the header info read in, allocate memory for *
   * the bitmap and read it in...  
   */
  imgsize = (*info)->bmiHeader.biSizeImage;
  // sometimes imagesize is not set in files
  if (imgsize == 0)
     imgsize = ((*info)->bmiHeader.biWidth *
                (*info)->bmiHeader.biBitCount + 7) / 8 *
                 abs((*info)->bmiHeader.biHeight);

  if ((pixels = (unsigned char *)malloc(imgsize)) == NULL)
  {
    free(*info);
    fclose(fp);
    return (NULL);
  }

  if (fread(pixels, 1, imgsize, fp) < imgsize)
  {
    free(*info);
    free(pixels);
    fclose(fp);
    return (NULL);
   }

   fclose(fp);
   return (pixels);
}


/*
 * 'SaveBitmap()' - Save a BMP file to disk.
 *
 * Returns 0 on success or -1 on failure...
 */

int                                
SaveBitmap(const char *filename,  /* File to save to */
            BITMAPINFO *info,     /* Bitmap information */
              GLubyte    *bits)     /*Bitmap data */
    {
    FILE             *fp;          
    int              size, infosize, bitsize;  
    BITMAPFILEHEADER header;   


    /* Try opening the file; use "wb" mode to write this *binary* file. */
    if ((fp = fopen(filename, "wb")) == NULL)
        return (-1);

    /* Figure out the bitmap size */
    if (info->bmiHeader.biSizeImage == 0)
        bitsize =(int) ((info->bmiHeader.biWidth *
               info->bmiHeader.biBitCount + 7) / 8 * fabs((double)info->bmiHeader.biHeight));
    else
        bitsize = info->bmiHeader.biSizeImage;

    /* Figure out the header size */
    infosize = sizeof(BITMAPINFOHEADER);
    switch (info->bmiHeader.biCompression)
      {

      case BI_RGB :
      if (info->bmiHeader.biBitCount > 8 &&
            info->bmiHeader.biClrUsed == 0)
          break;

      }

    size = sizeof(BITMAPFILEHEADER) + infosize + bitsize;

    /* Write the file header, bitmap information, and bitmap pixel data... */
    header.bfType      = 'MB'; /*'MB' set to 'B' */
    header.bfSize      = size;
    header.bfReserved1 = 0;
    header.bfReserved2 = 0;
    header.bfOffBits   = sizeof(BITMAPFILEHEADER) + infosize;

    if (fwrite(&header, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER))
        {
        /* Couldn't write the file header - return... */
        fclose(fp);
        return (-1);
        }

    if (fwrite(info, 1, infosize, fp) < infosize)
        {
        /* Couldn't write the bitmap header - return... */
        fclose(fp);
        return (-1);
        }

    if (fwrite(bits, 1, bitsize, fp) < bitsize)
        {
        /* Couldn't write the bitmap - return... */
        fclose(fp);
        return (-1);
        }

    fclose(fp);
    return (0);
    }

GLubyte * 
ReadBitmapFromScreen(BITMAPINFO **info)
{
  long i,j,bitsize, width;
  GLint viewport[4];
  GLubyte *bits;
  GLubyte *rgb, tmp;

  // get the extents of the viewport of the window
  glGetIntegerv(GL_VIEWPORT, viewport);

  if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER))) == NULL)
    return NULL;
  width = viewport[2]*3;
  width = (width+3)& ~3;
  bitsize = width*viewport[3];

  if ((bits = (unsigned char *)calloc(bitsize,1)) ==NULL)
    return NULL;

  glPixelStorei(GL_PACK_ALIGNMENT,4);
  glPixelStorei(GL_PACK_ROW_LENGTH,0);
  glPixelStorei(GL_PACK_SKIP_ROWS,0);
  glPixelStorei(GL_PACK_SKIP_PIXELS,0);

  glReadPixels(0,0,viewport[2], viewport[3], GL_BGR_EXT, GL_UNSIGNED_BYTE,bits);

  (*info)->bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
  (*info)->bmiHeader.biWidth    = viewport[2];
  (*info)->bmiHeader.biHeight   = viewport[3];
  (*info)->bmiHeader.biPlanes   = 1;
  (*info)->bmiHeader.biBitCount = 24;
  (*info)->bmiHeader.biCompression = 0L; // BI_RGB;
  (*info)->bmiHeader.biSizeImage = bitsize;
  (*info)->bmiHeader.biXPelsPerMeter = 2952;
  (*info)->bmiHeader.biYPelsPerMeter = 2952;
  (*info)->bmiHeader.biClrUsed = 0;
  (*info)->bmiHeader.biClrImportant = 0;

  return(bits);

}

#pragma endregion Operacii so sliki

void PrintText(float x, float y, string text) {
    glRasterPos2f(x, y);
    for each(char c in text) {
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c);
    }

    //Mozni frednosti za fontot i negovata golemina se slednive
    //GLUT_BITMAP_8_BY_13
    //GLUT_BITMAP_9_BY_15
    //GLUT_BITMAP_TIMES_ROMAN_10
    //GLUT_BITMAP_TIMES_ROMAN_24
    //GLUT_BITMAP_HELVETICA_10
    //GLUT_BITMAP_HELVETICA_12
    //GLUT_BITMAP_HELVETICA_18

    //DRUGI VREDNOSTI NE SE PRE-DEFINIRANI

}





// routine to draw a circle approximated by line segments
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){
    #define PI 3.1415926535898  // recall that cos and sin functions require angles in radians
                                // 2PI radians = 360 degrees, a full circle
    GLint circle_points = 100; 
    GLint i;
    GLdouble angle;
    glBegin(GL_POLYGON); 
    for (i = 0; i < circle_points; i++) {    
        angle = 2*PI*i/circle_points; 
        glVertex2f(centerx+radius*cos(angle), centery+radius*sin(angle)); 
    } 
    glEnd();
}



//funkcija koja se povikuva na promena na dimenziite na prozorecot
void reshape (int w, int h)
{
   // on reshape and on startup, keep the viewport to be the entire size of the window
   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity ();
   // keep our logical coordinate system constant
   gluOrtho2D(0.0, w, 0.0, h);
}



#pragma region Klasa HangMan i nejzini metodi
class HangMan
{
public:
    HangMan(string word);
    virtual ~HangMan();
    void Draw();
    void DrawHead(); //Draw the head
    void DrawLeftEye(); //Draw the Left Eye
    void DrawRightEye(); //Draw the Right Eye
    void DrawBody(); //Draw the body
    void DrawLeftArm(); //Draw the Left Arm
    void DrawRightArm(); //Draw the Right Arm
    void DrawLeftLeg(); //Draw the Left Leg
    void DrawRightLeg(); //Draw the Right Leg
    void SetWord(string w); //Set the word to be guessed
    void ContainLetter(char a); //returns true if the meteor is out of screen
    GLint MissedLetters; // unique ID to identify the meteor
private:
    string wordtobeguessed; //broj na pixeli za koi se pomestuva meteorot vertikalno nadolu vo sekoj cekor, moze da se smeta kako nekoj vid na brzina na dvizenje, sto e pogolema tolku meteorot pobrzo ke stigne do dnoto na prozorecot t.e. zemjata
    GLfloat location[2]; // meteor's location. location[0]=x, location[1]= y-coordinate
};

HangMan::HangMan(string word){
    wordtobeguessed = word;
    MissedLetters = 0;
};
void HangMan::ContainLetter(char a){
    string::size_type loc1 = wordtobeguessed.find( a, 0 );
    if(loc1 != string::npos){

        //ovaa proverka treba da se prosiri so cel da se proveruva dali vo stringot bukvata se sodrzi na poveke od edna pozicija
        //ako ja ima bukvata treba da se ispise na ekranot na tocno predefinirana lokacija pod besilkata zaedno so prethodno pogodenite bukvi
    }else{

        //ako ja nema bukvata da se stavi vo lista na nepogodeni bukvi i site bukvi od taa lista da se ispisat vo gorniot del od ekranot za da mu sluzat kako pomos na igracot.
        MissedLetters++;
    }
};
void HangMan::SetWord(string w){
    wordtobeguessed = w;
};
void HangMan::Draw(){
    switch ( MissedLetters )
        {
             case 1:
                DrawHead();
                break;
             case 2:
                DrawHead();
                DrawLeftEye();
                break;
            case 3:
                DrawHead();
                DrawLeftEye();
                DrawRightEye();
                break;
            case 4:
                DrawBody();
                break;
            case 5:
                DrawBody();
                DrawRightArm();
                break;
            case 6:
                Drawbody();
                drawRightArm();
                drawLeftArm();
                break;
            case 7:
                Drawbody();
                drawRightArm();
                drawLeftArm();
                drawRightleg();
                break;
            case 8 :
            Drawbody();
                drawRightArm();
                drawLeftarm();
                drawRightleg();
                drawLeftleg();
                break;


            //vo slucaj da ne se pogodeni 4, 5, 6, i tn bukvi od zborot togas se iscrtuvaat ostanatite delovi
                //treba da se vnimava da se iscrtuvaat i site prethodno nacrtani vo sprotivno istite nema da bidat prikazani
            default:
                //ako se nacrtani site delovi od teloto igrata treba da zavrsi
                //se iscrtuvaat site delovi od teloto
                //se ispisuva celiot zbor t.e. se dava resenieto
                //igrata zavrsuva
                PrintText(100, 120, wordtobeguessed);
                break;
        }
}
void HangMan::DrawHead(){
    glColor3f(1.0f,0.0f,0.0f); //odberi boja za glava
    MyCircle2f(300, 300, 30); //Nacrtaj glava
};
void HangMan::DrawLeftEye(){
    glColor3f(0.0f,0.0f,1.0f); //odberi boja za levo oko
    MyCircle2f(290, 300, 5); //Nacrtaj levo oko
};
void HangMan::DrawRightEye(){
    glColor3f(0.0f,0.0f,1.0f); //odberi boja za desno oko
    MyCircle2f(310, 300, 5); //Nacrtaj desno oko
};
void HangMan::DrawLeftArm(){
    glClearColor(1.0,1.0,0.0); 
    glBegin(GL_POLYGON); //vrata
    glColor3f(0.7,0.3,0.0);
    glVertex2f(30.0,10.);
    glVertex2f(30.0,25.);
    glVertex2f(40.0,25.);
    glVertex2f(40.0,10.);
    glEnd();

    //odberi boja za leva raka
    //Nacrtaj leva raka
void HangMan::DrawRightArm(){
    glClearColor(1.0,1.0,0.0);
    glBegin(GL_POLYGON); //vrata
    glColor3f(0.7,0.3,0.0);
    glVertex2f(30.0,10.);
    glVertex2f(30.0,25.);
    glVertex2f(40.0,25.);
    glVertex2f(40.0,10.);
    glEnd();//odberi boja za desna raka
    //Nacrtaj desna raka
void HangMan::DrawBody(){
    glClearColor(1.0,1.0,0.0); //odberi boja za teloto
    //nacrtaj go teloto
    glBegin(GL_POLYGON); //vrata
    glColor3f(0.7,0.3,0.0);
    glVertex2f(30.0,10.);
    glVertex2f(30.0,25.);
    glVertex2f(40.0,25.);
    glVertex2f(40.0,10.);
    glEnd();

void HangMan::DrawLeftLeg(){
    glClearColor(1.0,0.0,0.0);
    glBegin(GL_POLYGON); //vrata
    glColor3f(0.7,0.3,0.0);
    glVertex2f(30.0,10.);
    glVertex2f(30.0,25.);
    glVertex2f(40.0,25.);
    glVertex2f(40.0,10.);
    glEnd();//odberi boja za leva noga
    //Nacrtaj leva noga
void HangMan::DrawRightLeg(){
    glClearColor(1.0,0.0,0.0);
    glBegin(GL_POLYGON); //vrata
    glColor3f(0.7,0.3,0.0);
    glVertex2f(30.0,10.);
    glVertex2f(30.0,25.);
    glVertex2f(40.0,25.);
    glVertex2f(40.0,10.);
    glEnd();//odberi boja za desna noga
    //Nacrtaj desna noga


HangMan::~HangMan() {
    wordtobeguessed = "";
    MissedLetters = 0;
}

#pragma endregion Klasa HangMan i nejzini metodi

HangMan *hm = new HangMan("");


void Display(void)
{
  //clear all pixels with the specified clear color
  glClear(GL_COLOR_BUFFER_BIT);

  //iscrtaj ja slikata za pozadina na istata lokacija vo istiot razmer 
 // if (bgpixels){
    //glRasterPos2f(0,0);
    //glPixelZoom(1,1);
    //glDrawPixels(bginfo-> bmiHeader.biWidth, bginfo-> bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, bgpixels);
 // }

    hm->Draw();
    glFlush();
    glutSwapBuffers();
}

void keyPressed (unsigned char key, int x, int y) {
    hm->ContainLetter(key);
    glutPostRedisplay();
} 

void init(void){
    //set the clear color to be white
    glClearColor(1.0,1.0,1.0,1.0);
    glLineWidth(5.0);
    // polygons drawn should be filled
    glPolygonMode(GL_FRONT, GL_FILL);
    glutKeyboardFunc(keyPressed); // Tell GLUT to use the method "keyPressed" for key presses  

}


int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  glutInitWindowSize (600, 600);  
  glutCreateWindow("Boris Stojanov 10111");

  //vcitaj ja slikata za pozadina od eksteren fajl 
  //ovaa slika moze da ja sodrzi i samata besilka
  bgpixels = ReadBitmap("HangManBackgruond.bmp", &bginfo);

  //postavete go zborot sto treba da se pogoduva bidejki prethodno objektot bese kreiran so prazen zbor
  hm->SetWord("Seska");

  init();
  glutDisplayFunc(Display);
  glutReshapeFunc(reshape);
  glutMainLoop();
}

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by NP-complete
1

How many times do you want DANIWEB to remind you of CODE TAGS?? They are so sick and tired that they have also watermarked "please wrap code in code tags..." in every "post reply" message box. Still you guys can't see. Its a shame.

I also found that you have used comments in a foreign language!!!

Now, how about me giving you some help in Bengali, my mother tongue?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.