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

BBangHouse::BBangHouse()
{
	pServant = new Servant();
	table = new DiningTable();
}


BBangHouse::~BBangHouse(void)
{
	delete pServant; pServant = NULL;
	delete table; table = NULL;
}

void BBangHouse::join(MuckBBang *person)
{
	table->join(person);
}

void BBangHouse::run()
{
	for(int meal = 0; meal < MAX_MEAL; meal++) {
		table->servedBy(pServant); // pServant->serve(table);

		LinkedList<MuckBBang *> *customers = table->getCustomers();
		POSITION pos = customers->getHeadPosition();
		while (pos != NULL) {
			MuckBBang *person = customers->getNext(pos);
			person->digest();
		}
		printf("...\n");
	}
}

void BBangHouse::print()
{
	printf("=== 최종 상태 보고서 ===\n");
	int nBBang = pServant->getNBBang();
	printf("현재 빵집에는 빵이 %d개 남아있고요...\n",nBBang);
	table->print();
}