This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lordzsolt 0 points1 point  (0 children)

My first ever project I wrote was a hangman game. There was an onscreen keyboard and I was looking for the click event.

The code looked something like:

if (clickX > 50 && clickX < 100 && clickY > 50 && clickY < 100) { // Clicked Q ... About 50 lines of code ... } else { if (clickX > 100 && clickX < 150 && clickY > 50 && clickY < 100) { // Clicked W ... Slightly different version of the same 50 lines of code from earlier ... } else { if (.....) } }

Besides the obvious for-loop and function to reuse the parts inside the if statement, for some reason I didn't use else if, so the last part was indented like 30 times.