SNES Megaman X Opening

Windows 7/Dev C++ 5.11

I'm working on an opening for games/programs that will run in the command window and I'm basing it off the Super Nintendo Entertainment System's "Megaman X" opening title. I've got everything exactly as I want it, however, I'm trying to clean up my code and make things a bit more manageable. Did I do things right or is there another way to structure things?

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
#include <iostream>

#include <ctype.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <windows.h>

using namespace std;


//GLOBAL CHARACTERS
char
center[] = "\t\t\t",
initializing[] = "Initializing...\n",
loading[] = "Loading...\n",
terminated[] = "Program Terminating...\n",
dots[] = "...............................................................................",
runprogram[] = "Run program \"program.exe\"? (Y/N)\n" /*replace program.exe with name of current game/program*/,
prompt[] = "C:\\> ",
runproganswer,
invalid[] = "Invalid Entry. Please Try Again.\n\n",

//SPECIFIC CHARACTERS

//Mega-Man Opening
mm01[] = "NOM ENGINEER WORK SYSTEM\n",
mm02[] = "Model CPS-9204\n\n",
mm03[] = "Copyright (c) ",
mmcopydates[] = "2105, 2109, 2114\n",
mm04[] = "NOM Corporation\n",
mm05[] = "All Rights Reserved\n\n",
mm06[] = "real  mem = ",
mmtb[] = " TB\n",
mm07[] = "avail mem = ",
mm08[] = "\nprimary data cache : ",
mmkb[] = "KB\n",
mm09[] = "primary inst.cache : ",
mm10[] = "secondary cache    : ",
mm11[] = "\nlogin: ",
mm12[] = "Dr.CAIN\n",
mm13[] = "code : ",
mmasterisk[] = "******",
mm14[] = "device -dvl -a\n\n",
mm15[] = "reading ",
mm16[] = "\"M.X.S.\"\n",
mm17[] = "\"BD-E\"\n",
mm18[] = "\"WARNING\"\n";

int main()
{
	
	//Start-up Beeps
	Sleep (1000);
	Beep (723,150);
	Sleep (5000);
	Beep (723,250);
	Sleep (1000);
	
	
	//"NOM ENGINEER WORK" to "All Rights Reserved" 
	for (int i=0; mm01[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm01[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm02[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm02[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm03[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm03[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mmcopydates[i] != '\0'; i++)
	{
		Sleep ((3 + rand() % 7) * 10);
		cout << mmcopydates[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm04[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm04[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm05[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm05[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm06[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mm06[i];
	}
	
	Sleep (1500);
	
	
	//"real mem = 8192 TB" to "secondary cache    : 32768KB"
	cout << "\r";
	for (int realmem = 1; realmem != 8192; ++realmem)
	{
		cout << "real  mem = ";
		Sleep (1 +rand() % 5);
		cout << realmem;
		cout << "\r";
	}
	cout << "\r" << "real  mem = 8192";
	
	for (int i=0; mmtb[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 5) * 10);
		cout << mmtb[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm07[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm07[i];
	}
	
	Sleep (1500);
	
	cout << "\r";
	for (int availmem = 1; availmem != 32768; ++availmem)
	{
		cout << "avail mem = ";
		Sleep (1 +rand() % 2);
		cout << availmem;
		cout << "\r";
	}
	cout << "\r" << "avail mem = 32768";
	
	for (int i=0; mmtb[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mmtb[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm08[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm08[i];
	}
	
	Sleep (1500);
	
	cout << "\r";
	for (int cache01 = 1; cache01 != 512; ++cache01)
	{
		cout << "primary data cache : ";
		Sleep (1 +rand() % 3);
		cout << cache01;
		cout << "\r";
	}
	cout << "\r" << "primary data cache : 512";
	
	for (int i=0; mmkb[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mmkb[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm09[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm09[i];
	}
	
	Sleep (1500);
	
	cout << "\r";
	for (int cache02 = 1; cache02 != 768; ++cache02)
	{
		cout << "primary inst.cache : ";
		Sleep (1 +rand() % 3);
		cout << cache02;
		cout << "\r";
	}
	cout << "\r" << "primary inst.cache : 768";
	
	for (int i=0; mmkb[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mmkb[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm10[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm10[i];
	}
	
	Sleep (1500);
	
	cout << "\r";
	for (int cache03 = 1; cache03 != 32768; ++cache03)
	{
		cout << "secondary cache    : ";
		Sleep (1 +rand() % 2);
		cout << cache03;
		cout << "\r";
	}
	cout << "\r" << "secondary cache    : 32768";
	
	for (int i=0; mmkb[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mmkb[i];
	}
	
	Sleep (1500);
	
	//"login: Dr.CAIN" to "reading \"WARNING\"
	for (int i=0; mm11[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm11[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm12[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mm12[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm13[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm13[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mmasterisk[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mmasterisk[i];
	}
	
	cout << "\n\n>";
	Sleep (1500);
	
	for (int i=0; mm14[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mm14[i];
	}
	
	Sleep (1500);
	
	for (int i=0; mm15[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm15[i];
	}
		
	Sleep (2000);
	
	for (int i=0; mm16[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mm16[i];
	}
		
	Sleep (1500);
	
	for (int i=0; mm15[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm15[i];
	}
	
	Sleep (2000);
	
	for (int i=0; mm17[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mm17[i];
	}
		
	Sleep (1500);
	
	for (int i=0; mm15[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << mm15[i];
	}
	
	Sleep (2000);
	
	for (int i=0; mm18[i] != '\0'; i++)
	{
		Sleep ((5 + rand() % 10) * 10);
		cout << mm18[i];
	}
	
	
	//Initializing and Load bar	
	Sleep (3000);
	
	cout << "\n\t" << center;
	
	for (int i=0; initializing[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << initializing[i];
	}
	
	Sleep (1500);
	
	for (int i=0; dots[i] != '\0'; i++)
	{
		Sleep ((10 + rand() % 75) * 10);
		cout << dots[i];
	}
	
	Sleep (1500);
	
	system("CLS");
	
	//Run Program? (Y/N)
	Beep (723,150);
	Sleep (5000);
	Beep (723,250);
	Sleep (1000);
	
	for (int i=0; runprogram[i] != '\0'; i++)
	{
		Sleep ((1 + rand() % 3) * 10);
		cout << runprogram[i];
	}
	
	Sleep (1500);
	
	while(true)
	{
			for (int i=0; prompt[i] != '\0'; i++)
			{
				Sleep ((1 + rand() % 2) * 10);
				cout << prompt[i];
			}
			
			cin >> runproganswer;
			runproganswer = toupper(runproganswer);
			
			//YES
			if (runproganswer == 'Y')
			{
				Sleep (1500);
				system("CLS");
				break;
			}
			
			//NO
			if (runproganswer == 'N')
			{
				Sleep (3000);
				system("CLS");
				Sleep (3000);
	
				cout << center;
	
				for (int i=0; terminated[i] != '\0'; i++)
				{
					Sleep ((1 + rand() % 3) * 10);
					cout << terminated[i];
				}
	
				Sleep (1500);
				
				for (int i=0; dots[i] != '\0'; i++)
				{
					Sleep ((10 + rand() % 75) * 10);
					cout << dots[i];
				}
	
				system("CLS");
				Sleep(3000);
				Beep (723,250);
				Beep (723,250);
				return 0;
			}
			
			//INVALID ENTRY
			if (runproganswer != 'Y' && runproganswer != 'N')
			{
				Sleep (1500);
	
				for (int i=0; invalid[i] != '\0'; i++)
				{
					Sleep ((1 + rand() % 3) * 10);
					cout << invalid[i];
				}
	
				Sleep (1500);
				continue;
			}
		}
		
//PROGRAM
cout << "\n\t\t\t\tTEST OK" << endl;	
	
	return 0;
}
Let's take this in stages. First, use an array to declare what you want to print, don't just declare a bunch of variable with different names. This is called a data-driven design, and it's almost always preferable to the completely unmanageable list of statements you have. Before you move onto the next example I'll give, just note how clean this is. It's a list of strings and a loop that loops over them. All the behavior (in this case just which strings to print) is defined in the data.

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
#include <iostream>
#include <vector>
#include <string>

std::vector<std::string> intro{
   "NOM ENGINEER WORK SYSTEM\n",
   "Model CPS-9204\n\n",
   "Copyright (c) ",
   "2105, 2109, 2114\n",
   "NOM Corporation\n",
   "All Rights Reserved\n\n",
   "real  mem = ",
   " TB\n",
   "avail mem = ",
   "\nprimary data cache : ",
   "KB\n",
   "primary inst.cache : ",
   "secondary cache    : ",
   "\nlogin: ",
   "Dr.CAIN\n",
   "code : ",
   "******",
   "device -dvl -a\n\n",
   "reading ",
   "\"M.X.S.\"\n",
   "\"BD-E\"\n",
   "\"WARNING\"\n"
};

int main() {
   for(auto& str : intro) {
      std::cout << str;
   }
   return 0;
}


Now things get more complicated. Instead of just a list of string to print out, some of the things I see you need to do are to print a string slowly to the terminal, wait, and beep. We need a way to represent 3 different commands. There are a number of ways to do this, but I've chosen virtual function calls. Note again that there is no code piling up, there are 3 types of command that know how to execute themselves, there is a list of commands and there is a simple for loop that iterates over the commands. (I've also had to change the sleep method, if you're on Windows you'll need to use whatever sleep you were using, not usleep).

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
#include <iostream>
#include <vector>
#include <string>

#include <unistd.h>

class Command {
public:
   virtual void execute() = 0;
};

class Beep : public Command {
public:
   void execute() override {
      std::cout << '\a';
      std::cout.flush();
   }
};

class Sleep : public Command {
   int duration_ms_;
public:
   Sleep(int duration_ms) : duration_ms_(duration_ms) {}

   void execute() override {
      usleep(duration_ms_ * 1000);
   }
};

class TypeString : public Command {
   std::string str_;
   int delay_;
public:
   TypeString(std::string str, int delay = 25) : str_(str), delay_(delay) {}

   void execute() override {
      for(auto c : str_) {
         std::cout << c;
         std::cout.flush();
         usleep(delay_ * 1000);
      }
   }
};


std::vector<Command*> commands{
   new Beep(),
   new Sleep(1000),
   new Beep(),
   new TypeString("NOM ENGINEER WORK SYSTEM\n"),
   new TypeString("Model CPS-9204\n\n"),
   new TypeString("Copyright (c) "),
   new TypeString("2105, 2109, 2114\n"),
   new TypeString("NOM Corporation\n"),
   new TypeString("All Rights Reserved\n\n"),
   new TypeString("real  mem = "),
   new TypeString(" TB\n"),
   new TypeString("avail mem = "),
   new TypeString("\nprimary data cache : "),
   new TypeString("KB\n"),
   new TypeString("primary inst.cache : "),
   new TypeString("secondary cache    : "),
   new TypeString("\nlogin: "),
   new TypeString("Dr.CAIN\n"),
   new TypeString("code : "),
   new TypeString("******"),
   new TypeString("device -dvl -a\n\n"),
   new TypeString("reading "),
   new TypeString("\"M.X.S.\"\n"),
   new TypeString("\"BD-E\"\n"),
   new TypeString("\"WARNING\"\n")
};

int main() {
   for(auto& cmd : commands) {
      cmd->execute();
   }

   return 0;
}
Topic archived. No new replies allowed.