-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProperty-property.c
1572 lines (1276 loc) · 50.7 KB
/
Property-property.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
/*
Description: This is a turn-based two-player board game. Players
compete to acquire wealth by buying or renting properties.
The game ends when a player goes bankrupt i.e he does not have enough
money to pay rent.
Programmed by: Reign Elaiza Larraquel S15
Last modified: 02/07/2022
Version: 1
Acknowledgements:
- Use of Structs: https://www.youtube.com/watch?v=7zXqMD6Fj_E
- Use of Rand: Sir Bon Jorelle Domingo (SHS iACADEMY Teacher)
- Use of Getch: https://www.geeksforgeeks.org/getch-function-in-c-with-examples/
*/
#include <stdio.h>
#include <stdlib.h> // To use rand() for a randomized number
#include <time.h> // To get a randomized number EVERY use of the rand()
#include <conio.h> // Allows the function of getch()
/* Type of positions the player may land on */
#define GO 'G'
#define FEELIN_LUCKY 'L'
#define JAIL 'J'
#define PROPERTY 'P'
#define ELECTRIC_COMPANY 'E'
#define RAILROAD 'R'
/* True or False */
#define TRUE 1
#define FALSE 0
/* Player Status */
typedef struct Player
{
int nPlayer;
int nCash;
int nPosition;
int nJail;
} Player;
/* Rent Value */
typedef struct Rent
{
int nRailRent;
int nElecRent;
} Rent;
/* Cost Value */
typedef struct Cost
{
int nRailCost;
int nElecCost;
int nRenovCost;
} Cost;
/* Range of amounts in Feelin' Lucky */
typedef struct LuckyRange
{
int nPrimeMax;
int nPrimeMin;
int nNonPrimeMax;
int nNonPrimeMin;
} LuckyRange;
/* Displays the menu for the game */
void menuDisplay()
{
printf("\n-----------------------------------------------\n");
printf("\t PROPERTY... PROPERTY\n");
printf("-----------------------------------------------\n\n");
printf(" [1] Start a New Game\n");
printf(" [2] Settings\n");
printf(" [3] Exit The Program\n");
}
/* Displays the settings for the game */
void settingDisplay()
{
printf("\n-----------------------------------------------\n");
printf("\t SETTINGS\n");
printf("-----------------------------------------------\n\n");
printf("Rent:\n");
printf(" [1] Change Railroad Rent Value\n");
printf(" [2] Change Electric Company Rent Value\n");
printf("\nCost:\n");
printf(" [3] Change Railroad Cost Value\n");
printf(" [4] Change Electric Company Cost Value\n");
printf(" [5] Change Cost of Renovation\n");
printf("\nOther Settings:\n");
printf(" [6] Change Initial Cash Value\n");
printf(" [7] Change Range of Amounts in Feelin' Lucky\n");
printf("\nGame End Condition:\n");
printf(" [8] Set Specific Cash Limit\n");
printf("-----------------------------------------------");
printf("\nEnter [9] to go back to menu\n\n");
}
/* Informs the user when the value they input is invalid */
void invalid()
{
printf("\n[INVALID INPUT]\n");
}
/*
This function prints a text according to the settings the user
planning to change in the settings so that it is easier to identify
and understand. The settings consist of:
- Railroad Rent
- Electric Company Rent
- Railroad Cost
- Electric Company Cost
- Renovation Cost
- Initial Cash
This allows the program to change 6 values without repeating the same
line of codes due to needing different title texts
@param nAnswer The type of setting that the user plans to change
@return Title of the setting the user plans to change
*/
void changeValueDisplay(int nAnswer)
{
switch(nAnswer)
{
case 1:
printf("\t Change Railroad Rent Value\n");
break;
case 2:
printf(" Change Electric Company Rent Value\n");
break;
case 3:
printf("\t Change RailRoad Cost Value\n");
break;
case 4:
printf(" Change Electric Company Cost Value\n");
break;
case 5:
printf("\t Change Renovation Cost Value\n");
break;
case 6:
printf("\t Change Initial Cash Value\n");
break;
}
}
/*
The user inputs a new cash value that will replace the original
values of the following settings:
- Railroad Rent
- Electric Company Rent
- Railroad Cost
- Electric Company Cost
- Renovation Cost
- Initial Cash
The function will continue to loop and ask the user to input a new
value until the value that the user places is more than 1
Precondition: nAnswer ranges from 1 - 6
@param nAnswer The type of setting that the user plans to change
@return The new value that the user has inputted
*/
int changeSettingValue(int nAnswer)
{
int nNewVal = 0;
while(nNewVal < 1)
{
printf("\n-----------------------------------------------\n");
changeValueDisplay(nAnswer);
printf("-----------------------------------------------\n\n");
printf("Input: ");
scanf(" %d", &nNewVal); // Inputs the new value
if(nNewVal < 1) invalid();
}
return nNewVal;
}
/*
Changes the range of amounts in Feeling' Lucky such as the maximum
amount if the dice value is prime, minimum amount if the dice value
is prime, maximum amount if the dice value is not prime, and minimum
amount if the dice value is not prime.
@param luckyRange The range of amount in Feelin' Lucky, including
the minimum and maximum amount for the dice
value if the dice value is prime and the minimum
and maximum amount for the dice value if the
dice value is NOT prime
@return New values to replace the original values of the range of
amount in Feelin' Lucky
*/
void setLuckyRange(LuckyRange* luckyRange)
{
luckyRange -> nPrimeMax = 0; // Resets value to 0
luckyRange -> nNonPrimeMax = 0; // Resets value to 0
printf("\n-----------------------------------------------\n");
printf(" Change Range of Amounts in Feelin' Lucky\n");
printf("-----------------------------------------------\n\n");
printf("Dice value is a prime number:\n");
// Inputs the new maximum amount if the dice value is prime
while(luckyRange -> nPrimeMax < 1)
{
printf(" Max: ");
scanf(" %d", &luckyRange -> nPrimeMax);
if(luckyRange -> nPrimeMax < 1)
{
invalid();
printf(" New");
}
}
// Sets the minimum amount to the maximum amount if the dice value is prime
luckyRange -> nPrimeMin = luckyRange -> nPrimeMax;
// Inputs the new minimum amount if the dice value is prime
while(luckyRange -> nPrimeMin >= luckyRange -> nPrimeMax)
{
printf(" Min: ");
scanf(" %d", &luckyRange -> nPrimeMin);
if(luckyRange -> nPrimeMin >= luckyRange -> nPrimeMax)
{
invalid();
printf(" New");
}
}
printf("\nDice value is NOT a prime number:\n");
// Inputs the new maximum amount if the dice value is NOT prime
while(luckyRange -> nNonPrimeMax < 1)
{
printf(" Max: ");
scanf(" %d", &luckyRange -> nNonPrimeMax);
if(luckyRange -> nNonPrimeMax < 1)
{
invalid();
printf(" New");
}
}
// Sets the minimum amount to the maximum amount if the dice value is NOT prime
luckyRange -> nNonPrimeMin = luckyRange -> nNonPrimeMax;
// Inputs the new minimum amount if the dice value is NOT prime
while(luckyRange -> nNonPrimeMin >= luckyRange -> nNonPrimeMax)
{
printf(" Min: ");
scanf(" %d", &luckyRange -> nNonPrimeMin);
if(luckyRange -> nNonPrimeMin >= luckyRange -> nNonPrimeMax)
{
invalid();
printf(" New");
}
}
}
/*
This function allows the user to activate another game end condition
where the game ends when a specific cash-on-hand is reached. The
specific cash-on-hand that the user must reach should be more than
the initial cash to not cause the game to end instantly. The user may
also choose between which condition (or both) must be satisfied.
@param nInitialCash To know the minimum amount the specific
cash-on-hand must not reach.
@param nCashLimit The variable that will contain the specific
cash-on-hand
@param nEndCond Will determine what end condition must be
satisfied. If "1" the player losees if they do
not have enough cash to pay rent, if "2" the
player loses when the other player reaches a
specific cash-on-hand, and if "3" the player
loses when both conditions are satisfied.
@return The specific cash-on-hand and chosen end game condition.
*/
void setCashLimit (int nInitialCash, int* nCashLimit, int* nEndCond)
{
*nEndCond = 0; // Resets value to 0
*nCashLimit = 0; // Resets value to 0
while(*nCashLimit <= nInitialCash)
{
printf("\n-----------------------------------------------\n");
printf("\t Game End Condition\n");
printf("-----------------------------------------------\n\n");
printf("Cash limit must not be less than %d\n", nInitialCash);
printf("\nSet Specific Cash Limit:\n");
// Inputs the specific cash-on-hand
printf("Input: ");
scanf(" %d", nCashLimit);
if(*nCashLimit <= nInitialCash) invalid();
}
// Determines which end condition must be satisfied
while(*nEndCond < 1 || *nEndCond > 3)
{
printf("\n-----------------------------------------------\n");
printf(" Choose which condition will end the game:\n");
printf("-----------------------------------------------\n\n");
printf(" [1] Not enough cash\n");
printf(" [2] Specific Cash-on-hand Reached\n");
printf(" [3] Both\n");
printf("\nInput: ");
scanf(" %d", nEndCond);
if(*nEndCond < 1 || *nEndCond > 3) invalid();
}
}
/*
The settings allows the user to change zero or more of the initial
settings of the game. This function will call another function
depending on what the user plans to change specifically and it will
replace the initial value of the setting to what the user inputs.
@param nAnswer This will determine which setting will be edited
1 - Rent for Railroad
2 - Rent for Electric Company
3 - Cost for Railroad
4 - Cost for Electric Company
5 - Cost for Renovation
6 - Initial Cash
7 - Range of Amounts in Feelin' Lucky
8 - Game End Condition
@param nInitialCash The initial cash of the player in the start of
@param rent Contains the values of the rent for Railroad and
Electric Company
@param cost Contains the value of the cost for Railroad,
Electric Company, and the renovation
the game
@param luckyRange The range of amount in Feelin' Lucky, including
the minimum and maximum amount for the dice value
if the dice value is prime and the minimum and
maximum amount for the dice value if the dice value
is NOT prime
@param nCashLimit The specific cash-on-hand the players must reach
@param nEndCond Will determine what end condition must be
satisfied
@return The new values of the edited settings
*/
void settings(int nAnswer, int* nInitialCash, Rent* rent, Cost* cost, LuckyRange* luckyRange, int* nCashLimit, int* nEndCond)
{
switch(nAnswer)
{
case 1:
rent -> nRailRent = changeSettingValue(nAnswer);
break;
case 2:
rent -> nElecRent = changeSettingValue(nAnswer);
break;
case 3:
cost -> nRailCost = changeSettingValue(nAnswer);
break;
case 4:
cost -> nElecCost = changeSettingValue(nAnswer);
break;
case 5:
cost -> nRenovCost = changeSettingValue(nAnswer);
break;
case 6:
*nInitialCash = changeSettingValue(nAnswer);
break;
case 7:
setLuckyRange(luckyRange);
break;
case 8:
setCashLimit(*nInitialCash, nCashLimit, nEndCond);
break;
}
}
/*
This function presents the users with options in a form of a menu.
The user may choose to start a new game, change the settings, or exit
the program.
@param nGame The status of the game. "1" is to start a new
game, "2" to change the settings, and "3" to
exit the program.
@param nInitialCash The initial cash of the player in the start of
@param rent Contains the values of the rent for Railroad and
Electric Company
@param cost Contains the value of the cost for Railroad,
Electric Company, and the renovation
the game
@param luckyRange The range of amount in Feelin' Lucky, including
the minimum and maximum amount for the dice value
if the dice value is prime and the minimum and
maximum amount for the dice value if the dice value
is NOT prime
@param nCashLimit The specific cash-on-hand the players must reach
@param nEndCond Will determine what end condition must be
satisfied.
@return The new values of the edited settings and the status of the
game
*/
void menu(int* nGame, int* nInitialCash, Rent* rent, Cost* cost, LuckyRange* luckyRange, int* nCashLimit, int* nEndCond)
{
int nAnswer = 0; // This will determine which setting will be edited
*nGame = 0; // Resets the value to 0
while(*nGame != 3 && *nGame != 1)
{
// Displays the menu
menuDisplay();
printf("\nInput: ");
scanf("%d", nGame);
if(*nGame == 2)
{
nAnswer = 0;
// Displays the settings
while(nAnswer != 9)
{
settingDisplay();
printf("Input: ");
scanf("%d", &nAnswer);
// Calls the function to change the settings
settings(nAnswer, nInitialCash, rent, cost, luckyRange, nCashLimit, nEndCond);
if(nAnswer < 1 || nAnswer > 9) invalid();
}
}
else if(*nGame > 3 || *nGame < 1)
{
invalid();
}
}
}
/* Rolls the dice in the range of 1 to 6 */
int rollDice()
{
srand(time(NULL)); // To get a randomized number every run
printf("\n\nPress any key to roll the dice...\n");
getch();
return rand() % 6 + 1; //Returns a value between the range of 1 - 6
}
/*
Displays the title of property according to the board position
@param nPosition The position of the property in the board
@return The title of the property
*/
void boardPosition(int nPosition)
{
switch (nPosition)
{
case 0:
printf("Go");
break;
case 1:
printf("Tree House\t\t\t");
break;
case 2:
printf("Electric Company\t\t");
break;
case 3:
printf("Beach House\t\t");
break;
case 4:
printf("Jail Time");
break;
case 5:
printf("Castle\t\t\t");
break;
case 6:
printf("Feelin' Lucky");
break;
case 7:
printf("Railroad\t\t\t");
break;
case 8:
printf("Igloo\t\t\t");
break;
case 9:
printf("Farm House\t\t\t");
break;
}
}
/*
Returns a character that determines the type of the position the
player landed on
G - Go
L - Feelin' Lucky
J - Jail Time
P - House Property
E - Electric Company
R - Railroad
@param nPosition - The position of the player
@return character determining the type of the position
*/
char positionType(int nPosition)
{
switch (nPosition)
{
case 0:
return GO;
break;
case 1:
return PROPERTY;
break;
case 2:
return ELECTRIC_COMPANY;
break;
case 3:
return PROPERTY;
break;
case 4:
return JAIL;
break;
case 5:
return PROPERTY;
break;
case 6:
return FEELIN_LUCKY;
break;
case 7:
return RAILROAD;
break;
case 8:
return PROPERTY;
break;
case 9:
return PROPERTY;
break;
default:
return ' ';
}
}
/*
Extracts the status of the needed property according to the position
the player lands. Status meaning:
- If the value of the property is 0, nobody owns this property
- If the value of the property is 1, Player 1 owns this property
- If the value of the property is 2, Player 2 owns this property
- If the value of the property is 3, Player 1 owns this RENOVATED
property
- If the value of the property is 4, Player 2 owns this RENOVATED
property
To extract the status, it uses a For-loop that will keep looping
until the counter has the same value as the position of the player.
nPlace is the place value of the property that needs to be extracted,
example if the function needed to extract the "4" in 110040100 then
the place value would be 10000. nExtNum is the place value after the
property that needs to be extracted, this will be used to remove all
the numbers that follow after the property.
Precondition: nProperties is a 9 digit integer
Precondition: nProperties must consist of only the numbers: 0, 1, 2,
3, and 4
@param nProperties A 9 digit integer containing the status of all
properties
@param nPosition The position of the property the player landed
@return The status of the property the player landed on
*/
int getProperty(int nProperties, int nPosition)
{
int nPlace = 1; // place value of the property
int nExtNum = 1; // the place value following after the property
int nCounter;
int nProperty;
for(nCounter = 1; nCounter <= nPosition; nCounter++)
{
nPlace *= 10;
if(nCounter == nPosition) nProperty = nProperties % nPlace / nExtNum;
nExtNum *= 10;
}
return nProperty;
}
/*
Checks if the player has any properties owned by them
@param nProperties A 9 digit integer containing the status of all
properties
@param nPlayer The player that is being checked
@return 1 if the player has any properties and 0 if the player
does not have any properties
*/
int checkProperties(int nProperties, int nPlayer)
{
int nIsOwned = FALSE;
int nCounter;
for(nCounter = 1; nCounter <= 9; nCounter++)
{
if(getProperty(nProperties, nCounter) == nPlayer) nIsOwned = TRUE;
else if(getProperty(nProperties, nCounter) == (nPlayer + 2)) nIsOwned = TRUE;
}
return nIsOwned;
}
/*
Checks if a player's owned house property is renovated or not.
- "1" means the property is not renovated
- "2" means the property is renovated
@param nProperties A 9 digit integer containing the status of all
properties
@param nPosition The specific house property that will be checked
if renovated or not
@param nPlayer The owner of the house property
@return The status of an owned house property if renovated or not
*/
int checkRenovation(int nProperties,int nPosition, int nPlayer)
{
if(getProperty(nProperties, nPosition) == nPlayer) return 1;
else if(getProperty(nProperties, nPosition) == (nPlayer + 2)) return 2;
else return 0;
}
/*
Gets the cost of the property according its type
@param nPosition The position of the property
@param cost A struct that contains the cost for the Electric
Company and Railroad property
@return The cost of the property
*/
int getPropertyCost(int nPosition, Cost cost)
{
char cType = positionType(nPosition);
if(cType == ELECTRIC_COMPANY) return cost.nElecCost;
else if(cType == RAILROAD) return cost.nRailCost;
else if(cType == PROPERTY) return nPosition % 7 * 20;
else return 0;
}
/*
Gets the rent of the property according its type
@param nPlayer The player that is paying the rent
@param nPosition The position of the property
@param nProperties A 9 digit integer containing the status of all
properties
@param nDice The value of the dice the player rolled
@param rent A struct that contains the rent value for the
Electric Company and Railroad property
@param cost A struct that contains the cost for the Electric
Company and Railroad property
@return The rent of the property
*/
int getPropertyRent(int nPlayer, int nPosition, int nProperties, int nDice, Rent rent, Cost cost)
{
char cType = positionType(nPosition);
int nCost = getPropertyCost(nPosition, cost);
int nIsRenov = checkRenovation(nProperties, nPosition, nPlayer);
int nRent = 0;
if(cType == ELECTRIC_COMPANY)
{
nRent = nDice * rent.nElecRent;
}
else if(cType == RAILROAD)
{
nRent = rent.nRailRent;
}
else if(cType == PROPERTY)
{
nRent = nCost * 0.2;
// If the property is renovated then the rent value becomes twice the rent and add 1
if(nIsRenov == 2) nRent = nRent * 2 + 1;
}
return nRent;
}
/*
Checks if the player owns the property that is inputted
@param nProperties A 9 digit integer containing the status of all
properties
@param nPlayer The player that is being checked
@param nPosition The property that is being checked
@return 1 if the player owns the property and 0 if the player
does not own the property
*/
int checkOwnership(int nProperties, int nPlayer, int nPosition)
{
if(getProperty(nProperties, nPosition) == nPlayer) return 1;
else if(getProperty(nProperties, nPosition) == (nPlayer + 2)) return 1;
else return 0;
}
/* Edits the values of the 9 digit integer property
1 = sell property
2 = buy property
3 = renovate property
precondition: nSign is either 1, 2, or 3
@param nProperties A 9 digit integer containing the status of all
properties
@param nPosition The position of the property
@param nPlayer The player that is making the edit
@param nSign The kind of edit the player would like to make
@return A new value of the 9 digit integer property
*/
void changeOwnership(int* nProperties, int nPosition, int nPlayer, int nSign)
{
int nNewValue = 1;
int nProperty = getProperty(*nProperties, nPosition); //return 1, 2, 3, 4
for(int x = 1; x <= nPosition; x++)
{
if(x == nPosition)
{
if(nSign == 1) // sell property
{
nNewValue *= nProperty;
*nProperties -= nNewValue; // subtracts the value of the property from the nProperties
}
else if(nSign == 2) // buy property
{
nNewValue *= nPlayer;
*nProperties += nNewValue; // adds the value of the property to the nProperties
}
else if(nSign == 3) // renovate property
{
nNewValue *= 2;
*nProperties += nNewValue; // adds the value of the property to the nProperties
}
}
else
{
nNewValue *= 10;
}
}
}
/*
Displays all the properties owned by the player and whether or not
the property they own is renovated.
@param nProperties A 9 digit integer containing the status of all
properties
@param nPlayer The player that is currently playing
*/
void displayOwnership(int nProperties, int nPlayer)
{
int nCounter;
char cType;
//Checks if there is a property owned by the player
if(checkProperties(nProperties, nPlayer) == 0) printf(" N/A\n");
else if(checkProperties(nProperties, nPlayer) == 1)
{
//Displays the properties owned by the player
for(nCounter = 1; nCounter <= 9; nCounter++)
{
cType = positionType(nCounter);
if(checkRenovation(nProperties, nCounter, nPlayer) == 1)
{
printf(" [%d] ", nCounter);
boardPosition(nCounter); // prints the title of the property
if(cType == PROPERTY) printf(" (Unrenovated)");
else printf(" N/A");
printf("\n");
}
else if(checkRenovation(nProperties, nCounter, nPlayer) == 2)
{
printf(" [%d] ", nCounter);
boardPosition(nCounter); // prints the title of the property
if(cType == PROPERTY) printf(" (Renovated)");
else printf(" N/A");
printf("\n");
}
}
}
}
/*
Display Player's Cash and properties that they own
@param nProperties A 9 digit integer containing the status of all
properties
@param nPlayer The player that is currently playing
@param nCash The current cash of the player. This will update
whenever the player earns or loses money
*/
void playerStatus(int nProperties, int nPlayer, int nCash)
{
printf("\n[PLAYER %d]\n", nPlayer);
printf("-----------------------------------------------\n");
printf("Cash: %d\n", nCash);
printf("-----------------------------------------------\n");
printf("Properties:\n");
displayOwnership(nProperties, nPlayer);
printf("-----------------------------------------------\n");
}
/* Displays the new position of the player depending on the dice roll
@param nDice The number of times the player moves
@param nPosition Changes according to the dice roll
If the player exceeds the 9th position, the
player returns to position 0
@param nCash Player gets 200 cash for passing the position 0
@return The new position of the player and the cash
*/
void displayPosition(int nDice, int* nPosition, int* nCash)
{
int nReceived = FALSE;
*nPosition += nDice; // adds the dice roll to the current position
if(*nPosition > 9)
{
*nCash += 200; // adds 200 cash to the player's cash for passing the position 0
*nPosition -=10; //Subtracts 10 to make the player start from 0 again
nReceived = TRUE;
}
printf("\n> Player rolled on a %d\n", nDice);
printf("> Moving player to position %d\n", *nPosition);
printf("> You have landed on the ");
boardPosition(*nPosition);
if(nReceived == TRUE) printf("\n\n> You have received 200 cash from the bank for passing Go.");
}
/*
Checks if the player has enough cash to pay for the cost
@param nCash The current cash of the player
@param nCost The cost of what the player has to pay
@return 1 if the player has enough cash and 0 if the player
does not have enough cash
*/
int isEnoughCash(int nCash, int nCost)
{
if(nCash >= nCost) return TRUE;
else return FALSE;
}
/*
Displays a message if the player's cash is enough to pay for the cost
and subtracts the cost from the player's cash
@param nCash The player cash increases or decreases according to
the decision of the user to pay or sell
@param nCost The cost of what will be paid by the player
@return updated cash value of the player
*/
void cashPay(int* nCash, int nCost)
{
int nCheckCash = isEnoughCash(*nCash, nCost);
if(nCheckCash == TRUE)
{
printf("\nPayment successful\n");
printf("\n> You paid %d cash\n", nCost);
}
else if(nCheckCash == FALSE)
{
printf("\nInsufficient Cash\n");
}
*nCash -= nCost;
}
/*
Places the player in jail when they land on the position 4 (Jail
Time). When in jail, the player lose their next turn
precondition: nPosition is 4
@param player1 The jail status of player 1
@param player2 The jail status of player 2
@param nPlayer The player that is currently playing
@return Updated jail status of the player
*/
void jail(Player* player1, Player* player2, int nPlayer)
{
printf("\n> You cannot play for your next turn.\n");
if(nPlayer == player1 -> nPlayer) player1 -> nJail = 1;
else if(nPlayer == player2 -> nPlayer) player2 -> nJail = 1;
}
/*
This function allows the user to resell a property to the bank and
updates the status of the ownership by changing the value of the
property that was sold to 0. The resell value is half the cost of the
property
@param nPosition The position of the property that the player
wants to resell
@param nPlayer The player that is currently playing
@param nProperties Changes value when the player resells a property
@param nCash The player cash increases according to the