Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Created by Michael Gorman on 11/9/12.
- // Copyright (c) 2012 Michael Gorman. All rights reserved.
- //
- #include <iostream>
- #include <string>
- #include <windows.h>
- #include <process.h>
- #include <conio.h>
- #include <time.h>
- using namespace std;
- int input;
- char askYesNo(string question);
- class SpaceShip //class definition -- defines a new type
- {
- public:
- SpaceShip(int power = 0, string sname = "", string cname = "");
- string shipName;
- string m_computerName;
- int m_power;
- int m_apower;
- int m_speed;
- int m_engines;
- int m_shields;
- int m_weapons;
- int m_x;
- int m_y;
- int m_z; //3d for the future.
- int m_cx;
- int m_cy;
- void LaunchPrep(); // member function prototype
- void Flight();
- void Charts();
- void Movement(string moveCommand);
- void doMovement();
- };
- SpaceShip::SpaceShip(int power, string sname, string cname):
- m_apower(power),
- m_power(power),
- m_computerName(cname),
- m_speed(0),
- m_engines(0),
- m_shields(0),
- m_weapons(0)
- {}
- void SpaceShip::LaunchPrep() // member function definition
- {
- string shipControl = "";
- while (shipControl != "q")
- {
- cout << "\nHello! I'm the Ship's Computer. You may call me " << m_computerName << "\n\n";
- while (true) {
- char startShip = askYesNo("Shall I start all the automated ship systems?");
- if (startShip == 'y')
- break;
- }
- Sleep(500);
- cout << "\n.";
- Sleep(500);
- cout << "\n..";
- Sleep(500);
- cout << "\n...";
- Sleep(500);
- cout << "\n....";
- Sleep(500);
- cout << "\n.....";
- Sleep(500);
- cout << "\n......" << endl;
- Sleep(500);
- cout << m_computerName << ": Okay, we're ready for launch preperation." << endl;
- Sleep(500);
- while(true)
- {
- cout << m_computerName << ": \n\tShip's Status:\n\n";
- cout << "\t\tTotal power: " << m_power << " Units | Available Power: " << m_apower << " Units" << endl;
- cout << "\t\tPower Unit Assignment: Engines: " << m_engines << " Shields: " << m_shields << " Weapons: " << m_weapons << endl;
- cout << m_computerName << ": How would you like to assign power?\n\t(E for engine, S for Shields and W for weapons): ";
- cin >> shipControl;
- if (shipControl == "e" || shipControl == "E") {
- m_engines += 1;
- m_apower -= 1;
- cout << m_computerName << ": Engines powered to: " << m_engines << endl; }
- if (shipControl == "s" || shipControl == "S") {
- m_shields += 1;
- m_apower -= 1;
- cout << m_computerName << ": Shields powered to: " << m_shields << endl;}
- if (shipControl == "w" || shipControl == "W") {
- m_weapons += 1;
- m_apower -= 1;
- cout << m_computerName << ": Weapons powered to: " << m_weapons << endl; }
- if (m_apower == 0)
- break;
- else if (shipControl != "w" && shipControl != "e" && shipControl != "s")
- cout << m_computerName << ": Sorry, that's not a valid system" << endl;
- }
- cout << m_computerName << ": The power levels have been assigned. Ship is ready for launch: ";
- cin >> shipControl;
- if (shipControl != "launch")
- cout << "Huh?";
- else
- cout << "\nVROOOOOOM!" << endl;
- m_x = 12;
- m_y = 25;
- m_cx = m_x;
- m_cy = m_y;
- shipControl = "q";
- }
- }
- void SpaceShip::Flight()
- {
- string flightCommand;
- time_t starttime, curtime;
- int done = 0;
- cout << m_computerName << ": Before you get too crazy, let me explain how flight works, it consits of these commands";
- cout << "\n\tThrottle\tCourse\t\tJump";
- cout << "\n\tCharts\t\tComms\t\t";
- cout << "\n\tLock\t\tFire\t\tAutoFire";
- cout << "\n\tLand\t\tPower\t\tEject";
- char flightHelp = askYesNo("\n\nDo you need an explaination of each function? ");
- if (flightHelp == 'y')
- {
- cout << endl << m_computerName << ": Throttle allows input as a percentage, this makes piloting more \n\tsimple, I will handle the rest for the time being.\n\tWhen you're more comfortable we can go over using individual thrusters.";
- cout << endl << m_computerName << ": Course is for plotting your destination. You'll do it with \n\tx, y and z coordinates. I handle the computation and\n\tspecifics for you.";
- cout << endl << m_computerName << ": Jump allows you activate your Ether Drive for faster travel.\n\tYou'll want to manually chart jumps around \n\tproblem areas.";
- cout << endl << m_computerName << ": Charts displays your Nav Computer.";
- cout << endl << m_computerName << ": Comms brings up the communication array";
- cout << endl << m_computerName << ": Lock, Fire and Autofire allow you to target and attack.";
- cout << endl << m_computerName << ": Land allows me to compute trajectory and beging the landing sequence.";
- cout << endl << m_computerName << ": Power lets you tweak your previously set power distribution.";
- cout << endl << m_computerName << ": Eject, well just be sure you're ready for the consequences of\n\tbeing thrown into space...";
- }
- cout << endl << m_computerName << ": That should be everything you need to get started.";
- while(true)
- {
- cout << "\n<(Speed: " << m_speed << " Coordinates: " << m_x << "x " << m_y << "y)> ";
- time(&starttime);
- do
- {
- time(&curtime);
- if(_kbhit())
- {
- cin >> flightCommand;
- if (flightCommand == "charts")
- SpaceShip::Charts();
- if (flightCommand == "throttle")
- SpaceShip::Movement("throttle");
- if (flightCommand == "course")
- SpaceShip::Movement("course");
- }
- } while((curtime - starttime) < 5);
- if (m_speed > 0)
- SpaceShip::doMovement();
- }
- }
- void SpaceShip::Charts()
- {
- char space[150][150];
- for(int i = (m_x -10);i < (m_x + 10);i++) //row by 80.
- {
- for(int j = (m_y - 20);j < (m_y + 20);j++) //columns by 100.
- {
- space[i][j]='.';
- space[m_x][m_y]='^';
- space[10][20]='*';
- space[12][24]='O';
- cout << space[i][j];
- }
- cout << endl;
- }
- return 0;
- }
- void SpaceShip::doMovement()
- {
- if (m_cx > m_x)
- m_x += 1;
- if (m_cx < m_x)
- m_x -= 1;
- if (m_cy > m_y)
- m_y += 1;
- if (m_cy < m_y)
- m_y -= 1;
- }
- void SpaceShip::Movement(string moveCommand)
- {
- int throttle;
- int cx, cy;
- if (moveCommand == "throttle")
- {
- cout << "\nWhat percentage of throttle would you like to apply? ";
- cin >> throttle;
- m_speed = throttle;
- return;
- }
- if (moveCommand == "course")
- {
- cout << "\nWhat X coordinate would you like to set? ";
- cin >> cx;
- m_cx = cx;
- cout << "\nWhat Y coordinate would you like to set? ";
- cin >> cy;
- m_cy = cy;
- return;
- }
- }
- char askYesNo(string question)
- {
- char response;
- do
- {
- cout << question << " (y/n); ";
- cin >> response;
- } while (response != 'y' && response != 'n');
- return response;
- }
- int main()
- {
- SpaceShip XGP(9, "The XGP", "Gillium");
- SpaceShip XWING(4, "X-Wing", "R2D2");
- SpaceShip ENTERPRISE(10, "The Enterprise", "Data");
- SpaceShip DEATHSTAR(25, "The Death Star", "EVIL");
- cout << "Welcome to the Gorman Space Simulator. The following ships are available for test flights:" << endl;
- cout << "\n\t1. The XGP";
- cout << "\n\t2. An X-Wing Fighter";
- cout << "\n\t3. The USS Enterprise";
- cout << "\n\t4. The Death Star";
- cout << "\nPlease input the number of the desired ship class: ";
- cin >> input;
- switch (input) {
- case 1:
- XGP.LaunchPrep();
- XGP.Flight();
- break;
- case 2:
- XWING.LaunchPrep();
- XWING.Flight();
- break;
- case 3:
- ENTERPRISE.LaunchPrep();
- ENTERPRISE.Flight();
- break;
- case 4:
- DEATHSTAR.LaunchPrep();
- DEATHSTAR.Flight();
- break;
- default:
- cout << "Something went wrong...";
- break;
- }
- cout << "\nTakeoff complete!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement