-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1916 lines (1677 loc) · 51.4 KB
/
main.cpp
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
//Personal Project by Luka Brown
//The Deep Below
//Mining Game
//In development, should work on both windows and linux
//Feel free to compile and playtest!
/* Gameplay:
Explore an (almost) endless mass of blocks and dig your way around!
The game starts with a grid output to a console with 'P' for player in the
middle.
Go towards * if you see them, they're rare and sparkly
$ is a friendly shop!
+ is an enemy miner, beware!
Have fun! */
#include <vector>
#include <iostream>
#include <random>
#include <ctime>
#include <cstdlib>
#include <map>
#include <string>
#include <fstream>
#ifdef _WIN32
#include <Windows.h>
#else //linux
#include <unistd.h>
#endif
//enemy AI class
struct Rogue {
int damage, coins, ore, artifacts, health, x, y, direction;
bool moved;
};
//function prototypes
//intro/helper functions
static void Init();
static void Intro();
static void InputClear();
static void MySleep(double seconds);
//game functions
static int GameInput();
static void Move(int x);
static bool CollectItem(int y, int x);
static void GameReport();
static bool TitleScreen();
static bool Miniboss();
static bool Boss();
static void Revive();
//map/grid functions
static void GenerateGrid();
static void PrintGrid();
static bool SaveGame(std::string name);
static bool LoadGame(std::string name);
//shop functions
static void CallShop();
static void SellOre();
static void BuyArtifacts();
static void Trade();
static void Upgrade(int x);
//miner functions
static void InitMiner(Rogue &miner, int y, int x);
static void MoveMiners();
static void MoveMiner(Rogue &miner);
static bool ProcessBlock(Rogue &miner, int y, int x);
static bool MinerFight(int y, int x);
//Constants
static const int GRID_UPPER = 2000; //2000x2000 grid, 4 million blocks
static const int MINERS = GRID_UPPER * 3; //scales with grid size
static const int UPGRADE_UPPER = 7; //num of upgrades implemented
//"block" types
#define PLAYER 0
#define DIRT 1
#define MINED 2 //mined dirt
#define SHOP 3
#define ARTIFACT 4
#define ORE 5
#define MINER 6 //enemy
#define MINIBOSS 7
#define BOSS 8
//global vars
static bool game; //game on/off
static int upgrades[UPGRADE_UPPER]; //stores levels of upgrades
static std::map<std::string, int> player; //dictionary of player items, defined in Init()
static std::vector<std::vector<int>> grid(GRID_UPPER, std::vector<int> (GRID_UPPER)); //map
static std::vector<Rogue> MinerList; //list of all enemy miners
int main() {
Init(); //creates map and prints
Intro(); //prints opening statement
int action;
bool update;
while(game) {
action = GameInput();
switch (action) {
case -1:
std::cout << "Invalid Input\n";
MySleep(2);
InputClear();
update = false;
break;
case 0:
case 1:
case 2:
case 3:
Move(action);
update = true;
break;
case 4: //hold your ground
update = true;
break;
case 5:
update = TitleScreen();
break;
} //end switch
if (update)
MoveMiners();
if (player["died"] == 1)
Revive();
if (player["health"] <= 0)
game = false;
PrintGrid();
}// end game while
GameReport();
return 0;
}
///////////////////////////////////////////////////////////////////////////////
//creates 2d vector of blocks
static void GenerateGrid() {
int y, x, random;
int minerNum = 0;
srand((unsigned int)time(NULL)); //seeds random
//initializes map with basic blocks
for (y = 0; y < GRID_UPPER; y++) {
for (x = 0; x < GRID_UPPER; x++) {
random = rand() % 10000;
if (random < 30) //4m x .003 = 12,000
grid[y][x] = SHOP;
else if (random < 160) //4m x .013 = 52,000
grid[y][x] = ORE;
else if (random < 240) //4m x .008 = 32,000
grid[y][x] = ARTIFACT;
else if (random < 242) { //4m x .0002 = 800
//wont let miniboss spawn near spawn
if ((y < GRID_UPPER/2 + GRID_UPPER/100 && y > GRID_UPPER/2 - GRID_UPPER/100) &&
(x < GRID_UPPER/2 + GRID_UPPER/100 && x > GRID_UPPER/2 - GRID_UPPER/100))
grid[y][x] = DIRT;
else
grid[y][x] = MINIBOSS;
}
else if (random < 257) { //4m x .0015 = 6,000
minerNum++;
if (minerNum <= MINERS) {
//ensures not in player spawn
if (y == GRID_UPPER/2 && x == GRID_UPPER/2) {
grid[y][x] = DIRT;
}
else {
Rogue miner;
InitMiner(miner, y, x);
MinerList.push_back(miner);
grid[y][x] = MINER;
}
}
else //else too many miners
grid[y][x] = DIRT;
}
else
grid[y][x] = DIRT;
} //end for x
} //end for y
//ensures enough miners
for (int i = minerNum; i < MINERS; i++) {
y = rand() % GRID_UPPER;
x = rand() % GRID_UPPER;
//ensures not in player spawn
while (y == GRID_UPPER/2 && x == GRID_UPPER/2) {
y = rand() % GRID_UPPER;
x = rand() % GRID_UPPER;
}
Rogue miner;
InitMiner(miner, y, x);
MinerList.push_back(miner);
grid[y][x] = MINER;
}
//spawns boss
y = rand() % GRID_UPPER;
x = rand() % GRID_UPPER;
//ensures boss is not anywhere in a 500x500 square around spawn
while ((x < GRID_UPPER/2 + GRID_UPPER/8 && x > GRID_UPPER/2 - GRID_UPPER/8) ||
(y < GRID_UPPER/2 + GRID_UPPER/8 && y > GRID_UPPER/2 - GRID_UPPER/8)) {
y = rand() % GRID_UPPER;
x = rand() % GRID_UPPER;
}
grid[y][x] = BOSS; //sets boss position
player["bossY"] = y; //used for cursed compass upgrade
player["bossX"] = x; //used for cursed compass upgrade
//sets player position
grid[player["y"]][player["x"]] = PLAYER;
}
///////////////////////////////////////////////////////////////////////////////
//prints blocks around the player
static void PrintGrid() {
std::cout << "\n\n\n\n\n\n";
int y, x, chance, sight;
sight = upgrades[2] + 4;
grid[player["y"]][player["x"]] = PLAYER;
for (y = player["y"] - sight; y < player["y"] + sight + 1; y++) {
if (y > GRID_UPPER-1)
y = GRID_UPPER-1;
else if (y < 0)
y = 0;
for (x = player["x"] - sight; x < player["x"] + sight + 1; x++) {
if (x > GRID_UPPER-1)
x = GRID_UPPER-1;
else if (x < 0)
x = 0;
switch(grid[y][x]) {
case PLAYER:
std::cout << "P ";
break;
case MINER:
std::cout << "+ ";
break;
case DIRT:
std::cout << "# ";
break;
case MINED:
std::cout << " ";
break;
case SHOP:
std::cout << "$ ";
break;
case MINIBOSS:
std::cout << "\" ";
break;
case BOSS:
std::cout << "- ";
break;
case ARTIFACT: //ore and artifact have chance of not showing up
case ORE:
chance = rand() % (8 - (upgrades[4]*2)); //chance goes from 1/8 to 1/6
if (chance == 0) //to 1/4 to 1/2 chance of showing up on the map
std::cout << "* ";
else
std::cout << "# ";
break;
} //end switch
} //end for x
std::cout << '\n';
} //end for y
std::cout << "Ore: " << player["ore"] << " Artifacts: " << player["artifacts"];
std::cout << " Coins: " << player["coins"] << " HP: " << player["health"] << '\n';
if (upgrades[6] == 3) {
bool left, right, down, up;
left = right = down = up = false;
std::string direction;
if (player["x"] > player["bossX"])
left = true;
else if (player["x"] < player["bossX"])
right = true;
if (player["y"] > player["bossY"])
up = true;
else if (player["y"] < player["bossY"])
down = true;
if (up && right)
direction = "North-East";
else if (up && left)
direction = "North-West";
else if (down && left)
direction = "South-West";
else if (down && right)
direction = "South-East";
else if (up)
direction = "North";
else if (down)
direction = "South";
else if (right)
direction = "East";
else if (left)
direction = "West";
else
direction = "Error";
if (player["y"] >= player["bossY"])
y = player["y"] - player["bossY"];
else
y = player["bossY"] - player["y"];
if (player["x"] >= player["bossX"])
x = player["x"] - player["bossX"];
else
x = player["bossX"] - player["x"];
if (!(y < 7 && x < 7))
std::cout << "Your cursed compass points " << direction << '\n';
else
std::cout << "Your cursed compass begins spinning in all directions\n";
}
}
///////////////////////////////////////////////////////////////////////////////
//grabs player input and returns
static int GameInput() {
char input;
InputClear();
input = getchar();
switch (input) {
case 'w':
case 'W':
return 0;
case 'a':
case 'A':
return 1;
case 's':
case 'S':
return 2;
case 'd':
case 'D':
return 3;
case 'h':
case 'H':
return 4;
case 't':
case 'T':
return 5;
default:
return -1;
} //end switch
}
///////////////////////////////////////////////////////////////////////////////
//adjusts players position on map based on keypress
//parameter: int 1,2,3 or 4 of which direction to move player in
static void Move(int direction) {
bool valid;
switch (direction) {
case 0: //w, up
if (player["y"] > player["sight"]) { //makes sure it wont exceed map bounds
valid = CollectItem(player["y"]-1,player["x"]); //processes block stepped on
if (valid) {
grid[player["y"]-1][player["x"]] = PLAYER;
grid[player["y"]][player["x"]] = MINED;
player["y"]--;
}
}
break;
case 1: //a, left
if (player["x"] > player["sight"]) {
valid = CollectItem(player["y"],player["x"]-1);
if (valid) {
grid[player["y"]][player["x"]-1] = PLAYER;
grid[player["y"]][player["x"]] = MINED;
player["x"]--;
}
}
break;
case 2: //s, down
if (player["y"] < GRID_UPPER-player["sight"]-1) {
valid = CollectItem(player["y"]+1,player["x"]);
if (valid) {
grid[player["y"]+1][player["x"]] = PLAYER;
grid[player["y"]][player["x"]] = MINED;
player["y"]++;
}
}
break;
case 3: //d, right
if (player["x"] < GRID_UPPER-player["sight"]-1) {
valid = CollectItem(player["y"],player["x"]+1);
if (valid) {
grid[player["y"]][player["x"]+1] = PLAYER;
grid[player["y"]][player["x"]] = MINED;
player["x"]++;
}
}
break;
}
}
///////////////////////////////////////////////////////////////////////////////
//processes block player stepped on, but before that it checks the upgrades
//and processes those blocks first. from the upgraded mine the player can only
//gain ore and artifacts
//parameters: YX co-ord. of the item to be collected by player
static bool CollectItem(int y, int x) {
//gets direction of travel for upgrade processing
bool up, down, left, right;
up = down = left = right = false;
if (player["x"] > x)
left = true;
else if (player["x"] < x)
right = true;
else if (player["y"] > y)
up = true;
else if (player["y"] < y)
down = true;
if (upgrades[2] == 3 && upgrades[3] == 3) { //if upgraded depth & width
if (up) {
//left 3
for (int i = 0; i < 3; i++) {
if (grid[y-i][x-1] == ORE) {
grid[y-i][x-1] = MINED;
player["ore"]++;
}
else if (grid[y-i][x-1] == ARTIFACT) {
grid[y-i][x-1] = MINED;
player["artifacts"]++;
}
else if (grid[y-i][x-1] == DIRT) {
grid[y-i][x-1] = MINED;
player["dirt"]++;
}
}
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y-i][x] == ORE) {
grid[y-i][x] = MINED;
player["ore"]++;
}
else if (grid[y-i][x] == ARTIFACT) {
grid[y-i][x] = MINED;
player["artifacts"]++;
}
else if (grid[y-i][x] == DIRT) {
grid[y-i][x] = MINED;
player["dirt"]++;
}
}
//right 3
for (int i = 0; i < 3; i++) {
if (grid[y-i][x+1] == ORE) {
grid[y-i][x+1] = MINED;
player["ore"]++;
}
else if (grid[y-i][x+1] == ARTIFACT) {
grid[y-i][x+1] = MINED;
player["artifacts"]++;
}
else if (grid[y-i][x+1] == DIRT) {
grid[y-i][x+1] = MINED;
player["dirt"]++;
}
}
}
else if (down) {
//left 3
for (int i = 0; i < 3; i++) {
if (grid[y+i][x-1] == ORE) {
grid[y+i][x-1] = MINED;
player["ore"]++;
}
else if (grid[y+i][x-1] == ARTIFACT) {
grid[y+i][x-1] = MINED;
player["artifacts"]++;
}
else if (grid[y+i][x-1] == DIRT) {
grid[y+i][x-1] = MINED;
player["dirt"]++;
}
}
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y+i][x] == ORE) {
grid[y+i][x] = MINED;
player["ore"]++;
}
else if (grid[y+i][x] == ARTIFACT) {
grid[y+i][x] = MINED;
player["artifacts"]++;
}
else if (grid[y+i][x] == DIRT) {
grid[y+i][x] = MINED;
player["dirt"]++;
}
}
//right 3
for (int i = 0; i < 3; i++) {
if (grid[y+i][x+1] == ORE) {
grid[y+i][x+1] = MINED;
player["ore"]++;
}
else if (grid[y+i][x+1] == ARTIFACT) {
grid[y+i][x+1] = MINED;
player["artifacts"]++;
}
else if (grid[y+i][x+1] == DIRT) {
grid[y+i][x+1] = MINED;
player["dirt"]++;
}
}
}
else if (right) {
//left 3
for (int i = 0; i < 3; i++) {
if (grid[y-1][x+i] == ORE) {
grid[y-1][x+i] = MINED;
player["ore"]++;
}
else if (grid[y-1][x+i] == ARTIFACT) {
grid[y-1][x+i] = MINED;
player["artifacts"]++;
}
else if (grid[y-1][x+i] == DIRT) {
grid[y-1][x+i] = MINED;
player["dirt"]++;
}
}
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y][x+i] == ORE) {
grid[y][x+i] = MINED;
player["ore"]++;
}
else if (grid[y][x+i] == ARTIFACT) {
grid[y][x+i] = MINED;
player["artifacts"]++;
}
else if (grid[y][x+i] == DIRT) {
grid[y][x+i] = MINED;
player["dirt"]++;
}
}
//right 3
for (int i = 0; i < 3; i++) {
if (grid[y+1][x+i] == ORE) {
grid[y+1][x+i] = MINED;
player["ore"]++;
}
else if (grid[y+1][x+i] == ARTIFACT) {
grid[y+1][x+i] = MINED;
player["artifacts"]++;
}
else if (grid[y+1][x+i] == DIRT) {
grid[y+1][x+i] = MINED;
player["dirt"]++;
}
}
}
else if (left) {
//left 3
for (int i = 0; i < 3; i++) {
if (grid[y-1][x-i] == ORE) {
grid[y-1][x-i] = MINED;
player["ore"]++;
}
else if (grid[y-1][x-i] == ARTIFACT) {
grid[y-1][x-i] = MINED;
player["artifacts"]++;
}
else if (grid[y-1][x-i] == DIRT) {
grid[y-1][x-i] = MINED;
player["dirt"]++;
}
}
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y][x-i] == ORE) {
grid[y][x-i] = MINED;
player["ore"]++;
}
else if (grid[y][x-i] == ARTIFACT) {
grid[y][x-i] = MINED;
player["artifacts"]++;
}
else if (grid[y][x-i] == DIRT) {
grid[y][x-i] = MINED;
player["dirt"]++;
}
}
//right 3
for (int i = 0; i < 3; i++) {
if (grid[y+1][x-i] == ORE) {
grid[y+1][x-i] = MINED;
player["ore"]++;
}
else if (grid[y+1][x-i] == ARTIFACT) {
grid[y+1][x-i] = MINED;
player["artifacts"]++;
}
else if (grid[y+1][x-i] == DIRT) {
grid[y+1][x-i] = MINED;
player["dirt"]++;
}
}
}
}
else if (upgrades[2] == 3) { //just depth upgraded
if (up) {
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y-i][x] == ORE) {
grid[y-i][x] = MINED;
player["ore"]++;
}
else if (grid[y-i][x] == ARTIFACT) {
grid[y-i][x] = MINED;
player["artifacts"]++;
}
else if (grid[y-i][x] == DIRT) {
grid[y-i][x] = MINED;
player["dirt"]++;
}
}
}
else if (down) {
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y+i][x] == ORE) {
grid[y+i][x] = MINED;
player["ore"]++;
}
else if (grid[y+i][x] == ARTIFACT) {
grid[y+i][x] = MINED;
player["artifacts"]++;
}
else if (grid[y+i][x] == DIRT) {
grid[y+i][x] = MINED;
player["dirt"]++;
}
}
}
else if (right) {
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y][x+i] == ORE) {
grid[y][x+i] = MINED;
player["ore"]++;
}
else if (grid[y][x+i] == ARTIFACT) {
grid[y][x+i] = MINED;
player["artifacts"]++;
}
else if (grid[y][x+i] == DIRT) {
grid[y][x+i] = MINED;
player["dirt"]++;
}
}
}
else if (left) {
//2 in front of player
for (int i = 1; i < 3; i++) {
if (grid[y][x-i] == ORE) {
grid[y][x-i] = MINED;
player["ore"]++;
}
else if (grid[y][x-i] == ARTIFACT) {
grid[y][x-i] = MINED;
player["artifacts"]++;
}
else if (grid[y][x-i] == DIRT) {
grid[y][x-i] = MINED;
player["dirt"]++;
}
}
}
}
else if (upgrades[3] == 3) { //just width upgraded
if (up || down) {
//left
if (grid[y][x-1] == ORE) {
grid[y][x-1] = MINED;
player["ore"]++;
}
else if (grid[y][x-1] == ARTIFACT) {
grid[y][x-1] = MINED;
player["artifacts"]++;
}
else if (grid[y][x-1] == DIRT) {
grid[y][x-1] = MINED;
player["dirt"]++;
}
//right
if (grid[y][x+1] == ORE) {
grid[y][x+1] = MINED;
player["ore"]++;
}
else if (grid[y][x+1] == ARTIFACT) {
grid[y][x+1] = MINED;
player["artifacts"]++;
}
else if (grid[y][x+1] == DIRT) {
grid[y][x+1] = MINED;
player["dirt"]++;
}
}
else if (right || left) {
//top
if (grid[y-1][x] == ORE) {
grid[y-1][x] = MINED;
player["ore"]++;
}
else if (grid[y-1][x] == ARTIFACT) {
grid[y-1][x] = MINED;
player["artifacts"]++;
}
else if (grid[y-1][x] == DIRT) {
grid[y-1][x] = MINED;
player["dirt"]++;
}
//bottom
if (grid[y+1][x] == ORE) {
grid[y+1][x] = MINED;
player["ore"]++;
}
else if (grid[y+1][x] == ARTIFACT) {
grid[y+1][x] = MINED;
player["artifacts"]++;
}
else if (grid[y+1][x] == DIRT) {
grid[y+1][x] = MINED;
player["dirt"]++;
}
}
}
if (grid[y][x] == DIRT) { //process original block
int z = rand() % 100;
if (z == 0) { //1% chance artifact in dirt
std::cout << "\nWhile digging, you found an ancient artifact!" << '\n';
player["artifacts"]++;
MySleep(2);
}
else if (z == 1) { //1% chance ore in dirt
std::cout << "\nWhile digging, you found a rare ore!" << '\n';
player["ore"]++;
MySleep(2);
}
player["dirt"]++;
}
else if (grid[y][x] == SHOP) {
CallShop();
}
else if (grid[y][x] == ARTIFACT) {
std::cout << "\nWhile digging, you found an ancient artifact!" << '\n';
MySleep(2);
player["artifacts"]++;
}
else if (grid[y][x] == ORE) {
std::cout << "\nWhile digging, you found a rare ore!" << '\n';
MySleep(2);
player["ore"]++;
}
else if (grid[y][x] == MINER) {
return MinerFight(y,x); //valid only if miner dies
}
else if (grid[y][x] == MINIBOSS) {
return Miniboss();
}
else if (grid[y][x] == BOSS) {
return Boss();
}
return true;
}
///////////////////////////////////////////////////////////////////////////////
//calls shop when player steps into a shop
static void CallShop() {
bool finish = false;
bool asked = false;
char x;
std::cout << "You come across a small opening and see that there's a store inside.\n";
std::cout << "Would you like to shop? I buy Ore! Enter Y if yes!\n";
InputClear();
std::cin >> x;
if (!(x == 'y' || x == 'Y')) {
std::cout << "This could be goodbye forever. Enter Y if you want to shop.\n";
InputClear();
std::cin >> x;
}
if (x == 'y' || x == 'Y') {
//main store loop
while (!finish) {
std::cout << "\n\nYou take inventory: Ore: " << player["ore"] << " Artifacts: ";
std::cout << player["artifacts"] << " Coins " << player["coins"] << '\n';
std::cout << "The shop owner poins to a sign that reads:\n\nPick:\n";
std::cout << "1. Sell ore (5/pc!)\n2. Buy artifacts (30/pc)\n";
std::cout << "3. Deal of the Day\n4. Leave\n\nWhat would you like to do?\n";
InputClear();
std::cin >> x;
if (x == '1' || x == '2' || x == '3' || x == '4' || x == 'q') {
if (x == '1')
SellOre();
else if (x == '2')
BuyArtifacts();
else if (x == '3') {
if (!asked) { //can only see upgrade offer once
Trade();
asked = true;
} else {
std::cout << "We've already discussed that. I'm not sayin it all again.\n\n";
MySleep(3);
}
} else //q or 4
finish = true;
} else { //invalid input
std::cout << "Sorry, I didn't get that. Which number did you want?\n\n";
MySleep(3);
} //end input if/else
} //end store while loop
} //end if x == y
std::cout << "\nAlright, see you later. Oh, and grab some bread on your way out. Keeps ya hardy.\n";
MySleep(3);
player["health"] = player["maxHP"]; //heals player
std::cout << "The bread looks delicious. You grab some and take a bite. On your way out you feel";
std::cout << " refreshed. Ahh, bread.\n";
MySleep(4);
return;
}
///////////////////////////////////////////////////////////////////////////////
//initializes globals and calls GenMap
static void Init() {
//set globals
player["x"] = player["y"] = GRID_UPPER/2;//player starting in middle of the map
player["damage"] = 10;
player["ore"] = player["artifacts"] = player["dirt"] = player["coins"] = 0;
player["kills"] = player["died"] = player["level"] = 0;
player["health"] = player["maxHP"] = 35;
game = true;
for (int i = 0; i < UPGRADE_UPPER; i++) {
upgrades[i] = 0;
}
//make and set map
GenerateGrid();
}
///////////////////////////////////////////////////////////////////////////////
//shop helper if you want to sell ore
static void SellOre() {
int temp;
std::cout << "How much?\n";
InputClear();
std::cin >> temp;
if (temp > player["ore"]) {
std::cout << "You don't have enough ore! You only have " << player["ore"] << " ore\n\n";
MySleep(2);
}
else if (temp == 0) {
std::cout << "Alright...\n";
MySleep(2);
}
else {
player["ore"] -= temp;
player["coins"] += temp*5;
std::cout << "Pleasure doing business with you!\n\n";
MySleep(2);
}
}
///////////////////////////////////////////////////////////////////////////////
//shop helper if you want to buy artifacts
static void BuyArtifacts() {
int temp;
std::cout << "How much?\n";
InputClear();
std::cin >> temp;
if (temp*30 > player["coins"]) {
std::cout << "You don't have enough coins! You only have " << player["coins"] << " coins\n\n";
MySleep(2);
return;
}
else if (temp == 0) {
std::cout << "Umm... Okay.\n";
MySleep(2);
} else {
player["coins"] -= temp*30;
player["artifacts"] += temp;
std::cout << "Pleasure doing business with you!\n\n";
MySleep(2);
}
}
///////////////////////////////////////////////////////////////////////////////
//shop helper if you want to trade for an upgrade
static void Trade() {
char input;
//cost ranges from 15-35
//nums 16-29 have a higher probability
int cost = rand() % 35;
if (cost < 15) { cost += 15; }
std::cout << "\nOkay, I only have one fine deal for you.\n";
std::cout << "If you have " << cost << " ancient artifacts then I may consider selling...\n";
std::cout << "The only item that would help you is a magnificent Upgrade!\n\n";
int random = rand() % UPGRADE_UPPER; //picks what upgrade the shop has
if (upgrades[random] >= 3) { //3 is the max level an upgrade can achieve
std::cout << "Oh... It looks like you already have the upgrade I was going to offer.\n";