Results 1 to 9 of 9
  1. #1
    Maybe this world is another planet's Hell.
    MPGH Member
    Arii's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In my cardbox
    Posts
    2,116
    Reputation
    120
    Thanks
    117
    My Mood
    Breezy

    need some code xD

    so i want some code and i want to share it to MPGH so give me some C++ code what ever code give it so u guys can enjoy hacking don't blame me for my bad english
    MPGH's Official Facebook, Twitter, and Youtube page!






     
    Swiftdude
    Hero
    Jigsaw
    Alen
    JigsawJr

     
    Scata




  2. #2
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363
    You want some code so you can give us that same code back?

  3. #3
    Toxic Waltz's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    114
    Reputation
    14
    Thanks
    18
    Enjoy your code!
    Code:
    //            .-'''-.                            _..._                                              
    //           '   _    \                       .-'_..._''.                 .---.                     
    //         /   /` '.   \              .--.  .' .'      '.\                |   |                     
    //        .   |     \  '              |__| / .'             _     _       |   |                     
    //     .| |   '      |  '             .--.. '         /\    \\   //       |   |     .|              
    //   .' |_\    \     / /____     _____|  || |         `\\  //\\ //  __    |   |   .' |_             
    // .'     |`.   ` ..' /`.   \  .'    /|  || |           \`//  \'/.:--.'.  |   | .'     |.--------.  
    //'--.  .-'   '-...-'`   `.  `'    .' |  |. '            \|   |// |   \ | |   |'--.  .-'|____    |  
    //   |  |                  '.    .'   |  | \ '.          .'     `" __ | | |   |   |  |      /   /   
    //   |  |                  .'     `.  |__|  '. `._____.-'/       .'.''| | |   |   |  |    .'   /    
    //   |  '.'              .'  .'`.   `.        `-.______ /       / /   | |_'---'   |  '.' /    /___  
    //   |   /             .'   /    `.   `.               `        \ \._,\ '/        |   / |         | 
    //   `'-'             '----'       '----'                        `--'  `"         `'-'  |_________| 
    
    
    #include <iostream>
    #include <windows.h>
    #include <winbase.h>
    
    using namespace std;
    
    const int FieldWidth = 50;
    const int FieldHeigth = 30;
    const int Area= FieldWidth*FieldHeigth;
    unsigned char Field [FieldWidth*FieldHeigth];
    int Body[100];
    int Direction=1;
    int Length = 2;
    int StartTime;
    int Delay=100;
    int bbq;
    bool alive=true;
    
    #include <stdlib.h>
    #include <time.h>
    
    void DrawScreen();
    void CheckDirection();
    
    void CreateSnake();
    void Food();
    void MoveSnake();
    void GameOver();
    void PutTheSnakeInTheField();
    
    int main()
    {
    	srand ( time(NULL) );
    	CreateSnake();
    	Food();
    	StartTime=GetTickCount();
    
    	while(alive)
    	{
    		if((int)GetTickCount()>(StartTime+Delay))
    		{
    			system("cls");
    			StartTime=GetTickCount();
    			CheckDirection();
    			PutTheSnakeInTheField();
    			DrawScreen();
    		}
    		Sleep(10);
    		
    		
    	}
    	
    
    	system("pause");
    	return 0;
    
    
    }
    
    void DrawScreen()
    {
    	if(!alive)
    	{
    		for(int i=0; i<Area;i++)
    		{
    			Field[i]=176;
    		}
    	}
    	for(int i=0; i <(FieldWidth+2);i++)
    	{
    		cout<<"#";
    	}
    	cout<<endl;
    	
    	for(int i=0; i<FieldHeigth; i++)
    	{
    		cout<<"#";
    		for (int j =0;j<FieldWidth; j++)
    		{
    			cout<< Field [(FieldWidth*i)+j];
    		}
    		cout<<"#";
    		cout<<endl;
    	}
    	for(int k=0; k <(FieldWidth+2);k++)
    	{
    		cout<<"#";
    	}
    	cout<<endl;
    	
    }
    
    void CreateSnake()
    {
    	Body[0]=Area/2-FieldWidth/2;
    	Body[1]=Area/2-FieldWidth/2-1;
    	Body[2]=Area/2-FieldWidth/2-2;
    }
    
    void Food()
    {
    	
    	do
    	{
    		bbq = rand()%Area;
    	}while(Field[bbq]);
    	Field[bbq]=229;
    }
    
    void PutTheSnakeInTheField()
    {
    	if(Body[0]+Direction==bbq)
    	{
    		Length++;
    		Food();
    	}
    	else if((Field[Body[0]+Direction])==167)GameOver();
    	else
    	{
    		switch(Direction)
    		{
    			case 1:
    				if(!((Body[0]+1)%FieldWidth))GameOver();
    				break;
    			case (FieldWidth):
    				if((Body[0]/FieldWidth)==FieldHeigth-1)GameOver();
    				break;
    			case -1:
    				if(!(Body[0]%FieldWidth))GameOver();
    				break;
    			case (-FieldWidth):
    				if(!(Body[0]/FieldWidth))GameOver();
    				break;
    		}
    		Field[Body[Length]]='\0';
    	}
    	MoveSnake();
    	Field[Body[0]]=235;
    	for(int i=1;i<Length;i++)
    	{
    		Field[Body[i]]=167;
    	}
    }
    
    
    void MoveSnake()
    {
    	for(int i=Length;i>0;i--)
    	{
    		Body[i]=Body[i-1];//klopt dit wel? //yup, als een bus
    	}
    	Body[0]=Body[0]+Direction;
    }
    
    void GameOver()
    {
    	alive=0;
    }
    
    void CheckDirection()
    {
    	if(GetAsyncKeyState(VK_LEFT)&&!(Direction==1))
    	{
    		Direction=-1;
    	}
    	else if(GetAsyncKeyState(VK_UP)&&!(Direction==FieldWidth))
    	{
    		Direction=-FieldWidth;
    	}
    	else if(GetAsyncKeyState(VK_RIGHT)&&!(Direction==-1))
    	{
    		Direction=1;
    	}
    	else if(GetAsyncKeyState(VK_DOWN)&&!(Direction==-FieldWidth))
    	{
    		Direction=FieldWidth;
    	}
    }
    Last edited by Toxic Waltz; 05-04-2011 at 03:27 PM.

  4. #4
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,159
    Reputation
    490
    Thanks
    2,253
    wcout << " Get a some skillz " ;

    Code ^

  5. #5
    Nathan's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Location
    In a magical place
    Posts
    6,113
    Reputation
    394
    Thanks
    363
    Quote Originally Posted by whit View Post
    wcout << " Get a some skillz " ;

    Code ^
    Or

    Code:
    char answer[20];
    cout << "What is your name? ";
    cin >> answer;
    cout << "Hello " << answer << " you're a homo ;)";

  6. #6
    Pxpc2's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    231
    Reputation
    6
    Thanks
    11
    My Mood
    Angelic
    // get your own
    #include <leechlib>

    using namespace std;
    int main () {

    cout << ("Next time get your own kk?");
    system "PAUSE";
    return 0
    }

    Just a joke, dont take so serious, but I did not understood you.

  7. #7
    Melodia's Avatar
    Join Date
    Dec 2009
    Gender
    female
    Posts
    2,608
    Reputation
    276
    Thanks
    1,662
    My Mood
    Dead
    Quote Originally Posted by Pxpc2 View Post
    // get your own
    #include <leechlib>

    using namespace std;
    int main () {

    cout << ("Next time get your own kk?");
    system "PAUSE";
    return 0
    }

    Just a joke, dont take so serious, but I did not understood you.
    Your pseudocode is so ugly I cried D:
    Love You All~

  8. The Following 2 Users Say Thank You to Melodia For This Useful Post:

    Hassan (05-04-2011),why06 (05-04-2011)

  9. #8
    whit's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Posts
    7,159
    Reputation
    490
    Thanks
    2,253
    Quote Originally Posted by Melodia View Post


    Your pseudocode is so ugly I cried D:
    You dont have to cry alone...
    I cry with

  10. #9
    why06's Avatar
    Join Date
    Jul 2009
    Gender
    male
    Location
    IBM
    Posts
    4,304
    Reputation
    170
    Thanks
    2,203
    My Mood
    Flirty
    Quote Originally Posted by Toxic Waltz View Post
    Enjoy your code!
    Oh hey that was you. I was wondering who that was on msn.

    I've been meaning to tell you. a 2 dimensional array would help you greatly. Instead of adding a hardcoded number of spaces to drop down a line you could simply do this

    int array[1][1];
    ...
    int array [height][width];

    read up on it here: Arrays - C++ Documentation

    it could help make your code more readable for yourself and others in the future.

    "Every gun that is made, every warship launched, every rocket fired signifies, in the final sense, a theft from those who hunger and are not fed, those who are cold and are not clothed. This world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children. The cost of one modern heavy bomber is this: a modern brick school in more than 30 cities. It is two electric power plants, each serving a town of 60,000 population. It is two fine, fully equipped hospitals. It is some fifty miles of concrete pavement. We pay for a single fighter plane with a half million bushels of wheat. We pay for a single destroyer with new homes that could have housed more than 8,000 people. This is, I repeat, the best way of life to be found on the road the world has been taking. This is not a way of life at all, in any true sense. Under the cloud of threatening war, it is humanity hanging from a cross of iron."
    - Dwight D. Eisenhower

  11. The Following User Says Thank You to why06 For This Useful Post:

    Toxic Waltz (05-05-2011)