repl.it
@SharkFin/

Text adventure

C++11

No description

fork
loading
Files
  • main.cpp
  • paths.txt
main.cpp
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
#include <iostream>
#include <chrono>
#include <thread>
#include <string>
#include <fstream>

void scrollText(std::string text) {
	for(int i=0;i<text.length();i++) {
		std::cout << text[i] << std::flush;

		// using a switch instead of an if statement just to add an exotic element
		int delay;
		switch(text[i]) {
			case ',':
				delay = 500;
				break;
			case '.':
				delay = 1000;
				break;
			case '!':
				delay = 1000;
				break;
			case '?':
				delay = 1000;
				break;
			default:
				delay = 40;
				break;
		}
		std::this_thread::sleep_for(std::chrono::milliseconds(delay));
	}

	std::cout << std::endl;
}

int main() {
  std::thread welcome(scrollText, "Hey there, so here's a sentence that displays as if it's being typed. It's quite a cool effect, especially when I make it take longer when there's a comma or a period. Thanks for watching!");
	//welcome.join();

	for(int i=0;i<0;i++) {
		std::cout << std::endl << "Multithread clearly works" << std::endl;
		std::this_thread::sleep_for(std::chrono::milliseconds(500));
	}

	welcome.join();


	std::cout << std::endl << "Program finished" << std::endl;
	return 1;
}
?