Advertisement
2002C Games #9489

Toxetris

Toxetris is a version of the classical game, TETRIS. The difference is that, the pieces are sliding, not jumping to the next square. Also you can pull down faster. It is a one week project. All the files are accesible. You can change them. The sliding pieces bring some problems: Most of the time, I have to check more positions for a piece if it is an empty place or not. Anyway, here it is... Pl ease write in your comments if you check it.

AI

Ringkasan AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kode Sumber
original-source
Upload
/*   VIEWBMP.C
  This file opens 16 color images and not 256 color images as
  TURBO C supports only 16 colors only.
email:	chingpongin@yahoo.co.in	
PLEASE VOTE ME !!!!
  */
#include <stdio.h>
#include <graphics.h>
#define BYTE unsigned char
#define WORD unsigned int
#define DWORD unsigned long

	 /*  STRUCTURE OF BITMAP FILE HEADER  */
/* FILE HEADER */
struct fileheader  
{
	 char bftype[2];
	 DWORD bfsize;
	 WORD bfreserved1;
	 WORD bfreserved2;
	 DWORD bfoffbits;
};
/* IMAGE INFORMATION HEADER */
struct bitmapinfoheader
{
	DWORD bisize;
	DWORD biwidth;
	DWORD biheight;
	WORD biplanes;
	WORD bibitcount;
	DWORD bicompression;
	DWORD bisizeimage;
	DWORD bixpelspermeter;
	DWORD biypelspermeter;
	DWORD biclrused;
	DWORD biclrimportant;
};

/* PALETTE HEADER  */
struct colortable
{
	 BYTE rgbblue;
	 BYTE rgbgreen;
	 BYTE rgbred;
	 BYTE rgbreserved;
 };

 /* COMMAND LINE ARGUMENTS */
void main(int argc,char *argv[ ])
{
 int gd=DETECT,gm;
 int i=0,colorno,loop,x,y,higher,lower,color;
 unsigned long size;
 unsigned char *ptr;
 FILE *fp;
 struct fileheader header;
 struct bitmapinfoheader info;
 struct colortable table;
 struct palettetype pal;
 /*  TO CHECK THE EXISTENCE OF FILE */
if((fp=fopen(argv[1],"rb"))==NULL)
 {
	clrscr( );
	gotoxy(10,10);
	printf("bmp file %s does not exist",argv[1]);
	gotoxy(10,20);
	printf("press ENTER to continue....");
	getchar( );
	clrscr( );
	exit(0);
 }
	 fseek(fp,0,SEEK_END);
	 size=ftell(fp);
	 fseek(fp,0,SEEK_SET);
	 fread(&header,1,sizeof(header),fp);
	 clrscr( );
 /* TO CHECK THE SIGNATURE OF THE BITMAP FILE "BM" */
		 if(header.bftype[0]!='B' || header.bftype[1]!='M')
		 {
 			 gotoxy(10,10);
			 printf("%s is not a BMP file",argv[1]);
			 gotoxy(10,20);
			 printf("press ENTER to continue....");
			 getchar();
			 clrscr();
			 exit(1);
		 }
	fread(&info,1,sizeof(info),fp);

	/*  if required the following BMP header informations can be displayed */
	printf("\n\t\t\tBITMAP FILE HEADER");
	printf("\nBMPFILE's SIGNATURE    = %c",header.bftype[0]);
	printf("%c",header.bftype[1]);
	printf("\nSIZE OF BITMAPFILE    = %ld",header.bfsize);
	printf("\nRESERVED1         = %d",header.bfreserved1);
	printf("\nRESERVED2         = %d",header.bfreserved2);
	printf("\nOFFSET TO THE IMAGE DATA = %ld",header.bfoffbits);
	printf("\n\n\t\t\tBITMAP INFO HEADER");
	printf("\n\nBITMAPINFO HEADER SIZE\t\t\t= %ld",info.bisize);
	printf("\nIMAGE WIDTH\t\t\t\t= %ld",info.biwidth);
	printf("\nIMAGE HEIGHT\t\t\t\t= %ld",info.biheight);
	printf("\nNo. OF PLANES IN THE IMAGE\t\t= %d (usually '1')",info.biplanes);
	printf("\nBITS REQUIRED TO REPRESENT A PIXEL\t= %d",info.bibitcount);
	printf("\nCOMPRESSION BIT\t\t\t\t= %ld (0 -if no Compression used)",info.bicompression);
	printf("\nBYTES REQUIRED FOR IMAGE DATA ALONE\t= %ld",info.bisizeimage);
	printf("\nbixpelspermeter\t\t\t\t= %ld",info.bixpelspermeter);
	printf("\nbiypelspermeter\t\t\t\t= %ld",info.biypelspermeter);
	printf("\nNo. OF COLORS USED\t\t\t= %ld",info.biclrused);
	printf("\nCOLOR IMPORTANT\t\t\t\t= %ld",info.biclrimportant);
	getch( );
	if(info.bibitcount==1)
		colorno=2;
	if(info.bibitcount==4)
		colorno=16;
	if(info.bibitcount==8)
		colorno=256;
	if(info.bibitcount==0)
		colorno=0;
	if(info.biclrused!=0)
		colorno=info.biclrused;

	initgraph(&gd,&gm,"");

	 /*  TO SET THE PALETTE */
	getpalette(&pal);
	for(loop=0;loop<colorno;loop++)
	{
	 fread(&table,1,sizeof(table),fp);
/*	 printf("\n\tPalette %3d",loop+1);
	 printf("\tBLUE=%3d",table.rgbblue);
	 printf("\tGREEN=%3d",table.rgbgreen);
	 printf("\tRED=%3d",table.rgbred);
	 printf("\tRESERVED=%3d",table.rgbreserved);*/
	 setrgbpalette(pal.colors[loop],table.rgbred,table.rgbgreen,table.rgbblue);
	 }
	 cleardevice( );
			 if(colorno==256)
			 {
					for(i=0;i<16;i++)
					 setrgbpalette(pal.colors[i],i*4,i*4,i*4);
			 }

	 if(info.bibitcount==4) 	 /*  FOR 16 COLOR IMAGE */
	 {
		for(y=info.biheight;y>=1;y--)
		 {
			for(x=1;x<=info.biwidth;x++)
			 {
				fread(ptr,1,1,fp);
				color=*ptr; /* Each byte contains two 4-bit data */
				lower=color&15;
				higher=color&240; higher=higher>>4;
				putpixel(x,y,higher);x++;
				putpixel(x,y,lower);
			 }
		 }
	 }

	 if(info.bibitcount==8) 	 /*  FOR 256 COLOR IMAGE */
	 {
		for(y=info.biheight;y>=1;y--)
		 {
			for(x=1;x<=info.biwidth;x++)
			 {
					fread(ptr,1,1,fp);
					color=*ptr;
					putpixel(x,y,color/16-1);
			 }
		 }
	 }
	 getchar( );
	 closegraph( );
	 fclose(fp);
 }
Komentar Asli (3)
Dipulihkan dari Wayback Machine