View Poll Results: Which way should I go? (10 day vote)

Voters
7. You may not vote on this poll
  • Use gotoxy(); welcome to the console!

    4 57.14%
  • Refresh the map! It's easy and dynamic!

    3 42.86%

Thread: 2 options.... which way should I go?

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

    2 options.... which way should I go?

    I'm making an ASCII tile-based game. Which way should i go? Should I refresh the console every frame? (like a regular game)

    or should I use gotoxy() to cut down the refresh time but add complexity.

    Vote and comment.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Simple is always better, except when it is unquestionably inefficient ( bubblesort ). Go with the option that will save you time porting the game in the future and is easier to code/understand now.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Ok. Anyone else?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Heheh
    >Ok. Anyone else?
    Translation: That wasn't the answer I wanted, go away.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Refresh the map
    That's the way I do it, and it seems easier

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Well, I will disagree because refreshing the map on a console looks awful. gotoxy() will be good experience because it resembles dirty rectangles in "regular" games.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  7. #7
    Unregistered
    Guest
    gotoxy():
    + easy (talking about complezity?)
    + dirty rectangles is easy to implement =>
    + more efficient
    - not so portable (but doubt that you can make that game without using some non-portable functions...)

    or you could use graphics mode (or textmode(C4350) - though bot of these aren't very portable...) and leave gotoxy()...

  8. #8
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    >Well, I will disagree because refreshing the map on a console looks awful


    He speaks truth there. If you were not doing a console game, I would refresh the map, but refreshing in console does look awful. Its all flashy and seizure-causing.....

    So use gotoxy().
    My Website

    "Circular logic is good because it is."

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    >Translation: That wasn't the answer I wanted, go away.


    I thought it might sound like that. Not what I intended.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  10. #10
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Poke me with a stick; this is what I have.
    It should compile (except for the clrscr() which i haven't even used yet - I will) (You can actually comment it out if you wish to compile)

    Code:
    #include <iostream.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include <string.h>
    #include <fstream.h>
    #define _clrscr
    //nclude <monkey.h>
    
    
    typedef enum UPARAM {ZIP,UP,DOWN,LEFT,RIGHT,Q,A,Z,W,S,X};
    
    int COL_MAX = 49;
    int ROW_MAX = 11;
    int PLAYERX = 1;
    int PLAYERY = 13;
    int WINPLAYERX = PLAYERY;
    int WINPLAYERY = PLAYERX; 
    
    char ITEM = 'O';
    char PLAYER = (char)1;
    char ItemMessage[50] = "You picked up an item!";
    int ItemMessageLength = strlen(ItemMessage);
    char GamePath[50];
    char* message = new char[50];
    
    char MAP[11][49]    =  {"++____________________________________________++",
    						"||   |O     |#                                ||",
    						"||   |      |---------------_                 ||",
    						"||   |      |>              |---_----------_  ||",
    						"||   |                      | O |          |  ||",
    						"||   |      |>     |        |   |          |  ||",
    						"||   |      |      |        |                 ||",
    						"||   |______|______|         ---------------  ||",
    						"||                                            ||",
    						"||--------------------------------------------||",
    						"++============================================++"};
    
    void display();
    int ReadFiles();
    int QueryGame();
    int Log(const char* output);
    void gotoxy(int x,int y);
    UPARAM PassParam(UPARAM Uparam);
    
    int main()
    {
    	//QueryGame();
    	//ReadFiles();
    	message = " ";
    	char input;
    	char arrow;
    	UPARAM Uparam = ZIP;
    	display();
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    /////////////GAME PUMP/////////////GAME PUMP////////////////////
    	while(1)
    	{
    		
    		//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 = " ";
    
    
    		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);
    		}
    /////////////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 - 1))
                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] != ' ')
    			{
    				if(MAP[PLAYERX][PLAYERY - 1] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX - 1,WINPLAYERY);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERY = PLAYERY - 1;
    					WINPLAYERX = PLAYERY;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX - 1,WINPLAYERY);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERY = PLAYERY - 1;
    			WINPLAYERX = PLAYERY;
    			}
    	
    		}break;
    	case RIGHT:
    		{
    			if(MAP[PLAYERX][PLAYERY + 1] != ' ')
    			{
    				if(MAP[PLAYERX][PLAYERY + 1] == ITEM)
    				{
    					message = ItemMessage;
    					gotoxy(WINPLAYERX,WINPLAYERY);
    					printf(" ");
    					gotoxy(WINPLAYERX +1,WINPLAYERY);
    					printf("%c",PLAYER);
    					gotoxy(0,ROW_MAX);
    					PLAYERY = PLAYERY + 1;
    					WINPLAYERX = PLAYERY;
    				}
    				else
    				{
    				}
    			}
    			else
    			{
    			gotoxy(WINPLAYERX,WINPLAYERY);
    			printf(" ");
    			gotoxy(WINPLAYERX + 1,WINPLAYERY);
    			printf("%c",PLAYER);
    			gotoxy(0,ROW_MAX);
    			PLAYERY = PLAYERY + 1;
    			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);
    }
    "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. Doxygen failing
    By Elysia in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 04-16-2008, 01:24 PM
  2. What's the best way to handle many program options?
    By stickmangumby in forum C Programming
    Replies: 19
    Last Post: 06-06-2007, 04:06 PM
  3. Options Dialog
    By Morgul in forum Game Programming
    Replies: 3
    Last Post: 11-16-2005, 12:15 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  5. Opening files - Giving options?
    By wwwGazUKcom in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2001, 07:06 AM