1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
//Include SDL functions and datatypes
#include "SDL.h"
#include "SDL_ttf.h"
#include <string>
#include <stdlib.h>
#include <time.h>
#include <vector>
using namespace std;
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
const int X_SIZEOFMATRIX = 50;
const int Y_SIZEOFMATRIX = 50;
const int PERCENTDENSE = 70;
//function prototypes
SDL_Surface *load_image( std::string );
void apply_surface( int , int , SDL_Surface* , SDL_Surface* );
void seedArray(int[Y_SIZEOFMATRIX][X_SIZEOFMATRIX]);
bool displayLattice(int[Y_SIZEOFMATRIX][X_SIZEOFMATRIX]);
int checkForPath(int[Y_SIZEOFMATRIX][X_SIZEOFMATRIX]);
vector< vector<int> > processOpenList(vector< vector<int> >,vector< vector<int> >,int[Y_SIZEOFMATRIX][X_SIZEOFMATRIX]);
//Global Variables
SDL_Surface *screen = NULL;
SDL_Surface *message = NULL;
SDL_Event event;
TTF_Font *font = NULL;
SDL_Color textColor = {255, 255, 255 };
SDL_Color bgColor = {0,0,0};
bool renderBoard = true;
//The button Class
class Button
{
private:
//The attributes of the button
SDL_Rect box;
public:
//Initialize the variables
Button();
Button( int x, int y, int w, int h );
bool handle_events(bool playerTurn);
};
int main( int argc, char* args[] )
{
//Initialize all SDL stuff
bool quit = false;
SDL_Init( SDL_INIT_EVERYTHING );
TTF_Init();
font = TTF_OpenFont( "lazy.ttf", 20 );
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//Set the window caption
SDL_WM_SetCaption("Lab 1", NULL );
int lattice[Y_SIZEOFMATRIX][X_SIZEOFMATRIX];
seedArray(lattice);
message = TTF_RenderText_Shaded( font, "Press enter to solve",bgColor, textColor );
int numPaths = 0;
bool foundIt = false;
//While the user hasn't quit
while( quit == false )
{
//Something has been done
while( SDL_PollEvent( &event ) )
{
//If the user closed the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
if(event.type == SDL_KEYDOWN)
{
if(event.key.keysym.sym == SDLK_s)
{
message = TTF_RenderText_Shaded( font, "!!!!!!!!!!",bgColor, textColor );
renderBoard = true;
numPaths = checkForPath(lattice);
if(numPaths > 0){foundIt =true;}
}
}
}
if(foundIt)
{
string msg("Path Exisits ");
message = TTF_RenderText_Shaded( font, msg.c_str(), bgColor, textColor );
}
//Render the screen
if(renderBoard)
{
renderBoard = displayLattice(lattice);
}
apply_surface(300,450,message,screen);
SDL_Flip(screen);
}
return 0;
}
void seedArray(int Matrix[Y_SIZEOFMATRIX][X_SIZEOFMATRIX])
{
//removed for char count
}
bool displayLattice(int Matrix[Y_SIZEOFMATRIX][X_SIZEOFMATRIX])
{
//char count
}
int checkForPath(int Matrix[Y_SIZEOFMATRIX][X_SIZEOFMATRIX])
{
//see above
}
vector< vector<int> > processOpenList(vector< vector<int> > open, vector< vector<int> > closed, int Matrix[Y_SIZEOFMATRIX][X_SIZEOFMATRIX])
{
//see above
}
SDL_Surface *load_image( std::string filename )
{
SDL_Surface* loadedImage = NULL;
SDL_Surface* optimizedImage = NULL;
loadedImage = SDL_LoadBMP( filename.c_str() );
if( loadedImage != NULL )
{
optimizedImage = SDL_DisplayFormat( loadedImage );
SDL_FreeSurface( loadedImage );
}
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
SDL_Rect offset;
offset.x = x;
offset.y = y;
SDL_BlitSurface( source, NULL, destination, &offset );
};
|