All pastes #1186328 Raw Edit

Stuff

public text v1 · immutable
#1186328 ·published 2008-08-27 13:46 UTC
rendered paste body
#include <stdio.h>
#include <conio.h>

unsigned char xCenter;
unsigned char yCenter;
struct text_info oldTextInfo;

/* Prototypes */
void intializeScreen (void);
void moveRobot (void);
void redrawRobot (int newX, int newY);
void cleanupOnExit (void);

void main ( void )
{
	/* =================================== */
	/* Main function for the robot program */
	/* ----------------------------------- */
	/* This program will read text cursor  */
	/* movement keys from a user.          */
	/* =================================== */
	intializeScreen ( );
	moveRobot ();
	cleanupOnExit ();
}

/* Modules */
void intializeScreen (void)
{
	gettextinfo (&oldTextInfo);
	xCenter = (oldTextInfo.winright - oldTextInfo.winleft + 1) / 2;
	yCenter = (oldTextInfo.winbottom - oldTextInfo.wintop + 1) / 2;
	clrscr ();
	gotoxy (xCenter, yCenter);
	textcolor (10);
	putch (0xB2);
	gotoxy (wherex()-1, wherey());
}
void redrawRobot ( int newX, int newY)
{
	textcolor (0);
	putch (0xB2);
	gotoxy (newX, newY);
	textcolor (10);
	putch (0xB2);
	gotoxy (newX, newY);
}
/* redrawRobot */

/* intializeScreen */

void moveRobot ( void )
{
int userStop;
char userMove;
char extended;

userStop = 0;
do {
userMove = getch ();
switch (userMove)
{
case 'q':
case 'Q': userStop = 1; break;

	/* zero */
case 0: {
	extended = getch ();
	switch (extended)
	{
		case 75: if (wherex() > 1) redrawRobot (wherex() -1, wherey());
		break;
		case 77: if (wherex() < oldTextInfo.winright) redrawRobot (wherex() +1, wherey());
		break;
		case 72: if (wherey() > 1) redrawRobot (wherex(), wherey()-1);
		break;
		case 80: if (wherey() < oldTextInfo.winbottom) redrawRobot (wherex(), wherey()+1);
		break;
	}
	}; break;
}
}while (userStop ==0);
}
/* moveRobot */

void cleanupOnExit ( void )
{
	textcolor (7);
	window (oldTextInfo.winleft, oldTextInfo.wintop, oldTextInfo.winright, oldTextInfo.winbottom);
	clrscr ();
}