aboutsummaryrefslogtreecommitdiff
path: root/robottino/all_versions/v2.0/src/Robottino.java
blob: f1b0c49c200b33bbafb7e68466413f23b8fcaad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import java.util.Scanner;
class Robottino extends PartiDelRobot {
	static PartiDelRobot pdr[][] = { 
				{
				  new PartiDelRobot (false, "il braccio sinistro alzato"), 
		      		  new PartiDelRobot (false, "il braccio destro alzato"),
		      		  new PartiDelRobot (false, "la gamba sinistra alzata"),
		      		  new PartiDelRobot (false, "la gamba destra alzata")
												}
												};
	static String nomeRobot[] = { "" };
	int robotIndex = 0;
	public static void main(String argv[]) {
		Scanner sc = new Scanner(System.in);
		String comando;
		Robottino robottino = new Robottino();
		System.out.println ("**********************************************");
		System.out.println ("**********************************************");
		System.out.println ("*************Programma interattivo************");
		System.out.println ("**********************************************");
		System.out.println ("***Software realizzato da Sebastiano Tronto***");
		System.out.println ("**********************************************");
		System.out.println ("**********************************************");
		System.out.println ("Questo programma simula un robot al quale ven-");
		System.out.println ("gono assegnati ordini tramite comandi, simil-" );
		System.out.println ("mente a quanto bisognava fare con i computer " );
		System.out.println ("alcuni anni fa."                               );
		System.out.println ("Dato che all'epoca i comandi che dovevano es-" );
		System.out.println ("sere dati erano (e sono tutt'ora) in similin-" );
		System.out.println ("glese, ho cercato di mantenerli tali."         );
		System.out.println ("Il programma non fa distinzioni tra lettere"   );
		System.out.println ("maiuscole o minuscole."                        );
		System.out.println ("In questa versione non sono ancora disponibi-" );
		System.out.println ("li immagini e/o effetti grafici."               );
		System.out.println (""                                              );
		System.out.println ("Digita un comando e premi INVIO"               );
		System.out.println ("l = legenda comandi"                           );
		System.out.println ("");
		do {
			comando = sc.nextLine();
			System.out.println ("");
			System.out.println (robottino.Azioni(comando, nomeRobot, pdr));
			System.out.println ("");
		} while ( !(comando.equalsIgnoreCase("exit")) );
	}
	String Azioni(String comando, String nomeRobot[], PartiDelRobot pdr[][]) {
		Scanner sc2 = new Scanner(System.in);
		int contatore = 0;
		String stat[] = {"", "", "", ""};
		String Return = "Errore - si consiglia di picchiare il programmatore";
		if (comando.equalsIgnoreCase("leftarmmove"))
			this.pdr[this.robotIndex][0].statoParte = !this.pdr[this.robotIndex][0].statoParte;
		else if (comando.equalsIgnoreCase("rightarmmove"))
			this.pdr[this.robotIndex][1].statoParte = !this.pdr[this.robotIndex][1].statoParte;
		else if (comando.equalsIgnoreCase("leftlegmove"))
			this.pdr[this.robotIndex][2].statoParte = !this.pdr[this.robotIndex][2].statoParte;
		else if (comando.equalsIgnoreCase("rightlegmove"))
			this.pdr[this.robotIndex][3].statoParte = !this.pdr[this.robotIndex][3].statoParte;
		else if (comando.equalsIgnoreCase("leftarmon"))
			this.pdr[this.robotIndex][0].statoParte = true;
		else if (comando.equalsIgnoreCase("rightarmon"))
			this.pdr[this.robotIndex][1].statoParte = true;
		else if (comando.equalsIgnoreCase("leftlegon"))
			this.pdr[this.robotIndex][2].statoParte = true;
		else if (comando.equalsIgnoreCase("rightlegon"))
			this.pdr[this.robotIndex][3].statoParte = true;
		else if (comando.equalsIgnoreCase("leftarmoff"))
			this.pdr[this.robotIndex][0].statoParte = false;
		else if (comando.equalsIgnoreCase("rightarmoff"))
			this.pdr[this.robotIndex][1].statoParte = false;
		else if (comando.equalsIgnoreCase("leftlegoff"))
			this.pdr[this.robotIndex][2].statoParte = false;
		else if (comando.equalsIgnoreCase("rightlegoff"))
			this.pdr[this.robotIndex][3].statoParte = false;
		else if (comando.equalsIgnoreCase("exploud")) {
			System.out.println ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot[this.robotIndex] + "! Aspetta che te ne faccio un altro");
			System.out.println ("...");
			for (int i = 0; i < pdr[this.robotIndex].length; i++) {
				pdr[this.robotIndex][i].statoParte = false;
			}
			nomeRobot[this.robotIndex] = "";
			return "Fatto, puoi continuare a giocare";
		}
		else if (comando.equalsIgnoreCase("bier")) {
			System.out.println ("Il robottino " + nomeRobot[this.robotIndex] + "sta trangugiando una birra...");
			System.out.println ("Buurrrrrrrrp!");
			return "La birra analcolica fa schifo!";
		}
		else if (comando.equalsIgnoreCase("rename")) {
			System.out.println ("Con questo comando quoi cambiare il nome del robottino " + nomeRobot[this.robotIndex]);
			System.out.println ("Digita il nuovo nome e premi invio per coninuare");
			nomeRobot[this.robotIndex] = sc2.nextLine();
			if (!(nomeRobot[this.robotIndex].equalsIgnoreCase("")))
				nomeRobot[this.robotIndex] += " ";
			return "Ora il robottino si chiama " + nomeRobot[this.robotIndex];
		}
		else if (comando.equalsIgnoreCase("porky")) {
			System.out.println ("Porky è un grande");
			System.out.println ("Per maggiori informazioni visita il sito");
			return "http://kakati.forumfree.net/";
		}
		else if (comando.equalsIgnoreCase("xxx")) {
			System.out.println ("Il robottino " + nomeRobot[this.robotIndex] + "ha incontrato una bella robottina...");
			return "*Censura*";
		}
		else if (comando.equalsIgnoreCase("dance")) {
			System.out.println ("Immagini che il robottino " + nomeRobot[this.robotIndex] + " stia ballando...");
			System.out.println ("Il robottino ha smesso di ballare");
			for (int i = 0; i < pdr[this.robotIndex].length; i++) {
				pdr[0][i].statoParte = false;
			}
			return "Il robottino " + nomeRobot[this.robotIndex] + "si è fermato ed è  tornato nella posizione originale";
		}
		else if (comando.equalsIgnoreCase("newrobot")) {
			PartiDelRobot pdrAus[][] = new PartiDelRobot[(addRobot(this.pdr, this.pdr[this.robotIndex])).length][(addRobot(this.pdr, this.pdr[this.robotIndex]))[(addRobot(this.pdr, this.pdr[this.robotIndex])).length-1].length];
			this.pdr = new PartiDelRobot[pdrAus.length][pdrAus[pdrAus.length-1].length];
			for (int i=0; i<pdrAus.length; i++) {
				for (int j=0; j<pdrAus[i].length; j++) {
					pdrAus[i][j] = (addRobot(pdr, pdr[this.robotIndex]))[i][j];
					pdrAus[i][j].stringaParte = (addRobot(pdr, pdr[this.robotIndex]))[i][j].stringaParte;
					pdrAus[i][j].statoParte = (addRobot(pdr, pdr[this.robotIndex]))[i][j].statoParte;
				}
			}
			for (int i=0; i<this.pdr.length; i++) {
				for (int j=0; j<this.pdr[i].length; j++) {
					this.pdr[i][j] = pdrAus[i][j];
					this.pdr[i][j].stringaParte = pdrAus[i][j].stringaParte;
					this.pdr[i][j].statoParte = pdrAus[i][j].statoParte;
				}
			}
			System.out.println ("È stato creato un nuovo robot. Vuoi dare un nome al nuovo robot?");
			System.out.println ("Inserisci il nuovo nome e premi INVIO oppure lascia vuoto e premi INVIO");
			String newName = sc2.nextLine();
			String nomeRobotAus[] = new String[(addName(this.nomeRobot, newName)).length];
			this.nomeRobot = new String[nomeRobotAus.length];
			for (int i=0; i<nomeRobotAus.length; i++) {
				nomeRobotAus[i] = (addName(nomeRobot, newName))[i];
			}
			for (int i=0; i<nomeRobotAus.length; i++) {
				this.nomeRobot[i] = nomeRobotAus[i];
			}
			return "È stato creato il robottino " + newName;
		}
		else if (comando.equalsIgnoreCase("deleterobot")) 
			return "Comando non disponibile in questa versione del programma";
		else if (comando.equalsIgnoreCase("changerobot")) {
			if (pdr.length==1) {
				return "Hai solo un robottino, non puoi cambiarlo con un altro!";
			}
			else {
				System.out.println ("A quale robottino vuoi dare i comandi?");
				System.out.println ("");
				for (int numRobot = 0; numRobot<this.pdr.length; numRobot++) {
					System.out.println (numRobot + ". " + this.nomeRobot[numRobot]);
				}
				System.out.println ("");
				System.out.println ("Digita il numero corrispondente alla tua scelta e premi INVIO");
				this.robotIndex = sc2.nextInt();
				if (this.robotIndex<this.pdr.length)
					return "È stato selezionato il robottino numero " + this.robotIndex + ": " + this.nomeRobot[this.robotIndex];
				else
					return "Numero non valido";
			}
		}
		else if (comando.equalsIgnoreCase("robotlist")) {
			for (int numRobot = 0; numRobot<this.pdr.length; numRobot++) {
				System.out.println (numRobot + ". " + this.nomeRobot[numRobot]);
			}
			return "";
		}
		else if (comando.equalsIgnoreCase("l")) {
			System.out.println ("Legenda comandi");
			System.out.println ("");
			System.out.println ("Comandi relativi agli arti");
			System.out.println ("");
			System.out.println ("LeftArmMove: cambia la posizione corrente del braccio sinistro del robot");
			System.out.println ("RightArmMove: cambia la posizione corrente del braccio destro del robot");
			System.out.println ("LeftLegMove: cambia la posizione corrente della gamba sinistra del robot");
			System.out.println ("RightLegMove: cambia la posizione corrente della gamba destra del robot");
			System.out.println ("LeftArmOn: se il braccio sinistro non è alzato, lo alza, altrimenti la posizione resta invariata");
			System.out.println ("RightArmOn: se il braccio destro non è alzato, lo alza, altrimenti la posizione resta invariata");
			System.out.println ("LeftLegOn: se la gamba sinistra non è alzata, la alza, altrimenti la posizione resta invariata");
			System.out.println ("RightLegOn: se la gamba destra non è alzata, la alza, altrimenti la posizione resta invariata");
			System.out.println ("LeftArmOff: se il braccio sinistro non è abbassato, lo abbassa, altrimenti la posizione resta invariata");
			System.out.println ("RightArmOff: se il braccio destro non è abbassato, lo abbassa, altrimenti la posizione resta invariata");
			System.out.println ("LeftLegOff: se la gamba sinistra non è abbassata, la abbassa, altrimenti la posizione resta invariata");
			System.out.println ("RightLegOff: se la gamba destra non è abbassata, la abbassa, altrimenti la posizione resta invariata");
			System.out.println ("");
			System.out.println ("Altri comandi:");
			System.out.println ("");
			System.out.println ("NewRobot: aggiunge un nuovo robot");
			System.out.println ("ChangeRobot: cambia il robot attuale");
			System.out.println ("RobotList: visualizza la lista dei robot");
			System.out.println ("Rename: rinomina il robottino");
			System.out.println ("");
			System.out.println ("Comandi a sorpresa:");
			System.out.println ("");
			System.out.println ("Exploud");
			System.out.println ("Bier");
			System.out.println ("Porky");
			System.out.println ("xxx");
			System.out.println ("dance");
			System.out.println ("");
			System.out.println ("Exit: esci dal programma");
			return "";
			
		}
		else if (comando.equalsIgnoreCase("exit"))
			return "";
		else
			System.out.println ("Comando non riconosciuto - digitare l per una legenda dei comandi disponibili");
			System.out.println ("");
		for (int i = 0, j = 0; i < pdr[this.robotIndex].length; i++) {
			if (pdr[robotIndex][i].statoParte) {
				contatore += 1;
				stat[j++] = pdr[this.robotIndex][i].stringaParte;
			}
		}
		switch (contatore) { 
			case 0:
				Return = "Comunque il robottino " + nomeRobot[this.robotIndex] + "non sta facendo niente";
				break;
			case 1:
				Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + ".";
				break;
			case 2:
				Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + " e " + stat[1] + ".";
				break;	
			case 3: 
				Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + ", " + stat[1] + " e " + stat[2] + ".";
				break;
			case 4: 
				Return = "Immagini che il robottino " + nomeRobot[this.robotIndex] + "abbia " + stat[0] + ", " + stat[1] + ", " + stat[2] + " e " + stat[3] + ".";
				break;
		}
		return Return;
	}
	static PartiDelRobot[][] addRobot(PartiDelRobot pdrOld[][], PartiDelRobot pdrElement[]) {
		PartiDelRobot pdrNew[][] = new PartiDelRobot [pdrOld.length+1][pdrOld[pdrOld.length-1].length];
		for (int i=0; i<pdrOld.length; i++) {
			for (int j=0; j<pdrOld[i].length; j++) {
				pdrNew[i][j] = new PartiDelRobot(pdrOld[i][j].statoParte, pdrOld[i][j].stringaParte);
			}
		}
		for (int i=0; i<pdrElement.length; i++) {
			pdrNew[pdrNew.length-1][i] = new PartiDelRobot(false, pdrElement[i].stringaParte);
		}
		return pdrNew;
	}
	static String[] addName(String nomeRobot[], String name) {
		String nomeNewRobot[] = new String [nomeRobot.length+1];
		for (int i=0; i<nomeRobot.length; i++) {
			nomeNewRobot[i] = nomeRobot[i];
		}
		nomeNewRobot[nomeNewRobot.length-1] = name;
		if (!(nomeNewRobot[nomeNewRobot.length-1].equalsIgnoreCase(""))) {
			nomeNewRobot[nomeNewRobot.length-1] += " ";
		}
		return nomeNewRobot;
	}
}









Generated with cgit - Back to sebastiano.tronto.net