Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:05:49+00:00 2026-06-17T10:05:49+00:00

I have an assignment that is making a processing sketch that make 4 by

  • 0

I have an assignment that is making a processing sketch that make 4 by 4 Sudoku game and make the player enter the missing numbers to the playing grid, the problem that I’m facing now is to make a loop or something that allow the player to enter ALL the missing numbers ?
I’d Succeeded to allow the player to enter the first 4 numbers using switch statement and if statement but the program only go through the first if statement from each case, and I want to make it go through the rest ?
here is the cod that I make.

void setup ()
{
  background (255);
  size (125,125);
  board();
}

void cell (int x , int y , int s )
{
  rect (x,y,s,s);
}

void triple (int x , int y , int s )
{
  for (int i = 0 ; i < 2 ; i ++)
  {
    cell ( x,y,s);
    x += s;
  }
}

void block (int x , int y , int s )
{
  for (int i = 0 ; i < 2 ; i ++)
  {
    triple ( x , y , s);
    y += s;
  }
}

void row (int x , int y , int s )
{
  for ( int i = 0 ; i < 2 ; i ++)
  {
    block ( x , y , s);
    x += (s*2);
  }
}

void cellArray ( int x , int y , int s)
{
  for (int i = 0 ; i < 2 ; i ++)
  {
    row ( x , y , s);
    y += (s*2);

  }
}

void darwLines ( int x , int y , int s)
{
  strokeWeight (3);

  for (int i = 0 ; i < 1 ; i ++)
  {
    x += (s*2);
    line ( x , 0 , x , (s*4));
  }

  for ( int j = 0 ; j < 1 ; j ++)
  {
    y += (s*2);
    line ( 0 , y , (s*4) , y );
  }

  strokeWeight (1);
}

void board ()
{
  cellArray (0,0,30);
  darwLines (0,0,30);
}

void draw ()
{
   int [][] fixedArray = new int [4][4];
   fill (0);
   textSize(28);
    for (int i = 0 ; i < 4 ; i ++)
    {
      for (int j = 0 ; j < 4 ; j ++)
      {
        fixedArray [0][2] = 3; 
        fixedArray [1][1] = 4; 
        fixedArray [2][2] = 4;
        fixedArray [3][3] = 3;

        text(fixedArray [0][2], 65,25);
        text(fixedArray [1][1],35,58);
        text(fixedArray [2][2],65,88);
        text(fixedArray [3][3],95,117);
      }//end of inner loop.
    }//end of outter loop.

  if (mousePressed)
  {
    mouseClicked ();
  }
}
/*------------------------------------------------------------------------------------------*/
void mouseClicked ()
{
  int s = 30 ; 
  int cellX = mouseX / s;
  int cellY = mouseY / s;


  int [][] userInputArray = new int [4][4];



  for (int m = 0 ; m < 4 ; m ++)
  {
    for (int n = 0 ; n < 4 ; n ++)
    {

      switch (key)
     {
        case '1':

          if (mouseX > userInputArray [0][0] -s && mouseX < userInputArray [0][0]+s && mouseY > userInputArray [0][0] -s && mouseY < userInputArray [0][0] +s )
          {
            fill (0,0,255);
            text (key , 10,25);

          }

          else  if (mouseX > userInputArray [1][2] -30 && mouseX < userInputArray [1][2]+30 && mouseY > userInputArray [1][2] -30 && mouseY < userInputArray [1][2] +30)
             {
               fill (0,0,255);
               text ('1' , 65,58);
             }




          else  if (mouseX > userInputArray [2][3] -30 && mouseX < userInputArray [2][3]+30 && mouseY > userInputArray [2][3] -30 && mouseY < userInputArray [2][3] +30)
            {
              fill (0,0,255);
              text('1' ,95,88);
            }



         else   if (mouseX > userInputArray [3][1] -30 && mouseX < userInputArray [3][1]+30 && mouseY > userInputArray [3][1] -30 && mouseY < userInputArray [3][1] +30)
            {
              fill (0,0,255);
              text('1' ,35,117);
            }

          break ; 


          case '2':

            if (mouseX > userInputArray [0][1] -(s-s) && mouseX < userInputArray [0][1]+(s*2) && mouseY > userInputArray [0][1] -s && mouseY < userInputArray [0][1] +s )
            {
              fill (0,0,255);
              text(key ,35,25);
            }
           else  if (mouseX > userInputArray [1][3] - (s-s) && mouseX < userInputArray [1][3] +(s*2) && mouseY > userInputArray [1][3] -(s*2) && mouseY < userInputArray [1][3] +(s*2))
            {
              fill(0,0,255);
              text(key,95,58);
            }
           else  if (mouseX > userInputArray [2][0] -(s-s) && mouseX < userInputArray [2][0] +(s*2) && mouseY > userInputArray [2][0] -(s*2) && mouseY < userInputArray [2][0] +(s*2))
            {
              fill(0,0,255);
              text(key,10,88);
            }
            else if (mouseX > userInputArray [3][2] -(s-s) && mouseX < userInputArray [3][2] +(s*2) && mouseY > userInputArray [3][2] -(s*2) && mouseY < userInputArray [3][2] +(s*2))
            {
              fill(0,0,255);
              text(key,65,117);
            }

          break;

          case '3':

            if ( mouseX > userInputArray [1][0] -s && mouseX < userInputArray [1][0]+s && mouseY > userInputArray [1][0] -(s-s) && mouseY < userInputArray [1][0] +(s*2))
            {
              fill(0,0,255);
              text(key,10,58);
            }
            else if (mouseX > userInputArray [2][1] -s && mouseX < userInputArray [2][1]+s && mouseY > userInputArray [2][1] -(s-s) && mouseY < userInputArray [2][1] +(s*2))
            {
              fill(0,0,255);
              text(key,35,88);
            }

          break ;

          case '4':

            if (mouseX > userInputArray [0][3] +60 && mouseX < userInputArray [0][3]+120 && mouseY > userInputArray [0][3] -30 && mouseY < userInputArray [0][3] +30 )
            {
              fill(0,0,255);
              text(key,95,25);
            }

           else if (mouseX > userInputArray [3][0] +60 && mouseX < userInputArray [3][0]+120 && mouseY > userInputArray [3][0] -30 && mouseY < userInputArray [3][0] +30 )
            {
              fill(0,0,255);
              text(key,10,117);
            }
          break;

          default :
          {
            fill (255);
            rect ((cellX * s),(cellY*s),s,s);
          }
      }//end of switch.

    }//end of the inner loop.
  }//end of the outter for loop.
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:05:51+00:00Added an answer on June 17, 2026 at 10:05 am

    I have gone through your code, and observed some issues:

    • First of all, the code is quite messy. The drawlines + cellArray + row + … can be solved much more elegantly, without the need for such a complex nesting of functions.

    • Apparently, you want fixedArray to always remain constant. Therefore, you don’t need to define it and assign values at every draw loop. You can move that declaration to the beginning of your code.

    • Same happens with userInputArray, values are defined nowhere, and therefore equal 0.

    • You are drawing each number 16 times on top of itself, that’s why it looks so crancky… There is no need for the nested for loops when drawing the text.

    This said, please find attached a proposal of enhanced code. It fixes all the issues, is more flexible if in need if changing sudoku size and position, and is in general more consistent code.

    Nevertheless, if you want to make this really interesting, try to figure out how to make random value generation, so that every sudoku is different from the previous one! There are plenty of sudoku generation algorithms online.

    Good luck!

    // GLOBAL VARS DECLARATION
    int[][] resultsValue = {
      {1,2,3,4},
      {3,4,1,2},
      {2,3,4,1},
      {4,1,2,3}};
    boolean[][] resultsSolved = new boolean[4][4];
    int cellsX = 4;
    int cellsY = 4;
    float cellSize = 30; 
    float xPos = 0;
    float yPos = 0;
    
    void setup ()
    {
      background (255);
      size (130, 130);
      smooth();
    
      // GLOBAL VARS VALUE ASSIGNMENT            
      resultsSolved[0][2] = true;
      resultsSolved[1][1] = true;
      resultsSolved[2][2] = true;
      resultsSolved[3][3] = true;
    }
    
    void draw ()
    {
      background(255);
    
      drawBoard(cellsX, cellsY, cellSize, xPos, yPos, 2);
    
      pushStyle();
      fill (0);
      textSize(28);
    
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          if (resultsSolved[i][j] == true) {
             text(resultsValue[i][j], 5 + xPos + j * cellSize, -5 + yPos + (i + 1) * cellSize);
          }
        }
      }
    
      popStyle();
    
      if (mousePressed)
      {
        mouseClicked ();
      }
    
    }
    
    /*------------------------------------------------------------------------------------------*/
    
    void drawBoard(int rows, int cols, float cellSize, float xPos, float yPos, int cellBlocks) {
      pushStyle();
      noFill();
      stroke(0);
      strokeWeight(1);
    
      // DRAW RECTANGLES
      for (int i = 0; i < cols; i++) {
        for (int j = 0; j < rows; j++) {
          rect(xPos + i * cellSize, yPos + j * cellSize, cellSize, cellSize);
        }
      }
    
      strokeWeight(3);
    
      // DRAW LINES
      for (int i = 0; i < cols / cellBlocks; i++) {
          line(xPos + i * cellSize * cellBlocks, yPos, xPos + i * cellSize  * cellBlocks, yPos + rows * cellSize); 
      }
      for (int i = 0; i < rows / cellBlocks; i++) {
          line(xPos, yPos + i * cellSize * cellBlocks, xPos + cols * cellSize, yPos + i * cellSize * cellBlocks); 
      }
    
      popStyle();
    } 
    
    void mouseClicked ()
    {
      int cellX = (int) ((mouseX - xPos) / cellSize); 
      if (cellX > cellsX - 1) cellX = cellsX - 1;
      else if (cellX < 0) cellX = 0;
    
      int cellY = (int) ((mouseY - yPos) / cellSize); 
      if (cellY > cellsY - 1) cellY = cellsY - 1;
      else if (cellY < 0) cellY = 0;
    
      int lastKeyInt = int(key - '0');
    
      if (resultsValue[cellY][cellX] == lastKeyInt) {
        resultsSolved[cellY][cellX] = true;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an assignment that simulates a dice game. As part of the program,
For an assignment in college, we have to make a script in Perl that
I have an assignment that wants me to write an ternary search algorithm and
I have quite a large XSL document for an assignment that does a number
My assignment requires that I have an ER diagram that shows the dependencies between
For a school assignment I have to create a C++ program that will create
I'm making a simple registration application and I have an assignment to learn more
I have an assignment in my java class to make a very simple phishing
i have an erd for a school assignment that contains a many to many
I have an programming assignment in Java. I have implemented it by making an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.