/*
  Copyright (C) 2007 Alessandro Bugatti (alessandro.bugatti@istruzione.it)

  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version 2
  of the License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

/*! \file
 *  \brief Classe per gestire un game di una partita di tennis
 *  \author Alessandro Bugatti
 *
 *  \version 0.1
 *  \date  Creazione  10/10/2007
 *  \date  Ultima modifica 20/10/2013
 *
 */

#include <iostream>
#include <cmath>
#include <sstream>
#include "tabellone.h" // class's header file

using namespace std;

// class constructor
Tabellone::Tabellone()
{
    punteggio[0] = punteggio[1] = 0;
}

// Stampa a video il risultato
void Tabellone::visualizza()
{
    if (abs((double)(punteggio[0]- punteggio[1]))<=40 && punteggio[0]<=40)
        cout << giocatore[0] << " - " << giocatore[1] <<
        " : " << punteggio[0] << " - " << punteggio[1] << endl;
    if (punteggio[0] > punteggio[1] + 100)
           cout << "Ha vinto il game il giocatore " << giocatore[0]<< endl;
    if (punteggio[0]+100 punteggio[1])
            cout << "Ha vinto il game il giocatore " << giocatore[1]<< endl;
    if (punteggio[0] == punteggio[1] && punteggio[0]>40)
            cout << "Vantaggio pari"<< endl;
    if (punteggio[0] == punteggio[1] + 100)
            cout << "Vantaggio " << giocatore[0]<< endl;
    if (punteggio[0] + 100 == punteggio[1])
            cout << "Vantaggio "<< giocatore[1]<< endl;

}

// Azzera il punteggio
void Tabellone::azzera()
{
    punteggio[0]=0;
    punteggio[1]=0;
}

// Incrementa di uno il punteggio della squadra di casa
void Tabellone::incrementaGiocatore(int i)
{
    if (punteggio[i]<30punteggio[i]+=15;
    else if (punteggio[i]==30punteggio[i]=40;
    else punteggio[i]+=100;
}

//Inserisce i nomi dei giocatori
void Tabellone::setNomeGiocatore (const stringgint n)
{
    giocatore[n] = g;
}

string Tabellone::getPunteggio(int iconst
{
    ostringstream out;
    out << punteggio[i];
    return string(out.str());
}

int Tabellone::getSituazione() const
{
    if (punteggio[0] >= punteggio[1] + 200return 1;
    if (punteggio[1] >= punteggio[0] + 200return 2;
    if (punteggio[0] == 140 && punteggio[1]<40return 1;
    if (punteggio[1] == 140 && punteggio[0]<40return 2;
    return 0;
}