/*
Copyright (C) 2013 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 20/10/2013
* \date Ultima modifica 20/10/2013
*
*/
package tabellonetennisconsoletest;
/**
*
* @author alex_2
*/
public class TabelloneTennisConsoleTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TabelloneTennis a = new TabelloneTennis("Giorgio","Beppe");
a.visualizza();
a.incrementaPunteggio(0);
a.visualizza();
a.incrementaPunteggio(1);
a.visualizza();
}
}
class TabelloneTennis{
private int punteggio[];
private String giocatore[];
public TabelloneTennis(String g1, String g2)
{
punteggio = new int[2];
giocatore = new String[2];
giocatore[0] = g1;
giocatore[1] = g2;
}
public void visualizza()
{
if (Math.abs(punteggio[0]- punteggio[1])<=40 && punteggio[0]<=40)
System.out.println(giocatore[0] + " - " + giocatore[1] +
" : " + punteggio[0] + " - " + punteggio[1]);
if (punteggio[0] > punteggio[1] + 100)
System.out.println( "Ha vinto il game il giocatore " + giocatore[0]);
if (punteggio[0] + 100 < punteggio[1])
System.out.println( "Ha vinto il game il giocatore " + giocatore[1]);
if (punteggio[0] == punteggio[1] && punteggio[0]>40)
System.out.println("Vantaggio pari");
if (punteggio[0] == punteggio[1] + 100)
System.out.println("Vantaggio " + giocatore[0]);
if (punteggio[0] + 100 == punteggio[1])
System.out.println("Vantaggio " + giocatore[0]);
}
public void azzera()
{
punteggio[0] = punteggio[1] = 0;
}
public void incrementaPunteggio(int g)
{
if (g == 0 || g == 1)
if (punteggio[g]<30) punteggio[g]+=15;
else if (punteggio[g]==30) punteggio[g]=40;
else punteggio[g]+=100;
}
}