Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <cctype>
- #include <string>
- #include <chrono>
- #include <thread>
- #include <ctime>
- /*Current Problems:
- -Game Time Is Off
- -Game Time Is Stuck
- -Computer's Turn Does Not Process/Loop Correctly
- -Player's Turn Does Not Loop
- -No Return Zone Implemented
- -Need To Implement Final Score
- */
- using namespace std;
- //Goals And Returns:
- //Player Goal In Zone 1
- //Computer Goal In Zone 5
- //Returns 1,2,3,4,5 According To The Zone The Ball Was Turned Over In
- //Returns 6 If The Player/Computer Scores
- //Function Initialization
- int PlayerLoop(int startTime);
- int ComputerLoop(int startTime);
- bool IsGameOver(int startTime);
- int GetAccuracy();
- void Menu();
- int GetCoinToss();
- int GameStart();
- int ComputerGen();
- //Kick Percentages
- const int zone1ShortKick = 60;
- const int zone1LongKick = 20;
- const int zone1GoalKick = 75;
- const int zone2ShortKick = 70;
- const int zone2LongKick = 25;
- const int zone2GoalKick = 5;
- const int zone3ShortKick = 80;
- const int zone3LongKick = 35;
- int main()
- {
- srand(time(0));
- int startTime = time(NULL);
- //TESTING SPACE
- //TESTING SPACE
- Menu();
- //Scoring
- int playerScore;
- int computerScore;
- playerScore = 0;
- computerScore = 0;
- //Game Start If/Else
- char play;
- cout << "Press 1. To Play" << endl;
- cout << "Press 2. To Exit" << endl;
- cin >> play;
- int zone = 3;
- if (play = 1)
- {
- //Game starts here
- if (GameStart() == 1)
- {
- cout << "It's The Player's Turn." << endl;
- PlayerLoop(startTime);
- do
- {
- cout << "It Is Now The Computer's Turn." << endl;
- ComputerLoop(startTime);
- cout << "It Is Now The Player's Turn." << endl;
- PlayerLoop(startTime);
- } while (IsGameOver(startTime) == false);
- }
- else
- {
- cout << "It's The Computer's Turn." << endl;
- ComputerLoop(startTime);
- do
- {
- cout << "It Is Now The Player's Turn." << endl;
- PlayerLoop(startTime);
- cout << "It Is Now The Computer's Turn." << endl;
- ComputerLoop(startTime);
- } while (IsGameOver(startTime) == false);
- }
- //After Game Ends
- cout << "The Game Is Over!" << endl;
- cout << "The Player's Score Is: " << playerScore << endl;
- cout << "The Computer's Score Is: " << computerScore << endl;
- if (playerScore > computerScore)
- {
- cout << "Congratulations, You Won!";
- }
- else
- {
- cout << "You Lose. Better Luck Next Time!";
- }
- }
- else
- {
- exit(0);
- }
- return 0;
- }
- int GetAccuracy()
- {
- //Min - Max Variables
- int min = 0;
- int max = 100;
- int randomNumber = rand() % (min - max) + 1;
- return randomNumber;
- }
- //Menu for when the game is first started, or a previous game has finished
- void Menu()
- {
- //Game Menu
- cout << "===================================================" << endl;
- cout << "===============Soccer Game Project=================" << endl;
- cout << "===================================================" << endl;
- cout << "== How To Play: ==" << endl;
- cout << "== 5 Minute Games ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Player With The Highest Score Wins ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Move Ball To Opponents Goal ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Takes 2 Short Kicks To Advance Zones ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Takes 1 Long Kick To Advance Zones ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Long Kicks Are More Likely To Get Intercepted ==" << endl;
- cout << "== Goal Kicks Have A Better Chance At Landing ==" << endl;
- cout << "== The Closer The Ball Is To The Scoring Zone ==" << endl;
- cout << "== - ==" << endl;
- cout << "== Controls: ==" << endl;
- cout << "== 1. Short Kick ==" << endl;
- cout << "== 2. Long Kick ==" << endl;
- cout << "== 3. Goal Kick ==" << endl;
- cout << "== - ==" << endl;
- cout << "===================================================" << endl;
- cout << "Press Enter To Continue" << endl;
- cin.ignore();
- }
- int ComputerGen()
- {
- //Min - Max Variables
- int min = 0;
- int max = 100;
- int randomNumber = rand() % (min - max) + 1;
- return randomNumber;
- }
- int GetCoinToss()
- {
- //Min - Max Variables
- int min = 0;
- int max = 1;
- int coinToss = rand() % (min - max) + 1;
- return coinToss;
- }
- int GameStart()
- {
- //Variables
- char headsOrTails;
- int playerInput;
- do
- {
- cout << "The Game Will Now Start With A Coin Toss." << endl;
- cout << "Do You Choose Heads Or Tails?" << endl;
- cout << "Please type h for Heads or h for Tails." << endl;
- cout << "Input is case-sensitive." << endl;
- cin >> headsOrTails;
- //Get Player's Choice
- if (headsOrTails == 'h')
- {
- playerInput = 1;
- }
- else if (headsOrTails == 't')
- {
- playerInput = 0;
- }
- else
- {
- cout << "Input Incorrect. Please type h for Heads or t for Tails." << endl; //Need to fix. Not looping.
- }
- } while (headsOrTails != 'h' && headsOrTails != 't');
- //Determine Winner
- if (GetCoinToss() == playerInput)
- {
- //Player
- return 1;
- }
- else
- {
- //Computer
- return 0;
- }
- }
- int PlayerLoop(int startTime)
- {
- //Variables
- char kickType;
- int maxTime;
- maxTime = 300;
- int zone;
- zone = 3;
- bool opponentHasBall;
- opponentHasBall = false;
- //Do-While Loop
- do
- {
- cout << "Game Time:" << startTime << "/300 Seconds." << endl;
- cout << "The Ball Is In Zone " << zone << " Your Opponents Goal Is In Zone 5" << endl;
- cout << "It Is Your Move." << endl;
- cout << "Press 1. for Short Kick, press 2. for Long Kick, or press 3 for Goal Kick." << endl;
- cin >> kickType;
- //Kick Choice
- //Short Kick
- if (kickType == '1')
- {
- cout << "Kick Type: 1 selected." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (zone == 1)
- {
- //test
- cout << "In Zone 1." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (GetAccuracy() < zone1ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone1ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 2." << endl;
- zone = 2;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 2)
- {
- //test
- cout << "In Zone 2." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 3." << endl;
- zone = 3;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 3)
- {
- //test
- cout << "In Zone 3." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 4." << endl;
- zone = 4;
- }
- else
- {
- opponentHasBall == true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 4)
- {
- //test
- cout << "In Zone 4." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 5." << endl;
- zone = 5;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 5)
- {
- //test
- cout << "In Zone 5." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (GetAccuracy() < zone1ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone1ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball stays in zone 5" << endl;
- zone = 5;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- }
- //Long Kick
- else if (kickType == '2')
- {
- cout << "Kick Type: 2 selected." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (zone == 1)
- {
- cout << "In Zone 1." << endl;
- if (GetAccuracy() < zone1LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 2." << endl;
- zone = 2;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 2)
- {
- cout << "In Zone 2." << endl;
- if (GetAccuracy() < zone2LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 3." << endl;
- zone = 3;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 3)
- {
- cout << "In Zone 3." << endl;
- if (GetAccuracy() < zone3LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 4." << endl;
- zone = 4;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 4)
- {
- cout << "In Zone 4." << endl;
- if (GetAccuracy() < zone2LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball moves to zone 5." << endl;
- zone = 5;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 5)
- {
- cout << "In Zone 5." << endl;
- if (GetAccuracy() < zone1LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The ball stays in zone 5." << endl;
- zone = 5;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- }
- //Goal Kick
- else if (kickType == '3')
- {
- cout << "Kick Type: 3 selected." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(1000));
- if (zone == 1)
- {
- cout << "In Zone 1." << endl;
- if (GetAccuracy() < 0)
- {
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 2)
- {
- cout << "In Zone 2." << endl;
- if (GetAccuracy() < 0)
- {
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 3)
- {
- cout << "In Zone 3." << endl;
- if (GetAccuracy() < 0)
- {
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 4)
- {
- cout << "In Zone 4." << endl;
- if (GetAccuracy() < zone2GoalKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "You scored a goal!" << endl;
- return 6;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- else if (zone == 5)
- {
- cout << "In Zone 5." << endl;
- if (GetAccuracy() < zone1GoalKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "You scored a goal!" << endl;
- return 6;
- }
- else
- {
- opponentHasBall = true;
- cout << "Turnover! Your opponent now has the ball." << endl;
- }
- }
- }
- else
- {
- cout << "Input Incorrect." << endl;
- cout << "Press 1. for Short Kick, press 2. for Long Kick, or press 3 for Goal Kick." << endl;
- }
- } while ((kickType != '1' && kickType != '2' && kickType != '3' && opponentHasBall == false) && IsGameOver(startTime) != false);
- }
- //Player Goal In Zone 1
- //Computer Goal In Zone 5
- int ComputerLoop(int startTime)
- {
- //Variables
- char kickType;
- int maxTime;
- maxTime = 300;
- int zone;
- zone = 3;
- bool opponentHasBall;
- opponentHasBall = false;
- int decide = ComputerGen();
- //Do-While Loop
- //Kick Type
- //SK: decide < 40
- //LK: 41 < decide < 50
- //GK: 51 < decide
- do
- {
- //Zone 1
- if (zone == 1)
- {
- cout << "Your opponent is in Zone 1." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Your opponent shoots for a goal!" << endl;
- if (GetAccuracy() < zone1GoalKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Your opponent scores!" << endl;
- return 6;
- }
- else
- {
- opponentHasBall = true;
- }
- }
- //Zone 2
- else if (zone == 2)
- {
- cout << "Your opponent is in Zone 2." << endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- //Short Kick
- if (decide < 40)
- {
- cout << "Your opponent uses a short kick." << endl;
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone2ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- cout << "The ball moves to zone 1." << endl;
- zone = 1;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- //Long Kick
- else if (41 < decide < 50)
- {
- cout << "Your opponent uses a long kick." << endl;
- if (GetAccuracy() < zone2LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- cout << "The ball moves to zone 1." << endl;
- zone = 1;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- //Goal Kick
- else if (51 < decide)
- {
- cout << "Your opponent shoots for a goal!" << endl;
- if (GetAccuracy() < zone2GoalKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Your opponent scores!" << endl;
- return 6;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- }
- //Zone 3
- else if (zone == 3)
- {
- cout << "Your opponent is in Zone 3." << endl;
- //Short Kick
- if (decide < 49)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Your opponent uses a short kick." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- cout << "The ball moves to zone 2." << endl;
- zone = 2;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- //Long Kick
- else (50 < decide);
- {
- cout << "Your opponent uses a long kick." << endl;
- if (GetAccuracy() < zone3LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- cout << "The ball moves to zone 2." << endl;
- zone = 2;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- }
- //Zone 4
- else if (zone == 4)
- {
- cout << "Your opponent is in Zone 4." << endl;
- //Short Kick
- if (decide < 49)
- {
- cout << "Your opponent uses a short kick." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- cout << "The ball moves to zone 3." << endl;
- zone = 3;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- //Long Kick
- else (50 < decide);
- {
- cout << "Your opponent uses a long kick." << endl;
- if (GetAccuracy() < zone3LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- cout << "The ball moves to zone 3." << endl;
- zone = 3;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- }
- //Zone 5
- else if (zone == 5)
- {
- cout << "Your opponent is in Zone 5." << endl;
- //Short Kick
- if (decide < 49)
- {
- cout << "Your opponent uses a short kick." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "First pass is a success." << endl;
- if (GetAccuracy() < zone3ShortKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "Second pass is a success." << endl;
- cout << "The ball moves to zone 4." << endl;
- zone = 4;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- //Long Kick
- else if (50 < decide)
- {
- cout << "Your opponent uses a long kick." << endl;
- if (GetAccuracy() < zone3LongKick)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(200));
- cout << "The pass is successful." << endl;
- cout << "The ball moves to zone 4." << endl;
- zone = 4;
- }
- else
- {
- cout << "Turnover!" << endl;
- opponentHasBall = true;
- }
- }
- }
- } while (opponentHasBall = false);
- }
- const int GameRunTime = 5;
- bool IsGameOver(int startTime)
- {
- int currentTime = time(NULL);
- int elapsed = currentTime - startTime;
- if (elapsed >= GameRunTime * 60)
- {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement