-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.cs
More file actions
224 lines (198 loc) · 7.81 KB
/
MainWindow.cs
File metadata and controls
224 lines (198 loc) · 7.81 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Student_Simulator
{
public partial class MainWindow : Form
{
public bool IsGameActive
{
get => Continue_btn.Enabled;
set => Continue_btn.Enabled = value;
}
//private Lazy<>
private Lazy<NewGameWindow> _newGame;
public GameManager GameManager;
private Student _player;
public MainWindow()
{
InitializeComponent();
_newGame = new Lazy<NewGameWindow>(() => new NewGameWindow(this));
GameManager = new GameManager(this);
}
private void Quit_btn_Click(object sender, EventArgs e)
{
Close();
}
private void NewGame_btn_Click(object sender, EventArgs e)
{
ToggleMenuVisibility();
_newGame.Value.Clear();
_newGame.Value.ShowDialog();
}
private void Continue_btn_Click(object sender, EventArgs e)
{
ToggleMenuVisibility();
}
public void ToggleMenuVisibility()
{
MenuPanel.Visible = !MenuPanel.Visible;
}
public void CreateStudent(int id, string nickname, string fieldOfStudy)
{
var skillset = CreateSkillsetForTerm(1, fieldOfStudy);
_player = new Student(id, nickname, fieldOfStudy, skillset);
}
Dictionary<string, int> CreateSkillsetForTerm(int term, string fieldOfStudy)
{
var tempListOfSubjects = DatabaseManager.RetrieveListOfSubjectsForTerm(term, fieldOfStudy);
var skillset = new Dictionary<string, int>();
foreach (var subject in tempListOfSubjects)
{
skillset.Add(subject, 0);
}
return skillset;
}
public void SetPlayerIndicators(int time)
{
PlayerIndicator_UserControl.MentalHealth = _player.MentalHealth;
PlayerIndicator_UserControl.PhysicalHealth = _player.PhysicalHealth;
PlayerIndicator_UserControl.Time = time;
}
private bool IsPossibleToAdjust((int MH, int PH, int Time) indicatorsTuple)
{
if (PlayerIndicator_UserControl.MentalHealth + indicatorsTuple.MH < 0) { return false; }
if (PlayerIndicator_UserControl.PhysicalHealth + indicatorsTuple.PH < 0) { return false; }
if (PlayerIndicator_UserControl.Time + indicatorsTuple.Time < 0) { return false; }
return true;
}
public void AdjustPlayerIndicators((int MH, int PH, int Time) indicatorsTuple)
{
_player.MentalHealth += indicatorsTuple.MH;
_player.PhysicalHealth += indicatorsTuple.PH;
PlayerIndicator_UserControl.MentalHealth = _player.MentalHealth;
PlayerIndicator_UserControl.PhysicalHealth = _player.PhysicalHealth;
PlayerIndicator_UserControl.Time += indicatorsTuple.Time;
}
private void Menu_btn_Click(object sender, EventArgs e)
{
ToggleMenuVisibility();
}
private void EndTurn_btn_Click(object sender, EventArgs e)
{
GameManager.NextTurn(new(5, 5, 24));
ResetActionButtons();
}
public void InsertSubjectsInListbox()
{
//TODO insert the skillset on a form in a cleaner way (to eliminate problems when skillset list becomes too long)
// currenltly there are 2 listboxes that need to be scrolled separately
SkillsetName_listbox.BeginUpdate();
SkillsetLevel_listbox.BeginUpdate();
foreach (var skill in _player.Skillset)
{
SkillsetName_listbox.Items.Add(skill.Key);
SkillsetLevel_listbox.Items.Add(skill.Value);
}
SkillsetName_listbox.EndUpdate();
SkillsetLevel_listbox.EndUpdate();
}
public void UpdateSkillsetLevels()
{
SkillsetLevel_listbox.BeginUpdate();
SkillsetLevel_listbox.Items.Clear();
foreach (var skill in _player.Skillset)
{
SkillsetLevel_listbox.Items.Add(skill.Value);
}
SkillsetLevel_listbox.EndUpdate();
}
public void WriteWeeklyScheduleOnScreen()
{
WeeklySchedule_label.Text = GameManager.Schedule.ToString();
}
public void WriteCurrentTurnOnScreen(string currentTurn)
{
CurrentTurn_label.Text = currentTurn;
}
private void GoToUni_btn_Click(object sender, EventArgs e)
{
var todaysClasses = GameManager.Schedule.WeekdaysAndSubjects[GameManager.CurrentTurn.DayOfWeek];
var timeWasted = -1 * todaysClasses.Count * 2 + 2;
var potentialAdjustment = (-10, 0, timeWasted);
if (!IsPossibleToAdjust(potentialAdjustment))
{
MessageBox.Show("You don't have enough Time / Mental Health / Physical Health to do that.");
return;
}
if (todaysClasses.Count == 0)
{
MessageBox.Show("There are no classes today");
}
else
{
foreach (var subject in todaysClasses)
{
_player.Skillset[subject] += 2;
}
UpdateSkillsetLevels();
MessageBox.Show("You successfully get out of the house and manage to sit through the classes");
AdjustPlayerIndicators(potentialAdjustment);
}
GoToUni_btn.Enabled = false;
}
void ResetActionButtons()
{
GoToUni_btn.Enabled = true;
}
private void GoSocialise_btn_Click(object sender, EventArgs e)
{
var potentialAdjustment = (5, -10, -5);
if (!IsPossibleToAdjust(potentialAdjustment))
{
MessageBox.Show("You don't have enough Time / Mental Health / Physical Health to do that.");
return;
}
AdjustPlayerIndicators(potentialAdjustment);
MessageBox.Show("You go out with your friends. Your physical health takes a hit since you got drunk again.");
}
private void WorkOut_btn_Click(object sender, EventArgs e)
{
var potentialAdjustment = (-5, -5, -4);
if (!IsPossibleToAdjust(potentialAdjustment))
{
MessageBox.Show("You don't have enough Time / Mental Health / Physical Health to do that.");
return;
}
AdjustPlayerIndicators((0, 10, -4));
MessageBox.Show("You go out and exercise.");
}
private void StudyAtHome_btn_Click(object sender, EventArgs e)
{
var potentialAdjustment = (-5, -5, -4);
if (!IsPossibleToAdjust(potentialAdjustment))
{
MessageBox.Show("You don't have enough Time / Mental Health / Physical Health to do that.");
return;
}
if (SkillsetName_listbox.SelectedItem is null)
{
MessageBox.Show("You need to select a subject you want to study");
return;
}
AdjustPlayerIndicators(potentialAdjustment);
string subjectToStudy = SkillsetName_listbox.SelectedItem.ToString();
string message = $"{subjectToStudy} level has increased. You suffer from prolonged sitting and lack of human contact.";
MessageBox.Show(message);
_player.Skillset[SkillsetName_listbox.SelectedItem.ToString()] += 2;
UpdateSkillsetLevels();
}
}
}