From 7167b4341ef290d56fb96e2af10883a4b925d83b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Mar 2026 19:27:18 +0100 Subject: I found my old code! --- robottino/all_versions/v2.1/src/Robottino.java | 258 +++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100755 robottino/all_versions/v2.1/src/Robottino.java (limited to 'robottino/all_versions/v2.1/src/Robottino.java') diff --git a/robottino/all_versions/v2.1/src/Robottino.java b/robottino/all_versions/v2.1/src/Robottino.java new file mode 100755 index 0000000..550e027 --- /dev/null +++ b/robottino/all_versions/v2.1/src/Robottino.java @@ -0,0 +1,258 @@ +import java.util.Scanner; +import java.util.Vector; +class Robottino extends PartiDelRobot { + static Robottino robottino = new Robottino(); + static Vector pdrA = new Vector(1); + static Vector pdrB = new Vector(4); + static PartiDelRobot leftArm = new PartiDelRobot(false, "il braccio sinistro alzato"); + static PartiDelRobot rightArm = new PartiDelRobot(false, "il braccio destro alzato"); + static PartiDelRobot leftLeg = new PartiDelRobot(false, "la gamba sinistra alzata"); + static PartiDelRobot rightLeg = new PartiDelRobot(false, "la gamba destra alzata"); + static Vector nomeRobot = new Vector(1); + static int robotIndex = 0; + public static void main(String argv[]) { + pdrB.addElement(leftArm); + pdrB.addElement(rightArm); + pdrB.addElement(leftLeg); + pdrB.addElement(rightLeg); + pdrA.addElement(pdrB); + nomeRobot.addElement(""); + Scanner sc = new Scanner(System.in); + String comando; + 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, pdrA)); + System.out.println (""); + } while ( !(comando.equalsIgnoreCase("exit")) ); + } + String Azioni(String comando, Vector nomeRobot, Vector pdrA) { + Scanner sc2 = new Scanner(System.in); + int contatore = 0; + String stat[] = {"", "", "", ""}; + String Return = "Errore - si consiglia di picchiare il programmatore"; + if (comando.equalsIgnoreCase("leftarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte; + else if (comando.equalsIgnoreCase("rightarmmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte; + else if (comando.equalsIgnoreCase("leftlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte; + else if (comando.equalsIgnoreCase("rightlegmove")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = !((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte; + else if (comando.equalsIgnoreCase("leftarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = true; + else if (comando.equalsIgnoreCase("rightarmon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = true; + else if (comando.equalsIgnoreCase("leftlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = true; + else if (comando.equalsIgnoreCase("rightlegon")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = true; + else if (comando.equalsIgnoreCase("leftarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(0)).statoParte = false; + else if (comando.equalsIgnoreCase("rightarmoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(1)).statoParte = false; + else if (comando.equalsIgnoreCase("leftlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(2)).statoParte = false; + else if (comando.equalsIgnoreCase("rightlegoff")) + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(3)).statoParte = false; + else if (comando.equalsIgnoreCase("exploud")) { + System.out.println ("Che atroce! Hai fatto esplodere il robottino " + nomeRobot.elementAt(this.robotIndex) + "! Aspetta che te ne faccio un altro"); + System.out.println ("..."); + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + this.nomeRobot.setElementAt("", this.robotIndex); + return "Fatto, puoi continuare a giocare"; + } + else if (comando.equalsIgnoreCase("bier")) { + System.out.println ("Il robottino " + nomeRobot.elementAt(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.elementAt(this.robotIndex)); + System.out.println ("Digita il nuovo nome e premi invio per coninuare"); + this.nomeRobot.setElementAt(sc2.nextLine(), this.robotIndex); + if (!(((String)nomeRobot.elementAt(this.robotIndex)).equalsIgnoreCase(""))) + this.nomeRobot.setElementAt(this.nomeRobot.elementAt(this.robotIndex) + " ", this.robotIndex); + return "Ora il robottino si chiama " + nomeRobot.elementAt(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.elementAt(this.robotIndex) + "ha incontrato una bella robottina..."); + return "*Censura*"; + } + else if (comando.equalsIgnoreCase("dance")) { + System.out.println ("Immagini che il robottino " + nomeRobot.elementAt(this.robotIndex) + " stia ballando..."); + System.out.println ("Il robottino ha smesso di ballare"); + for (int i = 0; i < 4; i++) { + ((PartiDelRobot)((Vector)this.pdrA.elementAt(this.robotIndex)).elementAt(i)).statoParte = false; + } + return "Il robottino " + nomeRobot.elementAt(this.robotIndex) + "si è fermato ed è tornato nella posizione originale"; + } + else if (comando.equalsIgnoreCase("newrobot")) { + this.pdrA.addElement(pdrB); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightArm); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (leftLeg); + ((Vector)(this.pdrA.elementAt(pdrA.size()-1))).addElement (rightLeg); + 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(); + this.nomeRobot.addElement(newName); + return "È stato creato il robottino " + newName; + } + else if (comando.equalsIgnoreCase("deleterobot")) { + if (pdrA.size()>1) { + System.out.println ("Quale robottino vuoi eliminare?"); + System.out.println (""); + for (int i = 0; i1) { + System.out.println ("A quale robottino vuoi dare i comandi?"); + System.out.println (""); + for (int i = 0; i