#include "DiningTable.h"
#include "LinkedList.h"
#include "MuckBBang.h"
#include "Servant.h"

DiningTable::DiningTable()
{
	pCustomers = new LinkedList<MuckBBang *>();
}


DiningTable::~DiningTable(void)
{
	POSITION pos = pCustomers->getHeadPosition();
	while (pos != NULL) {
		MuckBBang *person = pCustomers->getNext(pos);
		delete person;
	}

	delete pCustomers;
	pCustomers = NULL;
}

void DiningTable::join(MuckBBang *person)
{
	nCustomer++;
	pCustomers->addLast(person);
}

void  DiningTable::servedBy(Servant *pServant)
{
	int i = 0;
	POSITION pos = pCustomers->getHeadPosition();
	while (pos != NULL) {
		MuckBBang *person = pCustomers->getNext(pos);

		person->eatAppetizer();
		int n = pServant->askAmountToServe(person);
		person->eatEntree(n);
		person->eatDessert();
	}
}

void DiningTable::print()
{
	int nCustomer = pCustomers->size();
	printf("테이블에는 손님이 %d분 계시는데요...\n",nCustomer);
	POSITION pos = pCustomers->getHeadPosition();
	while (pos != NULL) {
		MuckBBang *person = pCustomers->getNext(pos);
		person->print();
	}
}