File: image.c

package info (click to toggle)
freesweep 0.88-4.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 404 kB
  • ctags: 267
  • sloc: ansic: 3,813; sh: 2,460; makefile: 112
file content (51 lines) | stat: -rw-r--r-- 1,675 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
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
/**********************************************************************
*  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.                                                       *
*                                                                     *
*  $Id: image.c,v 1.2 2000/11/03 21:28:49 hartmann Exp $
*                                                                     *
**********************************************************************/

#include "sweep.h"

void SaveGameImage(GameStats* Game, char *fname)
{
	int width, height;
	unsigned char value;
	FILE *fo = NULL;

	fo = xfopen(fname, "w");
	
	/* dump the stats out */
	fprintf(fo, "P6\n%d\n%d\n255\n", Game->Width, Game->Height);
	
	for ( height = 0 ; height < Game->Height ; height++ ) {
		for ( width = 0 ; width < Game->Width ; width++ ) {
			if (( abs(width - Game->CursorX) < 2 ) && ( abs( Game->CursorY - height) < 10 )) {
				fwrite("\xff\x00\x00", 1, 3, fo);
			} else if (( abs(width - Game->CursorX) < 10 ) && ( abs(Game->CursorY - height) < 2 )) {
				fwrite("\xff\x00\x00", 1, 3, fo);
			} else {
				GetMine(width, height, value);
				switch ( value ) {
					case UNKNOWN: case MINE:
						fwrite("\x00\x00\x00", 1, 3, fo);
						break;
					case MARKED: case BAD_MARK:
						fwrite("\x00\x00\xff", 1, 3, fo);
						break;
					case DETONATED:
						fwrite("\xff\x00\x00", 1, 3, fo);
						break;
					case EMPTY: default:
						fwrite("\xff\xff\xff", 1, 3, fo);
						break;
				}
			}
		}
	}

	fclose(fo);
}