Exemplo n.º 1
0
Arquivo: gui.c Projeto: tuval10/Chess
/* 
*	SHOWS GRAPHICALLY THE GAME WINDOW WITH THE CHESSBOARD AND ALL THE PIECES ON 
*	THE RIGHT SIDE AND ON THE LEFT HAND SIDE WILL SHOW A SET OF 4 BUTTONS: 
*	RESTART GAME BUTTON, SAVE GAME BUTTON, RETURN TO THE MAIN MENU BUTTON AND A QUIT BUTTON
*	throws : malloc__error(), calloc_error(),SDL_LoadBMPError(), SDL_DisplayFormatError(), 
*   SDL_SetColorKeyError(), SDL_BlitSurfaceError(),SDL_FlipError() 
*	PRECONDITION: screen has no childs
*/
void showGame()
{
	Widget *mainWidget = NULL;
	mainWidget = BuildLabel(0, 0, 996, 692, "pics/main.bmp", screen);
	if(standart_fail){return;}

	if(mainGame->isLoadingAIMove)
	{
		BuildLabel(590, 25, 190, 146, "pics/loading.bmp", mainWidget);
		if(standart_fail){return;}
	}
	else{
		BuildButton(620, 25, 127, 49, "pics/RestartGame.bmp", mainWidget, handleRestart);
		if(standart_fail){return;}
		BuildButton(590, 100, 186, 49, "pics/SaveGame.bmp", mainWidget, showSavingMenu);
		if(standart_fail){return;}
		BuildButton(590, 175, 190, 49, "pics/MainMenu.bmp", mainWidget, handleMenu);
		if(standart_fail){return;}
		BuildButton(610, 475, 152, 90, "pics/quit.bmp", mainWidget, handleQuit);
		if(standart_fail){return;}
	}

	if(  isPawnBeforePromotionMarked() && (!standart_fail) )
	{
		
		showPromotionScreen();
		if(standart_fail){return;}
	}
	showCheckLabel();
	if(standart_fail){return;}
	BuildChessBoard(mainWidget, mainGame->gameInfo->boardPointer);
	if(standart_fail){return;}

	DrawWidgets(screen);
}
Exemplo n.º 2
0
Arquivo: gui.c Projeto: tuval10/Chess
/*
*	shows the menu for saving files
*	throws malloc errors, SDL_LoadBMPError(), SDL_DisplayFormatError(), SDL_SetColorKeyError(), SDL_BlitSurfaceError(), SDL_FlipError()
*/
void showSavingMenu(Widget *widget, int x, int y)
{
	Widget* saveMenu;
	int slotNum = 0;
	char *image_source;
	char *fullSlotFiles[]={"pics/1_0.bmp","pics/2_0.bmp","pics/3_0.bmp","pics/4_0.bmp","pics/5_0.bmp","pics/6_0.bmp","pics/7_0.bmp","pics/8_0.bmp","pics/9_0.bmp","pics/10_0.bmp"};
	char *emptySlotFiles[]={"pics/1_1.bmp","pics/2_1.bmp","pics/3_1.bmp","pics/4_1.bmp","pics/5_1.bmp","pics/6_1.bmp","pics/7_1.bmp","pics/8_1.bmp","pics/9_1.bmp","pics/10_1.bmp"};
	if(mainGame->isCheckMate==2) /* can't save during mate */
		return;
	DeleteWidgets(&screen->widgetChildren);
	saveMenu = BuildLabel(0, 0, 996, 692, "pics/main.bmp", screen);
	if(standart_fail) return;
	BuildLabel( 50, 25, 700, 113, "pics/saveDest.bmp", saveMenu);
	if(standart_fail) return;
	for(slotNum = 0; slotNum < SLOT_NUM; slotNum++)
	{
		image_source=(file_slots[slotNum].isFree)?emptySlotFiles[slotNum]:fullSlotFiles[slotNum];
		if(slotNum < 5){
			BuildButton( 100+125*slotNum, 175, 108, 48, image_source, saveMenu, SaveSlotClicked);
			if(standart_fail) return;
		}
		else{
			BuildButton( 100+125*(slotNum-5), 250,  108, 48, image_source, saveMenu, SaveSlotClicked);
			if(standart_fail) return;
		}
	}
	BuildButton(300, 325, 219, 65, "pics/cancel.bmp", saveMenu, mainGame->handleGameStartFunc);
	if(standart_fail) return;
	DrawWidgets(screen);
}
Exemplo n.º 3
0
ZoomWidget::ZoomWidget()
	:
	FaberWidget(B_HORIZONTAL)
{
	WidgetFrame* zoomView = new WidgetFrame();

	BLayoutBuilder::Group<>(zoomView, B_HORIZONTAL, 0.5f)
		.AddStrut(7.0f)
		.Add(BuildButton(B_TRANSLATE("Zoom in"), 
			MessageBuilder(FABER_ZOOM_IN), kZoomInIcon))

		.Add(BuildButton(B_TRANSLATE("Zoom out"),
			MessageBuilder(FABER_ZOOM_OUT), kZoomOutIcon))

		.Add(BuildButton(B_TRANSLATE("Zoom to selection"),
			MessageBuilder(FABER_ZOOM_SELECTION), kZoomToSelectionIcon))

		.Add(BuildButton(B_TRANSLATE("Zoom full wave"),
			MessageBuilder(FABER_ZOOM_FULL), kZoomFullWaveIcon))
		.AddStrut(7.0f)
	.End();

	BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0)
		.Add(zoomView);

	SetExplicitSize(BSize(140, 40));

}
Exemplo n.º 4
0
Arquivo: gui.c Projeto: tuval10/Chess
/* 
*	add the difficulty to the screen if needed in the settings menu
*	throws : malloc_error() 
*/
void showDifficultyMenu(){
	Widget *settingsMenu = screen->widgetChildren;
	game *g=mainGame->gameInfo;
	BuildLabel(25 , 250 , 329, 82, "pics/difficulty.bmp", settingsMenu);
	if(standart_fail){return;}
	BuildButton(25 , 350 , 71, 71, ((!(g->difficulty_best))&&(g->depth==1))?"pics/y1.bmp":"pics/1.bmp", settingsMenu, handle1);
	if(standart_fail){return;}
	BuildButton(100 , 350 , 71, 71, ((!(g->difficulty_best))&&(g->depth==2))?"pics/y2.bmp":"pics/2.bmp", settingsMenu, handle2);
	if(standart_fail){return;}
	BuildButton(175 , 350 , 71, 71, ((!(g->difficulty_best))&&(g->depth==3))?"pics/y3.bmp":"pics/3.bmp", settingsMenu, handle3);
	if(standart_fail){return;}
	BuildButton(250 , 350 , 71, 71, ((!(g->difficulty_best))&&(g->depth==4))?"pics/y4.bmp":"pics/4.bmp", settingsMenu, handle4);
	if(standart_fail){return;}
	BuildButton(325 , 350 , 171, 71, (g->difficulty_best)?"pics/yBest.bmp":"pics/best.bmp", settingsMenu, handleBest);
}
Exemplo n.º 5
0
Arquivo: gui.c Projeto: tuval10/Chess
/*
*	shows the settings menu for choosing game
*	throws : malloc_error(), SDL_LoadBMPError(), SDL_DisplayFormatError(), SDL_SetColorKeyError(), SDL_BlitSurfaceError(), SDL_FlipError()
*/
void ShowSettingsWindow(Widget* widget, int x, int y){
	int blackIsAI=false, whiteIsAI=false;
	Widget *settingsMenu = NULL;
	DeleteWidgets(&screen->widgetChildren);
	settingsMenu = BuildLabel(0, 0, 996, 692, "pics/main.bmp", screen);
	if(standart_fail){return;}
	BuildLabel(25 , 50 , 219, 82, "pics/white.bmp", settingsMenu);
	if(standart_fail){return;}
	BuildLabel(25 , 75+PIECE_SIZE , 219, 70, "pics/black.bmp", settingsMenu);
	if(standart_fail){return;}

	if(mainGame->gameInfo->gameMode==2){
		(mainGame->gameInfo->userColor==white)?(blackIsAI=true):(whiteIsAI=true);
		showDifficultyMenu(); 
		if(standart_fail){return;}
	}
	if(whiteIsAI){
		BuildButton(375 , 50 , PIECE_SIZE, PIECE_SIZE, "pics/whitePlayer.bmp", settingsMenu, handleWP);
		if(standart_fail){return;}
		BuildButton(400+PIECE_SIZE , 50 , PIECE_SIZE, PIECE_SIZE, "pics/yWhiteAI.bmp", settingsMenu, NULL);
		if(standart_fail){return;}
	}
	else{
		BuildButton(375 , 50 , PIECE_SIZE, PIECE_SIZE, "pics/yWhitePlayer.bmp", settingsMenu, NULL);
		if(standart_fail){return;}
		BuildButton(400+PIECE_SIZE , 50 , PIECE_SIZE, PIECE_SIZE, "pics/whiteAI.bmp", settingsMenu, handleWAI);
		if(standart_fail){return;}
	}
	if(blackIsAI){
		BuildButton(375 , 75+PIECE_SIZE , PIECE_SIZE, PIECE_SIZE, "pics/blackPlayer.bmp", settingsMenu, handleBP);
		if(standart_fail){return;}
		BuildButton(400+PIECE_SIZE , 75+PIECE_SIZE , PIECE_SIZE, PIECE_SIZE, "pics/yBlackAI.bmp", settingsMenu, NULL);
		if(standart_fail){return;}
	}
	else{
		BuildButton(375 , 75+PIECE_SIZE , PIECE_SIZE, PIECE_SIZE, "pics/yBlackPlayer.bmp", settingsMenu, NULL);
		if(standart_fail){return;}
		BuildButton(400+PIECE_SIZE , 75+PIECE_SIZE , PIECE_SIZE, PIECE_SIZE, "pics/blackAI.bmp", settingsMenu, handleBAI);
		if(standart_fail){return;}
	}
	BuildButton(375, 450, 123, 65, "pics/ok.bmp", settingsMenu, mainGame->handleGameStartFunc);
	if(standart_fail){return;}
	BuildButton(525, 450, 219, 65, "pics/cancel.bmp", settingsMenu, handleMenu);
	if(standart_fail){return;}
	DrawWidgets(screen);
}
Exemplo n.º 6
0
Arquivo: gui.c Projeto: tuval10/Chess
/* 
*	generates the main menu of the game 
*	throws malloc_errors(), SDL_LoadBMPError(), SDL_DisplayFormatError(), SDL_SetColorKeyError(), SDL_BlitSurfaceError(), SDL_FlipError()
*/
void showMenu()
{
	Widget* mainLabel = NULL;

	mainLabel = BuildLabel(0, 0, 996, 692, "pics/main.bmp", screen);
	if(standart_fail){return;}
	BuildLabel(50, 50, 700, 124, "pics/logo.bmp", mainLabel);
	if(standart_fail){return;}
	BuildButton(250, 250, 312, 90, "pics/newGame.bmp", mainLabel, ShowSettingsWindow);
	if(standart_fail){return;}
	BuildButton(250, 350, 312, 90, "pics/loadGame.bmp", mainLabel, showLoadingMenu);
	if(standart_fail){return;}
	BuildButton(325, 450, 152, 90, "pics/quit.bmp", mainLabel, handleQuit);
	if(standart_fail){return;}
	DrawWidgets(screen);
	if(standart_fail){return;}
}
Exemplo n.º 7
0
Arquivo: gui.c Projeto: tuval10/Chess
/* 
*	show promotion option on the game menu 
*	throws malloc errors
*/
void showPromotionScreen()
{
	int option, player=mainGame->gameInfo->nextTurnPlayerColor;
	Widget *mainWidget=screen->widgetChildren;
	if(mainGame->promoteTo==getQueenChar(player)) option=0;
	else if(mainGame->promoteTo==getBishopChar(player)) option=1;
	else if(mainGame->promoteTo==getRookChar(player)) option=2;
	else option=3;
	BuildButton(580+0*(PIECE_SIZE-20), 250, PIECE_SIZE, PIECE_SIZE, getPieceFileName(getQueenChar(player),option==0), mainWidget, updatePromotionToQueen);
	if(standart_fail){return;}
	BuildButton(580+1*(PIECE_SIZE-20), 250, PIECE_SIZE, PIECE_SIZE, getPieceFileName(getBishopChar(player),option==1), mainWidget, updatePromotionToBishop);
	if(standart_fail){return;}
	BuildButton(580+2*(PIECE_SIZE-20), 250, PIECE_SIZE, PIECE_SIZE, getPieceFileName(getRookChar(player),option==2), mainWidget, updatePromotionToRook);
	if(standart_fail){return;}
	BuildButton(580+3*(PIECE_SIZE-20), 250, PIECE_SIZE, PIECE_SIZE, getPieceFileName(getKnightChar(player),option==3), mainWidget, updatePromotionToKnight);
    if(standart_fail){return;}
}
Exemplo n.º 8
0
Arquivo: gui.c Projeto: tuval10/Chess
/*
* paints the ChessBoard and the pieces on it
* DrawBoard - the widget on which we'll be drawing the pieces on our board
* boardPointer - a pointer to the board we want to show graphically
* DrawBoard - the widget on which we'll be drawing the pieces on our board
* boardPointer - a pointer to the board we want to show graphically
*	throws : malloc__error(), calloc_error(),SDL_LoadBMPError(), SDL_DisplayFormatError(), 
*   SDL_SetColorKeyError(), SDL_BlitSurfaceError(),SDL_FlipError()
*/
void BuildChessBoard(Widget* DrawBoardOn, boardp boardPointer)
{
	int cols = 0, rows = 0 , x_axis, y_axis, isMarkedFlag=false;
	char piece;
	Widget* selectedTile = NULL;
	Widget* DrawBoard = BuildButton(15, 15, 564, 564, "pics/chessBoard.bmp", DrawBoardOn, handleBoardSelection);
	if(standart_fail) return;
     
	for(rows = 0; rows < BOARD_SIZE; rows++)
	{
		for(cols = 0; cols < BOARD_SIZE; cols++)
		{
			x_axis =5+  cols*PIECE_SIZE; /*get coordinate x for drawing */
			y_axis =5+ (BOARD_SIZE - 1 - rows)*PIECE_SIZE; /*get coordinate y for drawing */

			piece =(*boardPointer)[rows][cols];
			
			if(mainGame->pieceWasClicked){
				if(((isMarkedFlag)=(isMarked(rows,cols)))){
					if(standart_fail) return;
					selectedTile = BuildLabel( x_axis , y_axis, PIECE_SIZE, PIECE_SIZE, dark_square(rows,cols)?"pics/tile_w.bmp":"pics/tile_b.bmp", DrawBoard);
					if(standart_fail) return;
				}
				if( piece != EMPTY ){   
					  if(isMarkedFlag)
						 BuildButton(0 , 0 , PIECE_SIZE, PIECE_SIZE, getPieceFileName(piece,false), selectedTile, handleBoardSelection);
					  else{
						  if(mainGame->clickedPieceCol==cols&&mainGame->clickedPieceRow==rows)
							 BuildButton( x_axis , y_axis , PIECE_SIZE, PIECE_SIZE, getPieceFileName(piece,true), DrawBoard, handleBoardSelection);
						  else
							 BuildButton( x_axis , y_axis , PIECE_SIZE, PIECE_SIZE, getPieceFileName(piece,false), DrawBoard, handleBoardSelection);
					  }
				}
			}
			
			else 
			
				if( piece != EMPTY ){   
				 BuildButton( x_axis , y_axis , PIECE_SIZE, PIECE_SIZE, getPieceFileName(piece,false), DrawBoard, handleBoardSelection);
			}
			if(standart_fail) return;
		}
	}
}
Exemplo n.º 9
0
Arquivo: gui.c Projeto: tuval10/Chess
/*
*	shows the menu for loading files
*	throws malloc errors, SDL_LoadBMPError(), SDL_DisplayFormatError(), SDL_SetColorKeyError(), SDL_BlitSurfaceError(), SDL_FlipError()
*/
void showLoadingMenu(Widget *widget, int x, int y)
{
	Widget* loadMenu;
	int slotNum = 0;
	char *image_source;
	char *fullSlotFiles[]={"pics/1_0.bmp","pics/2_0.bmp","pics/3_0.bmp","pics/4_0.bmp","pics/5_0.bmp","pics/6_0.bmp","pics/7_0.bmp","pics/8_0.bmp","pics/9_0.bmp","pics/10_0.bmp"};
	char *emptySlotFiles[]={"pics/1_1.bmp","pics/2_1.bmp","pics/3_1.bmp","pics/4_1.bmp","pics/5_1.bmp","pics/6_1.bmp","pics/7_1.bmp","pics/8_1.bmp","pics/9_1.bmp","pics/10_1.bmp"};
	
	DeleteWidgets(&screen->widgetChildren);
	loadMenu = BuildLabel(0, 0, 996, 692, "pics/main.bmp", screen);
	if(standart_fail) return;
	BuildLabel( 50, 25, 700, 92, "pics/loadDest.bmp", loadMenu);
	if(standart_fail) return;
	for(slotNum = 0; slotNum < SLOT_NUM; slotNum++)
	{
		image_source=(file_slots[slotNum].isFree)?emptySlotFiles[slotNum]:fullSlotFiles[slotNum];
		if( file_slots[slotNum].isFree )
		{   /* if the slot is free means no file was saved to that slot, so we need to put a label */
			if(slotNum < 5){
				BuildLabel( 100+125*slotNum, 175, 108, 48, image_source, loadMenu);
				if(standart_fail) return;
			}
		    else{
				BuildLabel( 100+125*(slotNum-5), 250, 108, 48, image_source, loadMenu);
				if(standart_fail) return;
			}
	    }
		else
		{   
			if(slotNum < 5){
				BuildButton( 100+125*slotNum, 175, 108, 48, image_source, loadMenu, LoadSlotClicked);
				if(standart_fail) return;
			}
		    else{
				BuildButton( 100+125*(slotNum-5), 250,  108, 48, image_source, loadMenu, LoadSlotClicked);
				if(standart_fail) return;
			}
		}
	}
	BuildButton(300, 325, 219, 65, "pics/cancel.bmp", loadMenu, handleMenu);
	if(standart_fail) return;
	DrawWidgets(screen);
}