Exemple #1
0
Fichier : main.cpp Projet : sgh/aos
int main(void) {
	float angle = 0;
	int y;
	y = 100;
	UGui& gui = *UGui::instance();
	Drawable mainscreen(0 ,0, 320, 240);
	Drawable statusbar(0 ,0, 320, 30);
	Cross bladeview(0,30,320,120);
	Drawable mainfall(0,150,100,70);
	Drawable mast(105,150,110,70);
	Drawable rotation(220,150,100,70);
	Drawable quickmenu(0,220,320,20);
	

// 	Drawable menu(20 ,y-30, 200, 50);

	gtkfb_init();

	printf("sizeof Drawable: %lu\n", sizeof(Drawable));


	statusbar.setBG(0x555555);
	bladeview.setBG(0xFFFFFF);
	quickmenu.setBG(0x555555);

	mainfall.setBG(0x550000);
	mast.setBG(0x005500);
	rotation.setBG(0x000055);

// 	menu.setBG(0x005555);

	mainscreen.addChild(statusbar);
	mainscreen.addChild(bladeview);
	mainscreen.addChild(mainfall);
	mainscreen.addChild(mast);
	mainscreen.addChild(rotation);
	mainscreen.addChild(quickmenu);
	
// 	mainscreen.addChild(menu);

	gui.addRoot(mainscreen);
// 	gui.addRoot(menu);
	gui.eventLoop();

	for (;;) {
		int ch = getchar();

		switch (ch) {
			case 'A': mainfall.setBG(0xFF0000); break;
			case 'a': mainfall.setBG(0x550000); break;
			case 'B': mast.setBG(0x00FF00); break;
			case 'b': mast.setBG(0x005500); break;
			case 'C': rotation.setBG(0x0000FF); break;
			case 'c': rotation.setBG(0x000055); break;
			case 'f': rotation.focus(); break;
		}
		gui.eventLoop();
	}
}
Exemple #2
0
int main() {
	Screen mainscreen(vec2(80, 24));
	mainscreen.addBox(Renderbox(vec2(32, 8), vec2(16, 8), false, true, 220));
	mainscreen.addBox(Renderbox(vec2(32, 8), vec2(8, 3), true, true, 220));

	mainscreen.getBox(1)->writeLine("HELLO!", vec2(0, 0));

	std::string line;

	/*line = "0000001111100222";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 0));
	line = "0000022222232222";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 1));
	line = "0000222222222222";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 2));
	line = "0000332222222230";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 3));
	line = "0122222222222001";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 4));
	line = "2223322222222112";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 5));
	line = "0312122222222222";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 6));
	line = "0233222233300000";
	mainscreen.getBox(0)->writeLine(makePixels(line), vec2(0, 7));*/
	//line = "00000011111002220000022222232222000022222222222200003322222222300122222222222001222332222222211203121222222222220233222233300000";
	line = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
	Renderbox* box = mainscreen.getBox(0);
	Renderbox* box2 = mainscreen.getBox(1);
	box->writeLine(makePixels(line), vec2(0, 0));
	box->useColors(true);

	std::vector<vec2> colors = {
		vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(12, 0), vec2(12, 0), vec2(12, 0), vec2(12, 0), vec2(12, 0), vec2(0, 0), vec2(0, 0), vec2(6, 6), vec2(6, 6), vec2(6, 6),
		vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 12), vec2(0, 12), vec2(0, 12), vec2(6, 12), vec2(6, 12), vec2(0, 12), vec2(6, 12), vec2(0, 12), vec2(8, 12), vec2(8, 6), vec2(8, 6),
		vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(6, 6), vec2(0, 0), vec2(0, 6), vec2(6, 6), vec2(6, 6), vec2(6, 0), vec2(0, 6), vec2(6, 6), vec2(6, 6), vec2(6, 8), vec2(8, 8),
		vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(6, 6), vec2(6, 6), vec2(6, 6), vec2(6, 6), vec2(6, 0), vec2(6, 0), vec2(6, 0), vec2(8, 0), vec2(0, 8), vec2(0, 0),
		vec2(0, 0), vec2(8, 0), vec2(8, 8), vec2(8, 8), vec2(8, 8), vec2(8, 8), vec2(8, 8), vec2(8, 12), vec2(12, 8), vec2(8, 8), vec2(8, 8), vec2(8, 12), vec2(12, 8), vec2(0, 0), vec2(0, 0), vec2(8, 0),
		vec2(6, 6), vec2(6, 6), vec2(6, 8), vec2(0, 8), vec2(0, 8), vec2(12, 8), vec2(8, 8), vec2(12, 8), vec2(12, 12), vec2(12, 12), vec2(6, 12), vec2(12, 12), vec2(6, 12), vec2(12, 0), vec2(8, 0), vec2(8, 8),
		vec2(0, 0), vec2(0, 6), vec2(8, 0), vec2(8, 8), vec2(8, 0), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(8, 8), vec2(8, 8),
		vec2(0, 0), vec2(8, 8), vec2(0, 8), vec2(0, 8), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(12, 12), vec2(0, 12), vec2(0, 12), vec2(0, 12), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0), vec2(0, 0),
	};

	for (int i = 0; i < colors.size(); i++) {
		box->setColors(colors[i], i);
	}

	double t = 0;
	while (true) {
		std::this_thread::sleep_for(std::chrono::milliseconds(1000 / 60));
		t += 0.1;
		box2->setPosition(vec2(32, 8) + vec2(std::cos(t / 3) * 16 + std::sin(t / 2) * 16, std::sin(t * 2) * 8));
		box->setPosition(vec2(32, 8) + vec2(std::sin(t / 5) * 16 + std::cos(t / 2) * 16, std::cos(t) * 8));
		mainscreen.update();
	}
}
Exemple #3
0
main()
{
	union REGS ii, oo ;

	int BallX, BallY, Base1, Base2, dx = 1, dy = -1, OldX, OldY ;
	int totallayer[5] = { 10, 20, 30, 40, 50 }, max = 50, layer = 4 ;
	int i, flag = 0, speed = 25, score = 0, chance = 4, areareq ;

	char *m1, *m2 ;

	/* Function to initialise the graphics mode */
	initgraph ( &graphdriver, &graphmode, "e:\\tc\\bgi " ) ;
	mainscreen();
	initgraph ( &graphdriver, &graphmode, "e:\\tc\\bgi " ) ;
	/* get the maximum value of x and y coordinates of the screen */
	MaxX = getmaxx() ;
	MaxY = getmaxy() ;
	/* finding the center of the screen */
	MidX = MaxX / 2 ;
	MidY = MaxY / 2 ;


	/* create opening  screen and accept the level of the  player's  */
	level = screen() ;

	/* assign the  speed to ball as per the level chosen */
	switch ( level )
	{
		case 'M' :
		case 'm' :
			speed = 15 ;
			break ;

		case 'F' :
		case 'f' :
			speed = 10 ;
	}

	/* draw the four layer of bricks, the paddle and the ball */
	rectangle ( 0, 0, MaxX, MaxY - 12 ) ;
	bricks() ;
	rectangle ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 12 ) ;
	floodfill ( MidX, MaxY - 1 - 12, 12 ) ;
	circle ( MidX, MaxY - 13 - 12, 12 ) ;
	floodfill ( MidX, MaxY - 10 - 12, 12 ) ;

	/* memory allocation for storing the image of the paddle */
	areareq = imagesize ( MidX - 12, MaxY - 18, MidX + 12, MaxY - 8 ) ;
	m1 =((char*) malloc ( areareq )) ;

	/* memory allocation for storing the image of the ball */
	areareq = imagesize ( MidX - 25, MaxY - 7, MidX + 25, MaxY - 1 ) ;
	m2 =((char *) malloc ( areareq ) );

	/* if unable to alloacte the memory  */
	if ( m1 == NULL || m2 == NULL )
	{
		puts ( "Not Enough memory!!" ) ;
		exit ( 1 ) ;
	}

	/* image of the paddle and the ball is stored into allocated memory */
	getimage ( MidX - 12, MaxY - 7 - 12 - 12 + 1, MidX + 12, MaxY - 8 - 12, m1 ) ;
	getimage ( MidX - 25, MaxY - 7 - 12, MidX + 25, MaxY - 1 - 12, m2 ) ;

	/* store current position of the paddle and ball */
	Base1 = MidX - 25 ;
	Base2 = MaxY - 7 - 12 ;
	BallX = MidX - 12 ;
	BallY = MaxY - 7 - 12 + 1 - 12 ;

	/* display balls remaining ( initially 3 ) */
	gotoxy ( 45, 25 ) ;
	cout<< "Balls :"  ;
	for ( i = 0 ; i < 3 ; i++ )
	{
		circle ( 515 + i * 35, MaxY - 5, 12 ) ;
		floodfill ( 515 + i * 35, MaxY - 5, 12 ) ;
	}

	/* display starting score */
	gotoxy ( 1, 25 ) ;
	cout<< "Score:   ";
	gotoxy(16,25);
	cout<<score;

	/* select font and alignment for displaying text */
	settextjustify ( CENTER_TEXT, CENTER_TEXT ) ;
	changetextstyle ( GOTHIC_FONT, HORIZ_DIR, 4 ) ;

	while ( 1 )
	{
		flag = 0 ;

		/* saving current x and y coordinates of the ball */
		OldX = BallX ;
		OldY = BallY ;

		/* update ballx and bally to move the ball in correct direction */
		BallX = BallX + dx ;
		BallY = BallY + dy ;

		/* according to the position of ball the layer of bricks is determined */
		if ( BallY > 40 )
		{
			max = 50 ;
			layer = 4 ;
		}
		else
		{
			if ( BallY > 30 )
			{
				max = 40 ;
				layer = 3 ;
			}
			else
			{
				if ( BallY > 20 )
				{
					max = 30 ;
					layer = 2 ;
				}
				else
				{
					if ( BallY > 10 )
					{
						max = 20 ;
						layer = 1 ;
					}
					else
					{
						max = 10 ;
						layer = 0 ;
					}
				}
			}
		}

		/* if the ball hits the right boundary, move it to the left */
		if ( BallX > ( MaxX - 24 - 1 ) )
		{
			bell ( 5 ) ;
			BallX = MaxX - 24 - 1 ;
			dx = -dx ;
		}

		/* if the ball hits the left boundary, move it to the right */
		if ( BallX < 1 )
		{
			bell ( 5 ) ;
			BallX = 1 ;
			dx = -dx ;
		}

		/* if the ball hits the top boundary, move it down */
		if ( BallY < 1 )
		{
			bell (  5 ) ;
			BallY = 1 ;
			dy = -dy ;
		}

		/* if the ball is in the area of the bricks */
		if ( BallY < max )
		{
			/* if there is no brick  at the top of the ball */
			if ( bri[layer][ ( BallX + 10 ) / 32 ] == 1 )
			{
				/*  if the ball touches a brick */
				for ( i = 1 ; i <= 6 ; i++ )
				{
					/* check whether there is a brick to the right of the ball */
					if ( bri[layer][ ( BallX + i + 10 ) / 32 ] == 0 )
					{
						/* if there is a brick */
						BallX = BallX + i ;
						flag = 1 ;
						break ;
					}

					/* check whether there is a brick to the left of the ball */
					if ( bri[layer][ ( BallX - i + 10 ) / 32 ] == 0 )
					{
						BallX = BallX - i ;
						flag = 1 ;
						break ;
					}
				}

				/* if the ball does not touch a brick at the top, left or right */
				if ( !flag )
				{
					/* check if the ball has moved above the current layer */
					if ( BallY < totallayer[layer - 1] )
					{
						/* if so, change current layer appropriately */
						layer-- ;
						max = totallayer[layer] ;
					}

					/* restore the image of the ball at the old coordinates */
					putimage ( OldX, OldY, m1, OR_PUT ) ;

					/* erase the image at the old coordinates */
					putimage ( OldX, OldY, m1, XOR_PUT ) ;

					/* place the image of the ball at the new coordinates */
					putimage ( BallX, BallY, m1, XOR_PUT ) ;

					/*  delay for fewseconds*/
					delay ( speed ) ;

					/* carry on moving the ball */
					continue ;
				}
			}

			/* when ball touch the brick control comes to this point */
			bell ( 5 ) ;  /* play music */

			/* erase the touched brick  */
			delbrick ( ( BallX + 10 ) / 32, layer ) ;

			/* if the brick hit is on the extreme right */
			if ( ( BallX + 10 ) / 32 == 19 )
				line ( MaxX, 0, MaxX, 50 ) ;  /* redraw right boundary */

			/* if the brick hit is on the extreme left */
			if ( ( BallX + 10 ) / 32 == 0 )
				line ( 0, 0, 0, 50 ) ;  /* redraw left boundary */

			/* if the brick hit is in the topmost layer */
			if ( layer == 0 )
				line ( 0, 0, MaxX, 0 ) ;  /* redraw top boundary */

			/* set appropriate array element to 1 to indicate absence of brick */
			bri[layer][ ( BallX + 10 ) / 32 ] = 1 ;

			BallY = BallY + 1 ;  /* update the y coordinate */
			dy = -dy ;  /* change the current direction of the ball */
			score += 10 ;  /* increment the score by 10 */
			gotoxy ( 16, 25 ) ;
			cout<< score;  /* display latest score */

			/* if the first brick is hit during a throw*/
		}


		/* if  ball reached the bottom */
		if ( BallY > 180 - 12 )
		{

			/* if paddle missed the ball */
			if ( BallX < Base1 - 20 || BallX > Base1 + 50 )
			{
				/* continue the decrement of the ball */
				while ( BallY < 177 )
				{
					/* erase the image of the ball at the old coordinates */
					putimage ( OldX, OldY, m1, XOR_PUT ) ;

					/* put the image of the ball at the new coordinates */
					putimage ( BallX, BallY, m1, XOR_PUT ) ;

					/* introduce delay for fewseconds */
					delay ( speed ) ;

					/* saveing current x and y coordinates of the ball */
					OldX = BallX ;
					OldY = BallY ;

					/* update ballx and bally to move the ball in correct direction */
					BallX = BallX + dx ;
					BallY = BallY + dy ;
				}

				chance-- ;  /* decrement the total number of chances */
				score -= 10 ;  /* decrement 10 points for each ball lost */
				gotoxy ( 16, 25 ) ;
				cout<< score;  /* display latest score */
				bell ( 1 ) ;

				/* erase one  of the available balls */
				if ( chance )
					putimage ( 515 + ( chance - 1 ) * 35 - 12 , MaxY - 10, m1, XOR_PUT ) ;

				/* if the last ball is being played */
				if ( chance == 1 )
				{
					gotoxy ( 45, 25 ) ;
					cout<< "Last ball... careful!";
				}

				/* if all the balls are lost */
				if ( !chance )
				{
					gotoxy ( 45, 25 ) ;
					cout<<"Press any key to continue ...              " ;
					outtextxy ( MidX, MidY, "Better luck next time" ) ;
					bell ( 2 ) ;

					closegraph() ;
					restorecrtmode() ;
					closegraph();		/* Close the graphics mode */
					Initialize();		/* Intialize the graphics mode */
					setbkcolor(4);
					SayGoodbye(); 		/* Display the That's all Folks message */
					closegraph(); 		/* Return the system to text mode	*/
					exit ( 0 ) ;
				}
			}

			/* if ball is collected on paddle */
			bell ( 4 ) ;
			BallY = 180 - 12 ;  /* restore the y coordinate of ball */
			dy = -dy ;  /* move the ball upwards */
		}

		/* put the image of the ball at the old coordinates */
		putimage ( OldX, OldY, m1, OR_PUT ) ;

		/* erase the image of the ball at the old coordinates */
		putimage ( OldX, OldY, m1, XOR_PUT ) ;

		/* put the image of the ball at the upadted coordinates */
		putimage ( BallX, BallY, m1, XOR_PUT ) ;

		/* if all the bricks have been knockout */
		if ( score == 500 - ( ( 4 - chance ) * 20 ) )
		{
			outtextxy ( MidX, MidY, "Winner !!" ) ;

			if ( score < 600 )
				outtextxy ( MidX, MidY + 30, "Try to score 600" ) ;
			else
				outtextxy ( MidX, MidY + 30, " GREAT!" ) ;

			bell ( 2 ) ;

			closegraph() ;
			restorecrtmode() ;
			exit ( 0 ) ;
		}

		/* introduce delay for few seconds */
		delay ( speed ) ;

		/* if the key is pressed to move the paddle */
		if ( kbhit() )
		{
			/* interrupt issue to obtain the ascii and scan codes of key hit */
			ii.h.ah = 0 ;
			int86 ( 22, &ii, &oo ) ;

			/* put the image of the paddle at the old coordinates */
			putimage ( Base1, Base2, m2, OR_PUT ) ;

			/* erase the image of the paddle at the old coordinates */
			putimage ( Base1, Base2, m2, XOR_PUT ) ;

			/* if Esc key has been pressed */
			if ( oo.h.ah == 1 )
				exit ( 0 ) ;

			/* right arrow key */
			if ( oo.h.ah == 75 )
				Base1 = Base1 - 25 ;

			/* left arrow key */
			if ( oo.h.ah == 77 )
				Base1= Base1 + 25 ;

			/* if paddle goes beyond left boundary */
			if ( Base1 < 0 )
				Base1 = 0 ;

			/* if paddle goes beyond right boundary */
			if ( Base1 > 589 )
				Base1 = 589 ;

			/* put the image of the paddle at the proper position */
			putimage ( Base1, Base2, m2, XOR_PUT ) ;
		}

	}
	closegraph();
	Initialize();
	SayGoodbye(); 		/* Give user the closing screen 	*/
	closegraph(); 		/* Return the system to text mode	*/
	return(0);
}
Exemple #4
0
//start of main
void main()
{
//getch();
  initialize();      //initialises graphics mode
  setcolor(RED);     //sets text color red
  mainscreen();      //draws format for calculator
  mouse m;           //creates mouse object
  char string[100];
  int button,xx,yy,flag=0,index,i;
  int counter;
  int matrix[5][3]={{0,1,2},{3,4,5},{6,7,8},{9,10,11},{12,13,14}};
  int count=0;
  //setviewport(70,70,getmaxx()-80,100,1);
  //clearviewport();
  long double num[100],ii=0,rcount=0;
  drawscreen();         //creates output screen
  while(1)
  {


  counter=150;
  button=0;
  m.getmousepos(button,xx,yy);        //gets x&y position of mouse ptr

  if(((button & 1)==1)&&(flag==0))
    {
	for(int k=0;k<5;k++)
		{
		for(int x=400,i=0;x<=5*100;x+=50,i++)
			{
			if(xx>=x && xx<=x+30 && yy>=counter&&yy<=counter+20)
				{
				index=matrix[k][i];
				flag=1;
				//cout<<index;
				//delay(200);
				goto end;
				}
			}
		   counter+=40;
		}

    }

    end:
    //(430,350,500,375);
    if(((button & 1)==1)&&(flag==0))
    {
    if(xx>=430&&xx<=500&&yy>=350&&yy<=375)
    index=50;
    flag=1;
    }
    switch(index)
    {



    case 50:
	m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	 exit(0);
	}

    case 0:

	m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	//setcolor(WHITE);
       drawscreen();
	setcolor(WHITE);


	string[count]='9';
	num[ii]=9;
	ii++;
	//outtextxy(getmaxx()-(5*count+200),70,string);

	count++;
	string[count]='\0';
	outtextxy(getmaxx()-(200+5*count),70,string );
	//delay(0);
	flag=0;
	}
	break;

    case 1:

	m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	//setcolor(WHITE);
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"8" );


	string[count]='8';
	count++;
	string[count]='\0';
		num[ii]=8;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 2:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"7" );
	string[count]='7';
	count++;
	string[count]='\0';
		num[ii]=7;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 3:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"6" );
	string[count]='6';
	count++;
	string[count]='\0';
		num[ii]=6;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 4:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
       //	outtextxy(getmaxx()-100,70,"5" );
       string[count]='5';
	count++;
	string[count]='\0';
		num[ii]=5;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 5:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"4" );
	string[count]='4';
	count++;
	string[count]='\0';
		num[ii]=4;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 6:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"3" );
	string[count]='3';
	count++;
	string[count]='\0';
		num[ii]=3;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 7:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//+outtextxy(getmaxx()-100,70,"2" );
	string[count]='2';
	count++;
	string[count]='\0';
		num[ii]=2;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 8:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"1" );
	string[count]='1';
	count++;
	string[count]='\0';
		num[ii]=1;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 9:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"0" );
	string[count]='0';
	count++;
	string[count]='\0';
		num[ii]=0;
	ii++;
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 10:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"+" );
	string[count]='+';
	count++;
	string[count]='\0';
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 11:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);
	//outtextxy(getmaxx()-100,70,"-" );
	string[count]='-';
	count++;
	string[count]='\0';
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 12:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	clearscreen();

	setcolor(WHITE);
	//string[count]='/';
	//count++;
	//outtextxy(getmaxx()-100,70,"%" );
       //	string[count]='\0';
   //	outtextxy(getmaxx()-(200+5*count),70,string );
	count=0;
	flag=0;
	}
	break;
    case 13:
	  m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{
	drawscreen();
	setcolor(WHITE);

	string[count]='*';
	count++;
	string[count]='\0';
	outtextxy(getmaxx()-(200+5*count),70,string );
	flag=0;
	}
	break;
    case 14:
	char s1[100],s2[100];
	char * s11,s22;
	long double value=0;

	long double n1=0,n2=0;
	m.getmousepos(button,xx,yy);
	if(((button & 1)==0) && (flag==1))
	{

	drawscreen();
	setcolor(WHITE);


	for(int k=0;k<count;k++)
	{
	if(string[k]=='+'||string[k]=='-'||string[k]=='*'||string[k]=='-')
	{
	for(int p=0,q=k-1;p<k;p++,q--)
	{
	n1+=(num[p]*(pow(10,q)));

	}

	for(p=k,q=(ii-k-1);p<count-1;p++,q--)
	{

	 n2+=(num[p]*(pow(10,q)));

	}
	if(string[k]=='+')
	{
	value=(double)(n1+n2);

	break;
	}
	if(string[k]=='-')
	{
	value=(double)(n1-n2);
	break;
	}
	if(string[k]=='*')
	{
	value=(double)(n1*n2);
	break;
	}
       /*	if(string[k]=='cls')
	{
	value=(double)(n1/n2);
	break;
	}*/
	}
	}

	int ndig=0,dec,sign;
	s11 = fcvt(value,ndig, &dec, &sign);//converts a num into string
       drawscreen();
       setcolor(WHITE);
	outtextxy(getmaxx()-(5*strlen(s11)+200),70,s11);
	rcount++;
	flag=0;
	count=0;

	ii=0;
	}
	break;

    }

  }
  //getch();
  restorecrtmode();       //restores textmode
}
Exemple #5
0
int main(int argc, char *argv[])
{
	int rc, i, uid, n, c, ch, t, mtbl, line, offset;
	FILE *fp;
	char filename[64], inbuf[128], name[NATIONNMLEN+1], *p, *u;
	struct stat st_buf;


	/* set directory */

	if(argc > 1)
		if(chdir(argv[1]) == -1) {
			gmove(20,18);
			gprintf("Error Setting Directory %s\n", argv[1]);
			ggetch();
			gend();
			exit(1);
		}
	

	/* set up display */

	ginit();

	gmove(5, 10);
	gputs("WARTOOL 1.0 Game Editor for Solomoriah's WAR!");
	gmove(6, 10);
	gputs("Copyright 1994, J. Christopher Gonnerman");
	gmove(7, 10);
	gputs("All Rights Reserved.");

	
	/* load map file */

	rc = loadmap();

	if(rc != 0) {
		gmove(20,10);
		gprintf("Error Loading Map (%s)\n", errors[rc]);
		ggetch();
		gend();
		exit(1);
	}

	/* load game save */

	rc = loadsave();

	if(rc != 0) {
		gmove(20,10);
		gprintf("Error Loading Game Save (%s)\n", errors[rc]);
		ggetch();
		gend();
		exit(1);
	}

	/* execute master file */

	gmove(20,10);
	gputs("Reading Master Commands...  ");
	grefresh();

	fp = fopen(MASTERFL, "r");

	if(fp != NULL) {
		for(i = 0; fgets(inbuf, 128, fp) != NULL; i++) {
			rc = execpriv(inbuf);
			if(rc == 0) {
				if((i+1) % 10 == 0) {
					gmove(20,48);
					gprintf("%3d lines", i+1);
					grefresh();
				}
			} else {
				gmove(20,10);
				gprintf("Master Cmd Failed, Line %d, Code %d  ", i+1, rc);
				(void)ggetch();
				gend();
				exit(2);
			}
		}

		fclose(fp);
	}

	/* main loop */

	gmove(20,10);
	gputs("Press Any Key to Begin...  ");
	gclrline();

	ggetch();

	mainscreen();

	toolmain();

	unlink("game.bak");
	if(rename("game.sav", "game.bak") == 0)
		fp = fopen("game.sav", "w");
	else
		fp = fopen("game.sv!", "w");

	savegame(fp);

	fclose(fp);

	/* clean up */

	endwin();

	exit(0);
}