// Andrew Kim
// April 2, 2004
// cPlayer.cpp

#include "cPlayer.h"
#include <iostream>

cPlayer::cPlayer(char * name, int num)
: playerName_(name), currentHole_(1), playerNum_(num)
{	
	for(int i= 0; i<9; ++i)
	{
		score_[i]=0;
	}
	hDC=NULL;
}

cPlayer::~cPlayer()
{
}

void cPlayer::addShot()
{
	++score_[currentHole_-1];
}



void cPlayer::nextHole()
{
	++currentHole_;
}


void cPlayer::draw()
{
char c = '0';
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0,glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glColor3f(1,1,1);
char num[2];
num[0] = (char)playerNum_ + c;
num[1] = 0;
output(10,43, playerName_);
output(80,43, num);

output(10,18, "Hits: ");

char score[2];

score[2] = 0;
if(score_[currentHole_-1] >= 10)
{
	score[0] = (char)score_[currentHole_-1] / 10 +c;
	score[1] = (char)score_[currentHole_-1] % 10 +c;
}
else
{
	score[0] = 0+c;
	score[1]= (char)score_[currentHole_-1]+c;
}

output(65,18, score);

glColor3f(0,0,0);
output(9,44, playerName_);
output(79,44, num);
output(9,19, "Hits: ");
output(64,19, score);

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);


}

void cPlayer::output(int x, int y, char *string)
{
  int len, i;
	
  glRasterPos2f(x, y);
  len = (int) strlen(string);
  for (i = 0; i < len; i++)
    glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, string[i]);

}

void cPlayer::setInfo(char* name, int num)
{
	playerName_ = name;
	playerNum_ = num;
}
