Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Bisheshwor

Pages: [1]
1
General / Problem in File Handling
« on: August 07, 2017, 07:20:59 am »
I am having a problem in my game which includes file handling for some quiz and entertainment. I am having this problem for more than a week and I seriously need to submit my program to the University this week.
 
/void quesengg()
{
    ifstream file1("database/engineering.txt");
    ifstream file11("database/enggans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line[i]]);
        }
    }
    line_n+=2;
    getline(file11,line22[0]);

}

void quessport()
{
   ifstream file1("database/sports.txt");
    ifstream file11("database/sportsans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line2]);
        }
    }
    line_n22+=3;
    getline(file11,line11[0]);
}

void quesmedical()
{

   ifstream file1("database/medical.txt");
    ifstream file11("database/medicalans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line]);
        }
    }
    line_n+=2;
    getline(file11,line11[0]);

}

void quesgk()
{
    ifstream file1("database/gk.txt");
    ifstream file11("database/gkans.txt");
    for (int i=0;getline(file1,line1[i]);i++)
    {
        if (i==line_n)
        {
            getline(file1,line1[curr_line]);
        }
    }
    line_n+=2;
    getline(file11,line11[0]);
}

void ques(){

switch(Wwindow().QueBck)
{
case 1:
    quesengg();
    break;
case 2:
    quessport();
    break;
case 3:
    quesmedical();
    break;
default:
    quesgk();
}

}
void show(){
    void ques();
RenderWindow window(VideoMode (500,500),"!! Quiz !!");
   while(window.isOpen())
{

    Event event1,event;

    while (window.pollEvent(event1))
    {
        if (event1.type == Event::Closed)
                window.close();
    }
    if (Keyboard::isKeyPressed(Keyboard::Return))
        {
            if(texta.getString()== line11[0])
           {
                window.clear();
                texta.setString("");
                window.close();
           }
        }
    if (event1.type == Event::TextEntered && done == false)
    {
    if (event1.text.unicode < 128 && event1.text.unicode !=0)
        {
        str1 = static_cast<char>(event1.text.unicode);
        texta.setString(str1);
        }
    }
            textq1.setString(line1[curr_line]);
            textq2.setString(line1[curr_line+1]);
            textq3.setString(line1[curr_line+2]);

           // textq2.setString(line1[i+1]);
           // textq3.setString(line1[i+2]);
            window.draw(rect1);
            window.draw(rect2);
            window.draw(textq1);
            window.draw(texta);
            window.draw(textq2);
            window.draw(textq3);
            window.display();


}
curr_line+=3;
}
 
When I run this code , though I am calling the sports or medical or gk question , it only calls the engineering questions every time. What might be the problem?
Hoping to get positive response.

2
Window / Can't update and clear the window
« on: July 31, 2017, 05:53:26 pm »
I have got some problems regarding my project and I'm creating a quiz game where the window needs to be refreshed every time a new question appears. The initial menu works fine. But after the 1st question appears, the window doesn't update and doesn't clear when using the window.clear() function. Please help me in this regard.

while(window.isOpen())
{
    Event event1,event;

    while (window.pollEvent(event1))
    {
        if (event1.type == Event::Closed)
                window.close();
    }
    if (event1.type == Event::TextEntered && done == false)
    {
    if (event1.text.unicode < 128 && event1.text.unicode !=0)
        {
        str1 = static_cast<char>(event1.text.unicode);
        text2.setString(str1);
        //done = true;
        }
    }

    //window.clear();;
    window.draw(rect1);
    window.draw(rect2);
    window.draw(text2);
    window.draw(text1);

    window.draw(text3);
    window.draw(text4);
    window.draw(text5);
    window.display();


   if (Keyboard::isKeyPressed(Keyboard::Return))
        {
            if(text2.getString()=="1")
                /*{j=1;}
        }
    if(j==1)*/

        {
            text2.setString("");
            text1.setString(line1[i]);
            text3.setString(line1[i+1]);
            text4.setString(line1[i+2]);
            window.draw(rect1);
            window.draw(rect2);
            window.draw(text1);
            window.draw(text2);
            window.draw(text3);
            window.draw(text4);
            window.draw(text5);
            window.display();
   if (event.type == Event::TextEntered && done == false)
    {
    if (event.text.unicode < 128 && event.text.unicode !=0)
        {
        str1 = static_cast<char>(event.text.unicode);
        text5.setString(str1);
        }
    }

    window.draw(rect1);
    window.draw(rect2);
    window.draw(text1);
    window.draw(text2);
    window.draw(text3);
    window.draw(text4);
    window.draw(text5);
    window.draw(rect3);
    window.display();
    window.clear();


   if (Keyboard::isKeyPressed(Keyboard::Return))
        {
            if(text5.getString()=="a")



               /* {j=2;}
        }
    if(j==2)*/

       {
            text5.setString("");
            //window.clear();;
            text1.setString(line1[i+2]);
            text3.setString(line1[i+3]);
            text4.setString(line1[i+3]);
            window.draw(rect1);
            window.draw(rect2);
            window.draw(text1);
            window.draw(text2);
            window.draw(text3);
            window.draw(text4);
            window.draw(text5);
            window.display();
   // window.close();
   if (event.type == Event::TextEntered && done == false)
    {
    if (event.text.unicode < 128 && event.text.unicode !=0)
        {
        str1 = static_cast<char>(event.text.unicode);
        text2.setString(str1);
        //done = true;
        }
    }
//done=false;



    //window.clear();;
    window.draw(rect1);
    window.draw(rect2);
    window.draw(rect3);
    window.draw(text1);
    window.draw(text2);
    window.draw(text3);
    window.draw(text4);
    window.draw(text5);
    window.display();



   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
        {
            if(text5.getString()=="1")



               /* {j=2;}
        }
    if(j==2)*/

       {
            text5.setString("");
            //window.clear();;
            text1.setString(line1[i]);
            text3.setString(line1[i+1]);
            text4.setString(line1[i+2]);
            window.draw(rect1);
            window.draw(rect2);
            window.draw(text1);
            window.draw(text2);
            window.draw(text3);
            window.draw(text4);
            window.draw(text5);
            window.display();

        }
            }
}
}
}
}
}
 

Pages: [1]