-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
212 lines (182 loc) · 7.35 KB
/
Program.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace InteractiveStory
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Crypt Descent";
string byLine = "by Jon.A (Funwayguy)";
while (true)
{
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 - Console.Title.Length / 2, Console.WindowHeight / 2 - 1);
Console.Write(Console.Title);
Console.SetCursorPosition(Console.WindowWidth / 2 - byLine.Length / 2, Console.WindowHeight / 2);
Console.Write(byLine);
Console.SetCursorPosition(0, Console.WindowHeight - 3);
Console.WriteLine("1: Load");
Console.WriteLine("2: New Game");
Console.WriteLine("3: Quit");
Char charIn = Console.ReadKey().KeyChar;
if (Char.IsNumber(charIn))
{
int numIn = int.Parse(charIn.ToString());
if (numIn == 1)
{
Story myStory = LoadScreen();
if (myStory != null)
{
myStory.Start();
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 - "GAME OVER".Length / 2, Console.WindowHeight / 2 - 1);
Console.Write("GAME OVER");
Console.SetCursorPosition(Console.WindowWidth / 2 - ("Score: " + myStory.points).Length / 2, Console.WindowHeight / 2);
Console.Write("Score: " + myStory.points);
Console.SetCursorPosition(0, Console.WindowHeight - 1);
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}
else if (numIn == 2)
{
string name = "";
while (name == "")
{
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 - "Enter Name:".Length / 2, Console.WindowHeight / 2 - 1);
Console.Write("Enter Name:");
Console.SetCursorPosition(Console.WindowWidth / 2 - 5, Console.WindowHeight / 2);
name = Console.ReadLine();
}
Story myStory = new Story(name);
myStory.Start();
Console.Clear();
Console.SetCursorPosition(Console.WindowWidth / 2 - "GAME OVER".Length / 2, Console.WindowHeight / 2 - 1);
Console.Write("GAME OVER");
Console.SetCursorPosition(Console.WindowWidth / 2 - ("Score: " + myStory.points).Length / 2, Console.WindowHeight / 2);
Console.Write("Score: " + myStory.points);
Console.SetCursorPosition(0, Console.WindowHeight - 1);
Console.Write("Press any key to continue...");
Console.ReadKey();
}
else if (numIn == 3)
{
break;
}
}
}
}
static Story LoadScreen()
{
if (!Directory.Exists(@"saves\"))
{
try
{
DirectoryInfo dirInfo = Directory.CreateDirectory(@"saves\");
} catch(Exception e)
{
Console.Clear();
Console.WriteLine("Failed to create saves directory!");
Console.WriteLine();
Console.WriteLine("Error Report:");
Console.WriteLine(e);
Console.WriteLine();
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
return null;
}
}
string[] files = Directory.GetFiles(@"saves\", "*.crypt", SearchOption.TopDirectoryOnly);
for (int fx = 0; fx < files.Length; fx++)
{
files[fx] = Path.GetFileNameWithoutExtension(files[fx]);
}
int selected = 0;
while(true)
{
Console.Clear();
if (files.Length > 0)
{
Console.WriteLine("Choose file to load: ");
for (int i = 0; i < files.Length; i++)
{
if (i == selected)
{
Console.WriteLine(@"> " + files[i]);
}
else
{
Console.WriteLine(@" " + files[i]);
}
}
}
else
{
Console.WriteLine("No save files");
}
Console.WriteLine();
Console.WriteLine("1: Load");
Console.WriteLine("2: Back");
ConsoleKeyInfo lKey = Console.ReadKey();
Char lChar = lKey.KeyChar;
if (Char.IsNumber(lChar))
{
int lNum = int.Parse(lChar.ToString());
if (lNum == 1)
{
return LoadFile(files[selected]);
}
else if(lNum == 2)
{
return null;
}
}
else if (lKey.Key == ConsoleKey.UpArrow && selected > 0)
{
selected--;
}
else if (lKey.Key == ConsoleKey.DownArrow && selected + 1 < files.Length)
{
selected++;
}
}
}
static Story LoadFile(string filename)
{
Dictionary<string, int> data;
try
{
BinaryReader reader = new BinaryReader(File.Open(@"saves\" + filename + ".crypt", FileMode.OpenOrCreate));
int size = reader.ReadInt32();
data = new Dictionary<string, int>(size);
for (int x = 0; x < size; x++)
{
string key = reader.ReadString();
int obj = reader.ReadInt32();
data.Add(key, obj);
}
reader.Close();
}
catch (Exception e)
{
Console.Clear();
Console.WriteLine("An error occured while trying to load game:");
Console.WriteLine(e);
Console.ReadLine();
return null;
}
Story story = new Story(filename);
story.name = filename;
story.LoadGame(data);
//Player player = new Player(story, new int[] { data["hp"], data["str"], data["inv"] });
//story.player = player;
return story;
}
}
}