Executes Smoking Pot

This is a discussion on Executes Smoking Pot within the Game Programming forums, part of the General Programming Boards category; In this game I'm creating, I'm having a run problem. Whenever I run the program through the compiler (MSVC++6: execute ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907

    Executes Smoking Pot

    In this game I'm creating, I'm having a run problem. Whenever I run the program through the compiler (MSVC++6: execute button), it runs smoothly. When I copy the exe, and run it elsewhere, it has an extremely laggy keystroke response. Why-oh-why. Does it have to do with "external dependancies?" Here's the code if you need it:

    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <iostream.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include <string.h>
    #include <fstream.h>
    
    typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X};
    
    int Frames = 0;
    int COL_MAX = 80;
    int ROW_MAX = 24;
    int PLAYERX =  22;
    int PLAYERY =  39;
    int WINPLAYERX = PLAYERY;
    int WINPLAYERY = PLAYERX; 
    
    char ITEM = '$';
    char PLAYER = (char)1;
    char ItemMessage[50] = "You picked up an item!";
    int ItemMessageLength = strlen(ItemMessage);
    char GamePath[50];
    char* message = new char[50];//6
    
    char MAP[24][80] = {
    	" _____________________________________________________________________________ ",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                          $                                  |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	"|                                                                             |",
    	" ----------------------------------------------------------------------------- "};
    void display();
    int ReadFiles();
    void clrscr();
    int QueryGame();
    int Log(const char* output);
    void gotoxy(int x,int y);
    void PlaceChar();
    UPARAM PassParam(UPARAM Uparam);
    
    int main()
    {
    	//QueryGame();
    	//ReadFiles();
    	message = " ";
    	char input;
    	char arrow;
    	UPARAM Uparam = ZIP;
    	display();
    	PlaceChar();
    	gotoxy(ROW_MAX,COL_MAX);
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    	while(1)
    	{
    		//Clear game command
    		Uparam = ZIP;
    		//OUTPUT MESSAGE (BLANK IF THERE IS NOTHING TO SAY)
    		if(!strcmpi(message," "))
    		{
    		}
    		else
    		{
    		gotoxy(ROW_MAX,COL_MAX);
    		printf(message);
    		printf("          ");
    		gotoxy(ROW_MAX,COL_MAX);
    		//Log();
    		while(!kbhit());
    		}
    		message = " ";
    
    
    		while(!kbhit())
    		{
    			Frames++;
    		}
    		input = getch();
    		//IF ARROW KEY...
    		if((int)input == -32)
    			{
    				arrow = getch();
    				switch(arrow)
    					{
    				case 'H':
    					{
    						Uparam = UP;
    					}break;
    				case 'P':
    					{
    						Uparam = DOWN;
    					}break;
    				case 'K':
    					{
    						Uparam = LEFT;
    					}break;
    				case 'M':
    					{
    						Uparam = RIGHT;
    					}break;
    					}
    
    				}
    		//IF OTHER THAN ARROW KEY...
    			else
    			{
    				switch(input)
    				{
    				case 'x':
    					{
    						clrscr();
    						printf("%d",Frames);
    						getch();
    						return 0;
    					}break;
    				case 'a':
    					{
    						MessageBox(NULL,"FIRE!","You attacked",MB_ICONEXCLAMATION);
    					}break;
    				}
    			}
    
    
    		//SEND MESSAGE
    		PassParam(Uparam);
    		}
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    
    	
    	return 0;
    }
    
    void display()
    {
    	char displayer;
        for(int loop2 = 0; loop2 < ROW_MAX; loop2++)
        {
        for(int loop1 = 0; loop1 < COL_MAX; loop1++)
        {
            displayer = MAP[loop2][loop1];
            printf("%c",displayer);
            if(loop1 == (COL_MAX))
                printf("\n");
        }
        }
    }
    
    
    UPARAM PassParam(UPARAM Uparam)
    {
    	switch(Uparam)
    	{
    	case UP:
    		{
    			if(MAP[PLAYERX - 1][PLAYERY] != ' ')
    			{
    				if(MAP[PLAYERX - 1][PLAYERY] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX,WINPLAYERY - 1);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERX = PLAYERX - 1;
    					WINPLAYERY = PLAYERX;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX,WINPLAYERY - 1);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERX = PLAYERX - 1;
    			WINPLAYERY = PLAYERX;
    
    			}
    			
    		}break;
    	case DOWN:
    		{
    			if(MAP[PLAYERX + 1][PLAYERY] != ' ')
    			{
    				if(MAP[PLAYERX + 1][PLAYERY] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX,WINPLAYERY + 1);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERX = PLAYERX + 1;
    					WINPLAYERY = PLAYERX;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX,WINPLAYERY + 1);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERX = PLAYERX + 1;
    			WINPLAYERY = PLAYERX;
    			}
    		
    		}break;
    	case LEFT:
    		{
    			if(MAP[PLAYERX][PLAYERY - 1] != ' ' || MAP[PLAYERX][PLAYERY - 2] != ' ')
    			{
    				if(MAP[PLAYERX][PLAYERY - 2] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX - 2,WINPLAYERY);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERY = PLAYERY - 2;
    					WINPLAYERX = PLAYERY;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX - 2,WINPLAYERY);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERY = PLAYERY - 2;
    			WINPLAYERX = PLAYERY;
    			}
    	
    		}break;
    	case RIGHT:
    		{
    			if(MAP[PLAYERX][PLAYERY + 1] != ' ' || MAP[PLAYERX][PLAYERY + 2] != ' ')
    			{
    				if(MAP[PLAYERX][PLAYERY + 2] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX +2,WINPLAYERY);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERY = PLAYERY + 2;
    					WINPLAYERX = PLAYERY;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX + 2,WINPLAYERY);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERY = PLAYERY + 2;
    			WINPLAYERX = PLAYERY;
    			}
    			
    		}break;
    	default:
    		{
    		}break;
    	}
    	return ZIP;
    }
    
    int ReadFiles()
    {
    	char* COLMAX = new char[2];
    	char* ROWMAX = new char[2];
    
    	ifstream FileReader(GamePath/*\\boarddimensions.txt*/);
    	FileReader>>ROWMAX;
    	FileReader>>COLMAX;
    	FileReader.close();
    	COL_MAX = atoi(COLMAX);
    	return 0;
    }
    
    int QueryGame()
    {
    	printf("Input game path\n");
    	cin.getline(GamePath,50,'\n');
    	ReadFiles();
    	//clrscr();
    	return 0;
    }
    
    int Log(const char* output)
    {
    	ofstream writer(GamePath/*\\Log.txt*/);
    	writer<<message<<endl;
    
    	return 0;
    }
    
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    void PlaceChar()
    {
    	gotoxy(PLAYERY,PLAYERX);
    	printf("%c",PLAYER);
    	gotoxy(COL_MAX,ROW_MAX);
    }
    
    void clrscr()
    {
       COORD coordScreen = { 0, 0 };
       DWORD cCharsWritten;
       CONSOLE_SCREEN_BUFFER_INFO csbi;
       DWORD dwConSize;
       HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
       FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
       SetConsoleCursorPosition(hConsole, coordScreen);
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    I didnt really look through your code, but if your not alreay, you could try setting the 'active configuration' to release.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    Same problem.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Registered User got matt?'s Avatar
    Join Date
    Mar 2002
    Posts
    16
    mmm sounds like an idea.
    Got matt? likes title.
    "If there is a will, there is a way."

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    I fixed it! Bad pointers
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    done
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  7. #7
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    907
    Nevrmind... I didn't fix it. So I come to my question on the C++ board. A portable or windows function that acts like kbhit().....
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-26-2009, 02:47 PM
  2. Are you smoking?
    By audinue in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 12-31-2008, 12:05 AM
  3. Return to menu after switch executes
    By wco5002 in forum C++ Programming
    Replies: 5
    Last Post: 07-06-2008, 10:46 PM
  4. only smoking while drinking
    By neandrake in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 12-01-2003, 08:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21