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