my C++ pirate game [judge]

Pages: 12
closed account (3bfGNwbp)
idk what he mean't. he was just mad he had to work with it or something lol. he'll get over it eventually.

i told him the code was fine and he didnt believe me. im going to show him this thread tomorrow and prove him wrong!

now, what could i improve to make this game worth 50 cents to sell on hackforums?
There isn't much to your game to be honest. Just think about all of the free games that exist out there. There is always room for improvement, but before you concern yourself with making money, are you completely satisfied that your game is as good as it can get? Is there more things that you want to add to it? Just because you don't know how to do things, doesn't mean it can't be done.

Also, I feel there is many improvements just in the coding aspects of your game yet. Your friend isn't wrong by any means, and I don't particularly agree with anyone who says your code is fine. There is a saying floating around on another forum and it says:
ollydbg from Code Blocks wrote:
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

And I believe this particularly pertains to you. If you don't know how to turn them into variables, functions, classes, I suggest you learn them. You'll be glad you did.
Last edited on
i told him the code was fine and he didnt believe me. im going to show him this thread tomorrow and prove him wrong!


I'm sorry to break it to you, but your friend is right. In c++, there are a few particularly unacceptable practices. The first one is use of goto, in an unnecessary situation. The situation people seam to think goto is acceptable, is to break out of a nested loop. For example:
1
2
3
4
5
6
7
8
while (something){
    while (somethingelse){
        if (anotherthing){
            goto endloop;
        }
    }
}
endloop:

When I first started, I used goto's all over the place. It's convenient at first, but the longer and more complex your code gets, the more of a nightmare it becomes. People will say it makes for spaghetti code, where you have to sift through it like a mess of tangled wires.

The second thing in c++ which is loathed in most circumstances, is global variables.

The third thing people hate is system calls. For example, system("pause");.

These three features you should avoid as much as possible.
Last edited on
closed account (3bfGNwbp)
how do i avoid them if they are the easiest ways? y do they even have it in the language if if sucks?
I told you earlier, backwards compatibility. goto/labels are still needed, however, I can't think of a time when it's the only/best way to do something. But a lot of deprecated syntax in C++ is the same way, I can't think of reasons when they could possibly be used better than the newer version, but there are.

Avoid them by using functions, control structures, and local variables.
how do i avoid them if they are the easiest ways?


Here is a quote from learncp:

In general, use of goto is shunned in C++ (and most other high level languages as well). Edsger W. Dijkstra, a noted computer scientist, laid out the case in a famous but difficult to read paper called Go To Statement Considered Harmful. Almost any program written using a goto statement can be more clearly written using loops. The primary problem with goto is that it allows a programmer to cause the point of execution to jump around the code arbitrarily. This creates what is not-so-affectionately known as spaghetti code. Spaghetti code has a path of execution that resembles a bowl of spaghetti (all tangled and twisted), making it extremely difficult to follow the logic of such code.

As Dijkstra says somewhat humorously, “the quality of programmers is a decreasing function of the density of go to statements in the programs they produce”.

Rule: Avoid use of goto unless necessary


http://www.learncpp.com/cpp-tutorial/54-goto-statements/

y do they even have it in the language if if sucks?


Because it is useful for at least one common purpose. And, there might be other more specific places where it is more useful. And most important, they can't take it out, otherwise it would break existing code base.

In personally think that some things get overly shunned. They get a stigma to them. People don't want to use goto's at all, because other people who see a goto in your code will see it as a sign of a bad programmer. Still, there are uses where it makes a lot of sense to use goto's over anything else; I think.
Last edited on
Edsger W. Dijkstra, a noted computer scientist, laid out the case in a famous but difficult to read paper called Go To Statement Considered Harmful.

He should have written his book with goto/labels in it, they said difficult to read... That would ultimately prove his point =D
Pretty much everything to be said about your code has already been said. I would watch out for your friend though, he sounds like the type that might lead you in bad directions because of what he "thinks" is right. Make sure you dont believe EVERYTHING he says.
closed account (3bfGNwbp)
im not lol, just glad i can prove him wrong about my program. and thanks guys, you have really helped

and here is the other game we are working on, or i am working on, because he refuses to work with me if i keep using this stuff.
http://pastebin.com/ZjDnyqW3

i plan on selling these to as a pack for 0.25 and should make a nice profit(like $60) from hackforums if he hits global. and then i could sell the source for like a dollar or something.
Last edited on
He should have written his book with goto/labels in it, they said difficult to read... That would ultimately prove his point =D


lol

I refuse to read anymore of your code. You have completely missed the point of all of our posts. Only one person specifically said there is nothing wrong with goto/labels, but that was obviously the only one that you read. He was right about your program, there is a lot of issues with it, as myself, and others, have clearly pointed out, and given reasons why as well. We can't force you to change your ways, but you have over 1200 lines for a game that doesn't look to be very long. If you're working on it together, tell him to teach you about objects, functions, and how to keep your code neat.

Once I saw the enormous amounts of variables declared at the beginning, I realized there was no point in even trying to read the code and scrolled to the bottom. You have a lot to learn young one.
closed account (3bfGNwbp)
no, he's not working with me until i learn to fix my code, but its hard to learn to fix this when uve been using it like this for a year+. he wont help me because he's mad i kept saying he was wrong. thats why I need u guys to help me here and tell me exactly what needs to be fixed. like, what is label? im just trying to fix my c++ knowledge, not make you guys mad

what was i supposed to do with them? that's how u do it if you want to use that many.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main() {
   int i = 1;
StartLoop: // Label
   std::cout << "Hello World!\n";
   if (i < 10) {
      i ++;
      goto StartLoop; // Goto
   }

   return 0;
}

gotoStartLoop; and StartLoop: are considered a goto/label, respectively. If you don't know the name of them, why are you using them? You say you've been programming for over a year? You don't know functions? Or loops?

The same code above with a proper loop:
1
2
3
4
5
6
7
#include <iostream>

int main() {
   for (int i = 0; i < 10; i ++)
      std::cout << "Hello World!\n";
   return 0;
}


Much shorter, and in my opinion, much easier to read.
closed account (3bfGNwbp)
i know what a for loop is dude, i just dont care to use it because it looks bad in a program

and i havent learned becuz i have to finish high school this year and ive been focused on getting to a good college to learn about programming
Last edited on
A little bit of time spent just researching, reading and doing exercises will go a long way.

For now I would recommend going through a tutorial on functions.

Last edited on
like, what is label?
You're using them all over your code but you don't know what a label is?
Word of advice, invest in an intro to programming book.
I showed you the for loop because it actually makes code look a lot nicer than an alternative. I can't even begin to imagine what this code would look like without loops, but with labels instead:
1
2
3
4
5
6
7
8
9
10
11
12
      do {
         std::cout << "\nPlease enter a name to search for: ";
         getline(std::cin, strSearch);
         // Search mMembersList
         for (auto member : mMembersList)
            // If a member matched the search
            if (boost::algorithm::icontains(member.first, strSearch))
               // Make sure member doesn't exist in mPersonalResults
               if (mPersonalResults.find(member.first) == mPersonalResults.end())
                  // Add unused members to vFoundNames
                  vFoundNames.push_back(member.first);
      } while (!vFoundNames.size());


From what I understand about your knowledge on C++, you won't be able to do that. That was just pulled out of a small program I'm helping someone with and learning myself. I'm trying to help you understand why what you're doing is bad/wrong, as everyone else that posted here. There is nothing wrong with focusing on high school, knowledge is power my man, but I don't see that writing two completely different games with over 1K lines of code was worth not learning more essentials.

My point being, grab a book, google a good tutorial, or learn from someone that has experience. Try to lose all of the bad habits, starting with your attitude, and try to relearn the language. This stuff isn't easy, by any means, but it doesn't mean you need to get cocky or arrogant about it, but take every suggestion with a grain of salt. I've been bashed from doing things in my programs that are bad practice, and I've since moved away from doing so. I wasn't willing to give up what I knew and liked and felt comfortable with, but after thinking about it, weighing out the pros and cons, I decided to start trying it out, and I've since changed a lot of bad habits in my code.

I hope you stick with C++, but please, lighten up man.
Last edited on
i know what a for loop is dude, i just dont care to use it because it looks bad in a program


If you don't want to use a for loop because you think it looks bad, you might want to abandon c++ altogether.

But seriously though; Of course you friends code looks bad to you because it's written in a form you can't understand. It might as well be written in ancient Mayan Hieroglyph.

Once you've gained an understanding of loops, functions and objects, I think you'll see things differently.

Last edited on
TheBestHacker
I'm not sure if you're a troll or a ret... errrr... very inexperienced programmer.
I tend to think the former, in which case I should ignore you, but oh well...

Your code is horrible. Really. I mean it.
You think people are stupid enough to pay you? I think you should pay me as I had to look at this mess.
Nobody cares what you think looks good. Get a few years of experience, write some awesome software, and then, maybe, somebody will care what you think a good code looks like.
Topic archived. No new replies allowed.
Pages: 12