[C++] Scoreboard, Timer, and Graphics

denmax

You can change this now in User CP.
Reaction score
155
@camelCase & s3rius

I'm not sure if it is required or not, but may I ask for you real names, if it's okay with you? Even if you guys only 'directly' involved yourselves with the scoreboard, your teachings of classes, vectors, fstreams, and more, have been applied to other parts of the program. With that, I wanted to credit you guys for your heavy contribution to the project. Again, if that is okay with you.

Also, it seems my scoreboard causes the console to crash. I'm not sure why, so here are the final codes

SCOREBOARD CLASS
JASS:
class Scoreboard{
 
 
public:
//Add player to vector
    void AddPlayer(std::string name, int points){
        Entry e;
e.name = name;
e.score = points;
        m_scoreboard.push_back(e);
    }
 
//Display scoreboard to console
    void Print(string x){
int size = m_scoreboard.size();
if( size > 5){
size = 5;
}
cout <<   "*-------------------------- LEVEL " << x.c_str();
for(int i=0; i < size; ++i){
cout << "\n*----[" << (i+1) << "]-----";
cout &lt;&lt; &quot;\n*--Name:\t&quot; &lt;&lt; m_scoreboard<i>.name;
cout &lt;&lt; &quot;\n*--Score:\t&quot; &lt;&lt; m_scoreboard<i>.score;
}
    }
 
//Save vector to text file
void Save(std::string x) {
string output;
output = &quot;scoreboards/level&quot;;
output.append(x);
output.append(&quot;.txt&quot;);
ofstream HighScore(output.c_str(), ios::trunc);
for(int i=0; i &lt; 6; ++i) {
HighScore &lt;&lt; m_scoreboard<i>.name &lt;&lt; &quot;\n&quot; &lt;&lt; m_scoreboard<i>.score &lt;&lt; &quot;\n&quot;; //\n acts as a delimiter for getline()
}
HighScore.close();
}
 
//Set contents of txt file to vector
void Load(std::string x) {
string line, output;
repeat = 0;
output = &quot;scoreboards/level&quot;;
output.append(x);
output.append(&quot;.txt&quot;);
Entry e;
ifstream HighScore(output.c_str());
while ( repeat &lt; 5 ) {
getline (HighScore, line);
e.name = line;
getline (HighScore, line);
e.score = atoi( line.c_str() );
m_scoreboard.push_back(e);
repeat++;
}
HighScore.close();
}
    
//bubble sort
void Sort() {
for(int x=0; x&lt;m_scoreboard.size(); x++)
{
for(int y=0; y&lt;m_scoreboard.size()-1; y++)
{
                if(m_scoreboard[y].score &lt; m_scoreboard[y+1].score)
                {
                        Entry temporary = m_scoreboard[y+1];
                        m_scoreboard[y+1] = m_scoreboard[y];
                        m_scoreboard[y] = temporary;
                }
}
}
}
 
//wipes the vector clean
void Wipe(){
        for(std::vector&lt;Entry&gt;::iterator i = m_scoreboard.begin(); i != m_scoreboard.end(); ++i){
            m_scoreboard.erase(i);
        }
}
    
//checks if a similar name is present in the vector, then print it
//feature removed due to crashes
void Global(){
for(std::vector&lt;Entry&gt;::iterator i = m_scoreboard.begin(); i != m_scoreboard.end(); ++i){
if( i-&gt;name == playerName ){
cout &lt;&lt; &quot;\n*--Score:\t&quot; &lt;&lt; i-&gt;score;
}
}
}
 
private:
    std::vector&lt;Entry&gt; m_scoreboard;
int repeat;
};
</i></i></i></i>



EXECUTION
JASS:
switch (menuInput) {
case 1:
hs.Load(&quot;1&quot;);
hs.Sort();
hs.Print(&quot;ONE&quot;);
cin.ignore();
break;
case 2:
hs.Load(&quot;2&quot;);
hs.Sort();
hs.Print(&quot;TWO&quot;);
cin.ignore();
break;
case 3:
hs.Load(&quot;3&quot;);
hs.Sort();
hs.Print(&quot;THREE&quot;);
cin.ignore();
break;
case 4:
hs.Load(&quot;4&quot;);
hs.Sort();
hs.Print(&quot;FOUR&quot;);
cin.ignore();
break;
case 5:
hs.Load(&quot;5&quot;);
hs.Sort();
hs.Print(&quot;FIVE&quot;);
cin.ignore();
break;
case 6:
hs.Load(&quot;6&quot;);
hs.Sort();
hs.Print(&quot;SIX&quot;);
cin.ignore();
break;

PS:
hs is a global variable.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
There's no need to distinctively mention me. I'm just a random geek on the interwebs ;)

Regarding the error:
Can you pin point where it's crashing?

How to do basic debugging:
When you left-click to the left of a line of code you can put a breakpoint (http://i.msdn.microsoft.com/dynimg/IC56046.png - the red point at the left border).
When you then start the program the debugger will pause at this breakpoint. Now, everytime you press F10 (it's probably F10, even for VS2006), you execute a single line of code, until you reach the end of your program.

Put a break point at the start of your main() function, run it and step through it via F10. See which line of code is executed when the crash appears.
The current line that is executed should be indicated by a small yellow arrow. That's at least how it looks in newer versions.
 

denmax

You can change this now in User CP.
Reaction score
155
I've found out the issue minutes after I found out that it crashes, and forgot to edit.

I figured that Wipe() caused the issues. If it erased the nth entry, then the entries after that would have moved down to the lower value.

I initially fixed by just setting the points to negative and the name to something no one will ever ever ever use. I'm thinking of just using vector(m_scoreboard.being()).erase on every loop would fix it too, but I'm too late since I already submitted the project.

JASS:
void Wipe(){
    for(std::vector&lt;Entry&gt;::iterator i = m_scoreboard.begin(); i != m_scoreboard.end(); ++i){
        m_scoreboard.erase(m_scoreboard.begin());
    }
}
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top