diff --git a/blackjack/Makefile b/blackjack/Makefile new file mode 100644 index 0000000..042989b --- /dev/null +++ b/blackjack/Makefile @@ -0,0 +1,33 @@ +PREFIX=/usr + +#OBJS specifies which files to compile as part of the project +OBJS = blackjack.c + +#CC specifies which compiler to use +CC = clang + +#COMPILER_FLAGS specifies the additional compilation options we're using +# -w suppress all warnings +COMPILER_FLAGS = -Wall + +#LINKER_FLAGS specifies the libraries we're linking against +LINKER_FLAGS = + +#OBJ_NAME specifies the name of our executable +OBJ_NAME= blackjack + +#This is the target that compiles our executable +all : $(OBJS) + $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME) +install : + mkdir -p ${PREFIX}/share/${OBJ_NAME}tuxc + cp tuxc ${PREFIX}/share/${OBJ_NAME}/ + cp -R package_managers ${PREFIX}/share/${OBJ_NAME}/ + ln -si ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME} ${PREFIX}/bin/${OBJ_NAME} +uninstall : + rm ${PREFIX}/bin/${OBJ_NAME} + rm ${PREFIX}/share/${OBJ_NAME}/${OBJ_NAME} + rm -r ${PREFIX}/share/${OBJ_NAME} +clean : + rm ${OBJ_NAME} + diff --git a/blackjack/blackjack b/blackjack/blackjack new file mode 100755 index 0000000..78a33a7 Binary files /dev/null and b/blackjack/blackjack differ diff --git a/blackjack/blackjack.c b/blackjack/blackjack.c new file mode 100644 index 0000000..b7e81b2 --- /dev/null +++ b/blackjack/blackjack.c @@ -0,0 +1,76 @@ +#include +#include +#include +#include + +#define CARD_MAX 51 +#define len(x) sizeof(x)/sizeof(x[0]) + +void print_deck (int *deckOfCards); +void shuffel (int *array, int n); + +static int rand_int(int n); + +int main (int argc, char *argv[]) +{ + int i; + int deckOfCards[CARD_MAX]; + + time_t t; + srand((unsigned) time(&t)); + + + /* Clubs > Diamonds > Hearts > Spades + * 0-12 13-25 26-38 39-51 + */ + + for (i = 0; i-1 ;i--){ + + j = rand_int(i + 1); + + tmp = array[j]; + array[j] = array[i]; + array[i] = tmp; + } +} + +static int rand_int(int n){ + + int limit = RAND_MAX - RAND_MAX % n; + + int rnd; + + do { + rnd=rand(); + } + while (rnd >= limit); + + return rnd % n; +} + + diff --git a/blackjack/copy_pasta_test.c b/blackjack/copy_pasta_test.c new file mode 100644 index 0000000..7cf2d89 --- /dev/null +++ b/blackjack/copy_pasta_test.c @@ -0,0 +1,79 @@ + #include + + #include + + #include + #include + + + + + + static int rand_int(int n) { + + int limit = RAND_MAX - RAND_MAX % n; + + int rnd; + + + + do { + + rnd = rand(); + + } + + while (rnd >= limit); + + return rnd % n; + + } + + + + void shuffle(int *array, int n) { + + int i, j, tmp; + + + + for (i = n - 1; i > 0; i--) { + + j = rand_int(i + 1); + + tmp = array[j]; + + array[j] = array[i]; + + array[i] = tmp; + + } + + } + + int main(void) + + { +time_t t; +srand((unsigned) time(&t)); + + + int i = 0; + + int numbers[50]; + + for (i = 0; i < 50; i++) + + numbers[i]= i; + + shuffle(numbers, 50); + + printf("\nArray after shuffling is: \n"); + + for ( i = 0; i < 50; i++) + + printf("%d\n", numbers[i]); + + return 0; + + } diff --git a/loki_sample/alpha-example/alpha-sdl.c b/loki_sample/alpha-example/alpha-sdl.c new file mode 100644 index 0000000..0fa3d9f --- /dev/null +++ b/loki_sample/alpha-example/alpha-sdl.c @@ -0,0 +1,95 @@ +/* Example of alpha blending with SDL. */ + +#include +#include +#include +#include + +int main() +{ + SDL_Surface *screen; + SDL_Surface *background; + SDL_Surface *image_with_alpha; + SDL_Surface *image_without_alpha; + SDL_Rect src, dest; + + /* init sdl and check for erro */ + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + printf("Unable to init SDL: %s\n", SDL_GetError()); + return 1; + } + + atexit(SDL_Quit); + + screen = SDL_SetVideoMode(800, 600, 16, 0); + if (screen == NULL) { + printf("Unable to set video mode: %s\n", SDL_GetError()); + return 1; + } + + /* Load image file */ + image_with_alpha = IMG_Load("with-alpha.png"); + if (image_with_alpha == NULL) { + printf("Unable to load image. \n"); + return 1; + } + + image_without_alpha = IMG_Load("without-alpha.png"); + if (image_without_alpha == NULL) { + printf("Unable to load image\n"); + return 1; + } + + background = IMG_Load("background.png"); + if (background == NULL) { + printf("Unable to load background.png.\n"); + return 1; + } + + /* Draw background. */ + + src.x = 0; + src.y = 0; + src.w = background->w; + src.h = background->h; + dest.x = 0; + dest.y = 0; + dest.w = background->w; + dest.h = background->h; + SDL_BlitSurface(background, &src, screen, &dest); + + /* draw first image with alpha */ + + SDL_SetAlpha(image_with_alpha, SDL_SRCALPHA, 0); + src.w = image_with_alpha->w; + src.h = image_with_alpha->h; + dest.w = src.w; + dest.h = src.h; + dest.x = 40; + dest.y = 50; + SDL_BlitSurface(image_with_alpha, &src, screen, &dest); + + /* Draw second image without alpha. Set to 50% transparence for entire surface. + */ + SDL_SetAlpha(image_without_alpha, SDL_SRCALPHA, 128); + src.w = image_without_alpha->w; + src.h = image_without_alpha->h; + dest.w = src.w; + dest.h = src.h; + dest.x = 180; + dest.y = 50; + SDL_BlitSurface(image_without_alpha, &src, screen, &dest); + + /* Ask SDL to update entire screen */ + SDL_UpdateRect(screen, 0, 0, 0, 0); + + SDL_Delay(10000); + + /* Free memory */ + SDL_FreeSurface(background); + SDL_FreeSurface(image_with_alpha); + SDL_FreeSurface(image_without_alpha); + + return 0; +} + diff --git a/loki_sample/alpha-example/background.png b/loki_sample/alpha-example/background.png new file mode 100644 index 0000000..f4a5445 Binary files /dev/null and b/loki_sample/alpha-example/background.png differ diff --git a/loki_sample/alpha-example/with-alpha.png b/loki_sample/alpha-example/with-alpha.png new file mode 100644 index 0000000..2567fe7 Binary files /dev/null and b/loki_sample/alpha-example/with-alpha.png differ diff --git a/loki_sample/alpha-example/without-alpha.png b/loki_sample/alpha-example/without-alpha.png new file mode 100644 index 0000000..1d87d98 Binary files /dev/null and b/loki_sample/alpha-example/without-alpha.png differ diff --git a/loki_sample/simple_blit_example/blitting-surface-sdl.c b/loki_sample/simple_blit_example/blitting-surface-sdl.c new file mode 100644 index 0000000..4c1991c --- /dev/null +++ b/loki_sample/simple_blit_example/blitting-surface-sdl.c @@ -0,0 +1,62 @@ +/* Example of simple blitting with SD>. */ + +#include +#include +#include + +int main() +{ + SDL_Surface *screen; + SDL_Surface *image; + SDL_Rect src, dest; + + /* init and check for errors*/ + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + printf("Unable to init SDL: %s\n", SDL_GetError()); + return 1; + } + + atexit(SDL_Quit); + + /* 256x256 hicolor (16-bit) */ + + screen = SDL_SetVideoMode(512, 512, 32, 0); // finding BMPs is hard // Doesn't work anyway... + //I seem to remem ber having htis problem before + if (screen == NULL) { + printf("Setting video mode failed: %s\n", SDL_GetError()); + return 1; + } + + /* Load bitmap file. SDL_LoadBMP returns a pointer to a new surface containing + * the loaded image. */ + image = SDL_LoadBMP("test-image.bmp"); + if (image == NULL) { + printf("Unable to load bitmap.\n"); + return 1; + } + + /* The SDL blitting function needs to know how much data + * to copy. We provide this with SDL_Rect structures, which + * define the source and destination rectangles. The areas + * shoul be the same; SDL does not currently handle image + * stretching. */ + + src.x = 0; + src.y = 0; + src.w = image->w; /* copy entire image */ + src.h = image->h; + + /* Draw the bitmap to the screen. It is not necessary to lock surfaces + * before blitting; SDL will handle that. */ + + SDL_BlitSurface(image, &src, screen, &dest); + + SDL_Delay(3000); + + /* Free memory allocated to the bitmap. */ + SDL_FreeSurface(image); + + return 0; +} + + diff --git a/loki_sample/simple_blit_example/test-image.bmp b/loki_sample/simple_blit_example/test-image.bmp new file mode 100644 index 0000000..dbe51c4 Binary files /dev/null and b/loki_sample/simple_blit_example/test-image.bmp differ diff --git a/loki_sample/simple_blit_example/test-image.png b/loki_sample/simple_blit_example/test-image.png new file mode 100644 index 0000000..9426f5d Binary files /dev/null and b/loki_sample/simple_blit_example/test-image.png differ