You are on page 1of 4

#include <stdio.

h>
#include <string.h>
#include "Karte.h"
#include "Functions.h"
#include "vkliste.h"
int gameplay(KARTE* deck, double* x, double*y)
{

KARTE* head = NULL;


KARTE* e;
KARTE* head_dealer = NULL;
PLAYER hand;
hand.player_ace = 0;
hand.player_hand = 0;
DEALER hand_D;
hand_D.dealer_ace = 0;
hand_D.dealer_hand = 0;

KARTE* e_dealer;
int result,l = 2, i = 0,k = 0;

char c;
char space;

printf("Du hast %.2lf Dollars.\nSchliesse eine Wette ab!\n",*x);


do {
rewind(stdin); //Wegen ungewuenschte Eingabe
scanf("%lf", y);
if (*y < ((*x) / 2)||(*y>*x)) {
printf("NEIN!!!! Nochmal!\n");
}
} while (*y <= 0 || *y > *x||*y<(*x)/2);
/*fuer den spieler*/

for (k; k < 2; k++) {


e = create_list_element();
strcpy(e->typ, deck[i].typ);
strcpy(e->farbe, deck[i].farbe);
e->wert = deck[i].wert;
hand.player_hand = hand.player_hand + deck[i].wert;
if (deck[i].wert == 11) {
hand.player_ace = hand.player_ace + 1;
}
add_element(&head, e);
i=i+2;
}
print_liste(head);

/*fuer das dealer*/


i = 1;
for (k = 0; k < 2; k++) {
e_dealer = create_list_element();
strcpy(e_dealer->typ, deck[i].typ);
strcpy(e_dealer->farbe, deck[i].farbe);
e_dealer->wert = deck[i].wert;
hand_D.dealer_hand = hand_D.dealer_hand + deck[i].wert;
if (deck[i].wert==11) {
hand_D.dealer_ace = hand_D.dealer_ace + 1;
}
add_element(&head_dealer, e_dealer);
i = i+2;
}
i=4;

optimize_player(&hand);
optimize_dealer(&hand_D);
result = check_player(hand, hand_D, head_dealer);
if (result == 1) {
result= final_check(hand,hand_D);
del_list(head);
del_list(head_dealer);
return result;
}
print_element_dealer(head_dealer);
printf("************************\n");
printf("carte oder stehen? (c/s)\n");
do {
rewind(stdin);
scanf("%c%c", &c,&space);
if((c != 'c') && (c != 's')||space!='\n'){
printf("c oder s!\n");
}
} while ((c != 'c') && (c != 's')||space!='\n');
if (c == 'c') {
for (l; ; ++l) {
++i;
e = create_list_element();
strcpy(e->typ, deck[i].typ);
strcpy(e->farbe, deck[i].farbe);
e->wert = deck[i].wert;
hand.player_hand = hand.player_hand + deck[i].wert;
if (deck[i].wert == 11) {
hand.player_ace = hand.player_ace + 1;
}
optimize_player(&hand);
add_element(&head, e);
print_liste(head);
++i;
result = check_player(hand, hand_D, head_dealer);
if (result == 1) {
del_list(head);
del_list(head_dealer);
return 1;
}
if (result == 2) {
del_list(head);
del_list(head_dealer);
return 2;
}
printf("carte oder stehen? \n(c/s)");
do {
rewind(stdin);
scanf("%c%c", &c,&space);
if((c != 'c') && (c != 's')||space!='\n'){
printf("c oder s!!");
}
} while ((c != 'c') && (c != 's')||space!='\n');
if (c == 's') {
break;
}
}
}
if (c == 's') {

print_liste_dealer(head_dealer);
result=check_dealer(hand_D);
if (result == 1) {
del_list(head);
del_list(head_dealer);
return 1;
}
if (result == 2) {
del_list(head);
del_list(head_dealer);
return 2;
}

while ( hand_D.dealer_hand<17)
{
++i;
e_dealer = create_list_element();
strcpy(e_dealer->typ, deck[i].typ);
strcpy(e_dealer->farbe, deck[i].farbe);
e_dealer->wert = deck[i].wert;
hand_D.dealer_hand = hand_D.dealer_hand + deck[i].wert;
if (deck[i].wert == 11) {
hand_D.dealer_ace = hand_D.dealer_ace + 1;
}
optimize_dealer(&hand_D);
add_element(&head_dealer, e_dealer);
print_liste_dealer(head_dealer);
result=check_dealer(hand_D);

switch (result) {
case 1:
del_list(head);
del_list(head_dealer);
return 1;
case 2:
del_list(head);
del_list(head_dealer);
return 2;
default:
break;
}
}
result=final_check(hand, hand_D);
switch (result) {
case 2:
del_list(head);
del_list(head_dealer);
return 2;
case 1:
del_list(head);
del_list(head_dealer);
return 1;
default:
break;
}
del_list(head);
del_list(head_dealer);
return 0; //unentschieden

You might also like