You are on page 1of 10

main.cpp Files: *************************************************** Compiler Output: g++ main.cpp Miner.cpp Town_Hall.cpp Gold_Mine.cpp Cart_Vector.cpp Cart_Point.cp p -o main.

cpp_testing *************************************************** Program Output: ../Test0.txt Gold_Mine constructed Gold_Mine constructed Miner constructed Miner constructed Town_Hall constructed Time: 1 Miner M1 at (1,1) Stopped Miner M2 at (10,1) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Moving 1 to (20,30) M1: On my way. enter a command: Advancing one tick. M1: step... Time: 2 Miner M1 at (3.74013,5.18231) Moving at speed 5 to (20,30) <x,y> amounts on each step are <2.74013,4.18231> Miner M2 at (10,1) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Advancing to next event. M1: step... M1: step... M1: step... M1: step... M1: step... Time: 7 Miner M1 at (17.4408,26.0938) Moving at speed 5 to (20,30)

<x,y> amounts on each step are <2.74013,4.18231> Miner M2 at (10,1) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Stopping 1 Advancing one tick. Time: 8 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,1) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Advancing to next event. Time: 13 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,1) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Miner 2 mining at Gold_Mine 2 and depositing at Town_Hall 1 M2: Yes, my lord enter a command: Advancing one tick. M2: step... Time: 14 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,6) Outbound to a mine Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded

enter a command: Advancing to next event. M2: step... M2: step... M2: I'm There! Time: 17 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Getting gold from mine Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 100. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Advancing to next event. M2: Got 35 gold. Time: 18 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Inbound to home with load: 35 Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 65. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Advancing to next event. M2: step... M2: step... M2: step... M2: step... M2: I'm There! Time: 23 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Depositing gold. Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 65. Town_Hall t1 at (5,0) Contains 0 Not yet upgraded enter a command: Advancing to next event. M2: deposit 35 gold M2: Going back for more. Time: 24 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Outbound to a mine Gold_Mine G1 at (1,20)

contains 100. Gold_Mine G2 at (10,20) contains 65. Town_Hall t1 at (5,0) Contains 35 Not yet upgraded enter a command: Advancing to next event. M2: step... M2: step... M2: step... M2: step... M2: I'm There! Time: 29 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Getting gold from mine Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 65. Town_Hall t1 at (5,0) Contains 35 Not yet upgraded enter a command: Advancing to next event. M2: Got 35 gold. Time: 30 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Inbound to home with load: 35 Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 30. Town_Hall t1 at (5,0) Contains 35 Not yet upgraded enter a command: Advancing to next event. M2: step... M2: step... M2: step... M2: step... M2: I'm There! Time: 35 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Depositing gold. Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 30. Town_Hall t1 at (5,0) Contains 35 Not yet upgraded

enter a command: Advancing to next event. M2: deposit 35 gold M2: Going back for more. Town_Hall T1 has been upgraded Time: 36 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Outbound to a mine Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 30. Town_Hall T1 at (5,0) Contains 70 Upgraded enter a command: Advancing to next event. M2: step... M2: step... M2: step... M2: step... M2: I'm There! Time: 41 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Getting gold from mine Gold_Mine G1 at (1,20) contains 100. Gold_Mine G2 at (10,20) contains 30. Town_Hall T1 at (5,0) Contains 70 Upgraded enter a command: Advancing to next event. M2: Got 30 gold. Gold_Mine G2 has been depleted Time: 42 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (10,20) Inbound to home with load: 30 Gold_Mine G1 at (1,20) contains 100. Gold_Mine g2 at (10,20) contains 0. Town_Hall T1 at (5,0) Contains 70 Upgraded enter a command: M2: step... Gold_Mine G2 has M2: step... Gold_Mine G2 has M2: step... Gold_Mine G2 has M2: step... Advancing to next event. been depleted been depleted been depleted

Gold_Mine G2 has been depleted M2: I'm There! Gold_Mine G2 has been depleted Time: 47 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Depositing gold. Gold_Mine G1 at (1,20) contains 100. Gold_Mine g2 at (10,20) contains 0. Town_Hall T1 at (5,0) Contains 70 Upgraded enter a command: Advancing to next event. M2: deposit 30 gold M2: More work? Gold_Mine G2 has been depleted Time: 48 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine g2 at (10,20) contains 0. Town_Hall T1 at (5,0) Contains 100 Upgraded enter a command: your input command was not valid enter a command: your input command was not valid enter a command: Advancing one tick. Gold_Mine G2 has been depleted Time: 49 Miner M1 at (17.4408,26.0938) Stopped Miner M2 at (5,0) Stopped Gold_Mine G1 at (1,20) contains 100. Gold_Mine g2 at (10,20) contains 0. Town_Hall T1 at (5,0) Contains 100 Upgraded enter a command: your input command was not valid enter a command: your input command was not valid enter a command:

*************************************************** Code Output: #include <iostream> #include "Cart_Point.h" #include "Cart_Vector.h" #include "Gold_Mine.h" #include "Miner.h" #include "Town_Hall.h" using namespace std; int main() { Cart_Point Cart_Point Cart_Point Cart_Point Cart_Point

p1(1,20);//for gold mine 1 p2(10,20);//for gold mine 2 p3(1,1);//for miner 1 p4(10,1);//for miner 2 p5(5,0);//for town hall

Gold_Mine g1(1,p1); Gold_Mine g2(2,p2); Miner m1(1,p3); Miner m2(2,p4); Town_Hall t1(1,p5); int time=1;//time char in;//input int ID,ID1,ID2,ID3;//input ids int x,y;//location inputs; Gold_Mine *pg1;//pointer gold mine 1 Gold_Mine *pg2;//pointer gold mine 2 Town_Hall *pt1;//pointer town hall 1 pg1=&g1; pg2=&g2; pt1=&t1; cout<<"Time: "<<time<<endl; m1.show_status(); m2.show_status(); g1.show_status(); g2.show_status(); t1.show_status(); while(in!='q') { cout<<"\nenter a command: "; cin>>in; if((cin)&&((in=='m')||(in=='w')||(in=='s')||(in=='g')||(in=='r')||(in=='q' ))) { switch(in) { case 'm': cin>>ID>>x>>y; if(ID==1||ID==2) {

Cart_Point destination(x,y); if(ID==1) { m1.start_moving(destination); } else { m2.start_moving(destination); } } else { cout<<"Invalid input ID's for command 'm' \n"; } cin.clear(); cout.clear(); break; case 'w': cin>>ID1>>ID2>>ID3; if((ID1==1||ID1==2)&&(ID2==1||ID2==2)&&(ID3==1)) { if(ID1==1) { if(ID2==1) { m1.start_mining(pg1,pt1); } else if(ID2==2) { m1.start_mining(pg2,pt1); } } else if(ID1==2) { if(ID2==1) { m2.start_mining(pg1,pt1); } else if (ID2==2) { m2.start_mining(pg2,pt1); } } else { cout<< cout<<"Invalid input ID's for command 'w' \n"; } } cin.clear(); cout.clear(); break; case 's': cin>>ID; if(ID==1||ID==2) {

if(ID==1) { m1.stop(); } else { m2.stop(); } } case 'g': cout<<"Advancing one tick."<<endl<<endl; time=time+1; m1.update(); m2.update(); g1.update(); g2.update(); t1.update(); cout<<"Time: "<<time<<endl; m1.show_status(); m2.show_status(); g1.show_status(); g2.show_status(); t1.show_status(); break; case 'r': cout<<"Advancing to next event."<<endl; bool nextevent; nextevent=false; bool em1; bool em2; bool eg1; bool eg2; bool et1; int count; count=0;//number of ticks while(nextevent==false) { count=count+1; time=time+1; em1=m1.update(); em2=m2.update(); eg1=g1.update(); eg2=g2.update(); et1=t1.update(); if((count==5)||em1||em2||eg1||eg2||et1) { nextevent=true; cout<<"Time: "<<time<<endl; m1.show_status(); m2.show_status(); g1.show_status(); g2.show_status(); t1.show_status(); } }

break; case 'q': break; default: cout<<"error no valid case for input"<<endl; } } else { cout<<"your input command was not valid"<<endl; cin.clear(); cout.clear(); } }

return 0; }

You might also like