Ejemplo n.º 1
0
void main(int argc, char *argv[]){
	char keypress = START;
	int ch=0;
	int moves=0;
	char mc[10];

	set_graphics(VGA_320X200X256);

	PrintArrow(80, 105);

	do{	//Game loop
		PrintBorder();
		PrintMenu();
		keypress = (char)getch();

		if(keypress == QUIT){
			keypress = START;					//special condition so that it will not exit on Q press at menu
		}else if(keypress == UP || keypress == UP2){
			Erase(80, 120, 15, 15);
			PrintArrow(80, 105);
			ch = 0;
		}else if(keypress == DOWN || keypress == DOWN2){
			Erase(80, 100, 15, 15);
			PrintArrow(80, 125);
			ch = 1;
		}else if(keypress == ENTER || keypress == SPACE){
			switch(ch){
				case 0:
						EraseAll();
						NewGame(board);
						do{	//Inside-the-game loop
							PrintInstructions(180, 30);
							PrintBoard(30, 30);										//* Always prints update version of board at coordinates
							PrintBorder();														//* Always prints border
							sprintf(mc, "%d", moves);
							Erase(55, 175, 150, 15);
							write_text("Moves: ", 55, 175, WHITE, 0);
							write_text(mc, 120, 175, WHITE, 0);
							ShowHint();

							keypress=(char)getch();

							if(keypress == UP || keypress == UP2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == LEFT || keypress == LEFT2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == RIGHT || keypress == RIGHT2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == DOWN || keypress == DOWN2){
								//Erase(15, 15, 150, 150);
								MovePiece(keypress);
								moves++;
							}else if(keypress == QUIT){
								Erase(55, 175, 150, 15);
								write_text("Really exit? Y/N", 55, 175, WHITE, 0);
								do{
									keypress=(char)getch();
									if(keypress == YES){
										moves = 0;
										keypress = QUIT;
										break;
									}else if(keypress == NO){
										keypress = YES;
										Erase(55, 175, 150, 15);
										break;
									}
								}while(1);
							}else{
								Erase(55, 175, 150, 15);
								write_text("Invalid button!", 55, 175, WHITE, 0);
							}
							if(CheckWin(board)){
								EraseAll();
								write_text("You win!", 125, 85, WHITE, 0);
								moves = 0;
								keypress = QUIT;
							}
						}while(keypress != QUIT);
						EraseAll();
						PrintArrow(80, 105);
						keypress = START;
						break;
				case 1: keypress = QUIT;
						break;
				default: break;
			}
		}
		
	}while(keypress != QUIT);
	
	set_graphics(VGA_TEXT80X25X16);
	clrscr();
}
Ejemplo n.º 2
0
	void Renderer::reset_graphics()
	{
		set_graphics(GContainerSPtr());
	}
Ejemplo n.º 3
0
int main()
{
  
	char keypress = start;
	int i,j;
	char str[15];
	int champion = 0;

	set_graphics(VGA_320X200X256);
  	set_coordinates(X_coord, Y_coord); //initialize bulb coordinates

	do{
		erase(1,1,400,220);

	  	header(8,5); //print menu

		level=1; //initialize level
		champion = 0; //falsify championhood
		
		keypress=(char)getch();
		erase(1,1,400,220); //erase menu

		if(keypress==start){
		do{

			if(keypress == start){
				setup_level(); 
				row=0;
				col=0;
				flips=0;

				//update level display
				erase(25,125,40,30);
				write_text("0",25,125,WHITE,0);

			}		
			else
				print_board(X_coord, Y_coord);

			do{

				if (keypress=(char)getch()){
				
					// update selected bulb
					if(keypress==right_key){
						oldrow = row;
						oldcol = col;
						col = (col + 1) % maxcol;
					}
					
					else if(keypress==left_key){
						oldrow = row;
						oldcol = col;
						if(col <= 0)
							col = maxcol - 1;
						else
							col--;
					}
					
					else if(keypress==up_key){
						oldrow = row;
						oldcol = col;keypress=(char)getch();
						if(row <= 0)
							row = maxrow - 1;
						else
							row--;
					}
					
					else if(keypress==down_key){
						oldrow = row;
						oldcol = col;
						row = (row + 1) % maxrow;
					}
					
					else if(keypress == flip){				
						flips++;
						erase(25,125,30,30);
						sprintf(str,"%d",flips);
					   	write_text(str,25,125,WHITE,0);
						
						// flip bulbs
					
						// selected bulb
						if(board[row][col] == son){
							board[row][col] = soff;
							remaining_bulb--;
							flip_fxn(row, col);
						}
						else{
							board[row][col] = son;
							remaining_bulb++;
							flip_fxn(row, col);
						}
						
						// top
						if(row -1 >= 0){
							if(board[row-1][col] == on){
								board[row-1][col] = off;
								remaining_bulb--;
								flip_fxn(row-1, col);
							}
							else{
								board[row-1][col] = on;
								remaining_bulb++;
								flip_fxn(row-1, col);
							}
						}
						
						// down
						if(row + 1 < maxrow){
							if(board[row+1][col] == on){
								board[row+1][col] = off;
								remaining_bulb--;
								flip_fxn(row+1, col);
							}
							else{
								board[row+1][col] = on;
								remaining_bulb++;
								flip_fxn(row+1, col);
							}
						}
						
						// left
						if(col -1 >= 0){
							if(board[row][col-1] == on){
								board[row][col-1] = off;
								remaining_bulb--;
								flip_fxn(row, col-1);
							}
							else{
								board[row][col-1] = on;
								remaining_bulb++;
								flip_fxn(row, col-1);
							}
						}
						
						// right
						if(col + 1 < maxcol){
							if(board[row][col+1] == on){
								board[row][col+1] = off;
								remaining_bulb--;
								flip_fxn(row, col+1);
							}
							else{
								board[row][col+1] = on;
								remaining_bulb++;
								flip_fxn(row, col+1);
							}
						}
						
					}
					
					if(remaining_bulb <= 0){

						level++; //update level
						if(level==max_level){ //finished all puzzles

							write_text("Congratulations!",89,160,YELLOW,0);
							write_text("You finished all levels.",65,170,YELLOW,0);
							write_text("(Press any key)",101, 180,YELLOW,0);
							keypress=(char)getch();
							erase(1,1,350,280); //clear screen
							champion=1; //player is now champion

						}else{ //finished a puzzle
							write_text("Congratulations!",89,160,WHITE,0);
							write_text("Press any key",101, 170,WHITE,0);
							keypress=(char)getch();
							erase(80,160,150,40); //erase congratulations
							keypress = start;
						}
						break;
					}
					
					// update the display of the selected and previously selected
					if(keypress==right_key || keypress==left_key || keypress==up_key || keypress==down_key){
						board[row][col] = board[row][col] == on? son: soff;
						board[oldrow][oldcol] = board[oldrow][oldcol] == son? on: off;					
						edit_board();
					}
				}			
		      		
			} while (keypress != quit && keypress != reset && champion!=1);
				//continue while player is not quitting, restarting or champion

			if(champion==1){keypress = yes;}
			else if(keypress == quit){
				//prompt confirmation then erase message
				write_text("Do you want to exit? y/n ",60,160,WHITE,0); 
				keypress=(char)getch();
				erase(60,160,220,40);			
			}
			else if(keypress == reset){
				//prompt confirmation then erase message
				write_text("Do you want to restart? y/n ",50,160,WHITE,0);
				keypress=(char)getch();
				if(keypress == yes) keypress = start;
				erase(50,160,260,40);			
			}
			
			

			} while (keypress != yes);
		}
	} while (keypress != quit_game);

	set_graphics(VGA_TEXT80X25X16);
	clrscr();
}