drawing.c 21.7 KB
Newer Older
1 2 3 4 5 6
/**********************************************************************
*  This source code is copyright 1999 by Gus Hartmann & Peter Keller  *
*  It may be distributed under the terms of the GNU General Purpose   *
*  License, version 2 or above; see the file COPYING for more         *
*  information.                                                       *
*                                                                     *
7
*  $Id: drawing.c,v 1.25 2003-10-11 20:50:50 hartmann Exp $
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
*                                                                     *
**********************************************************************/

#include "sweep.h"

void StartCurses()
{
#ifdef SWEEP_MOUSE
	mmask_t Mask;
#endif
	initscr();
	if (has_colors())
	{
		start_color();
		init_pair(1,COLOR_WHITE,COLOR_BLACK);
		init_pair(2,COLOR_BLUE,COLOR_BLACK);
		init_pair(3,COLOR_CYAN,COLOR_BLACK);
		init_pair(4,COLOR_GREEN,COLOR_BLACK);
		init_pair(5,COLOR_MAGENTA,COLOR_BLACK);
		init_pair(6,COLOR_RED,COLOR_BLACK);
		init_pair(7,COLOR_BLACK,COLOR_WHITE);
		init_pair(8,COLOR_BLUE,COLOR_WHITE);
		init_pair(9,COLOR_CYAN,COLOR_WHITE);
		init_pair(10,COLOR_GREEN,COLOR_WHITE);
		init_pair(11,COLOR_MAGENTA,COLOR_WHITE);
		init_pair(12,COLOR_RED,COLOR_WHITE);
	}
	noecho();
	keypad(stdscr, TRUE);
	intrflush(stdscr, TRUE);
	cbreak();
	nonl();

#ifdef SWEEP_MOUSE
	Mask=REPORT_MOUSE_POSITION|BUTTON1_CLICKED|BUTTON1_DOUBLE_CLICKED|BUTTON3_CLICKED;
	Mask=mousemask(Mask,NULL);
#endif
	return;
}

void PrintInfo()
{
	WINDOW* InfoWin;
	InfoWin=newwin(6,21,0,(COLS-INFO_W));
	wborder(InfoWin,CharSet.VLine,CharSet.VLine,CharSet.HLine,CharSet.HLine,
		CharSet.ULCorner,CharSet.URCorner,CharSet.LLCorner,CharSet.LRCorner);
	mvwprintw(InfoWin,1,2,"-=- FreeSweep -=-");
	mvwprintw(InfoWin,2,2,"by Gus! & Psilord");
	wmove(InfoWin,3,1);
	whline(InfoWin,CharSet.HLine,19);
	mvwprintw(InfoWin,4,2,"Hit \'?\' for help");
	move(0,0);
	wnoutrefresh(InfoWin);
	delwin(InfoWin);
	return;
}

void AskPrefs(GameStats* Game)
{
	char ValueBuffer[(L_MAX_W+L_MAX_H+3)];
	int Value=0, Status=0, CurrentLine=0;

	/* User input needs to be echoed to the creen at this point. */
	echo();

	CurrentLine=0;

	ValueBuffer[0]=0;
	/* Ask user for grid height. */
	mvprintw(CurrentLine,0,"Enter the grid height [%d]:",Game->Height);
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for Height.");
			mvclrtoeol(CurrentLine,(26+L_MAX_H));
		}
#if defined HAVE_LIBNCURSES
		mvgetnstr(CurrentLine,(26+L_MAX_H),ValueBuffer,L_MAX_H);
#else
		mvgetnstr(CurrentLine,(26+L_MAX_H),ValueBuffer,L_MAX_H+2);
#endif /* HAVE_LIBNCURSES */
		refresh();
		if (ValueBuffer[0]==0)
		{
			Status=1;
			mvprintw(CurrentLine,(26+L_MAX_H),"%d",Game->Height);
		}
97
		/* Maybe put help here? */
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
		else
		{
			Value=atoi(ValueBuffer);
			if (CheckHeight(Value)>0)
			{
				Game->Height=Value;
				Status=1;
			}
			else
			{
				Status=-1;
			}
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;
	ValueBuffer[0]=0;
	CurrentLine++;

	/* Now for width. */
	mvprintw(CurrentLine,0,"Enter the grid width [%d]:",Game->Width);
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for Width.");
			mvclrtoeol(CurrentLine,(25+L_MAX_W));
		}
#if defined HAVE_LIBNCURSES
		mvgetnstr(CurrentLine,(25+L_MAX_W),ValueBuffer,L_MAX_W);
#else
		mvgetnstr(CurrentLine,(25+L_MAX_W),ValueBuffer,L_MAX_W+2);
#endif /* HAVE_LIBNCURSES */
		refresh();
		if (ValueBuffer[0]==0)
		{
			Status=1;
			mvprintw(CurrentLine,(25+L_MAX_W),"%d",Game->Width);
		}
		else
		{
			Value=atoi(ValueBuffer);
			if (CheckWidth(Value)>0)
			{
				Game->Width=Value;
				Status=1;
			}
			else
			{
				Status=-1;
			}
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;
	ValueBuffer[0]=0;
	CurrentLine++;

	/* Now for number of mines or percentage. */
	mvprintw(CurrentLine,0,"Enter the number or percentage of mines [");
	if (Game->NumMines==0)
	{
		printw("%d%%]:",Game->Percent);
	}
	else
	{
		printw("%d]:",Game->NumMines);
	}
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for Mines.");
			mvclrtoeol(CurrentLine,(41+L_MAX_H+L_MAX_W));
		}
#if defined HAVE_LIBNCURSES
		mvgetnstr(CurrentLine,(41+L_MAX_H+L_MAX_W),ValueBuffer,(L_MAX_H+L_MAX_W));
#else
		mvgetnstr(CurrentLine,(41+L_MAX_H+L_MAX_W),ValueBuffer,(L_MAX_H+L_MAX_W)+2);
#endif /* HAVE_LIBNCURSES */
		refresh();
		/* If they accept the default. */
		if (ValueBuffer[0]==0)
		{
			if (Game->NumMines==0)
			{
				mvprintw(CurrentLine,(41+L_MAX_H+L_MAX_W),"%d%%",Game->Percent);
				Status=1;
			}
			else
			{
				/* Since height and width may have changed, check the */
				/* default number of mines to make sure it's still valid. */
				if (CheckNumMines(Game->NumMines,Game->Height,Game->Width)>0)
				{
					mvprintw(CurrentLine,(41+L_MAX_H+L_MAX_W),"%d",Game->NumMines);
					Status=1;
				}
				else
				{
					Status=-1;
				}
			}
		}
		else
		{
			Value=atoi(ValueBuffer);
			if (strchr(ValueBuffer,'%')==0)
			{
				/* The value is an actual number. */
				if (CheckNumMines(Value,Game->Height,Game->Width)>0)
				{
					Game->NumMines=Value;
					Game->Percent=0;
					Status=1;
				}
				else
				{
					Status=-1;
				}
			}
			else
			{
				/* The value is a percent. */
				Game->NumMines=0;
				if (CheckPercent(Value)>0)
				{
					Game->Percent=Value;
					Game->NumMines=0;
					Status=1;
				}
				else
				{
					Status=-1;
				}
			}
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;
	ValueBuffer[0]=0;
	CurrentLine++;

	/* For the Yes-or-no questions, user input is not echoed. */
	noecho();

	/* Now for the charater set. */
	mvprintw(CurrentLine,0,"Use the PC linedraw character set? [");
	if (Game->LineDraw==1)
	{
		printw("Y/n]:");
	}
	else
	{
		printw("y/N]:");
	}
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for character set.");
			mvclrtoeol(CurrentLine,42);
		}
		ValueBuffer[0]=mvgetch(CurrentLine,42);
		refresh();

		switch (ValueBuffer[0])
		{
			case '\n': case '\r':
				Status=1;
				if (Game->LineDraw==1)
				{
					mvprintw(CurrentLine,42,"Yes");
				}
				else
				{
					mvprintw(CurrentLine,42,"No");
				}
				break;

			case 'n': case 'N':
				Value=0;
				mvprintw(CurrentLine,42,"No");
				InitCharSet(Game,Value);
				Status=1;
				break;

			case 'y': case 'Y':
				Value=1;
				mvprintw(CurrentLine,42,"Yes");
				InitCharSet(Game,Value);
				Status=1;
				break;

			default:
#ifdef DEBUG_LOG
				fprintf(DebugLog, "Unknown character: %c\n", ValueBuffer[0]);
#endif
				Status=-1;
				break;
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;

	ValueBuffer[0]=0;
	CurrentLine++;

	/* Now for the default starting behavior. */
	mvprintw(CurrentLine,0,"Use FastStart mode for new games? [");
	if (Game->Fast>=1)
	{
		printw("Y/n]:");
	}
	else
	{
		printw("y/N]:");
	}
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for FastStart mode.");
			mvclrtoeol(CurrentLine,41);
		}
		ValueBuffer[0]=mvgetch(CurrentLine,41);
		refresh();
		switch(ValueBuffer[0])
		{
			case '\n': case '\r':
				Status=1;
				if (Game->Fast==1)
				{
					mvprintw(CurrentLine,41,"Yes");
				}
				else
				{
					mvprintw(CurrentLine,41,"No");
				}
				break;
		
			case 'n': case 'N':
				Game->Fast=0;
				mvprintw(CurrentLine,41,"No");
				Status=1;
				break;
			
			case 'y': case 'Y':
				Game->Fast=1;
				mvprintw(CurrentLine,41,"Yes");
				Status=1;
				break;
			
			default:
#ifdef DEBUG_LOG
				fprintf(DebugLog, "Unknown character: %c\n", ValueBuffer[0]);
#endif
				Status=-1;
				break;
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;

	ValueBuffer[0]=0;
	CurrentLine++;

	/* Now ask about the alert prefs. */
	mvprintw(CurrentLine,0,"Use Beep/Flash/No alert? [");
	switch (Game->Alert)
	{
		case BEEP: default:
			printw("B/f/n]:");
			break;
		case FLASH:
			printw("b/F/n]:");
			break;
		case NO_ALERT:
			printw("b/f/N]:");
			break;
	}

	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for Alert mode.");
			mvclrtoeol(CurrentLine,41);
		}
		ValueBuffer[0]=mvgetch(CurrentLine,34);
		refresh();
		switch(ValueBuffer[0])
		{
			case '\n': case '\r':
				Status=1;
				switch (Game->Alert)
				{
					case BEEP: default:
						mvprintw(CurrentLine,34,"Beep");
						break;
					case FLASH:
						mvprintw(CurrentLine,34,"Flash");
						break;
					case NO_ALERT:
						mvprintw(CurrentLine,34,"None");
						break;
				}
				break;
		
			case 'b': case 'B':
				Game->Alert=BEEP;
				mvprintw(CurrentLine,34,"Beep");
				Status=1;
				break;
			
			case 'f': case 'F':
				Game->Alert=FLASH;
				mvprintw(CurrentLine,34,"Flash");
				Status=1;
				break;
			
			case 'n': case 'N':
				Game->Alert=NO_ALERT;
				mvprintw(CurrentLine,34,"None");
				Status=1;
				break;
			
			default:
#ifdef DEBUG_LOG
				fprintf(DebugLog, "Unknown character: %c\n", ValueBuffer[0]);
#endif
				Status=-1;
				break;
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;

	ValueBuffer[0]=0;
	CurrentLine++;

	/* Ask about color. */
	mvprintw(CurrentLine,0,"Use Color if available? [");
	if (Game->Color>=1)
	{
		printw("Y/n]:");
	}
	else
	{
		printw("y/N]:");
	}
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid entry for Color mode.");
			mvclrtoeol(CurrentLine,31);
		}
		ValueBuffer[0]=mvgetch(CurrentLine,31);
		refresh();
		switch(ValueBuffer[0])
		{
			case '\n': case '\r':
				Status=1;
				if (Game->Color==1)
				{
					mvprintw(CurrentLine,31,"Yes");
				}
				else
				{
					mvprintw(CurrentLine,31,"No");
				}
				break;
		
			case 'n': case 'N':
				Game->Color=0;
				mvprintw(CurrentLine,31,"No");
				Status=1;
				break;
			
			case 'y': case 'Y':
				Game->Color=1;
				mvprintw(CurrentLine,31,"Yes");
				Status=1;
				break;
			
			default:
#ifdef DEBUG_LOG
				fprintf(DebugLog, "Unknown character: %c\n", ValueBuffer[0]);
#endif
				Status=-1;
				break;
		}
	}
	mvclrtoeol(LINES-1,0);
	Status=0;

	ValueBuffer[0]=0;
	CurrentLine++;




	/* Ask about saving these prefs. */
	mvprintw(CurrentLine,0,"Save these preferences? [Y/n]:");
	while (Status<=0)
	{
		if (Status<0)
		{
			beep();
			mvprintw(LINES-1,0,"Invalid response for saving preferences.");
			mvclrtoeol(CurrentLine,31);
		}
		ValueBuffer[0]=mvgetch(CurrentLine,31);
		refresh();

		switch (ValueBuffer[0])
		{
			case '\n': case '\r':
				Status=1;
				mvprintw(CurrentLine,31,"Yes");
				WritePrefsFile(Game);
				break;

			case 'n': case 'N':
				mvprintw(CurrentLine,31,"No");
				Status=1;
				break;

			case 'y': case 'Y':
				mvprintw(CurrentLine,31,"Yes");
				WritePrefsFile(Game);
				Status=1;
				break;

			default:
#ifdef DEBUG_LOG
				fprintf(DebugLog, "Unknown character: %c\n", ValueBuffer[0]);
#endif
				Status=-1;
		}
	}
	mvclrtoeol(LINES-1,0);

	/* Do one last refresh. */
	refresh();
	return;
}

void Help()
{
	WINDOW* HelpWin;
	int Input=0, CurrentLine=0, LinesLeft=0, CurrentY=0;
#define HELP_MESSAGES 13
	char* Messages[]=
	{
		"Arrow keys and vi-style movement keys move the cursor.",
		"The space bar exposes a square.",
		"\'f\' flags a space as a mine.",
		"\'r\' redraws the screen.",
		"\'0\' moves the cursor to the upper left corner.",
		"\'$\' moves the cursor to the lower right corner.",
		"\'c\' centers the cursor.",
		"\'.\' repeats the last command.",
		"\'a\' toggles the character set.",
		"\'b\' toggles the color settings.",
		"\'?\' displays this help screen.",
		"\'g\' displays the GNU General Public License.",
		"\'n\' starts a new game.",
		"\'x\' prompts for new game parameters.",
		"\'q\' quits the game.",
		"Any non-zero number multiplies the next action."
	};

	if ((HelpWin=newwin(0,0,0,0))==NULL)
	{
		perror("Help::newwin");
		exit(EXIT_FAILURE);
	}
	wborder(HelpWin,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark);
	mvwprintw(HelpWin,1,2,"Time out - Freesweep Help");
	mvwhline(HelpWin,2,1,CharSet.HLine,COLS-2);
	mvwprintw(HelpWin,3,2,"Useful Keys:");
	mvwprintw(HelpWin,LINES-1,1,"--Press \'q\' to quit, space for more, any other key to continue.--");

	/* Be sure to update this to account for all of the error messages. */
	LinesLeft=HELP_MESSAGES;
	while (LinesLeft> (LINES - 6))
	{
		CurrentY=4;
		while (CurrentY< (LINES -2 ))
		{
			mvwprintw(HelpWin,CurrentY++,8,Messages[CurrentLine++]);
			LinesLeft--;
		}
		/* Now get a keystroke to continue. */
		wmove(HelpWin,0,0);
		wrefresh(HelpWin);
		Input=wgetch(HelpWin);

		switch (Input)
		{
			case 'q':
				clear();
				refresh();
				endwin();
				exit(EXIT_SUCCESS);
				break;

			case ' ':
				wmove(HelpWin,3,0);
				wclrtobot(HelpWin);
				wborder(HelpWin,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark);
				mvwprintw(HelpWin,LINES-1,1,"--Press \'q\' to quit, space for more, any other key to continue.--");
				wrefresh(HelpWin);
				break;

			default:
				wclear(HelpWin);
				delwin(HelpWin);
				clear();
				noutrefresh();
				return;
				break;
		}
	}
	/* Now print the last few lines */
	wborder(HelpWin,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark);
	mvwprintw(HelpWin,LINES-1,1,"--Press \'q\' to quit, or any other key to continue.--");
	CurrentY=4;
	while (LinesLeft > 0)
	{
			mvwprintw(HelpWin,CurrentY++,8,Messages[CurrentLine++]);
			LinesLeft--;
	}
	wmove(HelpWin,0,0);
	wrefresh(HelpWin);
	Input=wgetch(HelpWin);

	switch (Input)
	{
		case 'q':
			clear();
			refresh();
			endwin();
			exit(EXIT_SUCCESS);
			break;

		default:
			wclear(HelpWin);
			delwin(HelpWin);
			clear();
			noutrefresh();
			return;
			break;
	}
	return;
}

int DrawBoard(GameStats* Game)
{
	int CoordX=0, CoordY=0, HViewable=0, VViewable=0;
	unsigned char CellVal;

	VViewable=((Game->LargeBoardY!=0)?(LINES-6):(Game->Height));
	HViewable=((Game->LargeBoardX!=0)?((COLS-INFO_W-2)/3):(Game->Width));

	for (CoordY=Game->FocusY;CoordY<(Game->FocusY+VViewable);CoordY++)
	{
		for (CoordX=Game->FocusX;CoordX<(Game->FocusX+HViewable);CoordX++)
		{
			wmove(Game->Board,(CoordY-Game->FocusY),3*(CoordX-Game->FocusX)+1);
			CellVal=0;
			GetMine(CoordX,CoordY,CellVal);
			switch (CellVal)
			{
				case UNKNOWN:
					waddch(Game->Board,'-');
					break;
				case EMPTY:
					waddch(Game->Board,CharSet.Space);
					break;
				case 1:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,2,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 2:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,3,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 3:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,4,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 4:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,5,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 5:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,6,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 6:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,6,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 7:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,6,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case 8:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,5,NULL);
					}
					waddch(Game->Board,(CellVal)+'0');
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				case MINE:
					waddch(Game->Board,CharSet.Mine);
					break;
				case MARKED:
					waddch(Game->Board,CharSet.Mark);
					break;
				case BAD_MARK:
					waddch(Game->Board,CharSet.FalseMark);
					break;
				case DETONATED:
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,6,NULL);
					}
					waddch(Game->Board,CharSet.Bombed);
					if (Game->Color != 0 && (has_colors() == TRUE))
					{
						wcolor_set(Game->Board,1,NULL);
					}
					break;
				default:
					break;
			}
		}
	}
	wmove(Game->Board,0,0);

	wnoutrefresh(Game->Board);
	return 0;
}

/* PrintBestTimes() opens
   each entry in a new window, BestTimesWin, which is deleted afterwards.
*/
void PrintBestTimes(char* Filename)
{
	int Input=0;
	WINDOW* BestTimesWin;

	if ((BestTimesWin=newwin(0,0,0,0))==NULL)
	{
		perror("PrintHighs::AllocWin");
		exit(EXIT_FAILURE);
	}
	nodelay(BestTimesWin,FALSE);
	wborder(BestTimesWin,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark,CharSet.Mark);
	mvwprintw(BestTimesWin,1,2,"Best times");
	mvwhline(BestTimesWin,2,1,CharSet.HLine,COLS-2);
	mvwprintw(BestTimesWin,3,4,"Username");
	mvwhline(BestTimesWin,4,4,CharSet.HLine,8);
	mvwprintw(BestTimesWin,3,15,"Height");
	mvwhline(BestTimesWin,4,15,CharSet.HLine,6);
	mvwprintw(BestTimesWin,3,25,"Width");
	mvwhline(BestTimesWin,4,25,CharSet.HLine,5);
	mvwprintw(BestTimesWin,3,34,"Mines");
	mvwhline(BestTimesWin,4,33,CharSet.HLine,7);
	mvwprintw(BestTimesWin,3,44,"Time");
	mvwhline(BestTimesWin,4,42,CharSet.HLine,9);
	mvwprintw(BestTimesWin,3,62,"Date");
	mvwhline(BestTimesWin,4,54,CharSet.HLine,24);

	mvwprintw(BestTimesWin,LINES-1,1,"--Press \'q\' to quit, any other key to continue.--");
	wmove(BestTimesWin,0,0);
	wrefresh(BestTimesWin);
	Input=wgetch(BestTimesWin);
#ifdef DEBUG_LOG
	fprintf(DebugLog, "Leaving Bets Times view with %c\n", Input);
	fflush(DebugLog);
#endif /* DEBUG_LOG */

	if (Input=='q')
	{
		clear();
		refresh();
		endwin();
		exit(EXIT_SUCCESS);
	}
	else
	{
		wclear(BestTimesWin);
		delwin(BestTimesWin);
		clear();
		noutrefresh();
	}
	return;
}

void DrawCursor(GameStats* Game)
{
	mvwaddch(Game->Board,(Game->CursorY-Game->FocusY),(3*(Game->CursorX-Game->FocusX)),'<');
	mvwaddch(Game->Board,(Game->CursorY-Game->FocusY),(3*(Game->CursorX-Game->FocusX))+2,'>');
	move(0,0);
	return;
}

void UndrawCursor(GameStats* Game)
{
/*	mvwaddch(Game->Board,Game->CursorY,(3*Game->CursorX),' ');*/
/*	mvwaddch(Game->Board,Game->CursorY,(3*Game->CursorX)+2,' ');*/
	mvwaddch(Game->Board,(Game->CursorY-Game->FocusY),(3*(Game->CursorX-Game->FocusX)),' ');
	mvwaddch(Game->Board,(Game->CursorY-Game->FocusY),(3*(Game->CursorX-Game->FocusX))+2,' ');
	move(0,0);
	return;
}

/* Pan() is respondsible for keeping the relevant part of the board displayed.
In addition, it also draws the border, including doing any "arrows" to
indicate that part of the board is not presently displayed.
The panning itself it triggered when the cursor gets within two squares of
the edge of the currently displayed area. */
int Pan(GameStats* Game)
{
	chtype Right,Left,Top,Bottom;
	int VViewable=0, HViewable=0;

	Right=Left=CharSet.VLine;
	Top=Bottom=CharSet.HLine;

	/* The basic border needs to be drawn regardless. */

	/* If the board isn't larger than the screen, no need to pan. */
	if ((Game->LargeBoardX + Game->LargeBoardY) == 0)
	{
		wborder(Game->Border,CharSet.VLine,CharSet.VLine,CharSet.HLine,CharSet.HLine,CharSet.ULCorner,CharSet.URCorner,CharSet.LLCorner,CharSet.LRCorner);
		wnoutrefresh(Game->Border);
		return 0;
	}

	/* Now to figure out which way to go... */
	VViewable=(LINES-6);
	HViewable=((COLS-INFO_W-2)/3)-1;

	/* See if the current cursor is even in the focus. */
	if ((Game->CursorY < Game->FocusY) ||
		((Game->FocusY+VViewable) < Game->CursorY) ||
		((Game->CursorY-Game->FocusY) < 2) ||
		(((Game->FocusY+VViewable)-Game->CursorY) <= 2))
	{
		CenterY(Game);
	}

	if ((Game->CursorX < Game->FocusX) ||
		((Game->FocusX+HViewable) < Game->CursorX) ||
		((Game->CursorX-Game->FocusX) < 2) ||
		(((Game->FocusX+HViewable)-Game->CursorX) < 2))
	{
		CenterX(Game);
	}

	/* Then draw the borders. */
	if (Game->LargeBoardX)
	{
		/* Check to see if the left side needs to be an arrow boundary. */
		if (Game->FocusX>0)
		{
			Left=CharSet.LArrow;
		}

		/* Check to see if the right side needs to be an arrow boundary. */
		if ((Game->FocusX + ((COLS-INFO_W-2)/3) ) < Game->Width )
		{
			Right=CharSet.RArrow;
		}
	}

	if (Game->LargeBoardY)
	{
		/* Check to see if the top side needs to be an arrow boundary. */
		if (Game->FocusY>0)
		{
			Top=CharSet.UArrow;
		}

		/* Check to see if the bottom side needs to be an arrow boundary. */
		if ((Game->FocusY + (LINES-6)) < Game->Height )
		{
			Bottom=CharSet.DArrow;
		}

	}

	wborder(Game->Border,Left,Right,Top,Bottom,CharSet.ULCorner,CharSet.URCorner,CharSet.LLCorner,CharSet.LRCorner);
	wnoutrefresh(Game->Border);

	return 0;
}

int Center(GameStats* Game)
{
	CenterX(Game);
	CenterY(Game);
	return 0;
}

int CenterX(GameStats* Game)
{
	int HOffset=0;

	if (Game->LargeBoardX)
	{
		HOffset=(((COLS-INFO_W-2)/3)-1)/2;
		
		if (Game->CursorX > (Game->Width - HOffset))
		{
			Game->FocusX=(Game->Width-(2*HOffset)-1);
		}
		else if ((Game->CursorX - HOffset) >= 0)
		{
			Game->FocusX=(Game->CursorX-HOffset);
		}
		else
		{
			Game->FocusX=0;
		}
	}

	return 0;
}

int CenterY(GameStats* Game)
{
	int VOffset=0;

	if (Game->LargeBoardY)
	{
		VOffset=(LINES-6)/2;

		if (Game->CursorY > (Game->Height - VOffset))
		{
			Game->FocusY=(Game->Height - (LINES-6));
		}
		else if ((Game->CursorY - VOffset) >= 0)
		{
			Game->FocusY = (Game->CursorY - VOffset);
		}
		else
		{
			Game->FocusY=0;
		}
	}

	return 0;
}