-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathHasCoinState.cpp
35 lines (29 loc) · 912 Bytes
/
HasCoinState.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "HasCoinState.hpp"
#include<iostream>
#include<time.h>
#include<cstdlib>
using namespace std;
HasCoinState::HasCoinState(GumballMachine* gumballMachine) {
this->gumballMachine = gumballMachine;
srand(time(0));
}
void HasCoinState::insertCoin() {
cout << "ERROR: You have already inserted a coin!" << endl;
}
void HasCoinState::ejectCoin() {
cout << "Coin rolling out!" << endl;
gumballMachine->setState(gumballMachine->getNoCoinState());
}
void HasCoinState::turnCrank() {
cout << "You turned the crank ..." << endl;
int winner = rand()%10; // get a random number from 1 to 10
if(winner == 0) {
gumballMachine->setState(gumballMachine->getWinnerState());
}
else {
gumballMachine->setState(gumballMachine->getSoldState());
}
}
void HasCoinState::dispense() {
cout << "ERROR: You need to turn the crank to get your gumball." << endl;
}