All pastes #2047666 Raw Edit

tower of jokes

public c v1 · immutable
#2047666 ·published 2011-04-18 08:17 UTC
rendered paste body
#include<stdio.h># include "iGraphics.h"int i,j,temp1,temp2,msize=0;int coun=-1,max=-1;double pos1x,pos1y,pos2x,pos2y,X_Y,ix,iy,lsiz,p;bool iup=false,iside=false,idown=false,press=true,fini=false;struct TOWER {	int ndic;	int dic[12];}tow[4];struct MOVE {	int from;	int to;	int id;}move[550];void mup(){	pos1y+=10;}void mside(){	if(temp1>temp2)X_Y-=(22.5)/2;	else X_Y+=(22.5)/2;}void mdown(){	p-=10;}void _se_ar_ch(){	++coun;	press=false;	iup=true;		temp1=move[coun].from;	temp2=move[coun].to;	msize=tow[temp1].dic[tow[temp1].ndic];		if(temp1==1)pos1x=225-msize*22.5;	else if(temp1==2)pos1x=675-msize*22.5;	else pos1x=1125-msize*22.5;	if(temp2==1)pos2x=225-msize*22.5;	else if(temp2==2)pos2x=675-msize*22.5;	else pos2x=1125-msize*22.5;	pos1y=tow[temp1].ndic*20+30;	pos2y=tow[temp2].ndic*20+30;	--tow[temp1].ndic;}void iDraw(){			iClear();	iSetColor(1000,0,80);	iFilledRectangle(0,0,1350,30);		for(i=217.5;i<=1117.5;i+=450)iFilledRectangle(i,0,15,300);		for(i=1;i<4;i++){		if(tow[i].ndic){			iy=10;			for(j=1;j<=tow[i].ndic;j++){				ix=225*(2*i-1)-22.5*tow[i].dic[j];				iy+=20;				lsiz=2*(22.5*tow[i].dic[j]);				iSetColor(0,0,1500);				iFilledRectangle(ix,iy,lsiz,20);				iSetColor(0,0,0);				iLine(ix,iy,ix+lsiz,iy);			}		}	}		iSetColor(0,0,1500);	if(press==true)_se_ar_ch();	if(iup==true){		iFilledRectangle(pos1x,pos1y,45*msize,20);		if(pos1y==400){			iup=false;			iside=true;			X_Y=pos1x;		}	}	if(iside==true){		iFilledRectangle(X_Y,400,45*msize,20);		if(X_Y==pos2x){			iside=false;			idown=true;			p=400;		}	}	if(idown==true){		iFilledRectangle(pos2x,p,45*msize,20);		if(p==pos2y){			idown=false;			press=true;			tow[temp2].dic[++tow[temp2].ndic]=msize;		}	}	if(coun==max)press=false;}void iMouseMove(int mx, int my){	//place your codes here}void iMouse(int button, int state, int mx, int my){	if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)	{		//place your codes here		}	if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)	{		//place your codes here		}}void iKeyboard(unsigned char key){	if(key == ' ')	{		press=true;	}}void iSpecialKeyboard(unsigned char key){	if(key == GLUT_KEY_END)	{		exit(0);		}}void towerofhanoi(int disks,int a,int b,int c){	if(disks!=0)	{		towerofhanoi(disks-1,a,c,b);		move[++max].from=a;		move[max].to=c;		move[max].id=disks;		towerofhanoi(disks-1,b,a,c);	}}int main(){	int n;	scanf("%d",&n);	tow[1].ndic=n;	tow[2].ndic=0;	tow[3].ndic=0;	for(i=n;i>=1;i--)tow[1].dic[n+1-i]=i;	towerofhanoi(n,1,2,3);	iSetTimer(10,mup);	iSetTimer(10,mside);	iSetTimer(10,mdown);	iInitialize(1350,680,"TOWER OF JOKES");	return 0;}