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

2 days ago

Can you fix my code

KylesGallery KylesGallery

2 days ago

#
Basically whats happening is the tiles are suppose to turn green when pressed in a certaint order. But right now they don't turn green even though it is saying that it was pressed Heres an example of one tile public void act() { if (tileBeggining!=220) { if(tileBeggining==1 && tileSelection.Memory1==1) setImage("Tile Yellow.png"); else if (tileBeggining==1) setImage("Tile Gray.png"); if(tileBeggining==40 && tileSelection.Memory2==1) setImage("Tile Orange.png"); else if (tileBeggining==40) setImage("Tile Gray.png"); if(tileBeggining==80 && tileSelection.Memory3==1) setImage("Tile Yellow.png"); else if (tileBeggining==80) setImage("Tile Gray.png"); if(tileBeggining==120 && tileSelection.Memory4==1) setImage("Tile Orange.png"); else if (tileBeggining==120) setImage("Tile Gray.png"); if(tileBeggining==160 && tileSelection.Memory5==1) setImage("Tile Yellow.png"); else if (tileBeggining==160) setImage("Tile Gray.png"); if (tileBeggining==200) setImage("Tile Gray.png"); tileBeggining++; } else{ MouseInfo mi = Greenfoot.getMouseInfo(); tileRest(); if (tileNumber==1 && tileSelection.Memory1==1) { if (Greenfoot.mouseClicked(this)) correct(); } else if (tileNumber==1) { if (Greenfoot.mouseClicked(this)) inCorrect(); } if (tileNumber==2 && tileSelection.Memory1==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==2){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==3 && tileSelection.Memory1==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==3){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==4 && tileSelection.Memory1==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==4){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==5 && tileSelection.Memory1==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==5){ if (Greenfoot.mouseClicked(this)) inCorrect();} if(TilePressed==true) { if(t15==50) { TilePressed=false; t15=0; tileNumber++; setImage("Tile Gray.png"); } else t15++; }} if (tileNumber==6) { setImage("Tile Green.png"); tileNumber++; } } public void tileRest() { } public void inCorrect() { setImage("Tile Red.png"); fail=true; } public void correct() { setImage("Tile Green.png"); TilePressed=true; } And the code that is setting tileselction.Memory#'s tileSelection.Memory1=Greenfoot.getRandomNumber(5)+1; tileSelection.Memory2=Greenfoot.getRandomNumber(5)+1; tileSelection.Memory3=Greenfoot.getRandomNumber(5)+1; tileSelection.Memory4=Greenfoot.getRandomNumber(5)+1; tileSelection.Memory5=Greenfoot.getRandomNumber(5)+1; and there is no code in tile Selection
danpost danpost

2 days ago

#
What if 1 is not chosen as a random value for any memory slot?
KylesGallery KylesGallery

2 days ago

#
if one is not chosen, one of the other 4 slots are chosen only things that vary in the actors is the number after
tileSelection.Memory#==
Also I found a different problem that i fixed that only happened in this actor. But it still has the same problem, here is the fixed code public class Tile1Memory extends TilesMemory { /** * Act - do whatever the Tile1 wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ int tileBeggining; public void act() { if (tileBeggining!=220) { if(tileBeggining==1 && tileSelection.Memory1==1) setImage("Tile Yellow.png"); else if (tileBeggining==1) setImage("Tile Gray.png"); if(tileBeggining==40 && tileSelection.Memory2==1) setImage("Tile Orange.png"); else if (tileBeggining==40) setImage("Tile Gray.png"); if(tileBeggining==80 && tileSelection.Memory3==1) setImage("Tile Yellow.png"); else if (tileBeggining==80) setImage("Tile Gray.png"); if(tileBeggining==120 && tileSelection.Memory4==1) setImage("Tile Orange.png"); else if (tileBeggining==120) setImage("Tile Gray.png"); if(tileBeggining==160 && tileSelection.Memory5==1) setImage("Tile Yellow.png"); else if (tileBeggining==160) setImage("Tile Gray.png"); if (tileBeggining==200) setImage("Tile Gray.png"); tileBeggining++; } else{ MouseInfo mi = Greenfoot.getMouseInfo(); tileRest(); if (tileNumber==1 && tileSelection.Memory1==1) { if (Greenfoot.mouseClicked(this)) correct(); } else if (tileNumber==1) { if (Greenfoot.mouseClicked(this)) inCorrect(); } if (tileNumber==2 && tileSelection.Memory2==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==2){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==3 && tileSelection.Memory3==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==3){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==4 && tileSelection.Memory4==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==4){ if (Greenfoot.mouseClicked(this)) inCorrect();} if (tileNumber==5 && tileSelection.Memory5==1){ if (Greenfoot.mouseClicked(this)) correct();} else if (tileNumber==5){ if (Greenfoot.mouseClicked(this)) inCorrect();} if(TilePressed==true) { if(t15==50) { TilePressed=false; t15=0; tileNumber++; setImage("Tile Gray.png"); } else t15++; }} if (tileNumber==6) { setImage("Tile Green.png"); tileNumber++; } } public void tileRest() { } public void inCorrect() { setImage("Tile Red.png"); fail=true; } public void correct() { setImage("Tile Green.png"); TilePressed=true; } }
KylesGallery KylesGallery

2 days ago

#
it seems like its going through the voids but is not setting the image even though fail and TilePressed works
danpost danpost

2 days ago

#
KylesGallery wrote...
it seems like its going through the voids but is not setting the image even though fail and TilePressed works
I am finding it difficult to understand what is supposed to be happening with your tiles (or TilesMemory objects) throughout.
KylesGallery KylesGallery

yesterday

#
TilesNumber is used for telling what stage the game is at and after each one you get right it goes to the next set tile you need to press Memory# is used for detecting which tile you need to press TilePressed checks whether a tile has been pressed when green Fail restarts game if is equal to true If you want me to upload the game for you to see what it looks like i can do that
danpost danpost

yesterday

#
Is each tile only to be pressed once in a correct sequence of presses? And, what is up with the colors (yellow and orange switching)?
KylesGallery KylesGallery

yesterday

#
Yes there is a random sequence of tiles selected, and i added the yellow and orange switching because if the when the game shows you the order of the tiles there is a chance it you will have to press the same tile twice in a row. I don't know if i'll make it so the tiles cant be the same as the tile selected before that tile is selected, I know how to add it if I choose to though. And to answer your first part of the queston there is a chance that all five selected tiles are the same, i'm putting this in a combined game with some projects for my final project in computer science
danpost danpost

yesterday

#
KylesGallery wrote...
when the game shows you the order of the tiles
So ... the game shows the entire sequence and then the player must duplicate that same sequence?
KylesGallery KylesGallery

yesterday

#
Yes
danpost danpost

yesterday

#
I would totally simplify things. One array of int values is all you need to record a random sequence. You basically have two phases in the game -- sequence showing and sequence duplicating; so a boolean value can be used to control game play. Your World subclass would be the place for it and its act method can control everything. As far as the tiles, simple actors can be used (no codes). The world can maintain an array for them, also.
KylesGallery KylesGallery

21 hours ago

#
Could you send me what the array would look like, I've tried to use arrays before for a similar purpose but could figure out how. I searched for it before for awhile and I couldn't findo something that works, thanks.
danpost danpost

16 hours ago

#
KylesGallery wrote...
Could you send me what the array would look like, I've tried to use arrays before for a similar purpose but could figure out how. I searched for it before for awhile and I couldn't findo something that works, thanks.
An int array would be declared like this:
int[] values;
and assign an array (of length 5) like this:
values = new int[5];
Then you can assign random values by iterating through the array like this:
for (int i=0; i<values.length; i++) values[i] = Greenfoot.getRandomNumber(5)+1;
You need to login to post a reply.