Hangman

 

At the end of the first sequence, we combine our acquired knowledge in the field of graphic and string instructions and expand our knowledge of the fields. The result is the Hangman project.

Excerpts from the source code:

private void initAnzeige(String pWort, boolean pWahr){
        versteckt=new boolean[pWort.length()];
        for (int i=0;i<pWort.length();i++){
            versteckt[i]=pWahr;
        }
    }
    
    private void zeigeRatewort(){
        String lAusgabe="";
        for (int i=0;i<ratewort.length();i++){
            if (versteckt[i]) lAusgabe+="___   ";
            else lAusgabe+=" "+ratewort.charAt(i)+"    ";
        }
        txtFldRatewort.setText(lAusgabe);
    }
    
    private void zeigeVerbrauchteZeichen(){
        String lAusgabe="";
        for (int i=0;i<verbraucht.length();i++){
            lAusgabe+=" "+verbraucht.charAt(i)+"    ";
        }
        txtFldBenutzt.setText(lAusgabe);
    }
    
    private void loescheZeichenflaeche(){
        kenntGrafik.setColor(Color.white);
        kenntGrafik.fillRect(10,240,300,350);
        kenntGrafik.setColor(Color.black);        
    }
    
    private void zeichne(int pWahl){
        //loescheZeichenflaeche();
        switch(pWahl){
            case 0:break;
            case 1:loescheZeichenflaeche();kenntGrafik.drawLine(20,570,85,530);break;
            case 2:kenntGrafik.drawLine(85,530,150,570);break;
            case 3:kenntGrafik.drawLine(85,530,85,250);break;
            case 4:kenntGrafik.drawLine(85,250,200,250);break;
            case 5:kenntGrafik.drawLine(85,300,160,250);break;
            case 6:kenntGrafik.drawLine(200,250,200,300);break;
            case 7:kenntGrafik.drawOval(185,300,30,30);break;
            case 8:kenntGrafik.drawOval(175,330,50,100);break;
            case 9:kenntGrafik.drawLine(160,400,177,360);break;
            case 10:kenntGrafik.drawLine(223,360,240,400);break;
            case 11:kenntGrafik.drawLine(175,500,195,428);break;
            case 12:kenntGrafik.drawLine(205,428,225,500);break;
        }
    }
    
    private void zeichneGalgen(){
        for (int i=0;i<=12;i++){
            zeichne(i);
        }
    }
    
    private int pruefeEingabe(char pZeichen){
        int lTreffer=0;
        for (int i=0;i<ratewort.length();i++){
            if (ratewort.charAt(i)==pZeichen){
                versteckt[i]=false;
                lTreffer++;
            }
        }
        return lTreffer;
    }