-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_functions.c
126 lines (114 loc) · 2.83 KB
/
game_functions.c
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
//
// Created by raeen on 1/25/2022.
//
#include "game_functions.h"
#include "definition.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
void swap (int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void randomize ()
{
srand ( time(NULL) );
int n = 8;
for (int i = 1; i <= 8; i++){
hand_array[i-1] = i;
}
for (int i = n-1; i > 0; i--)
{
int j = rand() % (i+1);
swap(&hand_array[i], &hand_array[j]);
}
}
void hand_linked_list_maker(){
for (int i=0; i < 4; i++){
struct character_struct* new_node = (struct character_struct*)malloc(sizeof(struct character_struct));
new_node->playable_character = hand_array[i];
new_node->next = odd_hand;
odd_hand = new_node;
free(new_node);
}
for (int i=4; i < 8;i++){
struct character_struct* new_node = (struct character_struct*)malloc(sizeof(struct character_struct));
new_node->playable_character = hand_array[i];
new_node->next = even_hand;
even_hand = new_node;
free(new_node);
}
}
void set_jack(){
randomize();
jack = hand_array[0];
if (jack == 0){
strcpy(jack_name, "SH");
}
else if (jack == 1){
strcpy(jack_name, "JW");
}
else if (jack == 2){
strcpy(jack_name, "JS");
}
else if (jack == 3){
strcpy(jack_name, "JL");
}
else if (jack == 4){
strcpy(jack_name, "MS");
}
else if (jack == 5){
strcpy(jack_name, "SG");
}
else if (jack == 6){
strcpy(jack_name, "WG");
}
else if (jack == 7){
strcpy(jack_name, "JB");
}
printf("Jack is set to Character %s\n", jack_name);
}
void show_jack(){
printf("Jack is %s", jack_name);
}
void play_character(){
static int number_of_hand = 1;
if (number_of_hand % 2 == 1){
round_player_int = even_hand->playable_character;
even_hand = even_hand->next;
number_of_hand += 1;
}
else {
round_player_int = odd_hand->playable_character;
odd_hand = odd_hand->next;
number_of_hand += 1;
}
if (round_player_int == 1){
strcpy(round_player_name, "SH");
}
else if (round_player_int == 2){
strcpy(round_player_name, "JW");
}
else if (round_player_int == 3){
strcpy(round_player_name, "JS");
}
else if (round_player_int == 4){
strcpy(round_player_name, "JL");
}
else if (round_player_int == 5){
strcpy(round_player_name, "MS");
}
else if (round_player_int == 6){
strcpy(round_player_name, "SG");
}
else if (round_player_int == 7){
strcpy(round_player_name, "WG");
}
else if (round_player_int == 8){
strcpy(round_player_name, "JB");
}
printf("This round player is %s\n", round_player_name);
}