A change.... a problem!

This is a discussion on A change.... a problem! within the C++ Programming forums, part of the General Programming Boards category; I just created my first "make something move in a maze with the arrow keys" program. I then changed the ...

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

    A change.... a problem!

    I just created my first "make something move in a maze with the arrow keys" program. I then changed the map I was playing on (it's a string). I changed all of the variables I needed to accomidate the change. I get crap. The initial output is gibberish, and when I push the arrow keys, I can bareley see my map flichering in the BACHGROUND of this text. I'll give you the code and the output picture. Good luck to whoever dare venture into my hechtic code.... (well, not really; oh nevermind!):

    Code:
    #include "stdafx.h"
    #define _clrscr
    #include <monkey.h>
    //12x30
    
    
    typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X};
    
    int COL_MAX = 47;
    int ROW_MAX = 11;
    int PLAYERX = 1;
    int PLAYERY = 12;
    char ITEM = 'O';
    char ItemMessage[50] = "You picked up an item!";
    char* message = new char[50];
    char MAP[11][47]    =  {" ____________________________________________ ",
    						"|   |      |X                                |",
    						"|   |      |_______________                  |",
    						"|   |      |>              |---_----------_  |",
    						"|   |                      | O |          |  |",
    						"|   |      |>     |        |   |          |  |",
    						"|   |      |      |        |                 |",
    						"|   |______|______|         ---------------  |",
    						"|                                            |",
    						"(--------------------------------------------)"};
    
    void display();
    int ReadFiles();
    int MovePlayer(int x,int y);
    UPARAM PassParam(UPARAM Uparam);
    
    int main(int argc, char* argv[])
    {
    	message = " ";
    	char input;
    	char arrow;
    	UPARAM Uparam = ZIP;
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    	while(1)
    	{
    		//SHOW MAP SCREEN
    		display();
    		printf("\n");
    		//OUTPUT MESSAGE (BLANK IF THERE IS NOTHING TO SAY)
    		if(!strcmpi(message," "))
    		{
    		}
    		else
    		{
    		printf(message);
    		while(!kbhit());
    		}
    		message = " ";
    		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':
    					{
    						return 0;
    					}break;
    					}
    			}
    		//SEND MESSAGE
    		PassParam(Uparam);
    		//CLEAR THE SCREEN
    		clrscr();
    		}
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    /////////////END GAME PUMP/////////////END GAME PUMP////////////////////
    
    	return 0;
    }
    
    void display()
    {
        for(int loop2 = 0; loop2 < COL_MAX; loop2++)
        {
        for(int loop1 = 0; loop1 < ROW_MAX; loop1++)
        {
            char displayer;
            displayer = MAP[loop2][loop1];
            printf("%c",displayer);
            if(loop1 == (ROW_MAX - 1))
                printf("\n");
        }
        }
    }
    
    int MovePlayer(int x, int y)
    {
    	if(MAP[x][y] == ' ')
    	{
    		MAP[PLAYERX][PLAYERY] = ' ';
    		MAP[x][y] = 'X';
    		PLAYERX = x;
    		PLAYERY = y;
    	}
    	else if(MAP[x][y] == ITEM)
    	{
    		MAP[PLAYERX][PLAYERY] = ' ';
    		MAP[x][y] = 'X';
    		PLAYERX = x;
    		PLAYERY = y;
    		message = ItemMessage;
    	}
    	return 0;
    }
    
    UPARAM PassParam(UPARAM Uparam)
    {
    	switch(Uparam)
    	{
    	case UP:
    		{
    			MovePlayer(PLAYERX - 1,PLAYERY);
    		}break;
    	case DOWN:
    		{
    			MovePlayer(PLAYERX + 1,PLAYERY);
    		}break;
    	case LEFT:
    		{
    			MovePlayer(PLAYERX,PLAYERY - 1);
    		}break;
    	case RIGHT:
    		{
    			MovePlayer(PLAYERX,PLAYERY + 1);
    		}break;
    	default:
    		{
    		}break;
    	}
    	return ZIP;
    }
    
    int ReadFiles()
    {
    	char* COLMAX = new char[2];
    	char* ROWMAX = new char[2];
    
    	ifstream FileReader("C:\\Maze\\boarddimensions.txt");
    	FileReader>>COLMAX;
    	FileReader>>ROWMAX;
    	FileReader.close();
    	return 0;
    }
    Attached Files Attached Files
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    My only suggestion would be to go back to the original map and look for any differences that might cause errors between the two. For example, just because 1+1=1 does not imply that

    x + x = x.

    Althought it would be more complicated than that, maybe there was an algorithm that worked for one map, but not all maps. Otherwise you could have a program read in a file that was a map and have 1 program run many mazes. See what you find.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    891
    Old map gone

    I'm just stumped.
    "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. Reference parameters and calculating change
    By Cstudent2121 in forum C Programming
    Replies: 6
    Last Post: 11-04-2005, 02:19 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 07:55 AM
  3. problem with some simple code =/
    By Josh Norton in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2004, 05:27 AM
  4. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM
  5. problem with output
    By Garfield in forum C Programming
    Replies: 2
    Last Post: 11-18-2001, 07:34 PM

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