-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinecraft.cpp
More file actions
1678 lines (1508 loc) · 66.5 KB
/
Minecraft.cpp
File metadata and controls
1678 lines (1508 loc) · 66.5 KB
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
// CSCI1300 Fall 2022 Project 3
// Author: Benson Zou
//Partner: Trish Le
// Recitation: 303 – Chanheum Park
// Project 3 - Minecraft.cpp
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include "Minecraft.h"
#include "Mob.h"
#include "Resources.h"
#include "Map.h"
#include "Item.h"
using namespace std;
Minecraft::Minecraft() {
username_ = "";
}
//constructor
Minecraft::Minecraft(string username) {
//users stats
username_ = username;
health_points_ = 10;
max_hp_ = 10;
xp_ = 0;
mobs_killed_ = 0;
//game assets/tangibles
//mobs, we'll pull these out of the mobs_ array everytime the player needs to fight one
Resources creeper_drop = Resources("GUNPOWDER", 1);
Mob creeper = Mob("Creeper", 10, 5, creeper_drop);
mobs_.push_back(creeper);
Resources zombie_drop = Resources("ROTTEN FLESH", 1);
Mob zombie = Mob("Zombie", 10, 2, zombie_drop);
mobs_.push_back(zombie);
Resources skeleton_drop = Resources("BONE", 1);
Mob skeleton = Mob("Skeleton", 10, 3, skeleton_drop);
mobs_.push_back(skeleton);
Resources spider_drop = Resources("SPIDER EYE", 1);
Mob spider = Mob("Spider", 10, 2, spider_drop);
mobs_.push_back(spider);
//starting item
//player needs to be able to chop wood in the beginning, we'll give them an axe
Item wooden_axe = Item("WOODEN AXE", 4, 0, true, false);
items_.push_back(wooden_axe);
//starting resources
Resources food = Resources("FOOD", 1);
inventory_.push_back(food);
// Map("overworld"); //need to figure out how to generate multiple map TYPES, like end, lower level...
// Map("end_dimension");
// Map("lower_level");
//time permitting, nether
Resources dragon_drop = Resources("DRAGON DROP", 1);
ender_dragon_ = Mob("Dragon", 40, 10, dragon_drop);
}
/*
1. Displays user information such as username, HP, Xp, mobs killed
2. Loops through every vector and displays elements such as inventory and items
*/
void Minecraft::stats() { //displays stats for player at any given moment, username, gear, hp, xp, resources
cout << "---------------------------USER STATISTICS---------------------------" << endl;
cout << "USER TAG: " << username_ << " | " << "HP: " << health_points_ << " | XP: " << xp_ << " | TOTAL MOBS KILLED: " << mobs_killed_ << endl;
cout << "GEAR/ITEMS: [ ";
if(items_.size() > 0) {
cout << items_[0].getItemName();
for(int i = 1; i < items_.size(); i++){
cout << " , "<<items_[i].getItemName();
}
}
cout << " ] " << endl;
cout << "INVENTORY: [ ";
if(inventory_.size() > 0){
cout << inventory_[0].getName() << ": " << inventory_[0].getAmount();
for(int i = 1; i < inventory_.size(); i++){
cout << " , "<<inventory_[i].getName() << ": " << inventory_[i].getAmount();
}
}
cout << " ]" << endl;
cout << "---------------------------------------------------------------------" << endl;
return;
}
/*
1. presents a menu for the user to select which action they would like to do:
move, craft, trade, mine, eat, quit
2. pulls up another menu if craft or trade is chosen
3. calls on appropriate minecraft function for whatever choice the user picks
4. quit game if user picks so
*/
int Minecraft::action_menu(int mapIndex) { //displays actions for player in any given moment
//dynamic action menu, only prints certain action if player is in position to do them
string options[128]; //temporary string array
//index indicates choice number
//string indications action
//displays available actions
cout << "------------------------------ACTION MENU:--------------------------------" << endl;
cout << " USE 'W' 'A' 'S' 'D' KEYS TO MOVE ON MAP " << endl;
//cout << " 1. MOVE (Use 'W' 'A' 'S' 'D' as arrow keys)" << endl; //call on map function to move
cout << " 1. CRAFT " << endl; //crafting function not yet made: pull up a crafting menu
cout << " 2. EAT FOOD " << endl; //eat function: increase health, decrement food resource
int n = 2;
if (map_.isNextToVillage() && mapIndex == 0) {
n++;
options[n] = "TRADE";
cout << " " << n << ". TRADE " <<endl;
}
if (map_.isNextToIron() || map_.isNextToGold() || map_.isNextToDiamond()) {
if (mapIndex == 1) {
n++;
options[n] = "MINE";
cout << " " << n << ". MINE ORE " << endl;
}
}
if (map_.isNextToTree() && mapIndex == 0) {
n++;
options[n] = "CHOP";
cout << " " << n << ". CHOP" << endl;
}
if (map_.isNextToMob() && mapIndex == 0) {
n++;
options[n] = "FIGHT";
cout << " " << n << ". FIGHT" << endl;
}
if (map_.isNextToAnimal() && mapIndex == 0) {
n++;
options[n] = "GENTLY AND PAINLESSLY HARM AN INNOCENT ANIMAL AND TAKE ITS RESOURCE";
cout << " " << n << ". GENTLY AND PAINLESSLY HARM AN INNOCENT ANIMAL AND TAKE ITS RESOURCE" << endl;
}
if (map_.isNextToCave() && mapIndex == 0 ) {
n++;
options[n] = "ENTER CAVE";
cout << " " << n << ". ENTER CAVE" << endl;
}
if (map_.isNextToCave() && mapIndex == 1) {
n++;
options[n] = "LEAVE CAVE";
cout << " " << n << ". LEAVE CAVE" << endl;
}
if (map_.isNextToStronghold() && mapIndex == 0) {
n++;
options[n] = "GO TO END";
cout << " " << n << ". GO TO END" << endl;
}
if (map_.isNextToStronghold() & mapIndex == 2) {
n++;
options[n] = "LEAVE END";
cout << " " << n << ". LEAVE END" << endl;
}
if (map_.isNextToDragon() && mapIndex == 2) {
n++;
options[n] = "ATTACK DRAGON";
cout << " " << n << ". ATTACK DRAGON" << endl;
}
n++;
cout << " " << n << ". QUIT GAME " << endl; //ends program //in mcDriver, if world.action_menu() returns 0, return 0 in int main ()
cout << "--------------------------------------------------------------------------" << endl;
//take string input
string sInput;
char choice;
//do{
//checks for valid choice input
cin >> sInput;
//take char input from string
choice = sInput[0];
//ascii values, ADSW, adsw,
if(choice != 65 && choice != 68 && choice != 83 && choice != 87 && choice != 97 && choice != 100 && choice != 115 && choice != 119 && !(choice < (n + 48)) && !(choice > 48) ){
cout << "That is not a valid option. Please enter a choice between 1-" << n << " or 'w', 'a', 's', and 'd'. " << endl;
}
int intChoice = choice - '0';
if (intChoice == 1) {
crafting();
}
if (intChoice == 2) { //EAT FOOD
YOMPNOMPNOMNOM();
}
if (options[intChoice] == "MINE") {
bonkbonkbonk();
}
if (options[intChoice] == "TRADE") {
trading();
}
if (options[intChoice] == "CHOP") {
wackwackwack();
}
if (options[intChoice] == "FIGHT") {
fighting(); //function, should display hp and such
if(health_points_ <= 0){
cout << "YOU DIED!" << endl;
return playerIsDead();
}
}
if (options[intChoice] == "GENTLY AND PAINLESSLY HARM AN INNOCENT ANIMAL AND TAKE ITS RESOURCE") {
harmAnimal(); //prints hp and such of animal, + display info about animal drop!
}
if (options[intChoice] == "ENTER CAVE") {
map_.travelToFrom(1,0);
mapIndex = 1;
}
if (options[intChoice] == "LEAVE CAVE") {
map_.travelToFrom(0,1);
mapIndex = 0;
}
if (options[intChoice] == "GO TO END") {
map_.travelToFrom(2,0);
mapIndex = 2;
}
if (options[intChoice] == "LEAVE END") {
map_.travelToFrom(0,2);
mapIndex = 0;
}
if (options[intChoice] == "ATTACK DRAGON") {
dragon();
if(health_points_ <= 0){
cout << "YOU DIED!" << endl;
return playerIsDead();
}
if(ender_dragon_.getMobHealth() <= 0){
return playerIsDead();
}
}
if(!map_.move(choice, mapIndex)) { //check if move function returns false
//move function returns false sometimes when the player
//bumps into a map element or is out of map bounds
cout << "player did not move" << endl;
cout << " " << endl;
}
//display map every time input is detected regardless of input validity
if (intChoice == n) {
return 3;
}
return mapIndex;
}
/*
1. Presents menu of crafting options for the user to choose from
2. Takes user input and asks for amount of resources they would like to input
3. Checks if user has enough resources to craft desired amount:
if so: calculate total number of items they successfully crafted
4. Decreases amount of inputted resource in inventory: if 0 then delete item from inventory
5. Adds the newly crafted resource to inventory
*/
int Minecraft::crafting(){
int num_crafted = 0; // amount that can actually be crafted
int craft_choice;
string input_string;
do{
cout << " " << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
cout << "What would you like to Craft? (Enter a number between 1-6)" << endl;
cout << "1) 4 WOODEN PLANKS | NEED: 1 Wood" << endl;
cout << "2) 4 STICKS | NEED: 2 Wooden Planks" << endl;
cout << "3) 1 PICKAXE | NEED: 3 Ores(Wooden Plank,Iron,Gold,or Diamond), 2 Sticks" << endl;
cout << "4) 1 SWORD | NEED: 2 Ores(Wooden Plank,Iron,Gold,or Diamond), 1 Stick" << endl;
cout << "5) 1 AXE | NEED: 3 Ores(Wooden Plank,Iron,Gold,or Diamond), 2 Stick" << endl;
cout << "6) QUIT CRAFTING MENU" << endl;
cout << "--------------------------------------------------------------------------------------------------" << endl;
int num_wood, num_planks, num_sticks, num_ores, ore_index, stick_index, amountOres,amountSticks, maxToolOres, maxToolSticks;
bool enoughOres = false;
bool enoughSticks = false;
bool have_enough = false;
bool found = false;
bool found_sticks = false;
string mineral;
int maxTool = 0;
Resources temp;
do{ //checks for valid choice input
//cin >> craft_choice;
cin >> input_string;
craft_choice = input_string[0]-'0';
if(craft_choice < 1 || craft_choice > 6){
cout << "That is not a valid option. Please enter a choice between 1-6." << endl;
}
} while(craft_choice < 1 || craft_choice > 6);
switch(craft_choice){
case 1: //wooden planks
do{
do{
cout << "How many Wood blocks would you like to input?" << endl;
cin >> input_string;
num_wood = input_string[0]-'0';
if(num_wood < 1){
cout << "Invalid input. Number of wood blocks must be at least 1." << endl;
}
}while(num_wood <1);
for(int i = 0; i < inventory_.size(); i++){ //loops through inventory
int current_amount = inventory_[i].getAmount();
if(inventory_[i].getName() == "WOOD"){ //checks if user has wood
found =true;
if(num_wood <= current_amount){ //if they have enough wood for the amount desired
have_enough = true;
num_crafted = num_wood*4;
inventory_[i].setAmount(current_amount - num_wood); //*****decide if should get rid of resource from inventory if amount = 0
if(inventory_[i].getAmount()==0){
inventory_.erase(inventory_.begin() + i);
}
addResource("WOODEN PLANK", num_crafted); //adds to inventory: calls on addResource()
cout << "You've successfully crafted " << num_crafted << " Wooden Planks!" << endl;
}
else{
cout << "That's not a valid input." << endl;
}
}
}
if(found == false){
have_enough = true;
cout <<"You don't have any Wood blocks! Go chop down some trees before crafting Wooden Planks!" << endl;
}
}while(have_enough == false);
break;
case 2: //sticks
do{
do{
cout << "How many Wooden Planks would you like to input?" << endl;
cin >> input_string;
num_planks = input_string[0]-'0';
if(num_planks < 2){
cout << "You need at least 2 wooden planks to craft sticks!" << endl;
}
}while(num_planks<2);
for(int i = 0; i < inventory_.size(); i++){ //loops through inventory
int current_amount = inventory_[i].getAmount();
if(inventory_[i].getName() == "WOODEN PLANK"){ //checks if user has planks
found = true;
if(num_planks <= current_amount){ //if they have enough planks to craft
have_enough = true;
num_crafted = num_planks*2;
inventory_[i].setAmount(current_amount - num_planks);
if(inventory_[i].getAmount()==0){
inventory_.erase(inventory_.begin() + i);
}
addResource("STICK", num_crafted); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted " << num_crafted << " Sticks!" << endl;
}
else{
cout << "That's not a valid input." << endl;
}
}
}
if(found == false){
have_enough = true;
cout << "You don't have any Wooden Planks! Make sure you craft some using wood before making sticks!" << endl;
}
}while(have_enough == false);
break;
case 3: //pickaxe
do{
cout << "What kind of ore is being used? (Type in 'Wood', 'Iron', 'Gold', or 'Diamond')" << endl;
cin >> mineral;
for(int i = 0; i < mineral.length(); i++){
mineral[i] = toupper(mineral[i]);
}
if(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND"){
cout << "That's not a valid ore input! Please type in one of the listed ores." << endl;
}
}while(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND");
if(mineral == "WOOD"){
mineral = "WOODEN PLANK";
}
do{
do{
cout << "How many " << mineral << " blocks would you like to input?" << endl;
cin >> input_string;
num_ores = input_string[0]-'0';
if(num_ores < 3){
cout << "Invalid input. Number of ore blocks must be at least 3." << endl;
}
}while(num_ores <3);
do{
cout << "How many STICKS would you like to input?" << endl;
cin >> input_string;
num_sticks = input_string[0]-'0';
if(num_sticks < 2){
cout << "Invalid input. Number of sticks must be 2." << endl;
}
}while(num_sticks < 2);
for(int i = 0; i < inventory_.size(); i++){ //loops through inventory
int num_resources = inventory_[i].getAmount();
if(inventory_[i].getName()== mineral){ //checks if user has ores in their inventory
found = true;
amountOres = num_resources;
if(num_ores <= num_resources){ //if they have enough ores:
have_enough = true;
enoughOres = true;
ore_index = i;
//number of pix they can make from ores
maxToolOres = num_ores/3;
}else{
cout << "That's not a valid input." << endl;
}
}
if(inventory_[i].getName()== "STICK"){
found_sticks = true;
amountSticks = num_resources;
if(num_sticks <= num_resources){
have_enough = true;
enoughSticks = true;
stick_index = i;
maxToolSticks = num_sticks/2;
}else{
cout << "That's not a valid input." << endl;
}
}
}
if(found == false || found_sticks == false){
have_enough = true;
cout << " You either don't have Wooden Planks or Sticks! You can't craft a pickaxe quite yet." << endl;
}
}while(have_enough == false);
if(enoughOres && enoughSticks){
if(maxToolOres < maxToolSticks){
num_crafted = maxToolOres;
}
else{
num_crafted = maxToolSticks;
}
inventory_[ore_index].setAmount(amountOres - num_crafted*3);
inventory_[stick_index].setAmount(amountSticks - num_crafted*2);
removeResource();
if(num_crafted > 0){
if(mineral == "WOODEN PLANK"){
mineral = "WOODEN";
}
if(mineral == "DIAMOND"){
addItem(Item(mineral+ " PICKAXE", 5, 0, false, true));
cout << "You've succesfully crafted a " << mineral << " PICKAXE! It does 5 damage to mobs, and can mine ores!" << endl;
cout << " " << endl;
}else if(mineral == "GOLD"){
addItem(Item(mineral+" PICKAXE", 3, 0, false, true)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " PICKAXE! It does 3 damage to mobs, and can mine ores!" << endl;
cout << " " << endl;
}else if(mineral == "IRON"){
addItem(Item(mineral+" PICKAXE", 2, 0, false, true)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " PICKAXE! It does 2 damage to mobs, and can mine ores!" << endl;
cout << " " << endl;
}else{
addItem(Item(mineral+" PICKAXE", 1, 0, false, true)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " PICKAXE! It does 1 damage to mobs, and can mine ores!" << endl;
cout << " " << endl;
}
}
}
break;
case 4: //sword
do{
cout << "What kind of ore is being used? (Type in 'Wood', 'Iron', 'Gold', or 'Diamond')" << endl;
cin >> mineral;
for(int i = 0; i < mineral.length(); i++){
mineral[i] = toupper(mineral[i]);
}
if(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND"){
cout << "That's not a valid ore input! Please type in one of the listed ores." << endl;
}
}while(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND");
if(mineral == "WOOD"){
mineral = "WOODEN PLANK";
}
do{
do{
cout << "How many " << mineral << " blocks would you like to input?" << endl;
cin >> input_string;
num_ores = input_string[0]-'0';
if(num_ores < 2){
cout << "Invalid input. Number of ore blocks must be at least 2." << endl;
}
}while(num_ores <2);
do{
cout << "How many STICKS would you like to input?" << endl;
cin >> input_string;
num_sticks = input_string[0]-'0';
if(num_sticks < 1){
cout << "Invalid input. Number of sticks must be 1." << endl;
}
}while(num_sticks < 1);
for(int i = 0; i < inventory_.size(); i++){ //loops through inventory
int num_resources = inventory_[i].getAmount();
if(inventory_[i].getName()== mineral){ //checks if user has ores in their inventory
found = true;
amountOres = num_resources;
if(num_ores <= num_resources){ //if they have enough ores:
have_enough = true;
enoughOres = true;
ore_index = i;
//number of pix they can make from ores
maxToolOres = num_ores/2;
}else{
cout << "That's not a valid input." << endl;
}
}
if(inventory_[i].getName()== "STICK"){
found_sticks = true;
amountSticks = num_resources;
if(num_sticks <= num_resources){
have_enough = true;
enoughSticks = true;
stick_index = i;
maxToolSticks = num_sticks;
}else{
cout << "That's not a valid input." << endl;
}
}
}
if(found == false || found_sticks == false){
have_enough = true;
cout << " You either don't have Wooden Planks or Sticks! You can't craft a sword quite yet." << endl;
}
}while(have_enough == false);
if(enoughOres && enoughSticks){
if(maxToolOres < maxToolSticks){
num_crafted = maxToolOres;
}
else{
num_crafted = maxToolSticks;
}
inventory_[ore_index].setAmount(amountOres - num_crafted*2);
inventory_[stick_index].setAmount(amountSticks - num_crafted);
removeResource();
if(num_crafted > 0){
if(mineral == "WOODEN PLANK"){
mineral = "WOODEN";
}
if(mineral == "DIAMOND"){
addItem(Item(mineral+ " SWORD", 15, 0, false, false));
cout << "You've succesfully crafted a " << mineral << " SWORD! It does 15 damage to mobs, and can harm an animal!" << endl;
cout << " " << endl;
}else if(mineral == "GOLD"){
addItem(Item(mineral+" SWORD", 10, 0, false, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " SWORD! It does 10 damage to mobs, and can harm animals!" << endl;
cout << " " << endl;
}else if(mineral == "IRON"){
addItem(Item(mineral+" SWORD", 5, 0, false, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " SWORD! It does 5 damage to mobs, and can harm animals!" << endl;
cout << " " << endl;
}else{
addItem(Item(mineral+" SWORD", 2, 0, false, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " SWORD! It does 2 damage to mobs, and can harm animals!" << endl;
cout << " " << endl;
}
}
}
break;
case 5: //axe
do{
cout << "What kind of ore is being used? (Type in 'Wood', 'Iron', 'Gold', or 'Diamond')" << endl;
cin >> mineral;
for(int i = 0; i < mineral.length(); i++){
mineral[i] = toupper(mineral[i]);
}
if(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND"){
cout << "That's not a valid ore input! Please type in one of the listed ores." << endl;
}
}while(mineral!= "WOOD" && mineral!= "IRON"&& mineral != "GOLD" && mineral != "DIAMOND");
if(mineral == "WOOD"){
mineral = "WOODEN PLANK";
}
do{
do{
cout << "How many " << mineral << " blocks would you like to input?" << endl;
cin >> input_string;
num_ores = input_string[0]-'0';
if(num_ores < 3){
cout << "Invalid input. Number of ore blocks must be at least 3." << endl;
}
}while(num_ores <3);
do{
cout << "How many STICKS would you like to input?" << endl;
cin >> input_string;
num_sticks = input_string[0]-'0';
if(num_sticks < 2){
cout << "Invalid input. Number of sticks must be 2." << endl;
}
}while(num_sticks < 2);
for(int i = 0; i < inventory_.size(); i++){ //loops through inventory
int num_resources = inventory_[i].getAmount();
if(inventory_[i].getName()== mineral){ //checks if user has ores in their inventory
found = true;
amountOres = num_resources;
if(num_ores <= num_resources){ //if they have enough ores:
have_enough = true;
enoughOres = true;
ore_index = i;
//number of pix they can make from ores
maxToolOres = num_ores/3;
}else{
cout << "That's not a valid input." << endl;
}
}
if(inventory_[i].getName()== "STICK"){
found_sticks = true;
amountSticks = num_resources;
if(num_sticks <= num_resources){
have_enough = true;
enoughSticks = true;
stick_index = i;
maxToolSticks = num_sticks/2;
}else{
cout << "That's not a valid input." << endl;
}
}
}
if(found == false || found_sticks == false){
have_enough = true;
cout << " You either don't have Wooden Planks or Sticks! You can't craft an axe quite yet." << endl;
}
}while(have_enough == false);
if(enoughOres && enoughSticks){
if(maxToolOres < maxToolSticks){
num_crafted = maxToolOres;
}
else{
num_crafted = maxToolSticks;
}
inventory_[ore_index].setAmount(amountOres - num_crafted*3);
inventory_[stick_index].setAmount(amountSticks - num_crafted*2);
removeResource();
if(num_crafted > 0){
if(mineral == "WOODEN PLANK"){
mineral = "WOODEN";
}
if(mineral == "DIAMOND"){
addItem(Item(mineral+ " AXE", 5, 0, true, false));
cout << "You've succesfully crafted a " << mineral << " AXE! It does 5 damage to mobs, and can chop wood!" << endl;
cout << " " << endl;
}else if(mineral == "GOLD"){
addItem(Item(mineral+" AXE", 3, 0, true, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " AXE! It does 3 damage to mobs, and can chop wood!" << endl;
cout << " " << endl;
}else if(mineral == "IRON"){
addItem(Item(mineral+" AXE", 2, 0, true, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " AXE! It does 2 damage to mobs, and can chop wood!" << endl;
cout << " " << endl;
}else{
addItem(Item(mineral+" AXE", 2, 0, true, false)); //adds to inventory: calls on addResource()
cout << "You've succesfully crafted a " << mineral << " AXE! It does 1 damage to mobs, and can chop wood!" << endl;
cout << " " << endl;
}
}
}
break;
case 6:
cout << "EXITING CRAFTING TABLE!" << endl;
cout << " " << endl;
return 0;
}
}while(craft_choice != 6);
return num_crafted;
}
/*
1. Pulls up trading menu that shows user the choices that they can trade for
2. Asks for the item they would like to trade for
3. Determines if they have enough materials to trade for certain item
4. If so, decrease the inputted item from inventory and add the newly traded item to inventory or item vector
*/
void Minecraft::trading(){
string input_string;
int trade_choice;
do{
cout << " " << endl;
cout << "----------------------------------------------------------------" << endl;
cout << "What would you like to trade?" << endl;
cout << "1. Bone -----> Diamond Chestplate" << endl;
cout << "2. Rotten Flesh ---> Diamond Leggings" << endl;
cout << "3. Gunpowder ------> Diamond Boots" << endl;
cout << "4. Spider Eye -----> Diamond Helmet" << endl;
cout << "5. Quit Trading Menu" << endl;
cout << "----------------------------------------------------------------" << endl;
do{
cin >> input_string;
trade_choice = input_string[0]- '0';
if(trade_choice < 1 || trade_choice > 5){
cout << "That's not a valid choice. Please enter a number between 1-4." << endl;
}
}while(trade_choice < 1 || trade_choice > 5);
int num_items;
bool item_found = false;
switch(trade_choice){
case 1:
num_items = getResourceAmount("BONE");
if(num_items < 1){
cout << "You do not have enough bone to make this trade." << endl;
break;
}
else{
for(int i = 0; i < items_.size(); i++){
if(items_[i].getItemName() == "DIAMOND CHESTPLATE"){
cout << "You already have a Diamond Chestplate!" << endl;
item_found = true;
break;
}
}
if(item_found == false){
for(int i = 0; i < inventory_.size(); i++){
item_found = true;
if(inventory_[i].getName() == "BONE"){
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+i);
}
cout << "Succesfully traded 2 Bones for a Diamond Chestplate! Your max HP went up by 10." << endl;
addItem(Item("DIAMOND CHESTPLATE", 0, 10, false, false));
}
}
if(item_found == false){
cout << "You don't have any bones!" << endl;
break;
}
changeMaxHp(10);
changeXp(5);
break;
}
}
case 2:
num_items = getResourceAmount("ROTTEN FLESH");
if(num_items < 1){
cout << "Unable to make trade. You do not have rotten flesh. Your max HP went up by 10." << endl;
break;
}
else{
for(int i = 0; i < items_.size(); i++){
if(items_[i].getItemName() == "DIAMOND LEGGINGS"){
cout << "You already have Diamond leggings!" << endl;
item_found = true;
break;
}
}
if(item_found == false){
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName() == "ROTTEN FLESH"){
item_found = true;
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+i);
}
cout << "Succesfully traded Rotten Flesh for Diamond Legging!" << endl;
addItem(Item("DIAMOND LEGGINGS", 0, 10, false, false));
}
}
if(item_found == false){
cout << "You don't have any Rotten Flesh!" << endl;
break;
}
changeHp(5);
changeMaxHp(10);
changeXp(5);
break;
}
}
case 3:
num_items = getResourceAmount("GUNPOWDER");
if(num_items < 1){
cout << "Unable to make trade. You do not have gunpowder." << endl;
break;
}
else{
for(int i = 0; i < items_.size(); i++){
if(items_[i].getItemName() == "DIAMOND BOOTS"){
cout << "You already have Diamond boots!" << endl;
item_found = true;
break;
}
}
if(item_found == false){
cout << "Succesfully traded Gunpowder for a Diamond Boots! Your max HP went up by 10." << endl;
addItem(Item("DIAMOND BOOTS", 0, 10, false, false));
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName() == "GUNPOWDER"){
item_found = true;
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+i);
}
}
}
if(item_found == false){
cout << "You don't have any gunpowder!" << endl;
break;
}
changeHp(5);
changeMaxHp(10);
changeXp(5);
break;
}
}
case 4:
num_items = getResourceAmount("SPIDER EYE");
if(num_items < 1){
cout << "Unable to make trade. You do not have a Spider eye." << endl;
break;
}
else{
for(int i = 0; i < items_.size(); i++){
if(items_[i].getItemName() == "DIAMOND HELMET"){
cout << "You already have Diamond helmet!" << endl;
item_found = true;
break;
}
}
if(item_found == false){
cout << "Succesfully traded Spider Eye for a Diamond Helmet!" << endl;
addItem(Item("DIAMOND HELMET", 0, 10, false, false));
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName() == "SPIDER EYE"){
item_found = true;
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+i);
}
}
}
if(item_found == false){
cout << "You don't have any Spider eyes!" << endl;
break;
}
changeHp(5);
changeMaxHp(10);
changeXp(5);
break;
}
}
case 5:
cout << "EXITING TRADING MENU!" << endl;
return;
}
}while(trade_choice!=5);
return;
}
/*
1. Decreases food resource in inventory by 1
2. Increases HP by 2
*/
void Minecraft::YOMPNOMPNOMNOM() {
string input_string;
int count = 1;
int food_choice;
string food_name;
vector<string> names;
cout << "Select which food you would like to consume: " << endl;
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName()=="FOOD" || inventory_[i].getName()=="LAMBCHOP" || inventory_[i].getName()=="STEAK"|| inventory_[i].getName()=="CHICKEN"){
cout << count << ". " << inventory_[i].getName() << endl;
names.push_back(inventory_[i].getName());
count++;
}
}
if(count == 1){
cout << "You don't have any food." << endl;
cout << " " << endl;
}else{
cin >> input_string;
food_choice = input_string[0]- '0';
if(food_choice < 1 || food_choice > count){
cout <<"Invalid Choice!" << endl;
}else{
food_name = names[food_choice-1];
}
if(getHp() >= getMaxHp()){
cout << "Your health is already full!" << endl;
cout << " " << endl;
return;
}
else if(getHp()+2 <= getMaxHp()){
changeHp(2);
changeXp(2);
cout << "You're HP and XP both went up by 2!" << endl;
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName()== food_name){
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+ i);
}
}
}
return;
}
else{
changeHp(getMaxHp()-getHp());
changeXp(2);
cout << "You're HP and XP both went up by 2!" << endl;
for(int i = 0; i < inventory_.size(); i++){
if(inventory_[i].getName()== food_name){
inventory_[i].increaseAmount(-1);
if(inventory_[i].getAmount() == 0){
inventory_.erase(inventory_.begin()+ i);
}
}
}
return;
}
}
return;
}
/*
1. only applicable if user has axe and is next to a wood block
2. if requirements met: add wood resource to inventory or increment it, and decrease durability on axe
3. if axe durability is 0, remove it from items list
*/
void Minecraft::wackwackwack() {
string input_string;
int item_choice;
int coords[2];
int count = 1;
cout << "Which Item would you like to use to chop?" << endl;
for(int i = 0; i < items_.size(); i++){
if(items_[i].getCanChop()){
cout << count << ". " << items_[i].getItemName()<< endl;
count++;
}
}