Added stuff

This commit is contained in:
Logen Kain 2016-11-07 19:35:17 -07:00
parent 468b5dc71f
commit 8ce7637a0c
11 changed files with 345 additions and 0 deletions

33
blackjack/Makefile Normal file
View File

@ -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}

BIN
blackjack/blackjack Executable file

Binary file not shown.

76
blackjack/blackjack.c Normal file
View File

@ -0,0 +1,76 @@
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#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<CARD_MAX; i++){
deckOfCards[i]=i;
}
shuffel(deckOfCards, CARD_MAX);
print_deck(deckOfCards);
return 0;
}
// Add a starting position. I can have a variable that simply means "continue drawing/printing cards from here"
void print_deck(int *deckOfCards){
int i;
for (i = 0; i<CARD_MAX; i++){
printf("%d\n", deckOfCards[i]);
}
}
void shuffel (int *array, int n){
int i, j, tmp;
for (i=n; 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;
}

View File

@ -0,0 +1,79 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
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;
}

View File

@ -0,0 +1,95 @@
/* Example of alpha blending with SDL. */
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <stdio.h>
#include <stdlib.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,62 @@
/* Example of simple blitting with SD>. */
#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
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;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB