-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMenuProcess.cs
More file actions
205 lines (179 loc) · 5.71 KB
/
MenuProcess.cs
File metadata and controls
205 lines (179 loc) · 5.71 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
using CPCS3130_Project;
namespace CPSC3130_Project
{
//This class for the Menus process
//Provides Display all Menus
//Provides Check User, Check Password, Create User, Get User Infomation.
//Provides Create Character, Display Character Infomation
public class MenuProcess
{
int _userID = 0; //user ID - the arrayID of user in array
String _userName = "";
FileProcess _fileProcess = new FileProcess();
public MenuProcess()
{
}
//Get UserName
public String getUserName()
{
return _userName;
}
//Main Menu
public void DisplayMainMenu()
{
Console.WriteLine("Welcome to ***-Underdark Knights-***");
Console.WriteLine("1. Login ");
Console.WriteLine("2. Create Account ");
Console.WriteLine("3. Exit ");
}
//User Menu
public void DisplayUserMenu()
{
Console.WriteLine("1. Update account infomation ");
Console.WriteLine("2. Create new Character ");
Console.WriteLine("3. Display Character ");
Console.WriteLine("4. Log out ");
Console.WriteLine("5: Exit ");
}
//User Infomation Menu
public void DisplayUserInfoMenu()
{
Console.WriteLine("1. Change password: ");
Console.WriteLine("2. Change email: ");
Console.WriteLine("3. Exit:\n ");
}
//Method check user. Return true if user is found.
public bool CheckUser(String userInput, List<String[]> arrayData)
{
bool userCheck = false;
for (int i = 0; i < arrayData.Count; i++)
{
if (userInput.Equals(arrayData[i][0]))
{
this._userID = i;
_userName = arrayData[i][0];
userCheck = true;
}
}
return userCheck;
}
//Method check password. Return True if password match in 5 times
public bool CheckPassword(List<String[]> arrayData)
{
bool passwordCheck = false;
for (int count =4; count > -1; count --)
{
Console.Write("Passwords: ");
String passwordInput = Console.ReadLine();
if (passwordInput.Equals(arrayData[this._userID][1]))
{
Console.WriteLine("Login success.\n");
passwordCheck = true;
break;
}
else
{
Console.WriteLine($"\nWrong password for user {arrayData[this._userID][0]}.");
if (count == 0)
{
Console.WriteLine($"Sorry!!! - Return to Main Menu\n");
}
else
{
Console.WriteLine($"You have {count} attempt left.\n");
}
}
}
return passwordCheck;
}
//Method create user - init object from Account class and use its methods
public void CreateUser(String file, List<String[]> arrayData)
{
String[] userInfo = new String[3];
List<String[]> userData = new List<String[]>();
Account account = new Account();
bool userExist = true;
//Call create user method from Account Class
while (userExist == true)
{
account.CreateUsername();
//Call CheckUser method to check if username exist or not.
userExist = this.CheckUser(account.GetUsername(), arrayData);
if (userExist == true)
{
Console.WriteLine($"User {account.GetUsername()} exist. Get another username.\n");
}
}
//Call create password and email methods from Account Class
account.CreatePassword();
account.CreateEmail();
//Add values to Array
userInfo[0] = account.GetUsername();
userInfo[1] = account.GetPassword();
userInfo[2] = account.GetEmail();
//Add array values to List
userData.Add(userInfo);
//Create FileProcess instance object and write user info to file
//FileProcess fileProcess = new FileProcess();
_fileProcess.WriteFile(userData, file);
Console.WriteLine($"User created.\n");
}
//Method get user infomation. Return userinfo in array
public String[] GetUserInfo(String user)
{
String[] userInfo = new string[3];
String file = "UserData.txt";
List<String[]> arrayData = _fileProcess.GetArrayData(file);
for (int i = 0; i < arrayData.Count; i++)
{
if (user.Equals(arrayData[i][0]))
{
userInfo[0] = arrayData[i][0];
userInfo[1] = arrayData[i][1];
userInfo[2] = arrayData[i][2];
break;
}
}
return userInfo;
}
//Method Create Character - Create CharacterCreate instance object.
public void CreateCharacter(String fileName)
{
List<String[]> charData = new List<string[]> { };
Character character = new Character();
//Add data to Array and write to a file under "{username}_Character" name
character.DisplayCharacter();
charData.Add(character.GetName());
charData.Add(character.GetGender());
charData.Add(character.GetAlignment());
charData.Add(character.GetRace());
charData.Add(character.GetAge());
charData.Add(character.GetWeight());
charData.Add(character.GetHeight());
_fileProcess.WriteFile(charData, fileName);
}
//Method to Display Character infomation.
public void DisplayCharacter(String fileName)
{
//Read Character file and store in charInfo array
List<String[]> charInfo = _fileProcess.GetCharData(fileName);
Console.WriteLine("\n *** Character Infomation ***");
//Display array
for (int i = 0; i < charInfo.Count; i++)
{
for (int j = 0; j < charInfo[i].Length; j++)
{
if (j == charInfo[i].Length - 1)
{
Console.Write($":\t{charInfo[i][j]}\n");
}
else
{
Console.Write($"{charInfo[i][j]} \t ");
}
}
}
Console.WriteLine();
}
}
}