SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
Greenfoot
Una Introduzione a Java,
giocando

Marco Ronchetti
Università di Trento
Credits
      Questeslides sono basate sui tutorial di Greenfoot,
    raggiungibili qui:

    http://www.greenfoot.org/doc/tut-1




2
Prerequisiti
      Conosciamo    già alcune basi di programmazione:
        Concetto  di variabile
        Operazioni elementari
        Sintassi di un qualche linguaggio di
         programmazione
        Strutture di controllo di flusso (if, while, for…)




3
Installazione: 1) hai Java? (Win)
      Verifica   se sulla tua macchina c’è Java

      1.    Windows: “Run…”


      2.    Scrivi cmd




      3.    Scrivi java –version

      Se non da errore, hai java.
      La versione deve essere
      almeno 1.5!


4
Installazione: 1) hai Java? (Mac - Linux)
      Verifica    se sulla tua macchina c’è Java

      1.     -
                Mac: lancia Applicazioni/Utility/Terminale
                Linux: apri una shell (terminale)


      2.     Scrivi java –version

      Se non da errore, hai java.
      La versione deve essere
      almeno 1.5!


5
Installazione 2 – Verifica se hai il JDK
        Nel terminale, esegui javac
        Se da errore, hai il Java Runtime Environment e
         non il Java Development Kit




    Output simile a questo
    Se hai il JDK




6
Installazione 3 – carica Java
      Solo   se la tua macchina non ha già il JDK:
        Scarica   e installa il Java Development Kit




7
Installazione 4 – scarica Greenfoot
       Sempre dal sito
       http://www.greenfoot.org/download
       Scegli la versione adatta alla tua macchina




    Linux diversi da Ubuntu o Debian devono usare la versione Java




8
Installazione 5 - alternativa
      Solo   per Windows:




                    Installazione su chiavetta USB



9
Il mondo di Greenfoot (World)




10
Mettere degli oggetti nel mondo




                               Wombat = Vombatide


                      Click con il tasto destro




11
Mettere degli oggetti nel mondo




                     Impariamo il linguaggio
                             Gli oggetti = OGGETTI
                          Creare oggetti = ISTANZIARE
                       I prototipi (gli stampini) = CLASSI




12
Fare agire gli oggetti
       Clicchiamo   sul menu “act” di un Wombat

       Proviamo
               a mettere una foglia davanti a un
       Wombat e facciamolo andare sopra la foglia




13
Eseguire
       Clicchiamo    su run():

       Equivale   a fare act(); act(); act(); act(); …

     Ovvero a

     while (true) {
            act();
     }




14
Eseguire azioni


                       Click con il tasto destro




15
Eseguire azioni
                         Impariamo il linguaggio
                                   Le azioni = METODI
                       Eseguire un’azione= INVOCARE UN METODO




16
Eseguire azioni
                        Impariamo il linguaggio
                                boolean = {true, false }
                       int= {MIN, …, -3, -2, -1, 0, 1, 2, 3, …, MAX}




17
Creare un nuovo mondo
       bottone   di reset

     => Crea un “mondo” nuovo




18
Invocare un metodo del Mondo
           Anche   il mondo è un oggetto…




     Click con il tasto destro




19
Caricare un nuovo scenario
       Scarica   un file e unzippalo, da
     http://www.greenfoot.org/tutorial-files/modern-crab.zip
       Carica   lo scenario in Greenfoot




20
Caricare un nuovo scenario
       Scarica   un file e unzippalo, da
     http://www.greenfoot.org/tutorial-files/modern-crab.zip
       Carica   lo scenario in Greenfoot




                             Impariamo il linguaggio
                                 Lo scenario = IL PROGRAMMA




21
Aggiungiamo un oggetto, ed eseguiamo




22
Usiamo l’editor


               public void act(){

                       move(4);

               }


                   public void act(){

                       move(4);
                       turn(3);

                   }



23
Usiamo l’editor
                              Occhi alle parentesi!


               public void act(){

                   move(4);

                   if (Greenfoot.isKeyDown(“left”)){
                        turn(-3);
                   }

                   if (Greenfoot.isKeyDown(“right”)){
                        turn(3);
                   }


               }


24
Il granchio mangia i vermi
               public void act(){
                  move(4);
                  if (Greenfoot.isKeyDown(“left”)){
                       turn(-3);
                  }
                  if (Greenfoot.isKeyDown(“right”)){
                       turn(3);
                  }

                    Actor worm;
                   worm=getOneObjectAtOffset(0,0,Actor.class);
                   if (worm!=null) {
                        World world;
                        world=getWorld();
                        world.removeObject(worm);
                   }
               }


25
Ereditarietà
       Crabis-a Actor
       Worm is-a Actor


     Un Crab (granchio) è un Actor (attore)

     Esempi di generalizzazione-specializzazione:

     Studente is-a Persona
     Professore is-a Persona




26
Ereditarietà
     class Persona {
             String name;
             Date dataDiNascita;
     }

     class Studente extends Persona {
             int matricola;
     }

     Studente x=new Studente();
     x.name=“Marco”;
     x.matricola=123;


27
Un’occhiata alla documentazione
          Click su “Actor” – “Open Documentation”




      Ci serve per scoprire quali metodi abbiamo a disposizione!


28
Riepilogo di cosa abbiamo discusso in aula
       Classi
       Oggetti
       istanza,   istanziare
       Metodi
       Variabilidi istanza
       Ereditarietà: superclasse e sottoclasse
       Come accedere alla documentazione di Greenfoot
       Come accedere alla documantazione di Java




29

Mais conteúdo relacionado

Último

Storia dell’Inghilterra nell’Età Moderna.pptx
Storia dell’Inghilterra nell’Età Moderna.pptxStoria dell’Inghilterra nell’Età Moderna.pptx
Storia dell’Inghilterra nell’Età Moderna.pptxOrianaOcchino
 
Esame finale - riunione genitori 2024.pptx
Esame finale - riunione genitori 2024.pptxEsame finale - riunione genitori 2024.pptx
Esame finale - riunione genitori 2024.pptxfedericodellacosta2
 
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla Cresima
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla CresimaIL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla Cresima
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla CresimaRafael Figueredo
 
La seconda guerra mondiale per licei e scuole medie
La seconda guerra mondiale per licei e scuole medieLa seconda guerra mondiale per licei e scuole medie
La seconda guerra mondiale per licei e scuole medieVincenzoPantalena1
 
Ticonzero news 148.pdf aprile 2024 Terza cultura
Ticonzero news 148.pdf aprile 2024 Terza culturaTiconzero news 148.pdf aprile 2024 Terza cultura
Ticonzero news 148.pdf aprile 2024 Terza culturaPierLuigi Albini
 
lezione di fisica_I moti nel piano_Amaldi
lezione di fisica_I moti nel piano_Amaldilezione di fisica_I moti nel piano_Amaldi
lezione di fisica_I moti nel piano_Amaldivaleriodinoia35
 
Esperimenti_laboratorio di fisica per la scuola superiore
Esperimenti_laboratorio di fisica per la scuola superioreEsperimenti_laboratorio di fisica per la scuola superiore
Esperimenti_laboratorio di fisica per la scuola superiorevaleriodinoia35
 
La produzione e la gestione degli Open Data
La produzione e la gestione degli Open DataLa produzione e la gestione degli Open Data
La produzione e la gestione degli Open DataGianluigi Cogo
 

Último (8)

Storia dell’Inghilterra nell’Età Moderna.pptx
Storia dell’Inghilterra nell’Età Moderna.pptxStoria dell’Inghilterra nell’Età Moderna.pptx
Storia dell’Inghilterra nell’Età Moderna.pptx
 
Esame finale - riunione genitori 2024.pptx
Esame finale - riunione genitori 2024.pptxEsame finale - riunione genitori 2024.pptx
Esame finale - riunione genitori 2024.pptx
 
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla Cresima
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla CresimaIL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla Cresima
IL CHIAMATO ALLA CONVERSIONE - catechesi per candidati alla Cresima
 
La seconda guerra mondiale per licei e scuole medie
La seconda guerra mondiale per licei e scuole medieLa seconda guerra mondiale per licei e scuole medie
La seconda guerra mondiale per licei e scuole medie
 
Ticonzero news 148.pdf aprile 2024 Terza cultura
Ticonzero news 148.pdf aprile 2024 Terza culturaTiconzero news 148.pdf aprile 2024 Terza cultura
Ticonzero news 148.pdf aprile 2024 Terza cultura
 
lezione di fisica_I moti nel piano_Amaldi
lezione di fisica_I moti nel piano_Amaldilezione di fisica_I moti nel piano_Amaldi
lezione di fisica_I moti nel piano_Amaldi
 
Esperimenti_laboratorio di fisica per la scuola superiore
Esperimenti_laboratorio di fisica per la scuola superioreEsperimenti_laboratorio di fisica per la scuola superiore
Esperimenti_laboratorio di fisica per la scuola superiore
 
La produzione e la gestione degli Open Data
La produzione e la gestione degli Open DataLa produzione e la gestione degli Open Data
La produzione e la gestione degli Open Data
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Greenfoot - introduzione a Java giocando

  • 1. Greenfoot Una Introduzione a Java, giocando Marco Ronchetti Università di Trento
  • 2. Credits   Questeslides sono basate sui tutorial di Greenfoot, raggiungibili qui: http://www.greenfoot.org/doc/tut-1 2
  • 3. Prerequisiti   Conosciamo già alcune basi di programmazione:   Concetto di variabile   Operazioni elementari   Sintassi di un qualche linguaggio di programmazione   Strutture di controllo di flusso (if, while, for…) 3
  • 4. Installazione: 1) hai Java? (Win)   Verifica se sulla tua macchina c’è Java 1.  Windows: “Run…” 2.  Scrivi cmd 3.  Scrivi java –version Se non da errore, hai java. La versione deve essere almeno 1.5! 4
  • 5. Installazione: 1) hai Java? (Mac - Linux)   Verifica se sulla tua macchina c’è Java 1.  -   Mac: lancia Applicazioni/Utility/Terminale   Linux: apri una shell (terminale) 2.  Scrivi java –version Se non da errore, hai java. La versione deve essere almeno 1.5! 5
  • 6. Installazione 2 – Verifica se hai il JDK   Nel terminale, esegui javac   Se da errore, hai il Java Runtime Environment e non il Java Development Kit Output simile a questo Se hai il JDK 6
  • 7. Installazione 3 – carica Java   Solo se la tua macchina non ha già il JDK:   Scarica e installa il Java Development Kit 7
  • 8. Installazione 4 – scarica Greenfoot Sempre dal sito http://www.greenfoot.org/download Scegli la versione adatta alla tua macchina Linux diversi da Ubuntu o Debian devono usare la versione Java 8
  • 9. Installazione 5 - alternativa   Solo per Windows: Installazione su chiavetta USB 9
  • 10. Il mondo di Greenfoot (World) 10
  • 11. Mettere degli oggetti nel mondo Wombat = Vombatide Click con il tasto destro 11
  • 12. Mettere degli oggetti nel mondo Impariamo il linguaggio Gli oggetti = OGGETTI Creare oggetti = ISTANZIARE I prototipi (gli stampini) = CLASSI 12
  • 13. Fare agire gli oggetti   Clicchiamo sul menu “act” di un Wombat   Proviamo a mettere una foglia davanti a un Wombat e facciamolo andare sopra la foglia 13
  • 14. Eseguire   Clicchiamo su run():   Equivale a fare act(); act(); act(); act(); … Ovvero a while (true) { act(); } 14
  • 15. Eseguire azioni Click con il tasto destro 15
  • 16. Eseguire azioni Impariamo il linguaggio Le azioni = METODI Eseguire un’azione= INVOCARE UN METODO 16
  • 17. Eseguire azioni Impariamo il linguaggio boolean = {true, false } int= {MIN, …, -3, -2, -1, 0, 1, 2, 3, …, MAX} 17
  • 18. Creare un nuovo mondo   bottone di reset => Crea un “mondo” nuovo 18
  • 19. Invocare un metodo del Mondo   Anche il mondo è un oggetto… Click con il tasto destro 19
  • 20. Caricare un nuovo scenario   Scarica un file e unzippalo, da http://www.greenfoot.org/tutorial-files/modern-crab.zip   Carica lo scenario in Greenfoot 20
  • 21. Caricare un nuovo scenario   Scarica un file e unzippalo, da http://www.greenfoot.org/tutorial-files/modern-crab.zip   Carica lo scenario in Greenfoot Impariamo il linguaggio Lo scenario = IL PROGRAMMA 21
  • 22. Aggiungiamo un oggetto, ed eseguiamo 22
  • 23. Usiamo l’editor public void act(){ move(4); } public void act(){ move(4); turn(3); } 23
  • 24. Usiamo l’editor Occhi alle parentesi! public void act(){ move(4); if (Greenfoot.isKeyDown(“left”)){ turn(-3); } if (Greenfoot.isKeyDown(“right”)){ turn(3); } } 24
  • 25. Il granchio mangia i vermi public void act(){ move(4); if (Greenfoot.isKeyDown(“left”)){ turn(-3); } if (Greenfoot.isKeyDown(“right”)){ turn(3); } Actor worm; worm=getOneObjectAtOffset(0,0,Actor.class); if (worm!=null) { World world; world=getWorld(); world.removeObject(worm); } } 25
  • 26. Ereditarietà   Crabis-a Actor   Worm is-a Actor Un Crab (granchio) è un Actor (attore) Esempi di generalizzazione-specializzazione: Studente is-a Persona Professore is-a Persona 26
  • 27. Ereditarietà class Persona { String name; Date dataDiNascita; } class Studente extends Persona { int matricola; } Studente x=new Studente(); x.name=“Marco”; x.matricola=123; 27
  • 28. Un’occhiata alla documentazione Click su “Actor” – “Open Documentation” Ci serve per scoprire quali metodi abbiamo a disposizione! 28
  • 29. Riepilogo di cosa abbiamo discusso in aula   Classi   Oggetti   istanza, istanziare   Metodi   Variabilidi istanza   Ereditarietà: superclasse e sottoclasse   Come accedere alla documentazione di Greenfoot   Come accedere alla documantazione di Java 29