@Wo1ves1n0/

Corruption (game #2)

C++

Choice base game

fork
loading
Multiplayer beta is disabled as we rollout the new & improved version. Learn more here.
Share and collaborate in real-time
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
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
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <termios.h>
using namespace std;

//waits for input
char getch() {
        char buf = 0;
        struct termios old = {0};
        if (tcgetattr(0, &old) < 0)
                perror("tcsetattr()");
        old.c_lflag &= ~ICANON;
        old.c_lflag &= ~ECHO;
        old.c_cc[VMIN] = 1;
        old.c_cc[VTIME] = 0;
        if (tcsetattr(0, TCSANOW, &old) < 0)
                perror("tcsetattr ICANON");
        if (read(0, &buf, 1) < 0)
                perror ("read()");
        old.c_lflag |= ICANON;
        old.c_lflag |= ECHO;
        if (tcsetattr(0, TCSADRAIN, &old) < 0)
                perror ("tcsetattr ~ICANON");
        return (buf);
}

void spaceCont()
{
  char space;
  do{
    space = getch();
  }
  while (space != ' ');
}

int main() { //Start of the game
////////////////////////////////////////////////////////////////////////////////////////////
string name; //Players name
string go; //Telling the player to start the game
////////////////////////////////////////////////////////////////////////////////////////////
cout << "'What are you doing here? You're not suppose to be here. Oh no, this must be a mistake. Well I guess we are going to have to help you escape.'" << endl; //(Jack speaking) start of the story.  

cout << " " << endl; // Space
////////////////////////////////////////////////////////////////////////////////////////////

cout << "'Sorry, Names Jack. I've been here for almost a decade, learnt parts of the system that has came to curruption. It has taken over half the system. its dangerous. I need to know things about you. Tell me your name?'" << endl; //Part 1

cout << " " << endl; //Space
////////////////////////////////////////////////////////////////////////////////////////////
cout << "Enter Your Name: " << endl; //User asked to Enter name
cin >> name; //Input name
cout << " " << endl; //Space 

////////////////////////////////////////////////////////////////////////////////////////////
cout << "'That's your name? " << name << "? " << "Ok no time to be scarcastic. But that name sounds dramatic as hell! Anyways. Nice to meet you. First things first we need to follow the circut to the main port. Its going to be dangrous but its the only way. Let's go " << name << "!'" << endl; //Part 1.2
cout << " " << endl;//Space

cout << "Type 'go' to walk towards the main port to start your escape!" << endl; //Telling the users to start the walk
cout << " " << endl;//Space
do{
cin >> go;//Input for the user to start walking. 
if (go != "go") {cout << "\nInvalid input please Type -go- to proceed with the story.\n";}
} while (go != "go");
cout << " " << endl;//Space
cout << "You and jack start to take a walk through the circut. Its cold, dark and closure. You look in the far distance and see a smoky figure, as your mind wonders curiosity if that 'thing' is real? You have a choice, would you like to go and talk to the black figure? or bypass it? " << endl; //First decision. Part 1.3
////////////////////////////////////////////////////////////////////////////////////////////
string playerChoice;
//Repeats until given a valid input
do
{

cout << endl << "Type \"talk\" or \"pass\"" << endl;
cin >> playerChoice;

//tells you your input is invalid
if (playerChoice != "talk" && playerChoice != "pass")
{
  cout << endl << "Invalid option. Please enter -talk- or -pass- to continue" << endl;
}

}
while (playerChoice != "talk" && playerChoice != "pass");

//"hello\n" is the same as "hello" << endl

if (playerChoice == "talk") //If user picks Talk
{
  //Game

  //initiates the game variables
  int playerNum;
  int creatureNum;
  bool done = false;


  while (done == false)
  {
    cout << "\033[2J"; //clears the screen at the beginning of the game

    //You can put the introductory speech for the game here

    cout << "Figure: \"Let's play a little game... heads, I win, tails, you lose...\"";
    cout << " " << endl; //space
    cout << "Press SPACE to play\n\n";
    //Press SPACE to start
    spaceCont();

    //generates a random # between 1 and 50 for both
    playerNum = rand() % 50;
    creatureNum = rand() % 50;

    //Tests if you won
    if (playerNum > creatureNum)
    {
      //Win condition here
      cout << "\nFigure: *Mumbles*\n The Creature fades through the floor\n"; 
      cout << " " << endl; //Space

      cout << "Jack : \"Hey! Nice job! you are clearing the Coruption, you know this means a lot! Keep it up, " << name << "!\"" << endl;
      cout << " " << endl; //Space

      //Allows the loop to end
      done = true;
    }
    else
    {
      //Lose condition here
    cout << "Figure:\"HA! YOU HAVE LOST!\"\n";
      
      for (int i = 1; i < 90; i++)
      {
        cout << "Corrupted\n";
      }

      //ensure the loop will continue
      done = false;

      //ensures you see your results
      cout << "Press SPACE to continue\n";
     spaceCont();
    }
  }
  

}

  cout << "Story starting here" << endl;

return 0;
}//End of the story.