This site requires JavaScript, please enable it in your browser!
Greenfoot back
stefco05
stefco05 wrote ...

2022/1/27

Greenfoot.mouseclicked doesn't reacts after a click

stefco05 stefco05

2022/1/27

#
Hey guys, as u saw I the title I got the following Problem: Greenfoot doesn't recognzies or reacts to a click on the Object. I checked it in the debugger, to be sure that the click recognition is running, but it doesn't helps at all. Thanks for your help.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) java.util.ArrayList;
import java.util.*;
/**
 * Write a description of class Game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Game extends World
{
    //Color codes: 0=Black;1=Blue;2=Brown;3=Green;4=Grey;5=Red;6=White;7=Yellow
    //Declaring Variables
//I left some further declarations out of here beecause it would be too much
//Buttons
    PinTap black = new PinTap();
    PinTap blue = new PinTap();
    PinTap brown = new PinTap();
    PinTap green = new PinTap();
    PinTap grey = new PinTap();
    PinTap red = new PinTap();
    PinTap white = new PinTap();
    PinTap yellow = new PinTap();
public Game()
    {    
        super(1280, 720, 1);
        //Buttons
        addObject(black,50,(90-45));
        addObject(blue,50,(180-45));
        addObject(brown,50,(270-45));
        addObject(green,50,(360-45));
        addObject(grey,50,(450-45));
        addObject(red,50,(540-45));
        addObject(white,50,(630-45));
        addObject(yellow,50,(720-45));
        addObject(line,100,360);
}
public void act()
    {
        clearAll();
        run = true;
        generateCode();
        while(run)
        {
            if(Greenfoot.mouseClicked(black)){tappedBlack++;addToList();}
            else if(Greenfoot.mouseClicked(blue)){tappedBlue++;addToList();}
            else if(Greenfoot.mouseClicked(brown)){tappedBrown++;addToList();}
            else if(Greenfoot.mouseClicked(green)){tappedGreen++;addToList();}
            else if(Greenfoot.mouseClicked(grey)){tappedGrey++;addToList();}
            else if(Greenfoot.mouseClicked(red)){tappedRed++;addToList();}
            else if(Greenfoot.mouseClicked(white)){tappedWhite++;addToList();}
            else if(Greenfoot.mouseClicked(yellow)){tappedYellow++;addToList();}
        }
        //if(getCurrentRound() == 13){}else{}
    }
danpost danpost

2022/1/28

#
What are the codings for clearAll and generateCode? also, for addToList. And, how and where is the list declared?
stefco05 stefco05

2022/1/28

#
Thanks for answering. well the Project is very big, but I will post it now anyways completely... Please just don't say anything about what a mess that is... I already know it by myself...
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) java.util.ArrayList;
import java.util.*;
/**
 * Write a description of class Game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Game extends World
{
    //Color codes: 0=Black;1=Blue;2=Brown;3=Green;4=Grey;5=Red;6=White;7=Yellow
    //Declaring Variables
    private List code = new ArrayList();
    private List Row1 = new ArrayList();
    private List Row2 = new ArrayList();
    private List Row3 = new ArrayList();
    private List Row4 = new ArrayList();
    private List Row5 = new ArrayList();
    private List Row6 = new ArrayList();
    private List Row7 = new ArrayList();
    private List Row8 = new ArrayList();
    private List Row9 = new ArrayList();
    private List Row10 = new ArrayList();
    private List Row11 = new ArrayList();
    private List Row12 = new ArrayList();
    private boolean win;
    private int rdm;
    private boolean run;
    private int Try;
    private int tappedBlack;
    private int tappedBlue;
    private int tappedBrown;
    private int tappedGreen;
    private int tappedGrey;
    private int tappedRed;
    private int tappedWhite;
    private int tappedYellow;
    private int correctAnswer;
    private int correctColor;
    //Declaring GreenfootImages
    GreenfootImage PinBlack = new GreenfootImage("PinBlack.png");
    GreenfootImage PinBlue = new GreenfootImage("PinBlue.png");
    GreenfootImage PinBrown = new GreenfootImage("PinBrown.png");
    GreenfootImage PinGreen = new GreenfootImage("PinGreen.png");
    GreenfootImage PinGrey = new GreenfootImage("PinGrey.png");
    GreenfootImage PinRed = new GreenfootImage("PinRed.png");
    GreenfootImage PinWhite = new GreenfootImage("PinWhite.png");
    GreenfootImage PinYellow = new GreenfootImage("PinYellow.png");
    GreenfootImage PinNone = PinGrey;
    GreenfootImage Line = new GreenfootImage("Line.png");
    GreenfootImage FBlack = new GreenfootImage("PinBlack.png");
    GreenfootImage FBlue = new GreenfootImage("PinBlue.png");
    GreenfootImage FBrown = new GreenfootImage("PinBrown.png");
    GreenfootImage FGreen = new GreenfootImage("PinGreen.png");
    GreenfootImage FGrey = new GreenfootImage("PinGrey.png");
    GreenfootImage FRed = new GreenfootImage("PinRed.png");
    GreenfootImage FWhite = new GreenfootImage("PinWhite.png");
    GreenfootImage FYellow = new GreenfootImage("PinYellow.png");
    GreenfootImage HBlack = new GreenfootImage("PinBlack.png");
    GreenfootImage HWhite = new GreenfootImage("PinWhite.png");
    GreenfootImage HGrey = new GreenfootImage("PinGrey.png");
    //Declaring Actors
    //Row 1
    PinShow R1P1 = new PinShow();
    PinShow R1P2 = new PinShow();
    PinShow R1P3 = new PinShow();
    PinShow R1P4 = new PinShow();
    PinShow R1P5 = new PinShow();
    //Row 2
    PinShow R2P1 = new PinShow();
    PinShow R2P2 = new PinShow();
    PinShow R2P3 = new PinShow();
    PinShow R2P4 = new PinShow();
    PinShow R2P5 = new PinShow();
    //Row 3
    PinShow R3P1 = new PinShow();
    PinShow R3P2 = new PinShow();
    PinShow R3P3 = new PinShow();
    PinShow R3P4 = new PinShow();
    PinShow R3P5 = new PinShow();
    //Row 4
    PinShow R4P1 = new PinShow();
    PinShow R4P2 = new PinShow();
    PinShow R4P3 = new PinShow();
    PinShow R4P4 = new PinShow();
    PinShow R4P5 = new PinShow();
    //Row 5
    PinShow R5P1 = new PinShow();
    PinShow R5P2 = new PinShow();
    PinShow R5P3 = new PinShow();
    PinShow R5P4 = new PinShow();
    PinShow R5P5 = new PinShow();
    //Row 6
    PinShow R6P1 = new PinShow();
    PinShow R6P2 = new PinShow();
    PinShow R6P3 = new PinShow();
    PinShow R6P4 = new PinShow();
    PinShow R6P5 = new PinShow();
    //Row 7
    PinShow R7P1 = new PinShow();
    PinShow R7P2 = new PinShow();
    PinShow R7P3 = new PinShow();
    PinShow R7P4 = new PinShow();
    PinShow R7P5 = new PinShow();
    //Row 8
    PinShow R8P1 = new PinShow();
    PinShow R8P2 = new PinShow();
    PinShow R8P3 = new PinShow();
    PinShow R8P4 = new PinShow();
    PinShow R8P5 = new PinShow();
    //Row 9
    PinShow R9P1 = new PinShow();
    PinShow R9P2 = new PinShow();
    PinShow R9P3 = new PinShow();
    PinShow R9P4 = new PinShow();
    PinShow R9P5 = new PinShow();
    //Row 10
    PinShow R10P1 = new PinShow();
    PinShow R10P2 = new PinShow();
    PinShow R10P3 = new PinShow();
    PinShow R10P4 = new PinShow();
    PinShow R10P5 = new PinShow();
    //Row 11
    PinShow R11P1 = new PinShow();
    PinShow R11P2 = new PinShow();
    PinShow R11P3 = new PinShow();
    PinShow R11P4 = new PinShow();
    PinShow R11P5 = new PinShow();
    //Row 12
    PinShow R12P1 = new PinShow();
    PinShow R12P2 = new PinShow();
    PinShow R12P3 = new PinShow();
    PinShow R12P4 = new PinShow();
    PinShow R12P5 = new PinShow();
    //Final
    PinShow F1 = new PinShow();
    PinShow F2 = new PinShow();
    PinShow F3 = new PinShow();
    PinShow F4 = new PinShow();
    PinShow F5 = new PinShow();
    //Buttons
    PinTap black = new PinTap();
    PinTap blue = new PinTap();
    PinTap brown = new PinTap();
    PinTap green = new PinTap();
    PinTap grey = new PinTap();
    PinTap red = new PinTap();
    PinTap white = new PinTap();
    PinTap yellow = new PinTap();
    //Line
    Line line = new Line();
    //Hints Row 1
    PinShow H1R1 = new PinShow();
    PinShow H2R1 = new PinShow();
    PinShow H3R1 = new PinShow();
    PinShow H4R1 = new PinShow();
    //Hints Row 2
    PinShow H1R2 = new PinShow();
    PinShow H2R2 = new PinShow();
    PinShow H3R2 = new PinShow();
    PinShow H4R2 = new PinShow();
    //Hints Row 3
    PinShow H1R3 = new PinShow();
    PinShow H2R3 = new PinShow();
    PinShow H3R3 = new PinShow();
    PinShow H4R3 = new PinShow();
    //Hints Row 4
    PinShow H1R4 = new PinShow();
    PinShow H2R4 = new PinShow();
    PinShow H3R4 = new PinShow();
    PinShow H4R4 = new PinShow();
    //Hints Row 5
    PinShow H1R5 = new PinShow();
    PinShow H2R5 = new PinShow();
    PinShow H3R5 = new PinShow();
    PinShow H4R5 = new PinShow();
    //Hints Row 6
    PinShow H1R6 = new PinShow();
    PinShow H2R6 = new PinShow();
    PinShow H3R6 = new PinShow();
    PinShow H4R6 = new PinShow();
    //Hints Row 7
    PinShow H1R7 = new PinShow();
    PinShow H2R7 = new PinShow();
    PinShow H3R7 = new PinShow();
    PinShow H4R7 = new PinShow();
    //Hints Row 8
    PinShow H1R8 = new PinShow();
    PinShow H2R8 = new PinShow();
    PinShow H3R8 = new PinShow();
    PinShow H4R8 = new PinShow();
    //Hints Row 9
    PinShow H1R9 = new PinShow();
    PinShow H2R9 = new PinShow();
    PinShow H3R9 = new PinShow();
    PinShow H4R9 = new PinShow();
    //Hints Row 10
    PinShow H1R10 = new PinShow();
    PinShow H2R10 = new PinShow();
    PinShow H3R10 = new PinShow();
    PinShow H4R10 = new PinShow();
    //Hints Row 11
    PinShow H1R11 = new PinShow();
    PinShow H2R11 = new PinShow();
    PinShow H3R11 = new PinShow();
    PinShow H4R11 = new PinShow();
    //Hints Row 12
    PinShow H1R12 = new PinShow();
    PinShow H2R12 = new PinShow();
    PinShow H3R12 = new PinShow();
    PinShow H4R12 = new PinShow();
    private Object statRow1;
    private Object statRow2;
    private Object statRow3;
    private Object statRow4;
    private Object statRow5;
    private Object statFinal1;
    private Object statFinal2;
    private Object statFinal3;
    private Object statFinal4;
    private Object statFinal5;
    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    
        super(1280, 720, 1);
        //Buttons
        addObject(black,50,(90-45));
        addObject(blue,50,(180-45));
        addObject(brown,50,(270-45));
        addObject(green,50,(360-45));
        addObject(grey,50,(450-45));
        addObject(red,50,(540-45));
        addObject(white,50,(630-45));
        addObject(yellow,50,(720-45));
        addObject(line,100,360);
        //Finals
        addObject(F1,196, 90);
        addObject(F2,(236*2),90);
        addObject(F3,(236*3),90);
        addObject(F4,(236*4),90);
        addObject(F5,(236*5),90);
        //Set Row 1 + 7
        addObject(R1P1,150,675);
        addObject(R1P2,245,675);
        addObject(R1P3,340,675);
        addObject(R1P4,435,675);
        addObject(R1P5,530,675);
        addObject(R7P1,(1280-430),675);
        addObject(R7P2,(1280-335),675);
        addObject(R7P3,(1280-240),675);
        addObject(R7P4,(1280-145),675);
        addObject(R7P5,(1280-050),675);
        //Set Row 2 + 8
        addObject(R2P1,150,585);
        addObject(R2P2,245,585);
        addObject(R2P3,340,585);
        addObject(R2P4,435,585);
        addObject(R2P5,530,585);
        addObject(R8P1,(1280-430),585);
        addObject(R8P2,(1280-335),585);
        addObject(R8P3,(1280-240),585);
        addObject(R8P4,(1280-145),585);
        addObject(R8P5,(1280-050),585);
        //Set Row 3 + 9
        addObject(R3P1,150,495);
        addObject(R3P2,245,495);
        addObject(R3P3,340,495);
        addObject(R3P4,435,495);
        addObject(R3P5,530,495);
        addObject(R9P1,(1280-430),495);
        addObject(R9P2,(1280-335),495);
        addObject(R9P3,(1280-240),495);
        addObject(R9P4,(1280-145),495);
        addObject(R9P5,(1280-050),495);
        //Set Row 4 + 10
        addObject(R4P1,150,405);
        addObject(R4P2,245,405);
        addObject(R4P3,340,405);
        addObject(R4P4,435,405);
        addObject(R4P5,530,405);
        addObject(R10P1,(1280-430),405);
        addObject(R10P2,(1280-335),405);
        addObject(R10P3,(1280-240),405);
        addObject(R10P4,(1280-145),405);
        addObject(R10P5,(1280-050),405);
        //Set Row 5 + 11
        addObject(R5P1,150,315);
        addObject(R5P2,245,315);
        addObject(R5P3,340,315);
        addObject(R5P4,435,315);
        addObject(R5P5,530,315);
        addObject(R11P1,(1280-430),315);
        addObject(R11P2,(1280-335),315);
        addObject(R11P3,(1280-240),315);
        addObject(R11P4,(1280-145),315);
        addObject(R11P5,(1280-050),315);
        //Set Row 6 + 12
        addObject(R6P1,150,225);
        addObject(R6P2,245,225);
        addObject(R6P3,340,225);
        addObject(R6P4,435,225);
        addObject(R6P5,530,225);
        addObject(R12P1,(1280-430),225);
        addObject(R12P2,(1280-335),225);
        addObject(R12P3,(1280-240),225);
        addObject(R12P4,(1280-145),225);
        addObject(R12P5,(1280-050),225);
        //Set Hints Row 1 + 7
        addObject(H1R1,600,(675-(75/4)));
        addObject(H2R1,637,(675-(75/4)));
        addObject(H3R1,600,(675+(75/4)));
        addObject(H4R1,637,(675+(75/4)));
        addObject(H1R7,743,(675-(75/4)));
        addObject(H2R7,780,(675-(75/4)));
        addObject(H3R7,743,(675+(75/4)));
        addObject(H4R7,780,(675+(75/4)));
        //Set Hints Row 2 + 8
        addObject(H1R2,600,(585-(75/4)));
        addObject(H2R2,637,(585-(75/4)));
        addObject(H3R2,600,(585+(75/4)));
        addObject(H4R2,637,(585+(75/4)));
        addObject(H1R8,743,(585-(75/4)));
        addObject(H2R8,780,(585-(75/4)));
        addObject(H3R8,743,(585+(75/4)));
        addObject(H4R8,780,(585+(75/4)));
        //Set Hints Row 3 + 9
        addObject(H1R3,600,(495-(75/4)));
        addObject(H2R3,637,(495-(75/4)));
        addObject(H3R3,600,(495+(75/4)));
        addObject(H4R3,637,(495+(75/4)));
        addObject(H1R9,743,(495-(75/4)));
        addObject(H2R9,780,(495-(75/4)));
        addObject(H3R9,743,(495+(75/4)));
        addObject(H4R9,780,(495+(75/4)));
        //Set Hints Row 4 + 10
        addObject(H1R4,600,(405-(75/4)));
        addObject(H2R4,637,(405-(75/4)));
        addObject(H3R4,600,(405+(75/4)));
        addObject(H4R4,637,(405+(75/4)));
        addObject(H1R10,743,(405-(75/4)));
        addObject(H2R10,780,(405-(75/4)));
        addObject(H3R10,743,(405+(75/4)));
        addObject(H4R10,780,(405+(75/4)));
        //Set Hints Row 5 + 11
        addObject(H1R5,600,(315-(75/4)));
        addObject(H2R5,637,(315-(75/4)));
        addObject(H3R5,600,(315+(75/4)));
        addObject(H4R5,637,(315+(75/4)));
        addObject(H1R11,743,(315-(75/4)));
        addObject(H2R11,780,(315-(75/4)));
        addObject(H3R11,743,(315+(75/4)));
        addObject(H4R11,780,(315+(75/4)));
        //Set Hints Row 6 + 12
        addObject(H1R6,600,(225-(75/4)));
        addObject(H2R6,637,(225-(75/4)));
        addObject(H3R6,600,(225+(75/4)));
        addObject(H4R6,637,(225+(75/4)));
        addObject(H1R12,743,(225-(75/4)));
        addObject(H2R12,780,(225-(75/4)));
        addObject(H3R12,743,(225+(75/4)));
        addObject(H4R12,780,(225+(75/4)));
        //Set values
        setDefault();
        scaleAll();
    }
    private void setDefault()
    {
        black.setImage(PinBlack);
        blue.setImage(PinBlue);
        brown.setImage(PinBrown);
        green.setImage(PinGreen);
        grey.setImage(PinGrey);
        red.setImage(PinRed);
        white.setImage(PinWhite);
        yellow.setImage(PinYellow);
        line.setImage(Line);
        F1.setImage(FGrey);
        F2.setImage(FGrey);
        F3.setImage(FGrey);
        F4.setImage(FGrey);
        F5.setImage(FGrey);
        R1P1.setImage(PinNone);
        R1P2.setImage(PinNone);
        R1P3.setImage(PinNone);
        R1P4.setImage(PinNone);
        R1P5.setImage(PinNone);
        R2P1.setImage(PinNone);
        R2P2.setImage(PinNone);
        R2P3.setImage(PinNone);
        R2P4.setImage(PinNone);
        R2P5.setImage(PinNone);
        R3P1.setImage(PinNone);
        R3P2.setImage(PinNone);
        R3P3.setImage(PinNone);
        R3P4.setImage(PinNone);
        R3P5.setImage(PinNone);
        R4P1.setImage(PinNone);
        R4P2.setImage(PinNone);
        R4P3.setImage(PinNone);
        R4P4.setImage(PinNone);
        R4P5.setImage(PinNone);
        R5P1.setImage(PinNone);
        R5P2.setImage(PinNone);
        R5P3.setImage(PinNone);
        R5P4.setImage(PinNone);
        R5P5.setImage(PinNone);
        R6P1.setImage(PinNone);
        R6P2.setImage(PinNone);
        R6P3.setImage(PinNone);
        R6P4.setImage(PinNone);
        R6P5.setImage(PinNone);
        R7P1.setImage(PinNone);
        R7P2.setImage(PinNone);
        R7P3.setImage(PinNone);
        R7P4.setImage(PinNone);
        R7P5.setImage(PinNone);
        R8P1.setImage(PinNone);
        R8P2.setImage(PinNone);
        R8P3.setImage(PinNone);
        R8P4.setImage(PinNone);
        R8P5.setImage(PinNone);
        R9P1.setImage(PinNone);
        R9P2.setImage(PinNone);
        R9P3.setImage(PinNone);
        R9P4.setImage(PinNone);
        R9P5.setImage(PinNone);
        R10P1.setImage(PinNone);
        R10P2.setImage(PinNone);
        R10P3.setImage(PinNone);
        R10P4.setImage(PinNone);
        R10P5.setImage(PinNone);
        R11P1.setImage(PinNone);
        R11P2.setImage(PinNone);
        R11P3.setImage(PinNone);
        R11P4.setImage(PinNone);
        R11P5.setImage(PinNone);
        R12P1.setImage(PinNone);
        R12P2.setImage(PinNone);
        R12P3.setImage(PinNone);
        R12P4.setImage(PinNone);
        R12P5.setImage(PinNone);
        H1R1.setImage(HGrey);
        H2R1.setImage(HGrey);
        H3R1.setImage(HGrey);
        H4R1.setImage(HGrey);
        H1R2.setImage(HGrey);
        H2R2.setImage(HGrey);
        H3R2.setImage(HGrey);
        H4R2.setImage(HGrey);
        H1R3.setImage(HGrey);
        H2R3.setImage(HGrey);
        H3R3.setImage(HGrey);
        H4R3.setImage(HGrey);
        H1R4.setImage(HGrey);
        H2R4.setImage(HGrey);
        H3R4.setImage(HGrey);
        H4R4.setImage(HGrey);
        H1R5.setImage(HGrey);
        H2R5.setImage(HGrey);
        H3R5.setImage(HGrey);
        H4R5.setImage(HGrey);
        H1R6.setImage(HGrey);
        H2R6.setImage(HGrey);
        H3R6.setImage(HGrey);
        H4R6.setImage(HGrey);
        H1R7.setImage(HGrey);
        H2R7.setImage(HGrey);
        H3R7.setImage(HGrey);
        H4R7.setImage(HGrey);
        H1R8.setImage(HGrey);
        H2R8.setImage(HGrey);
        H3R8.setImage(HGrey);
        H4R8.setImage(HGrey);
        H1R9.setImage(HGrey);
        H2R9.setImage(HGrey);
        H3R9.setImage(HGrey);
        H4R9.setImage(HGrey);
        H1R10.setImage(HGrey);
        H2R10.setImage(HGrey);
        H3R10.setImage(HGrey);
        H4R10.setImage(HGrey);
        H1R11.setImage(HGrey);
        H2R11.setImage(HGrey);
        H3R11.setImage(HGrey);
        H4R11.setImage(HGrey);
        H1R12.setImage(HGrey);
        H2R12.setImage(HGrey);
        H3R12.setImage(HGrey);
        H4R12.setImage(HGrey);
    }
    private void scaleAll()
    {
        PinBlack.scale(75,75);
        PinBlue.scale(75,75);
        PinBrown.scale(75,75);
        PinGreen.scale(75,75);
        PinGrey.scale(75,75);
        PinRed.scale(75,75);
        PinWhite.scale(75,75);
        PinYellow.scale(75,75);
        PinNone.scale(75,75);
        Line.scale(10,720);
        FBlack.scale(150,150);
        FBlue.scale(150,150);
        FBrown.scale(150,150);
        FGreen.scale(150,150);
        FGrey.scale(150,150);
        FRed.scale(150,150);
        FWhite.scale(150,150);
        FYellow.scale(150,150);
        HBlack.scale((75/2),(75/2));
        HWhite.scale((75/2),(75/2));
        HGrey.scale((75/2),(75/2));
    }
    private void generateCode()
    {
        for(int i=0;i<5;i++)
        {
            rdm = Greenfoot.getRandomNumber(7);
            code.add(rdm);
        }
    }
    public void act()
    {
        clearAll();
        run = true;
        generateCode();
        while(run)
        {
            if(Greenfoot.mouseClicked(black)){tappedBlack++;addToList();}
            if(Greenfoot.mouseClicked(blue)){tappedBlue++;addToList();}
            if(Greenfoot.mouseClicked(brown)){tappedBrown++;addToList();}
            if(Greenfoot.mouseClicked(green)){tappedGreen++;addToList();}
            if(Greenfoot.mouseClicked(grey)){tappedGrey++;addToList();}
            if(Greenfoot.mouseClicked(red)){tappedRed++;addToList();}
            if(Greenfoot.mouseClicked(white)){tappedWhite++;addToList();}
            if(Greenfoot.mouseClicked(yellow)){tappedYellow++;addToList();}
        }
        //if(getCurrentRound() == 13){}else{}
    }
    private void clearAll()
    {
        run = false;
        code.clear();
        Row1.clear();
        Row2.clear();
        Row3.clear();
        Row4.clear();
        Row5.clear();
        Row6.clear();
        Row7.clear();
        Row8.clear();
        Row9.clear();
        Row10.clear();
        Row11.clear();
        Row12.clear();
        rdm = 0;
        Try = 1;
        tappedBlack = 0;
        tappedBlue = 0;
        tappedBrown = 0;
        tappedGreen = 0;
        tappedGrey = 0;
        tappedRed = 0;
        tappedWhite = 0;
        tappedYellow = 0;
        correctAnswer = 0;
        correctColor = 0;
        win = false;
    }
    private int getCurrentRound()
    {
        if(Row1.size()<4){return 1;}
        else if(Row2.size()<4){return 2;}
        else if(Row3.size()<4){return 3;}
        else if(Row4.size()<4){return 4;}
        else if(Row5.size()<4){return 5;}
        else if(Row6.size()<4){return 6;}
        else if(Row7.size()<4){return 7;}
        else if(Row8.size()<4){return 8;}
        else if(Row9.size()<4){return 9;}
        else if(Row10.size()<4){return 10;}
        else if(Row11.size()<4){return 11;}
        else if(Row12.size()<4){return 12;}
        else{return 13;}
    }
    private void addToList()
    {
        if(getCurrentRound() == 1){
            Row1.add(getCurrentTouch());
            if(Row1.size()==0){R1P1.setImage(paint());}
            else if(Row1.size()==1){R1P2.setImage(paint());}
            else if(Row1.size()==2){R1P3.setImage(paint());}
            else if(Row1.size()==3){R1P4.setImage(paint());}
            else if(Row1.size()==4){R1P5.setImage(paint());}
            clearTouch();
            if(Row1.size()==4){roundComplete(1);}
        }else if(getCurrentRound() == 2){
            Row2.add(getCurrentTouch());
            if(Row2.size()==0){R2P1.setImage(paint());}
            else if(Row2.size()==1){R2P2.setImage(paint());}
            else if(Row2.size()==2){R2P3.setImage(paint());}
            else if(Row2.size()==3){R2P4.setImage(paint());}
            else if(Row2.size()==4){R2P5.setImage(paint());}
            clearTouch();
            if(Row2.size()==4){roundComplete(2);}
        }else if(getCurrentRound() == 3){
            Row3.add(getCurrentTouch());
            if(Row3.size()==0){R1P1.setImage(paint());}
            else if(Row3.size()==1){R3P2.setImage(paint());}
            else if(Row3.size()==2){R3P3.setImage(paint());}
            else if(Row3.size()==3){R3P4.setImage(paint());}
            else if(Row3.size()==4){R3P5.setImage(paint());}
            clearTouch();
            if(Row3.size()==4){roundComplete(3);}
        }else if(getCurrentRound() == 4){
            Row4.add(getCurrentTouch());
            if(Row4.size()==0){R4P1.setImage(paint());}
            else if(Row4.size()==1){R4P2.setImage(paint());}
            else if(Row4.size()==2){R4P3.setImage(paint());}
            else if(Row4.size()==3){R4P4.setImage(paint());}
            else if(Row4.size()==4){R4P5.setImage(paint());}
            clearTouch();
            if(Row4.size()==4){roundComplete(4);}
        }else if(getCurrentRound() == 5){
            Row5.add(getCurrentTouch());
            if(Row5.size()==0){R5P1.setImage(paint());}
            else if(Row5.size()==1){R5P2.setImage(paint());}
            else if(Row5.size()==2){R5P3.setImage(paint());}
            else if(Row5.size()==3){R5P4.setImage(paint());}
            else if(Row5.size()==4){R5P5.setImage(paint());}
            clearTouch();
            if(Row5.size()==4){roundComplete(5);}
        }else if(getCurrentRound() == 6){
            Row6.add(getCurrentTouch());
            if(Row6.size()==0){R6P1.setImage(paint());}
            else if(Row6.size()==1){R6P2.setImage(paint());}
            else if(Row6.size()==2){R6P3.setImage(paint());}
            else if(Row6.size()==3){R6P4.setImage(paint());}
            else if(Row6.size()==4){R6P5.setImage(paint());}
            clearTouch();
            if(Row6.size()==4){roundComplete(6);}
        }else if(getCurrentRound() == 7){
            Row7.add(getCurrentTouch());
            if(Row7.size()==0){R7P1.setImage(paint());}
            else if(Row7.size()==1){R7P2.setImage(paint());}
            else if(Row7.size()==2){R7P3.setImage(paint());}
            else if(Row7.size()==3){R7P4.setImage(paint());}
            else if(Row7.size()==4){R7P5.setImage(paint());}
            clearTouch();
            if(Row7.size()==4){roundComplete(7);}
        }else if(getCurrentRound() == 8){
            Row8.add(getCurrentTouch());
            if(Row8.size()==0){R8P1.setImage(paint());}
            else if(Row8.size()==1){R8P2.setImage(paint());}
            else if(Row8.size()==2){R8P3.setImage(paint());}
            else if(Row8.size()==3){R8P4.setImage(paint());}
            else if(Row8.size()==4){R8P5.setImage(paint());}
            clearTouch();
            if(Row8.size()==4){roundComplete(8);}
        }else if(getCurrentRound() == 9){
            Row9.add(getCurrentTouch());
            if(Row9.size()==0){R9P1.setImage(paint());}
            else if(Row9.size()==1){R9P2.setImage(paint());}
            else if(Row9.size()==2){R9P3.setImage(paint());}
            else if(Row9.size()==3){R9P4.setImage(paint());}
            else if(Row9.size()==4){R9P5.setImage(paint());}
            clearTouch();
            if(Row9.size()==4){roundComplete(9);}
        }else if(getCurrentRound() == 10){
            Row10.add(getCurrentTouch());
            if(Row10.size()==0){R10P1.setImage(paint());}
            else if(Row10.size()==1){R10P2.setImage(paint());}
            else if(Row10.size()==2){R10P3.setImage(paint());}
            else if(Row10.size()==3){R10P4.setImage(paint());}
            else if(Row10.size()==4){R10P5.setImage(paint());}
            clearTouch();
            if(Row10.size()==4){roundComplete(10);}
        }else if(getCurrentRound() == 11){
            Row11.add(getCurrentTouch());
            if(Row11.size()==0){R11P1.setImage(paint());}
            else if(Row11.size()==1){R11P2.setImage(paint());}
            else if(Row11.size()==2){R11P3.setImage(paint());}
            else if(Row11.size()==3){R11P4.setImage(paint());}
            else if(Row11.size()==4){R11P5.setImage(paint());}
            clearTouch();
            if(Row11.size()==4){roundComplete(11);}
        }else if(getCurrentRound() == 12){
            Row12.add(getCurrentTouch());
            if(Row12.size()==0){R12P1.setImage(paint());}
            else if(Row12.size()==1){R12P2.setImage(paint());}
            else if(Row12.size()==2){R12P3.setImage(paint());}
            else if(Row12.size()==3){R12P4.setImage(paint());}
            else if(Row12.size()==4){R12P5.setImage(paint());}
            clearTouch();
            if(Row12.size()==4){roundComplete(12);}
        }
    }
    private int getCurrentTouch()
    {
        if(tappedBlack == 1){return 0;}
        else if(tappedBlue == 1){return 1;}
        else if(tappedBrown == 1){return 2;}
        else if(tappedGreen == 1){return 3;}
        else if(tappedGrey == 1){return 4;}
        else if(tappedRed == 1){return 5;}
        else if(tappedWhite == 1){return 6;}
        else if(tappedYellow == 1){return 7;}
        else{return -1;}
    }
    private void clearTouch()
    {
        tappedBlack = 0;
        tappedBlue = 0;
        tappedBrown = 0;
        tappedGreen = 0;
        tappedGrey = 0;
        tappedRed = 0;
        tappedWhite = 0;
        tappedYellow = 0;
    }
    private void roundComplete(int Row)
    {
        statFinal1 = code.get(0);
        statFinal2 = code.get(1);
        statFinal3 = code.get(2);
        statFinal4 = code.get(3);
        statFinal5 = code.get(4);
        if(Row==1){
            if(Row1.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row1.get(0);
            statRow2 = Row1.get(1);
            statRow3 = Row1.get(2);
            statRow4 = Row1.get(3);
            statRow5 = Row1.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R1.setImage(HBlack);}
            if(correctAnswer>=2){H2R1.setImage(HBlack);}
            if(correctAnswer>=3){H3R1.setImage(HBlack);}
            if(correctAnswer>=4){H4R1.setImage(HBlack);}
            if(correctColor>=1){if(H1R1.getImage()==HGrey){H1R1.setImage(HWhite);}else if(H2R1.getImage()==HGrey){H2R1.setImage(HWhite);}else if(H3R1.getImage()==HGrey){H3R1.setImage(HWhite);}else if(H4R1.getImage()==HGrey){H4R1.setImage(HWhite);}}
            if(correctColor>=2){if(H1R1.getImage()==HGrey){H1R1.setImage(HWhite);}else if(H2R1.getImage()==HGrey){H2R1.setImage(HWhite);}else if(H3R1.getImage()==HGrey){H3R1.setImage(HWhite);}else if(H4R1.getImage()==HGrey){H4R1.setImage(HWhite);}}
            if(correctColor>=3){if(H1R1.getImage()==HGrey){H1R1.setImage(HWhite);}else if(H2R1.getImage()==HGrey){H2R1.setImage(HWhite);}else if(H3R1.getImage()==HGrey){H3R1.setImage(HWhite);}else if(H4R1.getImage()==HGrey){H4R1.setImage(HWhite);}}
            if(correctColor>=4){if(H1R1.getImage()==HGrey){H1R1.setImage(HWhite);}else if(H2R1.getImage()==HGrey){H2R1.setImage(HWhite);}else if(H3R1.getImage()==HGrey){H3R1.setImage(HWhite);}else if(H4R1.getImage()==HGrey){H4R1.setImage(HWhite);}}
            }
        }else if(Row==2){
            if(Row2.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row2.get(0);
            statRow2 = Row2.get(1);
            statRow3 = Row2.get(2);
            statRow4 = Row2.get(3);
            statRow5 = Row2.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R2.setImage(HBlack);}
            if(correctAnswer>=2){H2R2.setImage(HBlack);}
            if(correctAnswer>=3){H3R2.setImage(HBlack);}
            if(correctAnswer>=4){H4R2.setImage(HBlack);}
            if(correctColor>=1){if(H1R2.getImage()==HGrey){H1R2.setImage(HWhite);}else if(H2R2.getImage()==HGrey){H2R2.setImage(HWhite);}else if(H3R2.getImage()==HGrey){H3R2.setImage(HWhite);}else if(H4R2.getImage()==HGrey){H4R2.setImage(HWhite);}}
            if(correctColor>=2){if(H1R2.getImage()==HGrey){H1R2.setImage(HWhite);}else if(H2R2.getImage()==HGrey){H2R2.setImage(HWhite);}else if(H3R2.getImage()==HGrey){H3R2.setImage(HWhite);}else if(H4R2.getImage()==HGrey){H4R2.setImage(HWhite);}}
            if(correctColor>=3){if(H1R2.getImage()==HGrey){H1R2.setImage(HWhite);}else if(H2R2.getImage()==HGrey){H2R2.setImage(HWhite);}else if(H3R2.getImage()==HGrey){H3R2.setImage(HWhite);}else if(H4R2.getImage()==HGrey){H4R2.setImage(HWhite);}}
            if(correctColor>=4){if(H1R2.getImage()==HGrey){H1R2.setImage(HWhite);}else if(H2R2.getImage()==HGrey){H2R2.setImage(HWhite);}else if(H3R2.getImage()==HGrey){H3R2.setImage(HWhite);}else if(H4R2.getImage()==HGrey){H4R2.setImage(HWhite);}}
            }
        }else if(Row==3){
            if(Row3.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row3.get(0);
            statRow2 = Row3.get(1);
            statRow3 = Row3.get(2);
            statRow4 = Row3.get(3);
            statRow5 = Row3.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R3.setImage(HBlack);}
            if(correctAnswer>=2){H2R3.setImage(HBlack);}
            if(correctAnswer>=3){H3R3.setImage(HBlack);}
            if(correctAnswer>=4){H4R3.setImage(HBlack);}
            if(correctColor>=1){if(H1R3.getImage()==HGrey){H1R3.setImage(HWhite);}else if(H2R3.getImage()==HGrey){H2R3.setImage(HWhite);}else if(H3R3.getImage()==HGrey){H3R3.setImage(HWhite);}else if(H4R3.getImage()==HGrey){H4R3.setImage(HWhite);}}
            if(correctColor>=2){if(H1R3.getImage()==HGrey){H1R3.setImage(HWhite);}else if(H2R3.getImage()==HGrey){H2R3.setImage(HWhite);}else if(H3R3.getImage()==HGrey){H3R3.setImage(HWhite);}else if(H4R3.getImage()==HGrey){H4R3.setImage(HWhite);}}
            if(correctColor>=3){if(H1R3.getImage()==HGrey){H1R3.setImage(HWhite);}else if(H2R3.getImage()==HGrey){H2R3.setImage(HWhite);}else if(H3R3.getImage()==HGrey){H3R3.setImage(HWhite);}else if(H4R3.getImage()==HGrey){H4R3.setImage(HWhite);}}
            if(correctColor>=4){if(H1R3.getImage()==HGrey){H1R3.setImage(HWhite);}else if(H2R3.getImage()==HGrey){H2R3.setImage(HWhite);}else if(H3R3.getImage()==HGrey){H3R3.setImage(HWhite);}else if(H4R3.getImage()==HGrey){H4R3.setImage(HWhite);}}
            }
        }else if(Row==4){
            if(Row4.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row4.get(0);
            statRow2 = Row4.get(1);
            statRow3 = Row4.get(2);
            statRow4 = Row4.get(3);
            statRow5 = Row4.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R4.setImage(HBlack);}
            if(correctAnswer>=2){H2R4.setImage(HBlack);}
            if(correctAnswer>=3){H3R4.setImage(HBlack);}
            if(correctAnswer>=4){H4R4.setImage(HBlack);}
            if(correctColor>=1){if(H1R4.getImage()==HGrey){H1R4.setImage(HWhite);}else if(H2R4.getImage()==HGrey){H2R4.setImage(HWhite);}else if(H3R4.getImage()==HGrey){H3R4.setImage(HWhite);}else if(H4R4.getImage()==HGrey){H4R4.setImage(HWhite);}}
            if(correctColor>=2){if(H1R4.getImage()==HGrey){H1R4.setImage(HWhite);}else if(H2R4.getImage()==HGrey){H2R4.setImage(HWhite);}else if(H3R4.getImage()==HGrey){H3R4.setImage(HWhite);}else if(H4R4.getImage()==HGrey){H4R4.setImage(HWhite);}}
            if(correctColor>=3){if(H1R4.getImage()==HGrey){H1R4.setImage(HWhite);}else if(H2R4.getImage()==HGrey){H2R4.setImage(HWhite);}else if(H3R4.getImage()==HGrey){H3R4.setImage(HWhite);}else if(H4R4.getImage()==HGrey){H4R4.setImage(HWhite);}}
            if(correctColor>=4){if(H1R4.getImage()==HGrey){H1R4.setImage(HWhite);}else if(H2R4.getImage()==HGrey){H2R4.setImage(HWhite);}else if(H3R4.getImage()==HGrey){H3R4.setImage(HWhite);}else if(H4R4.getImage()==HGrey){H4R4.setImage(HWhite);}}
            }
        }else if(Row==5){
            if(Row5.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row5.get(0);
            statRow2 = Row5.get(1);
            statRow3 = Row5.get(2);
            statRow4 = Row5.get(3);
            statRow5 = Row5.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R5.setImage(HBlack);}
            if(correctAnswer>=2){H2R5.setImage(HBlack);}
            if(correctAnswer>=3){H3R5.setImage(HBlack);}
            if(correctAnswer>=4){H4R5.setImage(HBlack);}
            if(correctColor>=1){if(H1R5.getImage()==HGrey){H1R5.setImage(HWhite);}else if(H2R5.getImage()==HGrey){H2R5.setImage(HWhite);}else if(H3R5.getImage()==HGrey){H3R5.setImage(HWhite);}else if(H4R5.getImage()==HGrey){H4R5.setImage(HWhite);}}
            if(correctColor>=2){if(H1R5.getImage()==HGrey){H1R5.setImage(HWhite);}else if(H2R5.getImage()==HGrey){H2R5.setImage(HWhite);}else if(H3R5.getImage()==HGrey){H3R5.setImage(HWhite);}else if(H4R5.getImage()==HGrey){H4R5.setImage(HWhite);}}
            if(correctColor>=3){if(H1R5.getImage()==HGrey){H1R5.setImage(HWhite);}else if(H2R5.getImage()==HGrey){H2R5.setImage(HWhite);}else if(H3R5.getImage()==HGrey){H3R5.setImage(HWhite);}else if(H4R5.getImage()==HGrey){H4R5.setImage(HWhite);}}
            if(correctColor>=4){if(H1R5.getImage()==HGrey){H1R5.setImage(HWhite);}else if(H2R5.getImage()==HGrey){H2R5.setImage(HWhite);}else if(H3R5.getImage()==HGrey){H3R5.setImage(HWhite);}else if(H4R5.getImage()==HGrey){H4R5.setImage(HWhite);}}
            }
        }else if(Row==6){
            if(Row6.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row6.get(0);
            statRow2 = Row6.get(1);
            statRow3 = Row6.get(2);
            statRow4 = Row6.get(3);
            statRow5 = Row6.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R6.setImage(HBlack);}
            if(correctAnswer>=2){H2R6.setImage(HBlack);}
            if(correctAnswer>=3){H3R6.setImage(HBlack);}
            if(correctAnswer>=4){H4R6.setImage(HBlack);}
            if(correctColor>=1){if(H1R6.getImage()==HGrey){H1R6.setImage(HWhite);}else if(H2R6.getImage()==HGrey){H2R6.setImage(HWhite);}else if(H3R6.getImage()==HGrey){H3R6.setImage(HWhite);}else if(H4R6.getImage()==HGrey){H4R6.setImage(HWhite);}}
            if(correctColor>=2){if(H1R6.getImage()==HGrey){H1R6.setImage(HWhite);}else if(H2R6.getImage()==HGrey){H2R6.setImage(HWhite);}else if(H3R6.getImage()==HGrey){H3R6.setImage(HWhite);}else if(H4R6.getImage()==HGrey){H4R6.setImage(HWhite);}}
            if(correctColor>=3){if(H1R6.getImage()==HGrey){H1R6.setImage(HWhite);}else if(H2R6.getImage()==HGrey){H2R6.setImage(HWhite);}else if(H3R6.getImage()==HGrey){H3R6.setImage(HWhite);}else if(H4R6.getImage()==HGrey){H4R6.setImage(HWhite);}}
            if(correctColor>=4){if(H1R6.getImage()==HGrey){H1R6.setImage(HWhite);}else if(H2R6.getImage()==HGrey){H2R6.setImage(HWhite);}else if(H3R6.getImage()==HGrey){H3R6.setImage(HWhite);}else if(H4R6.getImage()==HGrey){H4R6.setImage(HWhite);}}
            }
        }else if(Row==7){
            if(Row7.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row7.get(0);
            statRow2 = Row7.get(1);
            statRow3 = Row7.get(2);
            statRow4 = Row7.get(3);
            statRow5 = Row7.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R7.setImage(HBlack);}
            if(correctAnswer>=2){H2R7.setImage(HBlack);}
            if(correctAnswer>=3){H3R7.setImage(HBlack);}
            if(correctAnswer>=4){H4R7.setImage(HBlack);}
            if(correctColor>=1){if(H1R7.getImage()==HGrey){H1R7.setImage(HWhite);}else if(H2R7.getImage()==HGrey){H2R7.setImage(HWhite);}else if(H3R7.getImage()==HGrey){H3R7.setImage(HWhite);}else if(H4R7.getImage()==HGrey){H4R7.setImage(HWhite);}}
            if(correctColor>=2){if(H1R7.getImage()==HGrey){H1R7.setImage(HWhite);}else if(H2R7.getImage()==HGrey){H2R7.setImage(HWhite);}else if(H3R7.getImage()==HGrey){H3R7.setImage(HWhite);}else if(H4R7.getImage()==HGrey){H4R7.setImage(HWhite);}}
            if(correctColor>=3){if(H1R7.getImage()==HGrey){H1R7.setImage(HWhite);}else if(H2R7.getImage()==HGrey){H2R7.setImage(HWhite);}else if(H3R7.getImage()==HGrey){H3R7.setImage(HWhite);}else if(H4R7.getImage()==HGrey){H4R7.setImage(HWhite);}}
            if(correctColor>=4){if(H1R7.getImage()==HGrey){H1R7.setImage(HWhite);}else if(H2R7.getImage()==HGrey){H2R7.setImage(HWhite);}else if(H3R7.getImage()==HGrey){H3R7.setImage(HWhite);}else if(H4R7.getImage()==HGrey){H4R7.setImage(HWhite);}}
            }
        }else if(Row==8){
            if(Row8.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row8.get(0);
            statRow2 = Row8.get(1);
            statRow3 = Row8.get(2);
            statRow4 = Row8.get(3);
            statRow5 = Row8.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R8.setImage(HBlack);}
            if(correctAnswer>=2){H2R8.setImage(HBlack);}
            if(correctAnswer>=3){H3R8.setImage(HBlack);}
            if(correctAnswer>=4){H4R8.setImage(HBlack);}
            if(correctColor>=1){if(H1R8.getImage()==HGrey){H1R8.setImage(HWhite);}else if(H2R8.getImage()==HGrey){H2R8.setImage(HWhite);}else if(H3R8.getImage()==HGrey){H3R8.setImage(HWhite);}else if(H4R8.getImage()==HGrey){H4R8.setImage(HWhite);}}
            if(correctColor>=2){if(H1R8.getImage()==HGrey){H1R8.setImage(HWhite);}else if(H2R8.getImage()==HGrey){H2R8.setImage(HWhite);}else if(H3R8.getImage()==HGrey){H3R8.setImage(HWhite);}else if(H4R8.getImage()==HGrey){H4R8.setImage(HWhite);}}
            if(correctColor>=3){if(H1R8.getImage()==HGrey){H1R8.setImage(HWhite);}else if(H2R8.getImage()==HGrey){H2R8.setImage(HWhite);}else if(H3R8.getImage()==HGrey){H3R8.setImage(HWhite);}else if(H4R8.getImage()==HGrey){H4R8.setImage(HWhite);}}
            if(correctColor>=4){if(H1R8.getImage()==HGrey){H1R8.setImage(HWhite);}else if(H2R8.getImage()==HGrey){H2R8.setImage(HWhite);}else if(H3R8.getImage()==HGrey){H3R8.setImage(HWhite);}else if(H4R8.getImage()==HGrey){H4R8.setImage(HWhite);}}
            }
        }else if(Row==9){
            if(Row9.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row9.get(0);
            statRow2 = Row9.get(1);
            statRow3 = Row9.get(2);
            statRow4 = Row9.get(3);
            statRow5 = Row9.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R9.setImage(HBlack);}
            if(correctAnswer>=2){H2R9.setImage(HBlack);}
            if(correctAnswer>=3){H3R9.setImage(HBlack);}
            if(correctAnswer>=4){H4R9.setImage(HBlack);}
            if(correctColor>=1){if(H1R9.getImage()==HGrey){H1R9.setImage(HWhite);}else if(H2R9.getImage()==HGrey){H2R9.setImage(HWhite);}else if(H3R9.getImage()==HGrey){H3R9.setImage(HWhite);}else if(H4R9.getImage()==HGrey){H4R9.setImage(HWhite);}}
            if(correctColor>=2){if(H1R9.getImage()==HGrey){H1R9.setImage(HWhite);}else if(H2R9.getImage()==HGrey){H2R9.setImage(HWhite);}else if(H3R9.getImage()==HGrey){H3R9.setImage(HWhite);}else if(H4R9.getImage()==HGrey){H4R9.setImage(HWhite);}}
            if(correctColor>=3){if(H1R9.getImage()==HGrey){H1R9.setImage(HWhite);}else if(H2R9.getImage()==HGrey){H2R9.setImage(HWhite);}else if(H3R9.getImage()==HGrey){H3R9.setImage(HWhite);}else if(H4R9.getImage()==HGrey){H4R9.setImage(HWhite);}}
            if(correctColor>=4){if(H1R9.getImage()==HGrey){H1R9.setImage(HWhite);}else if(H2R9.getImage()==HGrey){H2R9.setImage(HWhite);}else if(H3R9.getImage()==HGrey){H3R9.setImage(HWhite);}else if(H4R9.getImage()==HGrey){H4R9.setImage(HWhite);}}
            }
        }else if(Row==10){
            if(Row10.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row10.get(0);
            statRow2 = Row10.get(1);
            statRow3 = Row10.get(2);
            statRow4 = Row10.get(3);
            statRow5 = Row10.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R10.setImage(HBlack);}
            if(correctAnswer>=2){H2R10.setImage(HBlack);}
            if(correctAnswer>=3){H3R10.setImage(HBlack);}
            if(correctAnswer>=4){H4R10.setImage(HBlack);}
            if(correctColor>=1){if(H1R10.getImage()==HGrey){H1R10.setImage(HWhite);}else if(H2R10.getImage()==HGrey){H2R10.setImage(HWhite);}else if(H3R10.getImage()==HGrey){H3R10.setImage(HWhite);}else if(H4R10.getImage()==HGrey){H4R10.setImage(HWhite);}}
            if(correctColor>=2){if(H1R10.getImage()==HGrey){H1R10.setImage(HWhite);}else if(H2R10.getImage()==HGrey){H2R10.setImage(HWhite);}else if(H3R10.getImage()==HGrey){H3R10.setImage(HWhite);}else if(H4R10.getImage()==HGrey){H4R10.setImage(HWhite);}}
            if(correctColor>=3){if(H1R10.getImage()==HGrey){H1R10.setImage(HWhite);}else if(H2R10.getImage()==HGrey){H2R10.setImage(HWhite);}else if(H3R10.getImage()==HGrey){H3R10.setImage(HWhite);}else if(H4R10.getImage()==HGrey){H4R10.setImage(HWhite);}}
            if(correctColor>=4){if(H1R10.getImage()==HGrey){H1R10.setImage(HWhite);}else if(H2R10.getImage()==HGrey){H2R10.setImage(HWhite);}else if(H3R10.getImage()==HGrey){H3R10.setImage(HWhite);}else if(H4R10.getImage()==HGrey){H4R10.setImage(HWhite);}}
            }
        }else if(Row==11){
            if(Row11.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row11.get(0);
            statRow2 = Row11.get(1);
            statRow3 = Row11.get(2);
            statRow4 = Row11.get(3);
            statRow5 = Row11.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R11.setImage(HBlack);}
            if(correctAnswer>=2){H2R11.setImage(HBlack);}
            if(correctAnswer>=3){H3R11.setImage(HBlack);}
            if(correctAnswer>=4){H4R11.setImage(HBlack);}
            if(correctColor>=1){if(H1R11.getImage()==HGrey){H1R11.setImage(HWhite);}else if(H2R11.getImage()==HGrey){H2R11.setImage(HWhite);}else if(H3R11.getImage()==HGrey){H3R11.setImage(HWhite);}else if(H4R11.getImage()==HGrey){H4R11.setImage(HWhite);}}
            if(correctColor>=2){if(H1R11.getImage()==HGrey){H1R11.setImage(HWhite);}else if(H2R11.getImage()==HGrey){H2R11.setImage(HWhite);}else if(H3R11.getImage()==HGrey){H3R11.setImage(HWhite);}else if(H4R11.getImage()==HGrey){H4R11.setImage(HWhite);}}
            if(correctColor>=3){if(H1R11.getImage()==HGrey){H1R11.setImage(HWhite);}else if(H2R11.getImage()==HGrey){H2R11.setImage(HWhite);}else if(H3R11.getImage()==HGrey){H3R11.setImage(HWhite);}else if(H4R11.getImage()==HGrey){H4R11.setImage(HWhite);}}
            if(correctColor>=4){if(H1R11.getImage()==HGrey){H1R11.setImage(HWhite);}else if(H2R11.getImage()==HGrey){H2R11.setImage(HWhite);}else if(H3R11.getImage()==HGrey){H3R11.setImage(HWhite);}else if(H4R11.getImage()==HGrey){H4R11.setImage(HWhite);}}
            }
        }else if(Row==12){
            if(Row12.equals(code)){run = false; win = true;}
            else{
            statRow1 = Row12.get(0);
            statRow2 = Row12.get(1);
            statRow3 = Row12.get(2);
            statRow4 = Row12.get(3);
            statRow5 = Row12.get(4);
            crosscheck();
            if(correctAnswer>=1){H1R12.setImage(HBlack);}
            if(correctAnswer>=2){H2R12.setImage(HBlack);}
            if(correctAnswer>=3){H3R12.setImage(HBlack);}
            if(correctAnswer>=4){H4R12.setImage(HBlack);}
            if(correctColor>=1){if(H1R12.getImage()==HGrey){H1R12.setImage(HWhite);}else if(H2R12.getImage()==HGrey){H2R12.setImage(HWhite);}else if(H3R12.getImage()==HGrey){H3R12.setImage(HWhite);}else if(H4R12.getImage()==HGrey){H4R12.setImage(HWhite);}}
            if(correctColor>=2){if(H1R12.getImage()==HGrey){H1R12.setImage(HWhite);}else if(H2R12.getImage()==HGrey){H2R12.setImage(HWhite);}else if(H3R12.getImage()==HGrey){H3R12.setImage(HWhite);}else if(H4R12.getImage()==HGrey){H4R12.setImage(HWhite);}}
            if(correctColor>=3){if(H1R12.getImage()==HGrey){H1R12.setImage(HWhite);}else if(H2R12.getImage()==HGrey){H2R12.setImage(HWhite);}else if(H3R12.getImage()==HGrey){H3R12.setImage(HWhite);}else if(H4R12.getImage()==HGrey){H4R12.setImage(HWhite);}}
            if(correctColor>=4){if(H1R12.getImage()==HGrey){H1R12.setImage(HWhite);}else if(H2R12.getImage()==HGrey){H2R12.setImage(HWhite);}else if(H3R12.getImage()==HGrey){H3R12.setImage(HWhite);}else if(H4R12.getImage()==HGrey){H4R12.setImage(HWhite);}}
            }
        }
    }
    private GreenfootImage paint()
    {
        if(getCurrentTouch()==0){return PinBlack;}
        else if(getCurrentTouch()==1){return PinBlue;}
        else if(getCurrentTouch()==2){return PinBrown;}
        else if(getCurrentTouch()==3){return PinGreen;}
        else if(getCurrentTouch()==4){return PinGrey;}
        else if(getCurrentTouch()==5){return PinRed;}
        else if(getCurrentTouch()==6){return PinWhite;}
        else if(getCurrentTouch()==7){return PinYellow;}
        else{return PinNone;}
    }
    private void crosscheck()
    {
        correctAnswer = 0;
        correctColor = 0;
        if(statRow1 == statFinal1){correctAnswer++;}
        if(statRow2 == statFinal2){correctAnswer++;}
        if(statRow3 == statFinal3){correctAnswer++;}
        if(statRow4 == statFinal4){correctAnswer++;}
        if(statRow5 == statFinal5){correctAnswer++;}
        if(statRow1 == statFinal2){correctColor++;}
        if(statRow1 == statFinal3){correctColor++;}
        if(statRow1 == statFinal4){correctColor++;}
        if(statRow1 == statFinal5){correctColor++;}
        if(statRow2 == statFinal1){correctColor++;}
        if(statRow2 == statFinal3){correctColor++;}
        if(statRow2 == statFinal4){correctColor++;}
        if(statRow2 == statFinal5){correctColor++;}
        if(statRow3 == statFinal1){correctColor++;}
        if(statRow3 == statFinal2){correctColor++;}
        if(statRow3 == statFinal4){correctColor++;}
        if(statRow3 == statFinal5){correctColor++;}
        if(statRow4 == statFinal1){correctColor++;}
        if(statRow4 == statFinal2){correctColor++;}
        if(statRow4 == statFinal3){correctColor++;}
        if(statRow4 == statFinal5){correctColor++;}
        if(statRow5 == statFinal1){correctColor++;}
        if(statRow5 == statFinal2){correctColor++;}
        if(statRow5 == statFinal3){correctColor++;}
        if(statRow5 == statFinal4){correctColor++;}
    }
}
Spock47 Spock47

2022/1/28

#
stefco05 wrote...
...
public void act()
    {
        clearAll();
        run = true;
        generateCode();
        while(run)
        {
            if(Greenfoot.mouseClicked(black)){tappedBlack++;addToList();}
            else if(Greenfoot.mouseClicked(blue)){tappedBlue++;addToList();}
            else if(Greenfoot.mouseClicked(brown)){tappedBrown++;addToList();}
            else if(Greenfoot.mouseClicked(green)){tappedGreen++;addToList();}
            else if(Greenfoot.mouseClicked(grey)){tappedGrey++;addToList();}
            else if(Greenfoot.mouseClicked(red)){tappedRed++;addToList();}
            else if(Greenfoot.mouseClicked(white)){tappedWhite++;addToList();}
            else if(Greenfoot.mouseClicked(yellow)){tappedYellow++;addToList();}
        }
        //if(getCurrentRound() == 13){}else{}
    }
Actually, I am pretty sure that the method reacts in your scenario. You just will not see the result. The UI will only update after the act-method call is finished. You added a while-loop to the act method and that blocks the program execution (especially the update of the UI). The idea of the act method is that it is for only one state-transition, i.e. the game is in some state, something happens -> act reacts to this one thing and must return immediately after that. With your while loop in the act method, you designed it so that the act method would react to a sequence of actions (user clicks at one thing, then another, then again another) and so on... But since the UI will only update after the act method call is finished, the act method cannot be used in that way in Greenfoot. Luckily, you don't have to use the act method this way. Instead of thinking about the whole program flow (basically infinite loop), you only have to think about ONE step at a time and Greenfoot will handle the "infinite loop" for you. For your source code, this means: change the line "while(run)" to "if (run)" and move the statements before that line from the act method to the constructor. Live long and prosper, Spock47
stefco05 wrote...
Please just don't say anything about what a mess that is... I already know it by myself...
I won't say anything about it, but here is a version where I added some blank lines, but is still nearly 650 lines shorter - for you to use however you wish. (Since the source code for the Actor types and images weren't attached, this version is not tested (except for compiling), so it could contain small mistakes.
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) java.util.ArrayList;
import java.util.*;
import java.util.stream.*;

/**
 * Write a description of class Game here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Game extends World
{
    
    //Color codes: 0=Black;1=Blue;2=Brown;3=Green;4=Grey;5=Red;6=White;7=Yellow
    enum MyColor {
        BLACK("PinBlack.png"),
        BLUE("PinBlue.png"),
        BROWN("PinBrown.png"),
        GREEN("PinGreen.png"),
        GREY("PinGrey.png"),
        RED("PinRed.png"),
        WHITE("PinWhite.png"),
        YELLOW("PinYellow.png");
        
        private final GreenfootImage pinImage;
        
        private MyColor(final String pinImageFile) {
            pinImage = new GreenfootImage(pinImageFile);
            pinImage.scale(75, 75);
        }
        
        public GreenfootImage pinImage() {
            return pinImage;
        }
    }
    
    private Stream<MyColor> colors() {
        return Arrays.stream(MyColor.values());
    }
    
    private final int rowCount = 12;
    
    //Declaring Variables
    private List code = new ArrayList();
    
    private List<ArrayList> rows = initRows();
    private List<ArrayList> initRows() {
        final List<ArrayList> result = new ArrayList();
        for (int row = 0; row < rowCount; ++row) {
            result.add(new ArrayList());
        }
        return result;
    }
    
    private boolean win;
    private int rdm;
    private boolean run;
    private int Try;
    
    private final Map<MyColor, Integer> tapped = colors().collect(Collectors.toMap(color -> color, color -> 0));
    private int correctAnswer;
    private int correctColor;
    //Declaring GreenfootImages
    GreenfootImage pinNone = MyColor.GREY.pinImage();
    GreenfootImage Line = new GreenfootImage("Line.png");
    GreenfootImage FBlack = new GreenfootImage("PinBlack.png");
    GreenfootImage FBlue = new GreenfootImage("PinBlue.png");
    GreenfootImage FBrown = new GreenfootImage("PinBrown.png");
    GreenfootImage FGreen = new GreenfootImage("PinGreen.png");
    GreenfootImage FGrey = new GreenfootImage("PinGrey.png");
    GreenfootImage FRed = new GreenfootImage("PinRed.png");
    GreenfootImage FWhite = new GreenfootImage("PinWhite.png");
    GreenfootImage FYellow = new GreenfootImage("PinYellow.png");
    GreenfootImage HBlack = new GreenfootImage("PinBlack.png");
    GreenfootImage HWhite = new GreenfootImage("PinWhite.png");
    GreenfootImage HGrey = new GreenfootImage("PinGrey.png");
    //Declaring Actors
    private final List<List<PinShow>> pins = initPins();
    private List<List<PinShow>> initPins() {
        final List<List<PinShow>> result = new ArrayList();
        for (int row = 0; row < rowCount; ++row) {
            final List<PinShow> entry = new ArrayList();
            for (int pin = 0; pin < 5; ++pin) {
                entry.add(new PinShow());
            }
            result.add(entry);
        }
        return result;
    }
    //Final
    PinShow F1 = new PinShow();
    PinShow F2 = new PinShow();
    PinShow F3 = new PinShow();
    PinShow F4 = new PinShow();
    PinShow F5 = new PinShow();
    //Buttons
    private final Map<MyColor, PinTap> buttons = colors().collect(Collectors.toMap(color -> color, color -> new PinTap()));
    
    //Line
    Line line = new Line();
    //Hints Row 1
    private final List<List<PinShow>> hints = Collections.nCopies(12, Collections.nCopies(4, new PinShow())); // TODO: check whether set by reference is used correctly.
    
    private List statRows = new ArrayList<>();
    private Object statFinal1;
    private Object statFinal2;
    private Object statFinal3;
    private Object statFinal4;
    private Object statFinal5;
    
    /**
     * Constructor for objects of class Game.
     * 
     */
    public Game()
    {    
        super(1280, 720, 1);
        //Buttons
        final MyColor[] colors = MyColor.values();
        for (int i = 0; i < colors.length; ++i) {
            addObject(buttons.get(colors[i]), 50, (90 * (i + 1) - 45));
        }
        addObject(line,100,360);
        //Finals
        addObject(F1,196, 90);
        addObject(F2,(236*2),90);
        addObject(F3,(236*3),90);
        addObject(F4,(236*4),90);
        addObject(F5,(236*5),90);
        //Set Row 1 + 7
        for (int row = 0; row < 6; ++row) {
            final List<PinShow> pinsInRow = pins.get(row);
            final List<PinShow> pinsInRowPlus6 = pins.get(row + 6);
            for (int pin = 0; pin < pinsInRow.size(); ++pin) {
                final int y = 675 - 90 * row;
                addObject(pinsInRow.get(pin),150 + 95 * pin, y);
                addObject(pinsInRowPlus6.get(pin), 850 + 95 * pin, y);
            }
        }
        for (int row = 0; row < 6; ++row) {
            final List<PinShow> hintsInRow = hints.get(row);
            final List<PinShow> hintsInRowPlus6 = hints.get(row + 6);
            final int hintY1 = 675 - 90 * row - 75 / 4;
            final int hintY2 = 675 - 90 * row + 75 / 4;
            addObject(hintsInRow.get(0), 600, hintY1);
            addObject(hintsInRow.get(1), 637, hintY1);
            addObject(hintsInRow.get(2), 600, hintY2);
            addObject(hintsInRow.get(3), 637, hintY2);
            addObject(hintsInRowPlus6.get(0), 743, hintY1);
            addObject(hintsInRowPlus6.get(1), 780, hintY1);
            addObject(hintsInRowPlus6.get(2), 743, hintY2);
            addObject(hintsInRowPlus6.get(3), 780, hintY2);
        }
        //Set values
        setDefault();
        scaleAll();
        clearAll();
        run = true;
        generateCode();
    }
    
    private void setDefault()
    {
        colors().forEach(color -> buttons.get(color).setImage(color.pinImage()));
        line.setImage(Line);
        F1.setImage(FGrey);
        F2.setImage(FGrey);
        F3.setImage(FGrey);
        F4.setImage(FGrey);
        F5.setImage(FGrey);
        pins.stream().forEach(pinsInRow -> pinsInRow.stream().forEach(pin -> pin.setImage(pinNone)));
        hints.stream().forEach(hintsInRow -> hintsInRow.stream().forEach(hint -> hint.setImage(HGrey)));
    }
    
    private void scaleAll()
    {
        // pinImages are scaled at creation
        //PinNone.scale(75,75);
        Line.scale(10,720);
        FBlack.scale(150,150);
        FBlue.scale(150,150);
        FBrown.scale(150,150);
        FGreen.scale(150,150);
        FGrey.scale(150,150);
        FRed.scale(150,150);
        FWhite.scale(150,150);
        FYellow.scale(150,150);
        HBlack.scale((75/2),(75/2));
        HWhite.scale((75/2),(75/2));
        HGrey.scale((75/2),(75/2));
    }
    
    private void generateCode()
    {
        for(int i=0;i<5;i++)
        {
            rdm = Greenfoot.getRandomNumber(7);
            code.add(rdm);
        }
    }
    
    public void act()
    {
        if (run)
        {
            for (final MyColor color : MyColor.values()) {
                if (Greenfoot.mouseClicked(color)){
                    tapped.put(color, tapped.get(color) + 1);
                    addToList();
                }
            }
        }
        //if(getCurrentRound() == 13){}else{}
    }
    
    private void clearAll()
    {
        run = false;
        code.clear();
        rows.stream().forEach(List::clear);
        rdm = 0;
        Try = 1;
        clearTouch();
        correctAnswer = 0;
        correctColor = 0;
        win = false;
    }
    
    private int getCurrentRound()
    {
        for (int i = 0; i < rows.size(); ++i) {
            if (rows.get(i).size() < 4) {
                return i + 1;
            }
        }
        return rows.size() + 1;
    }
    
    private void addToList()
    {
        final int currentRound = getCurrentRound();
        final List currentRow = rows.get(currentRound);
        currentRow.add(getCurrentTouch());
        pins.get(currentRound).get(currentRow.size()).setImage(paint());
        clearTouch();
        if (currentRow.size() == 4) {
            roundComplete(currentRound);
        }
    }
    
    private MyColor getCurrentTouch()
    {
        return colors().filter(color -> tapped.get(color) == 1).findFirst().orElse(null);
    }
    
    private void clearTouch()
    {
        colors().forEach(color -> tapped.put(color, 0));
    }
    
    private void roundComplete(int row)
    {
        statFinal1 = code.get(0);
        statFinal2 = code.get(1);
        statFinal3 = code.get(2);
        statFinal4 = code.get(3);
        statFinal5 = code.get(4);
        
        final List currentRow = rows.get(row);
        if (currentRow.equals(code)) {
            run = false;
            win = true;
        }
        statRows = currentRow; // TODO: use copy instead?
        crosscheck();
        final List<PinShow> hintsInCurrentRow = hints.get(row);
        for (int i = 0; i < hintsInCurrentRow.size(); ++i) {
            if (correctAnswer >= i + 1) {
                hintsInCurrentRow.get(i).setImage(HBlack);
            }
            if (correctColor >= i + 1) {
                final PinShow firstGrey = hintsInCurrentRow.stream().filter(hint -> hint.getImage() == HGrey).findFirst().orElse(null);
                if (firstGrey != null) {
                    firstGrey.setImage(HWhite);
                }
            }
        }
    }
    
    private GreenfootImage paint()
    {
        final MyColor currentTouch = getCurrentTouch();
        if (currentTouch == null) {
            return pinNone;
        }
        return currentTouch.pinImage();
    }
    
    private void crosscheck()
    {
        correctAnswer = 0;
        correctColor = 0;
        if(statRows.get(0) == statFinal1){correctAnswer++;}
        if(statRows.get(1) == statFinal2){correctAnswer++;}
        if(statRows.get(2) == statFinal3){correctAnswer++;}
        if(statRows.get(3) == statFinal4){correctAnswer++;}
        if(statRows.get(4) == statFinal5){correctAnswer++;}
        if(statRows.get(0) == statFinal2){correctColor++;}
        if(statRows.get(0) == statFinal3){correctColor++;}
        if(statRows.get(0) == statFinal4){correctColor++;}
        if(statRows.get(0) == statFinal5){correctColor++;}
        if(statRows.get(1) == statFinal1){correctColor++;}
        if(statRows.get(1) == statFinal3){correctColor++;}
        if(statRows.get(1) == statFinal4){correctColor++;}
        if(statRows.get(1) == statFinal5){correctColor++;}
        if(statRows.get(2) == statFinal1){correctColor++;}
        if(statRows.get(2) == statFinal2){correctColor++;}
        if(statRows.get(2) == statFinal4){correctColor++;}
        if(statRows.get(2) == statFinal5){correctColor++;}
        if(statRows.get(3) == statFinal1){correctColor++;}
        if(statRows.get(3) == statFinal2){correctColor++;}
        if(statRows.get(3) == statFinal3){correctColor++;}
        if(statRows.get(3) == statFinal5){correctColor++;}
        if(statRows.get(4) == statFinal1){correctColor++;}
        if(statRows.get(4) == statFinal2){correctColor++;}
        if(statRows.get(4) == statFinal3){correctColor++;}
        if(statRows.get(4) == statFinal4){correctColor++;}
    }
    
}
stefco05 stefco05

2022/1/28

#
Thank you! I’ll try it later.
You need to login to post a reply.