Skip to main content
GameDev.net gamedev.net
🔒 Locked

Oh my glorious code!

Started by Pufixas Jun 14, 2013 at 11:56 AM 20 replies 9.9k views
Original Post
Pufixas
Pufixas

I wrote this when I was 12-13 years old or something like that.

Edit: Now as I start to remember, I think I was more like 14 year old.

This game is probably playable if you compile it with Visual Studio on Windows machine. But I don't know because I don't use Windows machine anymore.

So Enjoy this super efficient, up-to-date, and amazingly readable code.

Also, I would like you to observe this awesome code snippet for a while, before diving straight into to full code. So that your brain could easier adapt to such heavy load of traumatizing code.


gameSpeed:
	cout << "What game speed do you want? (1-10):\n";
	int speedIn;
	int speedOut;
	cin >> speedIn;
	if(speedIn == 1) speedOut = 150;
	else if(speedIn == 2) speedOut = 140;
	else if(speedIn == 3) speedOut = 130;
	else if(speedIn == 4) speedOut = 120;
	else if(speedIn == 5) speedOut = 110;
	else if(speedIn == 6) speedOut = 100;
	else if(speedIn == 7) speedOut = 90;
	else if(speedIn == 8) speedOut = 80;
	else if(speedIn == 9) speedOut = 70;
	else if(speedIn == 10) speedOut = 60;
	else if(speedIn > 10 || speedIn < 1) goto gameSpeed; 

The full code:


?#include <iostream>
#include <Windows.h>
#include <WinUser.h>
#include <string>
#include <fstream>
using namespace std;

void drawLevel_1(char mapName[][30], char keyChar);
void drawLevel_2(char mapName[][30], char keyChar, char keyChar2);
void drawLevel_3(char mapName[][30], char keyChar);
void drawLevel_4(char mapName[][30], char keyChar);
void drawLevel_5(char mapName[][30], char keyChar);
void drawLevel_6(char mapName[][30], char keyChar);
void drawLevel_7(char mapName[][30], char keyChar, char keyChar2);
void drawLevel_8(char mapName[][30], char keyChar);
void drawLevel_9(char mapName[][30], char keyChar);
void drawLevel_10(char mapName[][30]);
void drawLevel_11(char mapName[][30], char keyChar);
void drawLevel_12(char mapName[][30], char keyChar);
void changeRoom(int room_after, int X, int Y);
void playerMovement(int * playerX, int * playerY,const char floorChar, char map[][30]);
bool pickKey(int * playerX, int * playerY, char keyChar, char map[][30]);
void ending();

// global variables
int playerY = 1;
int playerX = 1;
int room = 1;
// end global variables

int main()
{
	ifstream fin;
	fin.open("save.sav");
	char playerChar = '?';
	char map[20][30];
	bool exit = false;
	bool keyPicked[10] = {0,0,0,0,0,0,0,0,0,0};
	char key[10] = {' ','1','2','3','4','5','6','7','8','9'};

	system("title Lost in castle");
		fin >> playerY;
		fin >> playerX;
		fin >> room;
		for(int i = 0; i < 10; i++)
		{
			fin >> keyPicked[i];
		}
		if(fin.good() == false)
		{
	cout << "				HOW TO PLAY					";
	cout << "You need to escape from haunted castle, to do that you need to collect keys\nand open doors that may lead you outside the castle.\n";
	cout << "Move your character by pressing W,A,S,D keys\n";
	cout << "??????????????????????????????????????????????????????????????????????????????»\n"; 
	cout << "É????»                                                                        ?\n"; 
	cout << "?    5                                                                        ?\n";
	cout << "?           Represents a room with a door that requires a '5' key             ?\n";
	cout << "?    5                                                                        ?\n";
	cout << "?????¼                                                                        ?\n"; 
	cout << "??????????????????????????????????????????????????????????????????????????????¹\n";
	cout << "É????»                                                                        ?\n";                                                                      
	cout << "?    ?                                                                        ?\n";
	cout << "?  5 ?      Represents a room with a key that can open door '5' marked door   ?\n";  
	cout << "?    ?                                                                        ?\n";
	cout << "?????¼                                                                        ?\n"; 
	cout << "??????????????????????????????????????????????????????????????????????????????¹\n"; 
	cout << "É????»                                                                        ?\n";                                                                      
	cout << "?    ?                                                                        ?\n";
	cout << "?  " << playerChar << " ?      Represents your character in a room                               ?\n";  
	cout << "?    ?                                                                        ?\n";
	cout << "?????¼                                                                        ?\n"; 
	cout << "??????????????????????????????????????????????????????????????????????????????¼\n"; 
	cout << "PRESS \"ENTER\" TO CONTINUE\n";
	cin.get();
		}
	cout << "Select color scheme: \n";
	cout << "1. White text, black background (original)\n";
	cout << "2. Black text, white background\n";
	cout << "3. Green text, white background\n";
	cout << "4. White text, green background\n";
	cout << "5. Black text, green background\n";
	cout << "6. Green text, black background (matrix)\n";

	int choice;
	cin >> choice;
	if(choice == 1) system("color 07");
	else if(choice == 2) system("color f0");
	else if(choice == 3) system("color fa");
	else if(choice == 4) system("color af");
	else if(choice == 5) system("color a0");
	else if(choice == 6) system("color 0a");
	else system("color 07");
	cout << endl;
gameSpeed:
	cout << "What game speed do you want? (1-10):\n";
	int speedIn;
	int speedOut;
	cin >> speedIn;
	if(speedIn == 1) speedOut = 150;
	else if(speedIn == 2) speedOut = 140;
	else if(speedIn == 3) speedOut = 130;
	else if(speedIn == 4) speedOut = 120;
	else if(speedIn == 5) speedOut = 110;
	else if(speedIn == 6) speedOut = 100;
	else if(speedIn == 7) speedOut = 90;
	else if(speedIn == 8) speedOut = 80;
	else if(speedIn == 9) speedOut = 70;
	else if(speedIn == 10) speedOut = 60;
	else if(speedIn > 10 || speedIn < 1) goto gameSpeed;

	if(fin.good() == false)
	{
	cout << "\n\nONE MORE THING! If you want to quit game without saving, just press 'X' button\non the console window. If you WANT to save, click 'ESC' button on your keyboard.\nTo start a new game, just delete save.sav file.";
	cin.get();
	cin.get();
	}
while(GetAsyncKeyState(0x1B) == false)
{

	switch(room)
	{
	case 1:
		drawLevel_1(map, key[0]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 2:
		drawLevel_2(map, key[1],key[7]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 3:
		drawLevel_3(map,key[4]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 4:
		drawLevel_4(map,key[0]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 5:
		drawLevel_5(map,key[0]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 6:
		drawLevel_6(map,key[0]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 7:
		drawLevel_7(map,key[3],key[5]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 8:
		drawLevel_8(map,key[6]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 9:
		drawLevel_9(map,key[2]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 10:
		drawLevel_10(map);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 11:
		drawLevel_11(map,key[9]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	case 12:
		drawLevel_12(map,key[8]);
		playerMovement(&playerX,&playerY,' ',map);
		break;
	default:
		system("CLS");
		cout << "Error - there's no such room\n";
		system("PAUSE");
		exit = true;
		break;
	}

	map[playerY][playerX] = playerChar; // draw player

	if(keyPicked[1] == false && room == 2) keyPicked[1] = pickKey(&playerX,&playerY,key[1],map);
	else if(keyPicked[1] == true) key[1] = ' ';
	if(keyPicked[2] == false && room == 9) keyPicked[2] = pickKey(&playerX,&playerY,key[2],map);
	else if(keyPicked[2] == true) key[2] = ' ';
	if(keyPicked[3] == false && room == 7) keyPicked[3] = pickKey(&playerX,&playerY,key[3],map);
	else if(keyPicked[3] == true) key[3] = ' ';
	if(keyPicked[4] == false && room == 3) keyPicked[4] = pickKey(&playerX,&playerY,key[4],map);
	else if(keyPicked[4] == true) key[4] = ' ';
	if(keyPicked[5] == false && room == 7) keyPicked[5] = pickKey(&playerX,&playerY,key[5],map);
	else if(keyPicked[5] == true) key[5] = ' ';
	if(keyPicked[6] == false && room == 8) keyPicked[6] = pickKey(&playerX,&playerY,key[6],map);
	else if(keyPicked[6] == true) key[6] = ' ';
	if(keyPicked[7] == false && room == 2) keyPicked[7] = pickKey(&playerX,&playerY,key[7],map);
	else if(keyPicked[7] == true) key[7] = ' ';
	if(keyPicked[8] == false && room == 12) keyPicked[8] = pickKey(&playerX,&playerY,key[8],map);
	else if(keyPicked[8] == true) key[8] = ' ';
	if(keyPicked[9] == false && room == 11) keyPicked[9] = pickKey(&playerX,&playerY,key[9],map);
	else if(keyPicked[9] == true) key[9] = ' ';

	if(playerX == 18 && playerY == 10 && room == 1) changeRoom(2,1,playerY); // 1st room, right door
	if(playerY == 14 && room == 1) changeRoom(3,playerX,1); // 1st room, south door
	if(playerX == 29 && room == 1 && keyPicked[6] == true) changeRoom(2,1,playerY); // 1st room, north right door
	if(playerY == 14 && room == 2) changeRoom(4,22,1); // 2nd room, south door
	if(playerX == 0 && playerY == 2 && room == 2) changeRoom(1,28,playerY); // 2nd room, north left door
	if(playerX == 0 && playerY == 10) changeRoom(1,17,playerY); // 2nd room, south right door
	if(playerX == 29 && room == 2) changeRoom(5,1,3); // 2nd room, right door
	if(playerY == 0 && room == 3) changeRoom(1,playerX,13); // 3rd room, north door
	if(playerX == 29 && playerY == 3 && room == 3 && keyPicked[1] == true) changeRoom(4,1,3); // 3rd room, right door
	if(playerX == 29 && playerY == 12 && room == 3 && keyPicked[3] == true) changeRoom(4,1,12); //3rd room, south right door
	if(playerX == 9 && playerY == 14 && room == 3 && keyPicked[7] == true) changeRoom(9,playerX,1); // 3rd room, south door
	if(playerX == 0 && playerY == 3 && room == 4 && keyPicked[1] == true) changeRoom(3,28,3); // 4th room, left door
	if(playerX == 29 && room == 4 && keyPicked[5] == true) changeRoom(7,1,playerY-1); // 4th room, right door
	if(playerX == 0 && playerY == 12 && room == 4 && keyPicked[3] == true) changeRoom(3,28,playerY); // 4th room, south left door
	if(playerY == 0 && room == 4) changeRoom(2,22,13); // 4th room, north door
	if(playerX == 0 && room == 5) changeRoom(2,29,3); // 5th room left door
	if(playerX == 29 && room == 5 && keyPicked[9] == true) changeRoom(6,1,3);
	if(playerY == 14 && room == 5) changeRoom(7,playerX,1);  // 5th room, south door
	if(playerX == 0 && room == 6 && keyPicked[9] == true) changeRoom(5,28,3); // 6th room, left door
	if(playerX == 29 && room == 6) ending();
	if(playerY == 0 && room == 7) changeRoom(5,playerX,13); // 7th room, north door
	if(playerY == 3 && playerX == 29 && room == 7 && keyPicked[4] == true) changeRoom(8,1,playerY); // 7th room, right door
	if(playerX == 0 && room == 7 && keyPicked[5]) changeRoom(4,28,playerY+1); // 7th room left door
	if(playerX == 0 && playerY == 3 && room == 8 && keyPicked[4] == true) changeRoom(7,28,playerY); // 8th room, left door
	if(playerY == 14 && keyPicked[2] == true && room == 8) changeRoom(12,playerX,1); // 8th room, south door
	if(playerY == 0 && room == 9 && keyPicked[7] == true) changeRoom(3,playerX,13); //9th room, north door
	if(playerX == 29 && keyPicked[8] == true && room == 9) changeRoom(10,1,playerY); //9th room, right door
	if(playerX == 0 && keyPicked[8] == true && room == 10) changeRoom(9,28,playerY); // 10th room, left door
	if(playerX == 29 && room == 10) changeRoom(11,1,playerY); //10th room, right door
	if(playerX == 0 && room == 11) changeRoom(10,28,playerY); //11th room, left door
	if(playerY == 0 && keyPicked[2] == true && room == 12) changeRoom(8,playerX,13); //12th room, north door

	string key_string = "Keys: ";
	if(keyPicked[1] == true) key_string += "1 ";
	if(keyPicked[2] == true) key_string += "2 ";
	if(keyPicked[3] == true) key_string += "3 ";
	if(keyPicked[4] == true) key_string += "4 ";
	if(keyPicked[5] == true) key_string += "5 ";
	if(keyPicked[6] == true) key_string += "6 ";
	if(keyPicked[7] == true) key_string += "7 ";
	if(keyPicked[8] == true) key_string += "8 ";
	if(keyPicked[9] == true) key_string += "9 ";
	
	key_string += "                  ";
	for(int i = 0; i < 25; i++)
	{
		map[15][i] = key_string[i];
	}
	for(int mapY = 0; mapY < 16; mapY++)
	{
		for(int mapX = 0; mapX < 30; mapX++)
			cout << map[mapY][mapX];
		cout << endl;
	}
	Sleep(speedOut);
	system("cls");
}

	ofstream fout;
	fout.open("save.sav");

		fout << playerY;
		fout << " ";
		fout << playerX;
		fout << " ";
		fout << room;
		fout << " ";
		for(int i = 0; i < 10; i++)
		{
			fout << keyPicked[i];
			fout << " ";
		}
		for(int i = 0; i < 9999; i++)
		{
			fout << char(rand());
		}
		fin.close();
		fout.close();
	return 0;
}

void drawLevel_1(char mapName[][30], char keyChar)
{

	char map[20][300] =
	{
	"É????????????????????????????»",
	"?      ?                     6",
	"?      ?                      ",
	"?      ?                     6",
	"?      ?                     ?",
	"?      ?                     ?",
	"?      ?                     ?",
	"?      ??????     É??????????¼",
	"?                 ?",
	"?                 ?",
	"?                  ",
	"?                 ?",
	"?                 ?",
	"?                 ?",
	"???????????? ?????¼",
	};
	map[6][10] = keyChar; // key possition
		for(int mapY = 0; mapY < 17; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] == ' ') 
				map[mapY][mapX] = ' '; // change floor char
			    if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];
		}

}

void drawLevel_2(char mapName[][30], char keyChar, char keyChar2)
{
	char map[30][200] =
	{
	"É????????????????????????????»",
	"6       ?                    ?",
	"        ?                    ?",
	"6       ?                     ",
	"?       ?                    ?",
	"??????  ?                    ?",
	"?       ?                    ?",
	"?       ?                    ?",
	"?????????????????????        ?",
	"?          ?                 ?",
	"           ?                 ?", 
	"?          ?                 ?",
	"?          ?                 ?",
	"?          ?                 ?",
	"?????????????????????? ??????¼",
	};

	map[10][10] = keyChar; // key posiiton
	map[6][1] = keyChar2;
		for(int mapY = 0; mapY < 15; mapY++)
		for(int mapX = 0; mapX < 30; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];
		}
}

void drawLevel_3(char mapName[][30], char keyChar)
{
	char map[30][300] =
	{
	"É??????????? ????????????????»",
	"?               ?            ?",
	"?               ?            1",
	"?               ?             ",
	"?               ?            1",
	"?               ?            ?",
	"?               ?            ?",
	"?               ???? ????????¹",
	"?               ?            ?",
	"?               ?            ?",
	"?                            ?",
	"?????????????????????????????3",
	"?  ?   ?   ?   ?   ?   ?   ?  ",
	"?    ?       ?   ?   ?   ?   3",
	"????????7 7??????????????????¼",
	};

	map[12][1] = keyChar; // key position
		for(int mapY = 0; mapY < 17; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];

		}

}

void drawLevel_4(char mapName[][30], char keyChar)
{
	char map[30][300] =
	{
	"                     ? ??????»",
	"                     ?       ?",
	"1????????????????????¼       ?",
	"                             ?",
	"1??????????????????»         ?",
	"?²²²²²²²²²²²²²²²²²²?         ?",
	"?²²²²²²²²²²²²²²²²²²?         ?",
	"?²²²²²²²²²²²²²²²²²²?         ?",
	"???????????????????¼ ??????» ?",
	"?                          ? 5",
	"?                          ?  ",
	"3                          ??5",
	"                           ?²?",
	"3                          ?²?",
	"?????????????????????????????¼",
	"                              "
	};

	//map[5][7] = keyChar; // key position
		for(int mapY = 0; mapY < 16; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];

		}

}

void drawLevel_5(char mapName[][30], char keyChar)
{
	char map[30][300] =
	{
	"É????????????????????????????»",
	"?                            ?",
	"???? ????????????????????? ??9",
	"                    ?         ",
	"?                   ?        9",
	"?                   ?        ?",
	"?                   ?        ?",
	"???????????????????????? ????¹",
	"?          É?»  ?     ?      ?",
	"??????»    ? ???¼     ?      ?",
	"?     ?    ?          ?      ?",
	"? ?        ?    ?     ?      ?",
	"? ?????????¼    ?            ?",
	"?               ?     ?      ?",
	"???????????????????????? ????¼",
	};

	//map[5][7] = keyChar; // key position
		for(int mapY = 0; mapY < 16; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];

		}

}

void drawLevel_6(char mapName[][30], char keyChar)
{
	char map[30][300] =
	{
	"»#############################",
	"?@ @ @ @ @ @ @ @ @ @ @ @ @ @ ?",
	"?³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ?",
	"                           @ ?",
	"?@                         ³ ?",
	"?³                         @ ?",
	"?@                         ³ ?",
	"?³                            ",
	"?@                         @ ?",
	"?³                         ³ ?",
	"?@                         @ ?",
	"?³                         ³ ?",
	"?@ @ @ @ @ @ @ @ @ @ @ @ @ @ ?",
	"?³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ?",
	"¼#############################",
	};

		for(int mapY = 0; mapY < 16; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];

		}

}

void drawLevel_7(char mapName[][30], char keyChar, char keyChar2)
{
	char map[30][300] =
	{
	"É??????????????????????» É???»",
	"?  ?                   ? ?   ?",
	"?  ? É???????????????» ? ?   4",
	"?  ? ?               ? ? ?    ",
	"?  ? ?               ? ? ?   4",
	"?  ? ?               ? ? ?   ?",
	"?  ? ?               ? ? ?   ?",
	"?  ? ?               ? ? ?   ?",
	"5  ? ?               ? ? ?   ?",
	"   ? ?               ? ? ?   ?",
	"5??¼ ?               ? ? ?   ?",
	"?    ?               ?   ?   ?",
	"? ???????????????????????¼   ?",
	"?                            ?",
	"?????????????????????????????¼",
	"                              "
	};

	map[1][1] = keyChar; // key position
	map[1][28] = keyChar2;
		for(int mapY = 0; mapY < 16; mapY++)
		for(int mapX = 0; mapX < 31; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];

		}

}

void drawLevel_8(char mapName[][30], char keyChar)
{
	char map[30][200] =
	{
	"É????????????????????????????»",
	"?                            ?",
	"???????????????????          ?",
	"           ?                 ?",
	"É????????» ?   É??????? ?????¹",
	"?²²²²²²²²? ?   ?             ?",
	"?²²²²²²²²? ?   ?             ?",
	"?²²²²²²²²? ?   ????» É???????¹",
	"?????????¼ ?   ?   ? ?       ?",
	"?          ?   ?   ? ?       ?",
	"? É????????¼   ?   ?         ?", 
	"? ?            ?   ? ?       ?",
	"? ?            ?     ?       ?",
	"?              ?   ? ?       ?",
	"???????????????????2 2???????¼",
	};

	map[1][1] = keyChar; // key posiiton
		for(int mapY = 0; mapY < 17; mapY++)
		for(int mapX = 0; mapX < 30; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];
		}
}

void drawLevel_9(char mapName[][30], char keyChar)
{
	char map[30][200] =
	{
	"É???????7 7??????????????????»",
	"?²²²²²²²? ?                  ?",
	"?²²²²²²²? ? É??????????????» ?",
	"?²²²²²²²? ? ?            ? ? ?",
	"????????¼ ? ? ?          ? ? ?",
	"?         ? ? ?????????» ? ? ?",
	"? É???????¼ ? ?        ? ? ? ?",
	"? ?         ? ? É??????¼ ??? 8",
	"? ? É???????¹ ? ? ?   ?    ?  ",
	"?   ?       ? ?   ? ? ? ?  ? 8",
	"???????? ???¹ ? ? ? ? ? ?  ? ?",
	"?           ? ? ?   ?   ?  ? ?",
	"?             ? ???????????¼ ?",
	"?           ? ?              ?",
	"?????????????????????????????¼",
	};

	map[9][11] = keyChar; // key posiiton
		for(int mapY = 0; mapY < 17; mapY++)
		for(int mapX = 0; mapX < 30; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];
		}
}

void drawLevel_10(char mapName[][30])
{
	char map[30][200] =
	{
	"É????????????????????????????»",
	"?                            ?",
	"? ???????????????????????» É?¹",
	"?             ?²²²²²²²²²²? ? ?",
	"????????????» ?²²²²²²²²²²? ? ?",
	"?²²²²²²²²²²²? ?²²²²²²²²²²? ? ?",
	"?²²²²²²²²²²²? ?²²²²²²²²²²? ? ?",
	"8???????????¼ ?²²²²²²²²²²? ?  ",
	"              ?²²²²²²²²²²? ? ?",
	"8?????????????¹²²²²²²²²²²? ? ?",
	"?²²²²²²²²²²²²²???????????¼ ? ?",
	"?²²²²²²²²²²²²²?            ? ?",
	"?²²²²²²²²²²²²²? ???????????¼ ?",
	"?²²²²²²²²²²²²²?              ?",
	"?????????????????????????????¼",
	};

		for(int mapY = 0; mapY < 17; mapY++)
		for(int mapX = 0; mapX < 30; mapX++)
		{
			if(map[mapY][mapX] != mapName[mapY][mapX])
				mapName[mapY][mapX] = map[mapY][mapX];
		}
}

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
cr88192
cr88192

I don't have any code from when I was that age, as around the age of 14 or so, an HDD crash had wiped out everything I had before this point (this was in the days when CD-R burners for PCs didn't really exist yet, and computers typically only had a single HDD, *1).

*1: many case+MOBO designs in the 90s were a mess (only really space for a single HDD in the case, ISA cards and CPU/RAM on riser-cards, pushrod-operated PSUs, ...), though at least ATX mostly fixed this up, apart from the years of the evil heat-sink braces... (vs the plastic hook-based holders of older heatsinks, or the latter addition of levers).

however, code from back when I was between 15 and 17 was still pretty horrid...

it seems it wasn't until I was in my 20s that my coding skills actually started to get sort of worthwhile...

slicer4ever
slicer4ever
when i was 14, i only knew(and knew is a very long stretch) actionscript. so be proud of atleast knowing c at such a young age.
BennettSteele
BennettSteele

When I was 14 (Now 16, so not much of a stretch) I started out in as much as I could get myself into. Here is my first working and presentable code:

Nickie
Nickie

The feeling of finding old code is awesome. Last week I found my old naruto(cuz there are sprites biggrin.png) arena game in Visual Basic. Hah I wrote it when I was 13 or 14. Srsly I had multiplayer and 2 characters biggrin.png, though I didn't know what function is and everything was in one large, really large function(automatically generated from a timer I think, I had found that if I double click it shows me editor and I can start typing smile.png )

PS. I used the deprecated direct draw for drawing... tongue.png. My greatest achievement was the moving camera that is following the character. Ohh also I found a vid of my game:

hope you like it biggrin.png

Pufixas
Pufixas

when i was 14, i only knew(and knew is a very long stretch) actionscript. so be proud of atleast knowing c at such a young age.

Actually this is C++. But at that time I didn't even know what a class or an object was. All I knew was basic functions, variables. So there's nothing really to be proud of.

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
Pufixas
Pufixas

The feeling of finding old code is awesome. Last week I found my old naruto(cuz there are sprites biggrin.png) arena game in Visual Basic. Hah I wrote it when I was 13 or 14. Srsly I had multiplayer and 2 characters biggrin.png, though I didn't know what function is and everything was in one large, really large function(automatically generated from a timer I think, I had found that if I double click it shows me editor and I can start typing smile.png )

PS. I used the deprecated direct draw for drawing... tongue.png. My greatest achievement was the moving camera that is following the character. Ohh also I found a vid of my game:

hope you like it biggrin.png

Haha, It's great!

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
LennyLen
LennyLen

when i was 14, i only knew(and knew is a very long stretch) actionscript. so be proud of atleast knowing c at such a young age.

Actually this is C++. But at that time I didn't even know what a class or an object was. All I knew was basic functions, variables. So there's nothing really to be proud of.

AT least you knew how to use goto. ph34r.png

Pufixas
Pufixas

when i was 14, i only knew(and knew is a very long stretch) actionscript. so be proud of atleast knowing c at such a young age.

Actually this is C++. But at that time I didn't even know what a class or an object was. All I knew was basic functions, variables. So there's nothing really to be proud of.

AT least you knew how to use goto. ph34r.png

Yeah biggrin.png

In the way I wrote that code, it looks more like BASIC, than C++

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
TheChubu
TheChubu

When I was 12 I only knew how to put discs on my Playstation :D Later I learnt to put discs on my PC and the rest is history :P

Did you had automatic formatting or you wrote it just like that?

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"   My journals: dustArtemis ECS framework and 
Pufixas
Pufixas

When I was 12 I only knew how to put discs on my Playstation biggrin.png Later I learnt to put discs on my PC and the rest is history tongue.png

Did you had automatic formatting or you wrote it just like that?

Yes, I had automatic formatting enabled.

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
l0calh05t
l0calh05t

Ahhh, at 12 I was hacking the Half-Life SDK. Added ricochets (if the reflection angle was sufficiently shallow) and bullets that could go through walls. And made the UI green tongue.png

My first encounter with the horrors that are/were Visual C++ 6 and systems hungarian notation.

smr
smr




I don't have any code from when I was that age, as around the age of 14 or so, an HDD crash had wiped out everything I had before this point

Same, only my HDD was random girly-pop cassette tapes I "found" somewhere in the vicinity of my sister's tape player...

dAND3h
dAND3h

system("cls")...oh how those days were glorious!

RLS0812
RLS0812

10 CLS
20 "do stuff"
30 GOTO 20
I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me. ~ Ralph Waldo Emerson
Sik_the_hedgehog
Sik_the_hedgehog

If stdout supports ANSI escape codes (e.g. the terminals on *nix or DOS with ANSI.SYS) you could use the escape codes for even more interesting stuff without moving away from the standard library. Colors everywhere!

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Bacterius
Bacterius

If stdout supports ANSI escape codes (e.g. the terminals on *nix or DOS with ANSI.SYS) you could use the escape codes for even more interesting stuff without moving away from the standard library. Colors everywhere!

I've been having so much fun with those lately, they are really easy to use as well. Shame they aren't 100% portable, though. I know there's ncurses (and its Windows counterpart PDCurses) but sometimes you just want colors here and there without engineering a complete user interface solution.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”
Pufixas
Pufixas

If stdout supports ANSI escape codes (e.g. the terminals on *nix or DOS with ANSI.SYS) you could use the escape codes for even more interesting stuff without moving away from the standard library. Colors everywhere!

I've been having so much fun with those lately, they are really easy to use as well. Shame they aren't 100% portable, though. I know there's ncurses (and its Windows counterpart PDCurses) but sometimes you just want colors here and there without engineering a complete user interface solution.

Dude, ncurses is as easy as or even easier than standart cout in C++. You don't need to engineer complete UI interface or nothing.

Some guy on youtube was interested in this game, and said I should rewrite it in ncurses, so I began working on it.

Look my simple graphics class, which works very well, you can use it too, if you want to.


// GraphicsSystem.h


#ifndef GRAPHICSSYSTEM_H
#define GRAPHICSSYSTEM_H


class GraphicsSystem
{
private:
    static const int SCREEN_WIDTH = 79;
    static const int SCREEN_HEIGHT = 24;
    char m_frameBuffer[SCREEN_WIDTH][SCREEN_HEIGHT];

    void renderBuffer();
public:
    GraphicsSystem();
    ~GraphicsSystem();

    void clearFramebuffer();
    void renderPixel(int x, int y, char ch);
    void render();
    int getScreenWidth();
    int getScreenHeight();
};

#endif // GRAPHICSSYSTEM_H


//--------------------------------------------------------------
//GraphicsSystem.cpp


#include <curses.h>
#include "GraphicsSystem.h"

GraphicsSystem::GraphicsSystem()
{
	clearFramebuffer();
	initscr();
	cbreak();
	timeout(50);
	keypad(stdscr, TRUE);
}

GraphicsSystem::~GraphicsSystem()
{
    endwin();
}

void GraphicsSystem::render()
{
    wclear(stdscr);
    renderBuffer();
    clearFramebuffer();
    wrefresh(stdscr);
}

int GraphicsSystem::getScreenWidth(){
    return SCREEN_WIDTH;
}

int GraphicsSystem::getScreenHeight(){
    return SCREEN_HEIGHT;
}

void GraphicsSystem::renderPixel(int x, int y, char ch)
{
    m_frameBuffer[x][y] = ch;
}

void GraphicsSystem::renderBuffer()
{
    for(int y = 0; y < SCREEN_HEIGHT; y++)
        for(int x = 0; x < SCREEN_WIDTH; x++)
        {
            mvwaddch(stdscr, y, x, m_frameBuffer[x][y]);
        }
}

void GraphicsSystem::clearFramebuffer()
{
    for(int y = 0; y < SCREEN_HEIGHT; y++)
        for(int x = 0; x < SCREEN_WIDTH; x++)
        {
            m_frameBuffer[x][y] = ' ';
        }
}



And you can draw stuff with ease just like this:


#include <curses.h>
#include <cstdlib>
#include <cmath>
#include "GraphicsSystem.h"

GraphicsSystem graphicsSystem;

int main()
{
    while(true){
        for(int x = 0; x < graphicsSystem.getScreenWidth(); x++)
        {
            for(int y = 0; y < graphicsSystem.getScreenHeight(); y++)
            {
                graphicsSystem.renderPixel(x,y,'x'); // render char 'x', or "pixel" on the screen
            }
        }
        graphicsSystem.render(); //clears screen, and displays all chars
    }
	return 0;
}

“There are thousands and thousands of people out there leading lives of quiet, screaming desperation, where they work long, hard hours at jobs they hate to enable them to buy things they don't need to impress people they don't like.”? Nigel Marsh
Sik_the_hedgehog
Sik_the_hedgehog

I think he meant he just wanted to add colors to the terminal as-is and nothing else. Honestly though, if one starts adding things like that one may as well end up just taking over the entire console, which is what ncurses does, pretty much.

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Bacterius
Bacterius

I think he meant he just wanted to add colors to the terminal as-is and nothing else. Honestly though, if one starts adding things like that one may as well end up just taking over the entire console, which is what ncurses does, pretty much.

Not necessarily. What I meant was doing some minimal coloring of whatever you're outputting, without taking over the entire console, where simply wrapping up a string constant in an ANSI escape sequence is much easier than working with ncurses when the extra flexibility (menu helpers, borders, and so on) are not needed. Different solutions to different problems, really. ncurses is a nifty little library, and is great for making roguelikes and other games which lend themselves well to a 2D ASCII representation, as well as creating complete console interfaces, but that doesn't mean you need to use it every time you need to push a few colors to a terminal... sometimes a script is just a script wink.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.