How do I color tiles based on this?

evgeni mironov

I'm currently trying to create a Give up button that colors all the tiles based on certain conditions. My program generates numbers:

let's say 25 5 6 7 This numbers are then placed in

<List>String numberTracker= new ArrayList<String>(); 

(I converted them to a string)

{25,5,6,7}

My program will then build 5 tiles and place each digit in each tile 2 5 5 6 7

To build tiles I import Shape and create a class tile that has shape, color and position in it that also contains setTile, getTile, getColor, setColor, getPosition and setPosition.

To keep track of of the the tiles, I keep them in

List<Tile> tiles = new ArrayList<tile>();

To keep track and place the numbers in the tile I use

List<String> numberString= new ArrayList<String>;

To generate a Color I use tile.changeCoulour() which increments after each use

so if we go back to my previous example of 25 5 6 7 The tiles are created with

List<Tile> tiles = new ArrayList<tile>();

The string numbers inside each tile with

List<String> numberString= new ArrayList<String>;

each tile has 1 digit as I said, 2 5 5 6 7 (they are all strings and placed with drawString())

{2,5,5,6,7}

I need to somehow create a condition where 25 ( contained in 2 different tiles) will be the same color where the rest of the tiles will be different

for (Tile item: tiles) {
    int position = item.getPosition();
    if (numberString.get(position) == numberTracker.get(position)) {
        item.setColor(tile.changeColour());
        repaint();
    } else {


    }
}

In that code I tried to equal the tile position to numberString position and then to itemTracker and if its the same it will change colour. However, I have trouble with the else statement

gpasch

Your basic idea is as follows: keep advancing the pointer to tiles and change the color when a new number (from those initially entered) is encountered.

int ind=0;
for(i=0 to numberTracker.size()-1) {
  String s=numberTracker.get(i);
  Color nextColor=....
  for(j=0 to s.length()-1) { tile(ind).setColor(nextColor); ind++; }
}

This will give for example the tiles {2, 5, 5 ,6 ,7} the colors {Red, Red, Green, Blue, Colorx}.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i make the tiles in a grid change color When pressed?

How do I change the color of a column based on the color of other column?

How do I assign tiles to a pandas data frame based on equal parts of a column?

How do i change input field background color based on onclick?

How do I change the color of a row based on specific dates?

How do I color background based on 1 or 0 in Python

How do I change the color of an infobox in shinydashboard based on a string, not a value?

How can i Split the large image into small tiles based on zoom

How do I get color value from a color wheel based on X & Y coordinates?

Tile Fragment, how do I get different content in different tiles?

How do I fix grayed out live tiles?

How do I create a reversi function that encloses opponents tiles?

How do i check for tiles around a specific tile?

How can I fill and color based on a variable

CSS grid, Day.js, React: In my grid-based calendar, how do I push grid items with specific dates into grid tiles with the corresponding date?

in R, how do I have the scatterplot choose a color for a point based on the value of another variable?

How do I plot hexbin with Pandas and discrete axes? (alternatively, any color-based plotting)

How do I change color of interactions based on interaction value using an ifelse() statement in an plotweb bipartite?

How do I (very approximately) generalize the name of the color based in it's CMYK or RGB numbers?

How do I return color based on X,Y coordinates from the screen?

How do I combine feature-state and property based fill-color in Mapbox GL JS?

Metal fragment shader - How do I assign each pixel a color based on the uniforms that I can adjust via the draw function?

How do we tell apart metro tiles and desktop tiles?

How do I interpolate based on max value from geoJSON properties. Using Mapbox paint, circle-color, Data driven expressions

How do I override the style background color?

How do I change the grid color?

How do I fill the current selection with color?

How do I change the color of a variable in CSS?

how do I change color of hamburger icon?