Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Cotton Farm 0.0.2.02
/* ----------------------------------------------------------------------- ------------------------------------------------------------------- -------------------------- · COTTON FARM · ---------------------------- ------------------------------------------------------------------- ----------------------------------------------------------------------- A game by: - Green Onion Studios - 2017 ----------------------------------------------------------------------- ------------------------------------------------------------------- Curent Version:(Final/Beta/Alpha/Development Vesion): -[[0.0.2.02]]- Release date: 26/11/2017 VERSION NOTES: WORKS: MAYBE Changes: 1) Fixed bug in tempo_clock (REVISAR) 2) Improved Code Structure 3) Improved indicator bar 4) Create grading system (MUY BASIC) Future Changes: 1) Improve intro stability 3) Create flourishing stage 4) Create final money gained 5) Create tutorial / exit / highscore options on the menu 6) Let the user pick the speed, wihtout deadjusting anything 7) Improve Stability & Optimization Developer comments: Yeyyyy, alpha version boiii!!!!!!1!!1!!111!!! ----------------------------------------------------------------------- ------------------------------------------------------------------- */ //// 1: HEADER //// #include <iostream> // Basic Library #include <fstream> // Library that allows reading/writing on files #include <conio.h> // Library that allows reading key press #include <windows.h> // Library that allows sleep function #include <stdio.h> // Library that allows to change the background and text color using namespace std; // Setting up the cout<< and cin>> functions // WARNING! // IF YOU ARE READING THIS CODE, WE RECOMMEND TO START IN "INT MAIN", you can get back here when you have finished reading the "int main" //// 3: GROWING STAGE //// void growing_stage (float &growing_progress, int &w, int &f, int &h, int &time, float &score, int &w_grade, int &f_grade, int &h_grade, char &input, float &speed) { // HEADER : Here we declare and inicialise some variables that we will use later on int i = 0; // Variable used to print the indicator bars system ("cls"); // Celar Screen // DISPLAY: The code here affects what will be displayed on the screen cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " - COTTON FARM SIMULATOR -\n"; cout << " Growing Stage\n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "Time: " << time / 20 << "\n"; cout << "Score: " << score << "\n"; cout << "Speed: " << speed << "%\n"; cout << "__________________________________________________\n"; cout << " ||-........|.........-|| \n"; // GUIDANCE BAR: the goal is to get your variables as close to the center of this bar as possible. cout << " W = "; do { //This DO, WHILE condition will print a bar as long as needed, depending on the value of the variable cout << "-"; i ++; } while (i < w); cout << " \n"; i = 0; // We restart this variable, as we will use it later cout << " ||-........|.........-|| \n"; cout << " F = "; do { cout << "-"; i ++; } while (i < f); cout << " \n"; i = 0; cout << " ||-........|.........-|| \n"; cout << " H = "; do { cout << "-"; i ++; } while (i < h); cout << " \n"; // USER INPUT: This section of the code is risponsable of changing variables according to the user's input if (kbhit()) { // This if condition will save the key pressed by the user in the variable "input". If the user doesn't press any key, it skips some lines, going to "A" input = getch(); } else { goto A; } switch (input) { // This SWITCH condition will read the input variable and change some variables according to it case 'w': w = w + 2; break; case 'f': f = f + 2; break; case 'h': h = h - 4; break; default: cout<< "\n INCORRECT KEY"; break; } A: // When the last if condition is false, the code skips some lines and starts reading here cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; } //// 4: GROWING CLOCK //// lauches and controls the growing stage void growing_clock (float &growing_progress, int &w, int &f, int &h, int &time, float &score, int &w_grade, int &f_grade, int &h_grade, char &input, float &speed) { // HEADER : Here we declare and inicialise some variables that we will use later on int tempo_clock; char input1; // TIME MANAGEMENT tempo_clock++; // Adds 1 to the variable tempo_clock if (tempo_clock > 4 ){ // This if condition keeps the variable tempo_clock between 1 and 4 NOTE: THIS NUMBER HAS TO CHANGE WHEN WE CHANGE THE SPEED, NOW IT SET FOR 4FPS, Which is btw wrong tempo_clock = 1; } time++; // Adds 1 to the variable time if (tempo_clock == 1) { // this series of if conditions define the automatic adjusing of the variables w = w - 1; h = h + 1; } if (tempo_clock == 2) { f = f - 1; h = h + 1; } if (tempo_clock == 3) { h = h - 1; } if (tempo_clock == 4) { w = w - 1; h = h + 1; } Sleep (50); // This determines the FPS at wich the game operates (1000 = 1fps, 100 = 10 fps) //GRADE CALCULATOR if (w > 19) { w = 20; w_grade = w_grade - 5; } if (w < 1) { w = 1; w_grade = w_grade - 5; } if (w = 10) { w_grade = w_grade + 10; } if ((2 < w < 9) || (11 < w < 18)) { w_grade = w_grade - 1; } if (f > 19) { f = 20; f_grade = f_grade - 5; } if (f < 1) { f = 1; f_grade = f_grade - 5; } if (f = 10) { f_grade = f_grade + 10; } if ((2 < f < 9) || (11 < f < 18)) { f_grade = f_grade - 1; } if (h > 19) { h = 20; h_grade = h_grade - 5; } if (h < 1) { h = 1; h_grade = h_grade - 5; } if (h = 10) { h_grade = h_grade + 10; } if ((2 < h < 9) || (11 < h < 18)) { h_grade = h_grade - 1; } growing_stage (growing_progress, w, f, h, time, score, w_grade, f_grade, h_grade, input, speed); //Launches Growing_Stage } //// 2: MAIN FUNCTION //// int main(){ // HEADER : Here we declare and inicialise some variables and files that we will use later on float growing_progress = 0; // Variable used for switching phases, it will be changed by the score in future versions, the phase will change when you get to a certain ammount of score, the goal is to do it in the lowest time possible int time = 0, w = 10, f = 10, h = 10, w_grade = 10, f_grade = 10, h_grade = 10, input2; float speed = 100, score = 0; char input; ofstream f1("Scores.txt", ios::app); //Stream class to write on files ifstream f2("Scores.txt"); //Stream class to read from files // INTRO MESSAGE cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "__________________Game Version:___________________\n"; cout << "____________________0.0.2.01______________________\n"; cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "Press any key to skip \n"; Sleep (1500); // Wait 1.5 seconds system ("cls"); // Clear the screen if (kbhit()) { // This if condition will save the key pressed by the user in the variable "input". If the user doesn't press any key, it skips some lines, going to "A" goto B; } system ( "color 02"); // Change the color cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " - GREEN ONION STUDIOS - \n"; cout << " present \n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "Press any key to skip\n"; Sleep (4000); system ("cls"); if (kbhit()) { // This if condition will save the key pressed by the user in the variable "input". If the user doesn't press any key, it skips some lines, going to "A" goto B; } cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " A GAME BY: \n"; cout << " Alessandro Granadino & Roman Delgado \n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "Press any key to skip\n"; Sleep (4000); system ("cls"); if (kbhit()) { // This if condition will save the key pressed by the user in the variable "input". If the user doesn't press any key, it skips some lines, going to "A" goto B; } cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " With the support of: \n"; cout << " \n"; cout << " PRIMER TEAM \n"; cout << " & \n"; cout << " LA PATRI INDUSTRIES \n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "Press any key to skip \n"; if (kbhit()) { // This if condition will save the key pressed by the user in the variable "input". If the user doesn't press any key, it skips some lines, going to "A" goto B; } Sleep (4000); B: system ("cls"); system ( "color 2f"); cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " - COTTON FARM SIMULATOR -\n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "Type any key and hit enter to start: "; cin >> input; C: system ("cls"); // MAIN MENU cout << "__________________________________________________\n"; cout << "__________________________________________________\n"; cout << "--------------------------------------------------\n"; cout << " - MAIN MENU -\n"; cout << "--------------------------------------------------\n"; cout << "__________________________________________________\n"; cout << "1: New Game \n"; cout << "2: Tutorial \n"; cout << "3: Highscores \n"; cout << "4: Exit \n"; cout << ">> "; cin >> input2; // Reads an input provided by the user system ("cls"); do { switch (input2){ case 1: system ("cls"); // This will keep lauching the growing clock, which controls the gwrowing stage until the score reaches a level, it will be done by time in an upcomming version do {growing_clock (growing_progress, w, f, h, time, score, w_grade, f_grade, h_grade, input, speed);} while (growing_progress < 99); growing_progress = 0; break; case 2: // Tutorial system ("cls"); do {growing_clock (growing_progress, w, f, h, time, score, w_grade, f_grade, h_grade, input, speed);} while (growing_progress < 5); growing_progress = 0; goto C; break; case 3:{ //Highscores string list; cout << "Your highscores are: \n"; while (! f2.eof()){ //Reads everything written on the file getline (f2,list); cout << list << "\n"; } f2.close(); break; } case 4: system ("cls"); cout << "rere"; break; // In un upcomming version, it will launch the flourishing clock and the final money gained (and time and speed) that will be written down in a .txt file } } while ((input2 != 1) && (input2 != 2) && (input2 != 3) && (input2 != 4)); // GRADING SYSTEM f1 << "40"; score = (w_grade + f_grade + h_grade)/3; f1 << score << "\n"; float grade; // We use this variable to compare your actual score to the highscores, written on the file grade = score; while (! f2.eof()){ // With this structure we save a new grade, if this grade is higher than one of the highscores f2 >> score; if (grade > score){ f1 << grade; f1.close(); f2.close(); return 0; } f2 >> score; } f1.close(); f2.close(); return 0; // It would exit the program once it reached this, we will loop it back to the main menu in an upcommig version }
run
|
edit
|
history
|
help
0
Masking Credit Card Number
Chest Interaction Unity
jkloikujyt5r4e3wsxdf
Move 2 ushort to 1 int
Interface constraints in generics
30272 Program Ex4 if
C# Truly Random
Non-User input - Random Controlled - Guessing Game
first test
valida fechas sura