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
|
#include<iostream>
#include<stdio.h>
#include<Windows.h>
#include<mmsystem.h>
#include<thread>
#include<stdlib.h>
using namespace std;
void openingmusic()
{
PlaySound(TEXT("Untitled"), NULL, SND_ASYNC | SND_LOOP);
}
void storymusic()
{
PlaySound(TEXT("suppressed"), NULL, SND_ASYNC | SND_LOOP);
}
void title()
{
system("COLOR F3");
cout << "\n\n\n\n\n\n\n\n";
cout << "================================================================================\n";
cout << " Game Title \n\n";
cout << " Press any key to start the interactive story game...";
cout << "\n";
cout << "================================================================================";
system("pause>0");
}
struct node
{
char data[1000];
struct node* left;
struct node* right;
};
void printArray(char ints[], int len)
{
int i;
for (i = 0; i<len; i++) {
printf("%c", ints[i]);
}
#ifdef DEBUG_INFO
printf(" (%d)");
#endif
cout << "\n";
}
void printPathsRecur(struct node* node, char path[], int pathLen)
{
if (node == NULL) return;
strncpy_s(&path[pathLen], 1000, node->data, 1000 - pathLen);
pathLen += strlen(node->data);
strncpy_s(&path[pathLen], 1000, "", 1000 - pathLen);
pathLen++;
if (node->left == NULL && node->right == NULL)
{
printArray(path, pathLen);
}
else
{
printPathsRecur(node->left, path, pathLen);
printPathsRecur(node->right, path, pathLen);
}
}
void printPaths(struct node *node)
{
char path[1500];
printPathsRecur(node, path, 0);
}
struct node* newNode(char *data)
{
struct node* node = (struct node*)malloc(sizeof(struct node));
strncpy_s(node->data, data, 1000);
node->left = NULL;
node->right = NULL;
return node;
}
int main()
{
char choice;
thread a(openingmusic);
title();
a.join();
thread b(storymusic);
system("cls");
system("COLOR F2");
cout << ".......";
system("pause>0");
system("cls");
struct node *root = newNode("Hi");
root->left = newNode("Hello");
root->right = newNode("How are you");
cout << "Hi\n";
cout << "[a]Hello [b]How are you\n";
cout << "Your choice: ";
cin >> choice;
if (choice == 'a') {
printPaths(root->left);
cout << "[c] I'm good [d] lel\n";
cin >> choice;
if (choice == 'c')
{
root->left->left = newNode("I'm good");
printPaths(root->left->left);
}else
if (choice == 'd'){
root->left->right = newNode("lel");
printPaths(root->left->right);
}
}
if (choice == 'b'){
printPaths(root->right);
}
b.join();
system("pause>0");
return 0;
}
| |