I am currently working on a 10x10 grid and trying to make alterations to boxes of it. I have 3 classes operating for this operation but I can't change the view after making the changes. 3 classes:
Main (where I do changes)
placeButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { mGame.place(size, isHorizontal, row, column);});Game (where I handle and apply the changes)
System.out.println("Place Ships: " + size + isHorizontal + left + top); if(isHorizontal == true) {//if horiz if(gameGrid[top][left] ==0) { for (int i = 0; i < size; i++) { gameGrid[top][left + i] = size; } } else{ System.out.println("ALREADY FILLED"); }View (where I draw and paint my grid)
System.out.println("SETUP VIEW ARRAY"); for (int col = 0; col < colCount; col++) { for (int row = 0; row < rowCount; row++) { int x = mGame.placedCell(row, col); System.out.print(x + " ");//tocheck if the array obtained correctly float cx = separatorSize + (chosenDiameter + separatorSize) * col; float cy = separatorSize + (chosenDiameter + separatorSize) * row; if(x > 0){ System.out.println("FOOOOOOOOOOOUND! "); //received fine paint = mPlayer1Paint; }else { paint = mBGPaint; } canvas.drawRect(cx, cy, oneSide + (cx), oneSide + (cy), paint); } System.out.println(""); } System.out.println("SETUP VIEW ARRAY END");placedCell method in my game class
mainActivity.setRow(row); mainActivity.setCol(column); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { int flag = gameGrid[row][column]; if(i == column && j == row){ if(flag > 0){ //because unedited places is 0, edited places are more than 0 gameGrid[row][column] = flag; } } } } return gameGrid[row][column];
My issue is my view class can't obtain the changed array (gameGrid) from my game class. I tried to print the array to check if it has changed correctly and it is. I also declared the array in my Game class as static but nothing has changed. Any kind of help is appreciated.