static void Main(string[] args) { // current input String val; // make random class Random random = new Random(); // initate objects BankRobber bankRobber = new BankRobber(); Cop cop = new Cop(); //give starting message Console.WriteLine("Simulation is starting..."); while (Manager.isRunning == true) { // get input and convert to string val = Convert.ToString(Console.ReadLine()); // check if program needs to be stopped if (val == "stop") { Manager.isRunning = false; } else { // update states based of vars and echo feedback bankRobber.updateStates(); cop.updateStates(bankRobber); // dev output //Console.WriteLine(bankRobber.strength + " " + bankRobber.wealth + " " + bankRobber.distanceToCop + " " + cop.dutyTime); } } // wait till button press to exit Console.WriteLine(""); Console.WriteLine("Simulation Ended, Press a key to exit..."); Console.ReadLine(); }
public void updateStates(BankRobber robber) { // say current state sayFeedBack(cState); switch (cState) { // update vars case State.ON_STAKE_OUT: dutyTime -= 1; if (robber.distanceToCop > 10 && dutyTime < 1) { cState = State.OFF_DUTY; } if (robber.distanceToCop < 10 && dutyTime > 0) { cState = State.CHASING; } break; case State.OFF_DUTY: dutyTime = dutyTime + 2; robber.distanceToCop = 50; if (dutyTime > 5) { cState = State.ON_STAKE_OUT; } break; case State.CHASING: dutyTime -= 1; robber.distanceToCop -= 4; if (robber.distanceToCop < 2) { // make line and say feedback Console.WriteLine(" "); } Console.WriteLine(" "); cState = State.CAUGHT; sayFeedBack(cState); robber.cState = BankRobber.State.CAUGHT; robber.sayFeedBack(robber.cState); // stop simulation Manager.isRunning = false; if (robber.distanceToCop > 10 && dutyTime > 0) { cState = State.ON_STAKE_OUT; } break; default: // do nothing break; } }