-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamePlay.cs
140 lines (124 loc) · 3.6 KB
/
GamePlay.cs
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
using System;
using Swingy.Views;
namespace Swingy
{
public class GamePlay
{
private Hero Hero;
private View View;
public GamePlay(View view)
{
View = view;
}
/*
* Create Hero with name and type
*/
public Hero CreateHero()
{
string choice;
Console.ReadLine();
View.Write("Enter hero name: ");
Hero = new Hero();
Hero.Name = Console.ReadLine();
View.WriteLine("Choose hero type");
View.WriteLine("1. Wizard");
View.WriteLine("2. Warrior");
View.WriteLine("3. Alchemist");
View.Write("Your choice: ");
//Assign hero type based on player input
switch (TakeInt(3))
{
case 1:
choice = "Wizard";
break;
case 2:
choice = "Warrior";
break;
default:
choice = "Alchemist";
break;
}
Hero.Type = choice;
return Hero;
}
public void SetHero(Hero hero)
{
Hero = hero;
}
/*
* Pick a direction for hero to navigate
*/
public string Direction()
{
View.WriteLine("Choose a direction");
View.WriteLine("w: North");
View.WriteLine("d: East");
View.WriteLine("s: South");
View.WriteLine("a: West");
View.Write("Your direction: ");
//Return player input
return TakeDir();
}
/*
* Move on a position occupied by a villian and choose whether to fight or run
*/
public void EnemyEncounter(Board board, Character e)
{
if (e != null)
{
View.WriteLine("Enemy encountered, fight or run?");
View.WriteLine("1. Fight");
View.WriteLine("2. Run");
View.Write("Your response: ");
Hero.Opponent = e;
e.Opponent = Hero;
switch (TakeInt(2))
{
case 1:
Hero.Fight(board);
break;
case 2:
Hero.Run(board);
break;
}
Console.ReadLine();
}
}
/*
* Only accept an integer that is greater than or equal to 1 and less than cap from player input
*/
public int TakeInt(int cap)
{
int choice = Console.Read() - 48;
if (choice < 1 || choice > cap)
{
Console.ReadLine();
View.Write("Invalid choice, try again: ");
//Prompt player for another input
return TakeInt(cap);
}
else
return choice;
}
/*
* Prompt player for direction and only return valid input
*/
private string TakeDir()
{
string dir = Console.ReadLine();
switch (dir)
{
case "w":
case "d":
case "s":
case "a":
case "q":
return dir;
default:
View.Write("Invalid direction, choose again: ");
//Prompt player for another direction input
return TakeDir();
}
}
}
}