-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathS13B_Esperanza_MP-3.c
1539 lines (1339 loc) · 46.4 KB
/
S13B_Esperanza_MP-3.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************
This is to certify that this project is my own work, based on my personal efforts in studying and applying the concepts learned.
I have constructed the functions and their respective algorithm and corresponding code by myself. The program was run, tested,
and debugged by my own efforts. I further certify that I have not copied in part or whole or otherwise plagiarized the work of
other students and/or persons.
Franciz Emmanuelle Angelo L. Esperanza, DLSU ID# 12179922
******************************************************************/
/*
Description: This program runs a game called Doggos, Ladders, Slides, and U-Turns. It is a game similar to Snakes and Ladders
and it can be played by 2-5 players. Players need to roll a pair of 10-sided die to progress through the game and the chance
to encounter objects is determined by another 10-sided die. The game ends when a player reaches tile 100.
Programmed by: Franciz Emmanuelle Angelo L. Esperanza S13B
Last modified: 06 Feb 2022
Version: 1.2
[Acknowledgements: https://developer.gnome.org/documentation/guidelines/programming/coding-style.html#whitespace
https://devdocs.io/c/
https://www.cplusplus.com/reference/cstdlib/strtol/
https://www.geeksforgeeks.org/fgets-gets-c-language/
https://www.geeksforgeeks.org/memset-c-example/
edx's C Programming: Language Foundations]
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
// FUNCTION PROTOTYPES
int roll10SidedDie ();
int getSequence (int playerCount);
int updateSequence (int nSequence,
int playerCount);
int getCurrentPlayer (int nSequence,
int playerCount);
int getCurrentRow (int row [],
int *position);
int getCurrentColumn (int column [],
int *position);
int getTileNumber (int *rowRoll,
int *columnRoll,
int row [],
int column []);
int isValidPlayerCount (int playerCount);
int isItDouble5 (int firstRoll,
int secondRoll);
int isItDouble3 (int firstRoll,
int secondRoll);
int getDouble3Tile (int *firstRoll,
int *secondRoll,
int row [],
int column [],
int *startTile);
int getDoggoMovement (int *rowRoll,
int *columnRoll,
int row [],
int column []);
int getLadderMovement (int *rowRoll,
int *columnRoll,
int row [],
int column [],
int position);
int getSlideMovement (int *rowRoll,
int *columnRoll,
int row [],
int column [],
int position);
int getUTurnMovement (int startTile);
int getRow10Movement (int *firstRoll,
int startTile);
void fillBoard (int boardSpace []);
void fillRow (int row []);
void fillColumn (int column []);
void getObjectCount (int *objectRoll,
int objectCount [],
int currentPlayer);
void displayObjectMovement (int *objectRoll,
int *position,
int rowRoll,
int columnRoll,
int row[],
int column [],
int startTile);
void getFarthestObject (int nFarthestObject [],
int positionPreObject,
int position,
int *objectRoll,
int currentPlayer);
void doObjectRoll (int row [],
int column [],
int objectCount [],
int nFarthestObject [],
int prevPosition [],
int *objectRoll,
int *position,
int rowRoll,
int columnRoll,
int startTile,
int currentPlayer,
int positionPreObject);
void displayRow10Movement (int *firstRoll,
int startTile,
int *position,
int row [],
int column []);
void checkIfDisplayBoard (char ifDisplayBoard,
int boardSpace [],
int prevPosition []);
void displayBoard (int boardSpace [],
int prevPosition []);
void checkIfDisplayRank (char ifDisplayRank,
int prevPosition [],
int playerCount);
void displayRanking (int prevPosition [],
int playerCount);
void checkIfWin (int *position,
int objectCount [],
int objectRoll,
int currentPlayer,
int nFarthestObject [],
int prevPosition [],
int firstRoll);
void displayWin (int objectCount [],
int objectRoll,
int currentPlayer,
int nFarthestObject [],
int prevPosition [],
int firstRoll);
void checkIfPlayAgain (char ifPlayAgain,
int *replay,
int prevPosition [],
int objectCount [],
int nFarthestObject [],
int *position);
void resetValues (int prevPosition [],
int objectRoll [],
int nFarthestObject [],
int *position);
// MAIN
int main (void)
{
int boardSpace [100];
int row [100], column [100];
int prevPosition [5] = {0,0,0,0,0};
int objectCount [5] = {0,0,0,0,0};
int nFarthestObject [5] = {0,0,0,0,0};
int position = 0;
int playerCount, nSequence, positionPreObject, firstPlayer, currentPlayer, startTile, replay;
int firstRoll, secondRoll, objectRoll;
int rowRoll = 0, columnRoll = 0;
int i;
char userInput [5];
char* endPtr;
char ifDisplayBoard = '*';
char ifDisplayRank = '*';
char ifPlayAgain = '*';
srand (time (NULL));
printf ("Welcome to Doggos, Ladders, Slides and U-Turns!\n");
printf ("This game can be played by 2-5 players.\n");
do {
printf ("\nHow many players will play?: ");
fgets (userInput,
5,
stdin);
playerCount = strtol (userInput,
&endPtr,
0);
if (isValidPlayerCount (playerCount) != 1)
printf ("\nPlease input a valid number.");
} while (playerCount < 2 || playerCount > 5);
do {
nSequence = getSequence (playerCount);
firstPlayer = getCurrentPlayer (nSequence,
playerCount);
printf ("\n----------------------------------------");
printf ("\n\nHere is the sequence of play: %d\n", nSequence);
printf ("\nPlayer %d goes first,", firstPlayer);
printf ("\nfollowed by ");
for (i = 0; i < playerCount - 1; i++) {
nSequence = updateSequence (nSequence,
playerCount);
currentPlayer = getCurrentPlayer (nSequence,
playerCount);
if (i != playerCount - 2) {
printf ("Player %d, ", currentPlayer);
} else
printf ("and Player %d.", currentPlayer);
}
printf ("\n\nPress ENTER to start!");
nSequence = updateSequence (nSequence,
playerCount);
getchar();
//GAME START
fillRow (row);
fillColumn (column);
firstPlayer = getCurrentPlayer (nSequence, // to determine when a round ends
playerCount);
do {
currentPlayer = getCurrentPlayer (nSequence,
playerCount);
startTile = prevPosition [currentPlayer - 1];
printf ("\n\nPlayer %d, you're currently on tile %d.", currentPlayer,
startTile);
printf (" It's your turn to roll the pair of D10 dice!");
printf ("\nPress ENTER to roll!");
getchar();
objectRoll = 0; // for winning move
if (startTile >= 90) {
displayRow10Movement (&firstRoll,
startTile,
&position,
row,
column);
positionPreObject = position;
checkIfWin (&position,
objectCount,
objectRoll,
currentPlayer,
nFarthestObject,
prevPosition,
firstRoll);
if (position != 100) {
doObjectRoll (row,
column,
objectCount,
nFarthestObject,
prevPosition,
&objectRoll,
&position,
rowRoll,
columnRoll,
startTile,
currentPlayer,
positionPreObject);
checkIfWin (&position,
objectCount,
objectRoll,
currentPlayer,
nFarthestObject,
prevPosition,
firstRoll);
}
} else {
firstRoll = roll10SidedDie(); //normal movement rolls
secondRoll = roll10SidedDie();
printf ("\n\nThe dice rolled %d and %d.", firstRoll,
secondRoll);
if (isItDouble5 (firstRoll, // check for double-5
secondRoll) == 1) { // if 1, skips object roll
firstRoll = getCurrentRow (row,
&startTile);
secondRoll = getCurrentColumn (column,
&startTile);
printf ("\nSorry. You rolled a double-5. You stay on tile %d (row %d, col %d)", startTile,
firstRoll,
secondRoll);
prevPosition [currentPlayer - 1] = startTile;
} else { // normal movement segment
if (isItDouble3 (firstRoll, // check for double-3
secondRoll) == 1) {
if (startTile == 0) {
printf ("\nUnfortunate. You rolled a double-3 on the starting tile.");
printf (" You stay on tile 0 (row 0, col 0).");
position = 0;
} else {
position = getDouble3Tile (&firstRoll,
&secondRoll,
row,
column,
&startTile);
printf ("\nWow! You rolled a double-3. ");
printf ("\nYou move to tile %d (row %d, col %d).", position,
firstRoll,
secondRoll);
positionPreObject = position;
}
} else { // normal movement
position = getTileNumber (&firstRoll,
&secondRoll,
row,
column);
printf ("\nYou move to tile %d.", position);
positionPreObject = position;
}
checkIfWin (&position,
objectCount,
objectRoll,
currentPlayer,
nFarthestObject,
prevPosition,
firstRoll);
if (position != 0 && position != 100) {
doObjectRoll (row,
column,
objectCount,
nFarthestObject,
prevPosition,
&objectRoll,
&position,
rowRoll,
columnRoll,
startTile,
currentPlayer,
positionPreObject);
checkIfWin (&position,
objectCount,
objectRoll,
currentPlayer,
nFarthestObject,
prevPosition,
firstRoll);
} else
prevPosition [currentPlayer - 1] = position;
}
}
printf ("\n----------------------------------------");
nSequence = updateSequence (nSequence,
playerCount);
currentPlayer = getCurrentPlayer (nSequence,
playerCount);
if (currentPlayer == firstPlayer && position != 100) {
checkIfDisplayBoard (ifDisplayBoard,
boardSpace,
prevPosition);
checkIfDisplayRank (ifDisplayRank,
prevPosition,
playerCount);
getchar();
}
} while (position != 100);
checkIfPlayAgain (ifPlayAgain,
&replay,
prevPosition,
objectCount,
nFarthestObject,
&position);
} while (replay == 1);
return 0;
}
// FUNCTIONS
/* This function returns a random number from 1-10
@return a random number from 1-10
*/
int
roll10SidedDie ()
{
return rand () % 10 + 1;
}
/* This function returns a 2-5 digit integer that determines the sequence of players
Precondition: the player count is 2-5
@param playerCount is the number of players playing the game
@return the 2-5 digit integer that determines the sequence of players
*/
int
getSequence (int playerCount)
{
int sequenceDigit, exponent, final = 0;
int finalSequence [5];
int i, j = 0, k, l = 1;
sequenceDigit = rand () % playerCount + 1; // initialize first digit of the sequence
finalSequence [0] = sequenceDigit;
do {
for (i = 0; i < playerCount; i++) { // this loop checks for duplicates
if (sequenceDigit == finalSequence [j]) { // if there is number in the array that is equal to
sequenceDigit = rand () % playerCount + 1; // random number, roll again and scan the array once again
j=0;
i=0;
} else
j++;
} // this loop can only be escaped when there is no dupes
if (j == playerCount - 1) { // initialize the next digit of the sequence
finalSequence [l] = sequenceDigit;
l++;
j=0;
i=0;
}
} while (l < playerCount);
exponent = playerCount - 1;
for (k = 0; k < playerCount; k++) {
final += finalSequence [k] * pow (10, exponent);
exponent--;
}
return final;
}
/* This function puts the digit of the next player to the leftmost digit and the current player to the rightmost digit
@param nSequence is the 2-5 digit number that determines the sequence of play
@param playerCount is the number of players playing the game
@return the updated 2-5 digit integer that determines the sequence of players
*/
int
updateSequence (int nSequence,
int playerCount)
{
int prevFirst = 0, exponent = 0, update = 0;
exponent = playerCount - 1;
prevFirst = nSequence / pow (10, exponent);
update = nSequence % (int) pow (10, exponent) * 10 + prevFirst;
return update;
}
/* This function computes for the player that is currently in play
@param nSequence is the 2-5 digit number that determines the sequence of play
@param playerCount is the number of players playing the game
@return the 2-5 digit integer that determines the sequence of players
*/
int
getCurrentPlayer (int nSequence,
int playerCount)
{
return nSequence / pow (10, playerCount - 1);
}
/* This function computes for the row number that the player is currently in
Precondition: row [] is correctly arranged
@param row [] is an array filled with arranged row numbers
@param *position is the player's position after an event
@return the current row of the player based on their position
*/
int
getCurrentRow (int row [],
int *position)
{
if (*position != 0)
return row [*position - 1];
else
return 0;
}
/* This function computes for the column number that the player is currently in
Precondition: column [] is correctly arranged
@param column [] is an array filled with arranged column numbers
@param *position is the player's position after an event
@return the current column of the player based on their position
*/
int
getCurrentColumn (int column [],
int *position)
{
if (*position != 0)
return column [*position - 1];
else
return 0;
}
/* This function computes for the current tile that the player is on
Precondition: row [] and column [] is correctly arranged, rowRoll and columnRoll is a number from 1 - 10
@param *rowRoll is the 10-sided die roll that determines the row that the player is going to
@param *columnRoll is the 10-sided die roll that determines the column that the player is going to
@param row [] is an array filled with arranged row numbers
@param column [] is an array filled with arranged column numbers
@return the current tile of the player based on their position
*/
int
getTileNumber (int *rowRoll,
int *columnRoll,
int row [],
int column [])
{
int sameRow [10], sameColumn [10];
int i, j = 0, k = 0;
int l = 0, m = 0;
for (i = 0; i < 100; i++) {
if(row [i] == *rowRoll) { //stores the index of row[] if a value in row[] is equal to the rowRoll
sameRow [j] = i;
j++;
}
if(column [i] == *columnRoll) { //stores the index of column[] if a value in column[] is equal to the columnRoll
sameColumn [k] = i;
k++;
}
}
while (l != 10) {
if(sameRow [l] == sameColumn [m]) //if the same number is found on both arrays, return it + 1
return sameRow [l] + 1;
else
m++; //compare the next number on sameColumn to sameRow
if (m == 10) { //compare the next number on sameRow to sameColumn
m = 0;
l++;
}
}
return 0;
}
/* This function checks if the player count is a number from 2-5
@param playerCount is the number of players playing the game
@return 1 if the number is 2 - 5
0 if not
*/
int
isValidPlayerCount (int playerCount)
{
switch (playerCount) {
case 2:
case 3:
case 4:
case 5:
return 1;
break;
default:
return 0;
}
}
/* This function checks if the player rolled a double-5
@param firstRoll is the 10-sided die roll that determines the row that the player is going to
@param secondRoll is the 10-sided die roll that determines the column that the player is going to
@return 1 if both rolls is equal to 5
0 if not
*/
int
isItDouble5 (int firstRoll,
int secondRoll)
{
if (firstRoll == 5 && secondRoll == 5)
return 1;
else
return 0;
}
/* This function checks if the player rolled a double-3
@param firstRoll is the 10-sided die roll that determines the row that the player is going to
@param secondRoll is the 10-sided die roll that determines the column that the player is going to
@return 1 if both rolls is equal to 3
0 if not
*/
int
isItDouble3 (int firstRoll,
int secondRoll)
{
if (firstRoll == 3 && secondRoll == 3)
return 1;
else
return 0;
}
/* This function returns the tile number that the player should proceed to when they roll a double-3
Precondition: the player rolled a double-3 and the player's starting tile is not 0 and not on row 10
@param *firstRoll is the 10-sided die roll that determines the row that the player is going to
*firstRoll gets updated to the player's current row plus 3 if starting tile is not on row 8 and above
and 10 if it is
@param *secondRoll is the 10-sided die roll that determines the column that the player is going to
*secondRoll gets updated to the player's current column if starting tile is not on row 8 and above
and 2 if it is
@param row [] is an array filled with arranged row numbers
@param column [] is an array filled with arranged column numbers
@param *startTile is the player's tile at the start of their turn
@return the tile number that the player should proceed to when they roll a double-3
99 if the player's current row is 8-10
*/
int
getDouble3Tile (int *firstRoll,
int *secondRoll,
int row [],
int column [],
int *startTile)
{
if (getCurrentRow (row,
*&startTile) < 8) {
*firstRoll = getCurrentRow (row,
*&startTile) + 3;
*secondRoll = getCurrentColumn (column,
*&startTile);
return getTileNumber (*&firstRoll,
*&secondRoll,
row,
column);
} else {
*firstRoll = 10;
*secondRoll = 2;
return 99;
}
}
/* This function returns the tile number that the Doggo should proceed to. The Doggo
can go to any valid tile
Precondition: the objectRoll rolled a 1, the player is not on tile 0
@param *rowRoll is the 10-sided die roll that determines the row that the player is going to
*rowRoll gets updated to the random number generated by roll10SidedDie ()
@param *columnRoll is the 10-sided die roll that determines the column that the player is going to
*columnRoll gets updated to the random number generated by roll10SidedDie ()
@param row [] is an array filled with arranged row numbers
@param column [] is an array filled with arranged column numbers
@return the tile number that the Doggo should proceed to
*/
int
getDoggoMovement (int *rowRoll,
int *columnRoll,
int row [],
int column [])
{
int dogTile;
*rowRoll = roll10SidedDie ();
*columnRoll = roll10SidedDie ();
dogTile = getTileNumber (*&rowRoll,
*&columnRoll,
row,
column);
return dogTile;
}
/* This function returns the tile number where the top of the Ladder will go. The Ladder
can go to any tile on a row that is greater than the player's current row.
Precondition: the objectRoll rolled a 2, the player is not on tile 0 and not on row 10
@param *rowRoll is the 10-sided die roll that determines the row that the player is going to
*rowRoll gets updated to the random number generated by roll10SidedDie ()
@param *columnRoll is the 10-sided die roll that determines the column that the player is going to
*columnRoll gets updated to the random number generated by roll10SidedDie ()
@param row [] is an array filled with arranged row numbers
@param column [] is an array filled with arranged column numbers
@param *position is the player's position after an event
@return the tile number where the Ladder will take you
*/
int
getLadderMovement (int *rowRoll,
int *columnRoll,
int row [],
int column [],
int position)
{
int ladderTile, cRow;
cRow = getCurrentRow (row,
&position);
do {
*rowRoll = roll10SidedDie ();
*columnRoll = roll10SidedDie ();
ladderTile = getTileNumber (*&rowRoll,
*&columnRoll,
row,
column);
} while (*rowRoll <= cRow);
return ladderTile;
}
/* This function returns the tile number where the bottom of the Slide will go. The Slide
can go to any tile on a row that is less than the player's current row.
Precondition: the objectRoll rolled a 3, the player is not on tile 0 and not on row 1
@param *rowRoll is the 10-sided die roll that determines the row that the player is going to
*rowRoll gets updated to the random number generated by roll10SidedDie ()
@param *columnRoll is the 10-sided die roll that determines the column that the player is going to
*columnRoll gets updated to the random number generated by roll10SidedDie ()
@param row [] is an array filled with arranged row numbers
@param column [] is an array filled with arranged column numbers
@param *position is the player's position after an event
@return the tile number where the Slide will take you
*/
int
getSlideMovement (int *rowRoll,
int *columnRoll,
int row [],
int column [],
int position)
{
int slideTile, cRow;
cRow = getCurrentRow (row,
&position);
do {
*rowRoll = roll10SidedDie ();
*columnRoll = roll10SidedDie ();
slideTile = getTileNumber (*&rowRoll,
*&columnRoll,
row,
column);
} while (*rowRoll >= cRow);
return slideTile;
}
/* This function returns the tile number that the UTurn should proceed to. The UTurn
goes to the player's starting tile of the current turn
Precondition: the objectRoll rolled a 4, the player is not on tile 0
@param *startTile is the player's tile at the start of their turn
@return the tile number that the UTurn should proceed to
*/
int
getUTurnMovement (int startTile)
{
int uTurnTile;
uTurnTile = startTile;
return uTurnTile;
}
/* This function returns the tile number that the player should proceed to when the
player is on tiles 90-99
Precondition: the player is on tiles 90-99 at the start of their turn
@param *firstRoll is the 10-sided die roll that gets added to the player's startTile
*firstRoll gets updated to the random number generated by roll10SidedDie ()
@param startTile is the player's tile at the start of their turn
@return the tile number that the player should proceed to
*/
int
getRow10Movement (int *firstRoll,
int startTile)
{
int row10Tile;
*firstRoll = roll10SidedDie ();
row10Tile = startTile + *firstRoll;
return row10Tile;
}
/* This function fills the boardSpace [] array with numbers 1-100
ex. boardSpace [0] will have 1, boardSpace [1] will have 2, etc.
@param boardSpace [] is an array containing numbers 1-100
@return the boardSpace [] array with numbers 1-100
*/
void
fillBoard (int boardSpace [])
{
int i, numbers = 1;
for (i = 0; i < 100; i++) {
boardSpace [i] = numbers;
numbers++;
}
}
/* This function fills the row [] array with appropriate row numbers
ex. row [0] to row [9] will have 1-10, row [10] to row [19] will have 1-10, etc.
@param row [] is an array containing appropriate row numbers
@return the row [] array with correct row numbers
*/
void
fillRow (int row [])
{
int i = 0, j = 0;
int end = 9, rowNumber = 1;
for(i = 0; i < 10; i++) {
while (j <= end) {
row [j] = rowNumber;
j++;
}
end += 10;
rowNumber++;
}
}
/* This function fills the column [] array with appropriate column numbers
ex. column [0] to column [9] will have 1-10, column [10] to column[19] will have 10-1, etc.
@param column [] is an array containing appropriate column numbers
@return the column [] array with correct column numbers
*/
void
fillColumn (int column [])
{
int i = 0, j = 0, k = 19;
int oddStart = 0, oddEnd = 9, evenStart = 19, evenEnd = 10, columnNumber = 1;
for(i = 0; i < 5; i++) {
while (j >= oddStart && j <= oddEnd) {
column [j] = columnNumber;
columnNumber++;
j++;
}
columnNumber = 1;
while (k <= evenStart && k >= evenEnd) {
column [k] = columnNumber;
columnNumber++;
k--;
}
columnNumber = 1;
oddStart += 20;
oddEnd += 20;
evenStart += 20;
evenEnd += 20;
j = oddStart;
k = evenStart;
}
}
/* This function updates the objectCount [] array with a code that indicates the number of
object encountered by a player
ex. 3212 means the player has encountered 3 Doggos, 2 Ladders, 1 Slide, and 2 UTurns
@param *objectRoll is a 10-sided die that determines the object encountered by a player on a tile
@param objectCount [] is an array that contains the object count code of each player
@param currentPlayer is the digit of the player that is currently playing
@return the object count code of the current player
*/
void
getObjectCount (int *objectRoll,
int objectCount [],
int currentPlayer)
{
switch (*objectRoll) {
case 1:
objectCount [currentPlayer - 1] += 1000;
break;
case 2:
objectCount [currentPlayer - 1] += 100;
break;
case 3:
objectCount [currentPlayer - 1] += 10;
break;
case 4:
objectCount [currentPlayer - 1] += 1;
break;
}
}
/* This function displays the movement that happened after rolling for an object encounter or when
nothing is found
@param *objectRoll is a 10-sided die that determines the object encountered by a player on a tile
@param *position is the player's position after an event
*position gets updated to the changes after the object encounter
@param *rowRoll is the 10-sided die roll that determines the row that the player is going to
@param *columnRoll is the 10-sided die roll that determines the column that the player is going to
@param row [] is an array containing appropriate row numbers
@param column [] is an array containing appropriate column numbers
@param startTile is the player's tile at the start of their turn
*/
void
displayObjectMovement (int *objectRoll,
int *position,
int rowRoll,
int columnRoll,
int row[],
int column [],
int startTile)
{
int dogTile, ladderTile, slideTile, uTurnTile, uRow, uColumn;
uRow = getCurrentRow (row,
&startTile);
uColumn = getCurrentColumn (column,
&startTile);
switch (*objectRoll) {
case 1:
dogTile = getDoggoMovement (&rowRoll,
&columnRoll,
row,
column);
printf("\nYou found a Doggo!");
if (dogTile == *position)
printf (" The Doggo did not move at all. You are still on tile %d (row %d col %d).", dogTile,
rowRoll,
columnRoll);
else if (dogTile > *position)
printf (" You followed the dog to tile %d (row %d col %d). What a good dog!", dogTile,
rowRoll,
columnRoll);
else
printf (" You followed the dog to tile %d (row %d col %d). Oh no...", dogTile,
rowRoll,
columnRoll);
*position = dogTile;
break;
case 2:
ladderTile = getLadderMovement (&rowRoll,
&columnRoll,
row,
column,
*position);
printf ("\nYou found a Ladder! You climbed the ladder to tile %d (row %d col %d).", ladderTile,
rowRoll,
columnRoll);
*position = ladderTile;
break;
case 3:
slideTile = getSlideMovement (&rowRoll,
&columnRoll,
row,
column,
*position);
printf ("\nUh-oh. You found a Slide. You rode the slide to tile %d (row %d col %d).", slideTile,
rowRoll,
columnRoll);
*position = slideTile;
break;
case 4:
uTurnTile = getUTurnMovement (startTile);
printf ("\nYou found a U-Turn! You went back to tile %d (row %d col %d).", uTurnTile,
uRow,
uColumn);
*position = uTurnTile;
break;
default:
printf("\nHmm...you found nothing on this tile.");
}
}
/* This function forms a 3 digit code that determines the farthest distance covered by an object
and what object it is
ex. 390 means a SLide moved you 90 tiles in distance.
@param nFarthestObject [] is an array containing the code of each player for the farthest distance
covered by an object
nFarthestObject [] gets updated to the farthest object code of the current player