Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 10.05.2010, 15:27   #1
bz175
Новичок
Джуниор
 
Регистрация: 10.05.2010
Сообщений: 1
Радость Бегущая строка в графическом режиме Си

Делал программу вывода бегущей строки в графическом режиме.
Казалось бы всё работает но нет... строка бегает, но доходя до конца не разделяется, а исчезает полностью, затем заного появляется...
Просидел с этой задачей неделю... решил обратиться...
Вот код:
Код:
#define TEST 1

#include <GRAPHICS.H>
#include <CONIO.H>
#include <STDLIB.H>
#include <STRING.H>
#include <DOS.H>

#include "utinout.h"
#include "strrun.h"

int far GStrRunYD( int left, int top, 
		 int right, int bottom, 
		char far *text, 
		int fcolor, /* Цвет рамки, */
		int tcolor, /* Цвет текста, */
		int bcolor  /* Цвет фона,
		 )
{
int x, y, i, k, maxx, maxy, field;
char *ch, arr[] = { 0, 0 };

maxx = getmaxx();
maxy = getmaxy();

	if ( ((left < 0) || (left > maxx)) ||
		 ((right < 0) || (right > maxx)) )
		return -1;

	if ( ((top < 0) || (top > maxy )) ||
		 ((bottom < 0) || (bottom > maxy)) )
		return -2;

	if ( text == NULL )
		return -3;

	if ( strlen( text ) * CHPIXEL > bottom - top )
		return -4;

	if ( ((tcolor < 0) || (tcolor > 15)) ||
		 ((fcolor < 0) || (fcolor > 15)) ||
		 ((bcolor < 0) || (bcolor > 15)) )
		return -5;

	if( tcolor == bcolor )
		return -6;

	if( fcolor == bcolor )
		return -7;

	if ( (right - left) < 24 || (bottom - top < 40) )
		return -8;

	setbkcolor( bcolor );
	setcolor( fcolor );
	rectangle( left, top, right, bottom );
	settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );

	field = (bottom - top) % CHPIXEL;
	x * = left + (right - left) / 2;
	y * = bottom - 2 * CHPIXEL;

 /* ОСНОВНОЙ ЦИКЛ */

	while ( !kbhit() )
	{
		i = 0;
		k = 0;
		while( *(ch = text + k ) != 0 )
		{
			if( y - i < bottom && y - i > top )
			{
				setcolor( tcolor );
				arr[0] = *ch;
				outtextxy( x, y - i, arr );
                                             setcolor( bcolor );
				arr[0] = 219;
				outtextxy( x, y - i + CHPIXEL, arr );
				if( k > 0 )
				{
					*ch--;
					setcolor( tcolor );
					arr[0] = *ch;
					outtextxy( x, y - i + CHPIXEL, arr );
					*ch++;
				}
                                             setcolor( bcolor );
				arr[0] = 219;
				outtextxy( x, top + field, arr );
			}
			k++, i += CHPIXEL;
		}

		delay( 45000 );
		y -= CHPIXEL;
		if( y == top + field - CHPIXEL)
		     y = bottom - 2 * CHPIXEL;
	}
	return getch();
}

/*----------TEST PART----------*/

#ifdef TEST 1

void main( void )
{
int gd, gm, maxx, maxy,
left, right, top, bottom, fcolor, tcolor, bcolor, keycode;
char *text, buf[SBUFLEN];

	do
	{
                      detectgraph( &gd, &gm );
		initgraph( &gd, &gm, "c:\\tc2\\bgi" );

		maxx = getmaxx();
		maxy = getmaxy();

		restorecrtmode();

		textcolor( LIGHTMAGENTA ), textbackground( BLACK );
		cprintf( " * * * * * * * * * * * * *ELECTRONIC MOVING TEXT" );
		textcolor( LIGHTBLUE ), textbackground( BLACK );
		cprintf( "\n\rThe maximum value of X coordinate is %d
pixels", maxx );
		cprintf( "\n\rThe maximum value of Y coordinate is %d pixels", maxy );

		left * = (int)T_DoubleGetC( GREEN, BLACK, LIGHTRED, BLACK,
"The coordinate of the upper left corner on the X axis", 0, -2000, 2000 );

		top * *= (int)T_DoubleGetC( GREEN, BLACK,LIGHTRED, BLACK,
"The coordinate of the upper left corner on the Y axis", 0, -2000, 2000 );

		right *= (int)T_DoubleGetC( GREEN, BLACK, LIGHTRED, BLACK,
"The coordinate of the lower right corner on the X axis", 300, -2000, 2000 );

		bottom = (int)T_DoubleGetC( GREEN, BLACK,LIGHTRED, LACK,
"The coordinate of the lower right corner on the Y axis", 300, -2000, 2000 );

		cprintf( "\n\rString for output " );
		text = T_StrGetC( GREEN, BLACK, buf, STRMAXLEN );

		tcolor = (int)T_DoubleGetC( GREEN, BLACK,LIGHTRED, BLACK,
			"Enter color of the text", 14, -100, 100 *);
		bcolor = (int)T_DoubleGetC( GREEN, BLACK, LIGHTRED,BLACK,
			"Enter color of a background", 3, -100, 100 );
		fcolor = (int)T_DoubleGetC( GREEN, BLACK,LIGHTRED, BLACK,
			"Enter color of a frame", 5, -100, 100 );

		detectgraph( &gd, &gm );
		initgraph( &gd, &gm, "c:\\tc2\\bgi" );

		keycode = GStrRunYD( left, top, right, bottom, text,
				fcolor, tcolor, bcolor *);
		restorecrtmode();

		textcolor( LIGHTMAGENTA ), textbackground( BLACK );
		if( keycode > -1 )
			cprintf( "Code of the pressed key = %d", keycode );
		else
			cprintf( "GStrRunYD return = %d\a", keycode );
 * *}
	while ( T_YesNoC( LIGHTRED, BLACK, "REPEAT" ) );
}
#endif
CHPIXEL = 8 ( в квадрате 8 на 8 пикселей содержится символ)
T_DoubleGetC - функция запроса любого числа ( с защитой от "дурака" )
T_YesNoC - запрос на да/нет
T_StrGetC - вызывает cgets и на выходе передаёт указатель на строку

Как, изменив только основной цикл не затрагивая остальное, сделать так , чтобы она разделялась...
Алгоритм мне понятен... а код не пишется СОВСЕМ...
Помогите именно с кодом плз... вся прога почти готова... осталось только это...

Последний раз редактировалось bz175; 10.05.2010 в 15:30.
bz175 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
«Работа в графическом режиме» Антонова Евгения Паскаль, Turbo Pascal, PascalABC.NET 3 27.04.2010 10:33
Работа в графическом режиме adgam Assembler - Ассемблер (FASM, MASM, WASM, NASM, GoASM, Gas, RosAsm, HLA) и не рекомендуем TASM 2 23.04.2010 17:56
Вылетает паскаль в графическом режиме ai\ekcah^p Помощь студентам 20 05.05.2009 17:02