-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirtualPet1.0
704 lines (532 loc) · 24.5 KB
/
VirtualPet1.0
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
/*
Virtual Pet Selector 8000 made by Ishan Dutta
MIT License copyright
Virtual Pet 1.0 Project Submission
*/
using System;
namespace VirtualPet1._0
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Virtual Pet Selector 8000";
Console.Clear();
Story si = new Story();
}
}
class Pets
{
public string petname = "";
public string cat = "Cat";
public string dog = "Dog";
public string parrot = "Parrot";
public int petlevel = 0;
public string toy = "";
public int toylevel = 0;
public string input = "";
public bool feed = true;
public int hunger = 100;
public int playerlevel = 10;
public int coins = 0;
public int playercoins = 0;
public bool coincheck = true;
public int tries = 0;
public void intro()
{
Console.WriteLine("Welcome to Ishan's Virtual Pet Selector 8000");
Console.WriteLine("Press any key to get started...");
Console.ReadKey();
Console.Clear();
Console.WriteLine("Please select the type of pet you would like to take care of");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(cat);
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine(dog);
Console.ResetColor();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(parrot);
Console.ResetColor();
input = Console.ReadLine();
if (input.ToLower() == "dog")
{
Console.Clear();
Dog doggo = new Dog();
doggo.start();
doggo.playerstart();
doggo.doglevel();
}
else if (input.ToLower() == "cat")
{
Console.Clear();
Cat catto = new Cat();
catto.start();
catto.playerstart();
catto.catlevel();
Console.ReadKey();
}
else if (input.ToLower() == "parrot")
{
Console.Clear();
Parrot parrotto = new Parrot();
parrotto.start();
parrotto.playerstart();
parrotto.parrotlevel();
}
else
{
Console.WriteLine("Incorrect answer! Please try again...");
Console.Clear();
intro();
}
}
public void start()
{
Console.WriteLine("Excellent choice!! Please name your pet:");
petname = Console.ReadLine();
Console.Write("The name you have selected is ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(petname);
Console.ResetColor();
Console.Write(".\n\n");
Console.WriteLine("Press any key to start....");
Console.ReadKey();
Console.Clear();
}
public void playerstart()
{
Console.WriteLine("Currently the player level is ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel);
Console.ResetColor();
Console.Write(".\n\n");
Console.WriteLine("Currently the pet level is ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(petlevel);
Console.ResetColor();
Console.Write(".\n\n");
Console.Write("You have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins);
Console.ResetColor();
Console.Write(" coins.");
Console.ReadKey();
Console.Clear();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Let us begin our adventure");
Console.ResetColor();
Console.WriteLine("\n\n");
Console.WriteLine("Press any key to continue....");
Console.ReadKey();
Console.Clear();
}
}
class Cat : Pets
{
public void catlevel()
{
Console.WriteLine("Your cat is currently level ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(petlevel);
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Would you like to feed your cat?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.WriteLine("Your cat is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your cat is now full. Please wait till they are hungry again.");
Console.Write("Your cat's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
coincheck = true;
feed = true; //used for later usage
}
else
{
Console.WriteLine("That's alright! But your cat is very hungry, are you sure you do not want to feed your cat?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.Write("\nYou have not taken care of your cat, you have lost a level.\nYour level is now: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(playerlevel - 1);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins);
Console.ResetColor();
Console.Write(" coins.");
Console.Clear();
Console.Write("Oh! What's this? Your pet found a bag of ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("50");
Console.ResetColor();
Console.Write(" coins.\n");
Console.WriteLine("Please take care of your pet next time!");
coins = 50;
coincheck = false;
Console.ReadKey();
Console.Clear();
}
else
{
Console.WriteLine("Your cat is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your cat is now full. Please wait till they are hungry again.");
Console.Write("Your cat's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
coincheck = true;
feed = true; //used for later usage
Console.WriteLine("\n\nPress any key to proceed....");
Console.ReadKey();
}
}
}
}
class Dog : Pets
{
public void doglevel()
{
Console.WriteLine("Your dog is currently level ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(petlevel);
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Would you like to feed your dog?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.WriteLine("Your dog is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your dog is now full. Please wait till they are hungry again.");
Console.Write("Your dog's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
feed = true; //used for later usage
}
else
{
Console.WriteLine("That's alright! But your dog is very hungry, are you sure you do not want to feed your cat?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.Write("\nYou have not taken care of your dog, you have lost a level.\nYour level is now: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(playerlevel - 1);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins);
Console.ResetColor();
Console.Write(" coins.");
Console.Clear();
Console.Write("Oh! What's this? Your pet found a bag of ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("50");
Console.ResetColor();
Console.Write(" coins.\n");
Console.WriteLine("Please take care of your pet next time!");
coins = 50;
coincheck = false;
Console.ReadKey();
Console.Clear();
}
else
{
Console.WriteLine("Your dog is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your dog is now full. Please wait till they are hungry again.");
Console.Write("Your dog's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
feed = true; //used for later usage
Console.WriteLine("\n\nPress any key to proceed....");
Console.ReadKey();
}
}
}
}
class Parrot : Pets
{
public void parrotlevel()
{
Console.WriteLine("Your parrot is currently level ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(petlevel);
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Would you like to feed your parrot?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.WriteLine("Your parrot is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your parrot is now full. Please wait till they are hungry again.");
Console.Write("Your parrot's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
feed = true; //used for later usage
}
else
{
Console.WriteLine("That's alright! But your parrot is very hungry, are you sure you do not want to feed your cat?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
Console.Write("\nYou have not taken care of your parrot, you have lost a level.\nYour level is now: ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(playerlevel - 1);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins);
Console.ResetColor();
Console.Write(" coins.");
Console.Clear();
Console.Write("Oh! What's this? Your pet found a bag of ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("50");
Console.ResetColor();
Console.Write(" coins.\n");
Console.WriteLine("Please take care of your pet next time!");
coins = 50;
Console.ReadKey();
Console.Clear();
coincheck = false;
}
else
{
Console.WriteLine("Your parrot is happy. He says thank you for feeding them.\n");
Console.Write("Your level is now: ");
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(playerlevel + 1);
Console.ResetColor();
Console.WriteLine("\nYay!! Your parrot is now full. Please wait till they are hungry again.");
Console.Write("Your parrot's hunger level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(hunger);
Console.ResetColor();
Console.Write("\nYour pet level is now: ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(petlevel + 1);
Console.ResetColor();
Console.Write("\nYou have ");
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.Write(coins + 50);
Console.ResetColor();
Console.Write(" coins.");
coins = 50;
feed = true; //used for later usage
Console.WriteLine("\n\nPress any key to proceed....");
Console.ReadKey();
}
}
}
}
class Story
{
Pets pi = new Pets();
Store si = new Store();
public Story()
{
pi.intro();
level1();
level2();
si.storestart();
si.shop();
level3();
Console.ReadKey();
Console.Clear();
}
public void level1()
{
Console.Clear();
Console.WriteLine("You have set off on a long adventure because your boss was mean and hates you.");
Console.WriteLine("You also want your pets to have fun however.");
Console.WriteLine("But you cannot leave your pet alone, what will you ever do?\n");
Console.ForegroundColor = ConsoleColor.DarkGray;
for (int i = 0; i < 11; i++)
{
Console.WriteLine(".");
}
Console.ResetColor();
Console.WriteLine("\nA lot of time passes by and you finally think of an idea.");
Console.Write("You say to yourself, \"");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("I can send my pets on a boat with my trusty assistant");
Console.ResetColor();
Console.Write(" \".");
Console.ReadKey();
Console.Clear();
}
public void level2()
{
Console.WriteLine("Your pet is now sailing on the high seas with your assistant taking care of them.");
Console.ForegroundColor = ConsoleColor.DarkGray;
for (int i = 1; i < 4; i++)
{
Console.WriteLine(i + " days later.");
}
Console.ResetColor();
Console.WriteLine("Your assistant reports that your pet has been eating properly and drinking lots of water.");
Console.Clear();
Console.WriteLine("You then ask your assistant to stop by an island to buy some toys.");
Console.Write("\nYour assistant finds a nearby island called ");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write("Tiki Hama");
Console.ResetColor();
Console.Write(".\n\n");
Console.WriteLine("You arrive.\n\n");
Console.WriteLine("Press any key to continue....");
Console.ReadKey();
Console.Clear();
}
public void level3()
{
Console.WriteLine("You and your pet finally meet days later and have one big giant hug.\n");
Console.WriteLine("Thank you for playing my Virtual Pet selector.\n");
Console.WriteLine("Have a great day!!");
}
}
class Store : Pets
{
public void storestart()
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Welcome to Tiki Hama's world-famous pet store!!\n");
Console.ResetColor();
}
public void shop() //need to add economy system where player coins would be deducted accordingly
{
Console.WriteLine("What would you like to buy? Please enter the number.");
Console.Write("1) ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Chew Toy (50 coins)\n");
Console.ResetColor();
Console.Write("2) ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Doll (50 coins)\n");
Console.ResetColor();
Console.Write("3) ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("Ball (60 coins and Pet Level 2)\n");
Console.ResetColor();
toy = Console.ReadLine();
if (toy == "1")
{
Console.WriteLine("Excellent! You can now give your pet a Chew Toy.\n");
Console.WriteLine("Thank you for visiting Tiki Hama. See you later.");
Console.ReadKey();
} else if (toy == "2")
{
Console.WriteLine("Excellent! You can now give your pet a Doll\n");
Console.WriteLine("Thank you for visiting Tiki Hama. See you later.");
Console.ReadKey();
}
else
{
Console.WriteLine("You don't have enough coins to buy anything or your pet level is not high enough.");
Console.WriteLine("Would you like to go back to the shop?");
input = Console.ReadLine();
if (input.ToLower() == "yes")
{
shop();
}
else
{
Console.WriteLine("Thank you for visiting Tiki Hama. See you later.");
}
}
Console.Clear();
}
}
}
/*
Suggestions: 1) Reconsider your application's design. - You have a good base class: Pet (I would make it singular, though). You don't need to have the fields cat, dog, etc in Pet - those are already sub classes. Instead of the 3 strings you could have one: type. - Not sure why playerlevel is mixed in with the Pet? That would seem to make more sense as part of a Player class? Same thing with toylevel - that could be part of a Toy or Item class? Related, methods like Intro() and playerstart() seem out of place in the Pet class. 2) What makes a cat different from a dog or a parrot? Figure out what is unique about your sub classes and add in those fields/methods. 3) Catlevel and Doglevel have a lot of redundant code. Think about grouping the statements together and abstracting them out. For example the statements that allow a pet to be fed could be a general Eat() method, right? And if ALL pets eat, it could be part of the Pet class (instead of in the subclasses). It might help to think about the nouns and verbs. For example: A *Player* can *Feed()* a *Pet*. A *Pet* can *Eat()* what a *Player* has provided (maybe with a *Feed()* method). 4) Your documentation doesn't include much information about inheritance, but you are obviously using it in your application. You mention it in your UML, and you have it in your code: class Cat : Pets {} (Your class Cat is inheriting from Pets.) Can you better clarify how inheritance is being used in your application? 5) How can you better describe the use of abstraction and encapsulation in your project? 6) I see that you can choose the type of pet (cat, dog, parrot), and that you can customize the name. How do you allow players to customize their pet in two other ways? (for the minimum four aspects) 7) How is at least one of the pet's aspects influenced by another?
*/