Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Oh my glorious code!

  • You cannot reply to this topic
21 replies to this topic

#1 _greyfox()   Members   -  Reputation: 1134

Like
5Likes
Like

Posted 14 June 2013 - 05:56 AM

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];
		}
}


Edited by Edvinas Kilbauskas, 16 June 2013 - 12:47 AM.

“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

Sponsor:

#2 BGB   Crossbones+   -  Reputation: 1554

Like
0Likes
Like

Posted 14 June 2013 - 02:29 PM

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...


Edited by cr88192, 14 June 2013 - 02:32 PM.


#3 slicer4ever   Crossbones+   -  Reputation: 3986

Like
0Likes
Like

Posted 14 June 2013 - 02:53 PM

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.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#4 bennettbugs   Members   -  Reputation: 493

Like
0Likes
Like

Posted 14 June 2013 - 04:21 PM

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:

 

http://www.youtube.com/watch?v=98IW5IZNcfw



#5 Nickie   Members   -  Reputation: 322

Like
0Likes
Like

Posted 15 June 2013 - 12:20 AM

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: http://youtu.be/gYePr5AMBJE hope you like it biggrin.png


Edited by Nickie, 15 June 2013 - 12:32 AM.


#6 _greyfox()   Members   -  Reputation: 1134

Like
0Likes
Like

Posted 15 June 2013 - 12:21 AM

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

#7 _greyfox()   Members   -  Reputation: 1134

Like
0Likes
Like

Posted 15 June 2013 - 01:38 AM

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: http://youtu.be/gYePr5AMBJE 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

#8 LennyLen   Crossbones+   -  Reputation: 4026

Like
0Likes
Like

Posted 15 June 2013 - 09:50 AM

 

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 



#9 _greyfox()   Members   -  Reputation: 1134

Like
0Likes
Like

Posted 15 June 2013 - 10:14 AM

 

 

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++


Edited by Edvinas Kilbauskas, 15 June 2013 - 10:14 AM.

“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

#10 TheChubu   Crossbones+   -  Reputation: 4791

Like
0Likes
Like

Posted 15 June 2013 - 12:35 PM

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 Making a Terrain Generator


#11 _greyfox()   Members   -  Reputation: 1134

Like
0Likes
Like

Posted 16 June 2013 - 12:45 AM

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

#12 l0calh05t   Members   -  Reputation: 818

Like
0Likes
Like

Posted 17 June 2013 - 02:33 AM

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.


Edited by l0calh05t, 17 June 2013 - 02:34 AM.


#13 smr   GDNet+   -  Reputation: 1682

Like
1Likes
Like

Posted 30 July 2013 - 06:57 AM


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...



#14 dAND3h   Members   -  Reputation: 214

Like
1Likes
Like

Posted 02 August 2013 - 06:27 PM

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



#15 Code Fox   Members   -  Reputation: 1808

Like
1Likes
Like

Posted 03 August 2013 - 09:37 PM

10 CLS
20 "do stuff"
30 GOTO 20

Does Anyone Actually Read This ?
 


#16 Sik_the_hedgehog   Crossbones+   -  Reputation: 1834

Like
0Likes
Like

Posted 03 August 2013 - 10:52 PM

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.

#17 Bacterius   Crossbones+   -  Reputation: 9293

Like
0Likes
Like

Posted 07 August 2013 - 04:45 PM

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.


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#18 _greyfox()   Members   -  Reputation: 1134

Like
0Likes
Like

Posted 11 August 2013 - 11:46 AM

 

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;
}


Edited by Edvinas Kilbauskas, 11 August 2013 - 11:48 AM.

“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

#19 Sik_the_hedgehog   Crossbones+   -  Reputation: 1834

Like
0Likes
Like

Posted 11 August 2013 - 12:25 PM

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.

#20 Bacterius   Crossbones+   -  Reputation: 9293

Like
1Likes
Like

Posted 11 August 2013 - 02:59 PM

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


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis






PARTNERS