• Forum
  • Lounge
  • Coolest thing you have ever done in code

 
Coolest thing you have ever done in code

Pages: 1234
What is the coolest thing you have ever done in code? Don't write you answer in code if that is what you are interpreting this as.
closed account (Dy7SLyTq)
no matter what i do this will always be the coolest thing ive ever done:
1
2
3
4
5
6
7
#include <stdio.h>

int main(int argc, char **argv[])
{
	printf("Hello, world!\n");
	return 0;
}


of course, ncurses is cool too
My coolest thing is too big too post. Sorry. I made a text adventure called Orcs with custom battle plans, deaths and a ton of other stuff.
Last edited on
How does one 'kill a sneak attack'?
What line of code is that?
The project I'm working on now. The math is a bit complex for my grade, but dispite the headaches I've went through, it was worth it.
What is your project Lumpkin? You have piqued my interest.

@L B
That means the soldiers from your sneak attack.
What's the project, Lumpkin?
@t o a d 1 3 5 9
The wording is funny, "the other orcs hear your sneak attack coming and kill your sneak attack" - it just makes me laugh.
Just a small 3D RPG, nothing special. It's only complicated for me, I'm in the 8th grade and I don't know what a matrix is...
DLL injection to set environment variables in foreign processes. It was originally just an exe that I could call from the command-line (mpath.exe), because I messed with the %PATH% variable so much. It made life beautiful and simple.

I was modifying it to be usable as a DLL as well... when my HDs died.


I also had a beautiful program that manipulated the Windows desktop wallpaper for you. It was so nice!

I lost it when my HDs died.


Until I can afford 500 beans worth of get-my-data-back, I am back without them.

Alas.



Oh, I'm mostly proud of a lot of little things that no one cares about.
The board game Scrabble as user vs. computer.

This was one of my earliest big (for me) projects. Developing the code for the computers plays was, of course, the major challenge.

Getting it to make the most basic play of an entire word across one existing letter was fairly easy, but extending the plays to include playing across more than one letter, adding a suffix or prefix to, or making a compound word of an existing word became quite a challenge. The computers strategy is simple. It finds every play it can make then plays the highest scoring one.

It works well enough that I have a hard time beating it, with the program relying on a list of only about 6,000 words kept in a text file.
Oh, I'm mostly proud of a lot of little things that no one cares about.


I'm afraid to say good sir that is the story for most of us! I have my own button "widget" that I've been working on. (I actually have a reason for doing this I'm not reinventing the wheel because I feel like it). I got it so that buttons can actually have shiny effects when the mouse hovers over them and I was so excited, I had to share it with my buddies in class. Of course since I'm really the only programmer there (there's another guy who's supposed to be learning Java but he screws off mostly) nobody really understood why I was so happy, and just said "Big deal". I went from happy to "Don't look down on me you pathetic end user!".
Replaced explorer.exe on windows 2000 with explorer.exe + a feature such that everytime you did anything at all it would play this video (although the original, bout the same quality though.

www.youtube.com/watch?v=G5KxZ5Lc_YA‎



It's his fault for still running windows 2000 in 2010. It was my BFF's older brother :P


also it locked the input until the video was over.
Last edited on
Like, no joke, the things (there are two) that I got the most excited about when programming was when I first got my "Hello World" application to work, and secondly, the first time I was able to successfully draw a multicolored triangle on the screen with OpenGL.
That reminds me. I was pleased with my OpenGL solar system at Rutgers. You could zoom right in to any planet, and the earth was the coolest. I had it rotating gently, with day and night (simulated by two spheres slightly overlapping, textured with daytime and nighttime NASA images), all under another sphere with cloud cover (more NASA stuff) that drifted over the planet.

I could watch it for hours.


Sad, but true.



Another thing lost to my HD crash, waiting for me to have the money to send off to get it back.

I suppose I could rewrite all this stuff.

But then I suppose I have all the time in the world to play...

@toad1359

Sorry to be off topic by posting a big critique of your code (if you post code, be prepared for comment), but my motivation is to help you out dude! If you want, start a new topic, discussion can continue there, rather than here.

EDIT: I hate it when huge cout's make a topic 4 screens wide !! You can build up output in parts you know, no need to have a massive long cout.

With this:
281
282
283
284
285
286
287
288
289
290
if (scbp == "sneak=E FOA=N") {
if (sneak_num == 1 or 2 or 3 or 4 or 5) {
cout << "Your sneak attack succeeds at getting into the village from the east side. They have the objective of raising the gate. Your other troops attack from the north side after the sneak attack and allow the sneak attack to enter unnoticed. The sneak attack raises the gate and you get in. You immediatly go after the leader and kill him. By killing the leader you became the new leader and all the other troops surrender.";
fmlead();}
return; }

     if (scbp == "sneak=E FOA=N") {
if (sneak_num != 1 or 2 or 3 or 4 or 5) {
cout << "Your sneak attack gets shot at and dies. Your other troops attack from the north side after the sneak attack. Your soldiers can't break down the gate and die. You also die. Please try again.";
return; }}


The oroperators are OK, but the way you use them is invalid. For example line 282 will always be true, because 2,3,4,5 all evaluate to true. Instead of having an else to do something when it's false, you have another if statement that does the inverse of the first one. So better IMO to do this:

1
2
3
4
5
6
7
8
9
10
if (scbp == "sneak=E FOA=N") {
    if(sneak_num >= 1 or sneak_num <= 5) {
        cout << "Your sneak attack succeeds at getting into the village from the east side.";
        return;
    }
    else {
         cout << "Your sneak attack gets shot at and dies. Your other troops attack from the north ";
         return;
    }
}


There are several things that could improve your code IMO.

It seems to me that the whole cbpon function (whatever that means) is about actions carried out when sneak and FOA (whatever they are) are one of N,E,W,S (directions?). So there are 16 combinations. You could put these combinations into an enum, then use the enum value in a switch statement. This would be tidier IMO, and would save all those return; statements, and you won't need the code to build the string. Speaking of those returns, I think I mentioned elsewhere why that is unnecessary at the end of a void function.

Can you come up with better names for variables & functions? One shouldn't have to guess what they mean - we are not mind readers you know? At the very least comment them.

Instead of explicitly cout'ing all the text, consider putting it all into an array or vector of std::string, then you could just std::cout an array or vector element. This will keep the switch tidy.

1
2
//so i don't have to type std::cout
using namespace std;


You can do this:

1
2
3
4
5
6
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
// other std things here 


Then just use cout etc unqualified through your code. This is much better than bringing in the whole std namespace - which WILL cause you problems one day.

Don't use global variables - they are a really bad idea.

With this:

1
2
3
4
5
6
7
8
	if (answer == "E")
scbp = scbp + "E";
if (answer == "W")
scbp = scbp + "W";
if (answer == "S")
scbp = scbp + "S";
if (answer == "N")
scbp = scbp + "N";


could be replaced by this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
bool ValidInput = false;
char Direction = 'E'; // used this instead of answer string

while (!ValidInput) {
    cout << "On the east, west, north or south side? (E/W/N/S)";
    getline (cin, Direction);  // does answer have to be a string - why not char?
    answer = toupper(Direction); // needs char type to work

    if (Direction == 'E' or Direction == 'W' or Direction == 'S' or Direction == 'N') {
        sbcp += Direction; // just append it, string has += operator
        ValidInput = true;
    }
    else {
        std::cout << "Invalid Input - Enter E or W or N or S " << "\n";
    }
}


That was just to show a better way of doing that particular thing, but as I said earlier that whole function isn't necessary.

I eventually found the main function on line 476!! I prefer to put functions declarations first, then main, then function definitions at the end. That way it is easy to see what main does without having to search for it, or scroll down 600 LOC to see it. Also try to declare & define functions in the order they are called if possible - your first function is orc, so that should be at the top of the list in the definitions. Otherwise, when looking at your code, I find myself scrolling up & down madly to see how things work.

The placement of braces is confusing. Put the closing brace directly under (in the same column) as the statement that caused the opening brace. In the orc_sanctum function, the closing brace on line 579 belongs to the if on line 567 - can you see how that is confusing? Also, proper indentation aids in understanding as well. I always use braces - even when there is only 1 statement - it will save you one day when you add more code. When using an IDE, you should be able to get it to format things automatically, and on demand.

Hope all these suggestion might help you write better code.
Last edited on
How do you set starting line number in code tags? O:
Pages: 1234