1 /*
2 Copyright (C)2013 Alessandro Bugatti (alessandro.bugatti@istruzione.it)
3 3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 18
19 /*! \file
20 * \brief Classe per gestire un game di una partita di tennis
21 * \author Alessandro Bugatti
22 *
23 * \version 0.1
24 * \date Creazione 20/10/2013
25 * \date Ultima modifica 20/10/2013
26 *
27 */
28 28
29 public class TabelloneTennis {
30 private int punteggio[];
31 private String giocatore[];
32 public TabelloneTennis(String g1, String g2)
33 {
34 punteggio = new int[2];
35 giocatore = new String[2];
36 giocatore[0] = g1;
37 giocatore[1] = g2;
38 }
39 public void visualizza()
40 {
41 if (Math.abs(punteggio[0]- punteggio[1])<=40 && punteggio[0]<=40)
42 System.out.println(giocatore[0] + " - " + giocatore[1] +
43 " : " + punteggio[0] + " - " + punteggio[1]);
44 if (punteggio[0] > punteggio[1] + 100)
45 System.out.println( "Ha vinto il game il giocatore " + giocatore[0]);
46 if (punteggio[0] + 100 < punteggio[1])
47 System.out.println( "Ha vinto il game il giocatore " + giocatore[1]);
48 if (punteggio[0] == punteggio[1] && punteggio[0]>40)
49 System.out.println("Vantaggio pari");
50 if (punteggio[0] == punteggio[1] + 100)
51 System.out.println("Vantaggio " + giocatore[0]);
52 if (punteggio[0] + 100 == punteggio[1])
53 System.out.println("Vantaggio " + giocatore[0]);
54 54
55 }
56 public void azzera()
57 {
58 punteggio[0] = punteggio[1] = 0;
59 }
60 public void incrementaPunteggio(int g)
61 {
62 if (g == 0 || g == 1)
63 if (punteggio[g]<30) punteggio[g]+=15;
64 else if (punteggio[g]==30) punteggio[g]=40;
65 else punteggio[g]+=100;
66 }
67 public String getPunteggio(int i)
68 {
69 return String.valueOf(punteggio[i]);
70 }
71
72 public int getSituazione()
73 {
74 if (punteggio[0] >= punteggio[1] + 200) return 1;
75 if (punteggio[1] >= punteggio[0] + 200) return 2;
76 if (punteggio[0] == 140 && punteggio[1]<40) return 1;
77 if (punteggio[1] == 140 && punteggio[0]<40) return 2;
78 return 0;
79 }
80 }
81