Need help with game issues for christmas

Ok first off, Hello everyone.
I am new here and very new to coding. If you don’t care about the long backstory of my problem just skip to the next paragraph. I am currently working on my first large project, or at least large to me haha. I only know what i have learned from youtube I am not comfortable with all the different functions or how certain functions work. However I do have a semi working 2000ish lines of code making a personalized jeopardy game that is going to be for christmas for my family. Long story short its a tradition we have each year for doing a whole secret santa thing that allows us to choose gifts based on our score in the jeopardy game. This has never been an issue since all the family gathers together for Christmas.Due to some bad health some family members will not be joining this year and everyone seems to be concerned about our tradition not carrying on this year. So I decided to code a jeopardy game i can send to everyone and we can skype it together so we will all feel included in the fun.

Now to my issue. I know that the entire program i wrote is very sloppy, not well thought out, and very beginner, but again it works at the moment and its my first attempt. I have since continued learning more and more about coding and creating classes and objects that would have made this alot cleaner. Basically i don’t know if i should just fix the few issues i have in the current project or just redo the whole thing. Not knowing in full detail how all the functions work I may have the same issues in my next attempt. My main issue is I am using mousePressed() with alot of if()statements inside of it to act as my button presses for choosing questions on a jeopardy board and for button presses to select to see the answer. I am also using alot of if() statements to draw my board based on round 1 and 2 and whatever question it is currently displaying. In other words i have alot of layers that seem to be working all at once causing some of my mousePressed() functions to overlap each other so when i click lets say question in category 3 for 800 points its also clicking the show answer button i made on the draw function for showing the answer. https://editor.p5js.org/mcfiorino624/sketches/Z6yzpveeF
The way my mind is wrapping around this is i set my mousePressed to only function when on the board which i called “r” for round 1. Then i have a separate mousePressed for when the draw function is drawing the answer screen it should be a single mouse press to get back to the board. By doing this it seems that answer button is always there even when the board r is true which it shouldn’t. currently all i have variables and everything working for is round 1, i haven’t coded mouse presses or anything for round 2 yet.

If anyone has any ideas that could help me out for this project or completely thinks i should start from scratch and has a plan please let me know i want to get this all sorted out by early December so i can sort out adding all the questions and answers to this template.

1 Like

I wouldn’t start all over again but work from what you have.

when i click lets say question in category 3 for 800 points its also clicking the show answer button i made on the draw function for showing the answer.

Now in my opinion here are different screens involved and you have difficulties to separate them in a clear way.

In this forum, that’s mostly handled with a variable int state that tells you in which screen you are. So state 0 is the splash screen and state 1 is the game screen etc… You could also say state 11 is for round 1, state 12 for round 2 and so on.

Now in draw() we evaluate state using switch(state) { and show only the screen for this state. Very clean structure.

Similarly in mousePressed we evaluate state and check only the buttons that exist in this screen.

Example with a button class:


// demonstrates mouse usage with states.
// one 2D array buttons holds all the screen buttons.
// 2 user names can be entered.  

// states:
// consts (numbers must be unique)
final int stateSplashScreen  = 0; // start screen
final int stateName1         = 1;
final int stateName2         = 2;
final int stateGame          = 3;  
final int stateGameOver      = 4;
int state  = stateSplashScreen;       // current 
final int stateMAX = stateGameOver+1; // the max number 

// 2D array of buttons. 
// First index = state, 2nd index = number of button in that state
RectButton[][] buttons = new RectButton [stateMAX][3]; 

// for the tool tip text 
int timeSinceLastMouseMoved=0;

// messages --------------------
String msgText="";
float msgX=0;
float msgY=0;
boolean msgShow=false;
int msgFrameCount = 0;

// text field 
boolean textFieldCursorIsOn = true; // cursor on / off? 
String enteredText = "";  // temp input text

// player names 
String namePlayer1 = "";  // results
String namePlayer2 = "";

// --------------------

// colors
final color colWhite      = color(255);
final color colBlack      = color(0);
final color colDarkGray   = color(111);
//---
final color colRed        = color(255, 0, 0);
final color colGreen      = color(0, 255, 0);
final color colBlue       = color(0, 0, 255);
//---
final color colYellow     = color(244, 244, 44);
final color colDarkYellow = color(255, 200, 120);

// colors for Buttons 
final color col1 = #ff0000;
final color col2 = #ffff00;
final color col3 = #000000;


// -------------------------------------------------

void setup() {
  // init (runs only once)
  size(800, 800);

  // pre-init btns: set all to non-exist
  for (int i = 0; i<stateMAX; i++) {
    for (int i2 = 0; i2<buttons[i].length; i2++) {
      buttons[i][i2] =  new RectButton( 366, 3, 
        66, 70, col1, col2, false, "", "");
    }
  }

  // init btns

  // -------------
  // stateSplashScreen
  buttons[stateSplashScreen][0] =  new RectButton( 396 + 9, 433, 
    66, 70, col1, col2, true, "Next", "Go on, click me") ;

  // -------------
  // state name 1
  buttons[stateName1][0] =  new RectButton( 396 + 9, 433, 
    66, 70, col1, col2, true, "Next", "Go on, click me") ;

  // -------------
  // state name 2
  buttons[stateName2][0] =  new RectButton( 396 + 9, 433, 
    66, 70, col1, col2, true, "Next", "Go on, click me") ;

  // -------------
  // stateGame
  buttons[stateGame][0] =  new RectButton( 396 + 9, 433, 
    66, 70, col1, col2, true, "Hello", "Say Hello");

  buttons[stateGame][1] =  new RectButton( 396 + 9, 533, 
    66, 70, col1, col2, true, "Bye", "Say Bye");

  // -------------
  //stateGameOver
  buttons[stateGameOver][0] =  new RectButton( 396 + 9, 433, 
    66, 70, col1, col2, true, "Return", "return to game");
} // func 

void draw() { 
  // draw() runs on and on 

  getDataToDecideIfToolTipText();

  switch (state) {

  case stateSplashScreen:
    handleStateSplashScreen(); 
    break;

  case stateName1: 
    handleStateName1(); 
    break; 

  case stateName2: 
    handleStateName2(); 
    break; 

  case stateGame: 
    // Game
    handleStateGame();
    break; 

  case stateGameOver:
    // GameOver
    handleStateGameOver(); 
    break;

  default:
    // error
    println("Error number 939; unknown state : " 
      + state + ". Abort. #######################################");
    exit();
    break;
  } // switch
  //
} // func 

// ------------------------------------------------
// functions for states - called from draw() 

void handleStateSplashScreen() {
  background(11);
  fill(244, 3, 3); // red 
  text ("This is the Splash Screen....\n", 210, 313);
  showButtons();
} // func 

void handleStateName1() {
  background(11);
  fill(244, 3, 3); // red 
  text ("This is the Name state: PLAYER 1....\n", 210, 313);
  // draw the rest (the same for both states)
  handleInput();
} // func 

void handleStateName2() {
  background(11);
  fill(244, 3, 3); // red 
  text ("This is the Name state: PLAYER 2....\n", 210, 313);
  // draw the rest (the same for both states)
  handleInput();
} // func 

void handleInput() {
  // draw the rest 
  // (the same for both states) 
  //TextField
  fill(255);
  textSize(18);
  rect(25, 645, 200, 40);
  fill(0);
  text(enteredText+blinkChar(), 25+5, 645+30);
  fill(255, 2, 2, 11);
  toggleTextFieldCursorIsOn(); 
  // btns 
  showButtons();
}

void handleStateGame() {
  // Game
  background(11);
  fill(244, 3, 3); // red
  text (namePlayer1
    + " versus " 
    + namePlayer2
    + " <<<<<<<<<<<<<<<-------------", 
    17, 19);

  fill(244, 3, 3); // red 
  text ("This is the Game....\n"
    +" Don't touch the red rectangle...", 
    210, 313);

  noStroke();
  fill(255, 2, 2) ;
  rect(100, 100, 100, 100);
  fill(255, 2, 255) ;
  // rect(300, 100, 100, 100);

  if (mouseX > 100 && mouseX < 100 + 100  &&
    mouseY > 100   && mouseY < 100 + 100) {
    println ("collide");
    // change state
    timeSinceLastMouseMoved = millis();
    state = stateGameOver;
  }

  // btns
  showButtons();

  // message ----
  if (msgShow) {
    fill(colWhite);
    text (msgText, msgX, msgY); 
    if ( frameCount > msgFrameCount + 100 )
      msgShow=false;
  }//if
  //
} // func 

void handleStateGameOver() {
  // Game over / Lost 
  background(255);
  fill(244, 3, 3); // red 
  text ("You LOST....  ", 210, 313);
  text ("Hit any key to start Game", 210, 385);
  showButtons();
} // func 

// ----------------------------------------
// input keyboard

void keyPressed() {

  switch (state) {

  case stateSplashScreen: 
    // splash screen
    // do nothing 
    break; 

  case stateName1:
  case stateName2:
    // the same for both names
    //    if (keyCode>=32) 
    //      enteredText = enteredText + key;
    // SEE keyTyped() 
    break;

  case stateGame: 
    // Game
    // do nothing 
    break; 

  case stateGameOver:
    // Game Over
    timeSinceLastMouseMoved = millis();
    state = stateGame; 
    break;

  default:
    // error
    println("Error number 1039; unknown state : " 
      + state + ".");
    exit();
    break;
  } // switch
} // func 

void keyTyped() {
  // correct states? 
  if ( state == stateName1 || state == stateName2) {
    // yes 
    final char k = key;

    // quit?
    if (k == CODED)  
      return; // quit

    final int len = enteredText.length();

    if (k == BACKSPACE) {
      // shorten text   
      enteredText = enteredText.substring(0, max(0, len-1));
    } else if (len >= 44) { 
      return; // quit
    } else if (k == ENTER || k == RETURN) {
      // ignore
    } else if (k == TAB & len < 44-3) {
      // ignore 
      // tbox.txt += "    " ;
    } else if (k == DELETE) { 
      enteredText = ""; // reset
    } else if (k >= ' ') {  
      enteredText += str(k); // add this letter
    } // else if
  } // if
}

// ----------------------------------------
// input mouse

void mousePressed() {

  // reset timer for mouse over tool tip text  
  timeSinceLastMouseMoved = millis();

  // loop over all buttons (i) in the current state
  // when you add a new state, this func can stay the same 
  for (int i = 0; i<buttons[state].length; i++) {
    buttons[state][i].update();
    if (buttons[state][i].Exists && buttons[state][i].pressed()) {
      executeButton(state, i);
    }// if
  }//for
}//func

// ------------------------------------------ 
// tools

void showButtons() {
  // loop over all buttons (i) in the current state
  // when you add a new state, this func can stay the same 
  for (int i = 0; i<buttons[state].length; i++) {
    buttons[state][i].update();
    buttons[state][i].display();
    buttons[state][i].toolTip();
  } // for
} // func 

void executeButton(int stateLocal, int btnNumber) {
  // this is the command center for all states and all buttons : 
  // when you add a new state, you have to add something here.  
  switch(stateLocal) {
    // now the states: 

  case stateSplashScreen:
    // Splash Screen
    switch(btnNumber) {
    case 0:
      timeSinceLastMouseMoved = millis();
      state=stateName1;  // go on
      break; 
    default:
      // error
      println("Error number 1122; unknown button: " 
        + btnNumber
        + " in state: "
        + state 
        + ". Abort. #######################################");
      exit();
      break;
    } // inner switch
    break; 

  case stateName1:
    // only 1 btn
    namePlayer1 = enteredText;
    enteredText="";
    state=stateName2;   // go on
    break;

  case stateName2:
    // only 1 btn
    namePlayer2 = enteredText;
    enteredText="";
    state=stateGame;   // go on
    break;

  case stateGame:
    // game  
    switch(btnNumber) {
    case 0:
      println("Hello");
      msgOn("Hello ", 500, height-100);
      break; 
    case 1:
      println("Bye");
      msgOn("Bye ", 500, height-100);
      break; 
    default:
      // error
      println("Error number 1123; unknown button: " 
        + btnNumber
        + " in state: "
        + state 
        + ". Abort. #######################################");
      exit();
      break;
    } // inner switch
    break;

  case stateGameOver:
    // GameOver
    switch(btnNumber) {
    case 0:
      timeSinceLastMouseMoved = millis();
      state=stateGame; 
      break;    
    default:
      // error
      println("Error number 1124; unknown button: " 
        + btnNumber
        + " in state: "
        + state 
        + ". Abort. #######################################");
      exit();
      break;
    } // inner switch
    break;

  default:
    // error
    println("Error number 1339; unknown state : " 
      + state 
      + ". Abort. #######################################");
    exit();
    break;
    //------
  }// outer switch
}//func

void getDataToDecideIfToolTipText() {
  // get some data to decide if it is time to show tool tip text 
  if ((mouseX!=pmouseX) || (mouseY!=pmouseY)) {
    // mouse moved 
    // store time since last mouse moved 
    timeSinceLastMouseMoved = millis();
  }
}// func

void msgOn(String txt1, int x1, int y1) {
  msgText=txt1;
  msgX=x1;
  msgY=y1;
  msgShow=true;
  msgFrameCount = frameCount;
}

String blinkChar() {
  // returns a cursor or nothing 
  return (textFieldCursorIsOn) ? "|" : "";
}

void toggleTextFieldCursorIsOn() {
  // changes textFieldCursorIsOn 
  if (frameCount%30==0)
    textFieldCursorIsOn=!textFieldCursorIsOn;
} 

// =========================================
// class RectButton and Button  

class RectButton extends Button {

  // constr 
  public RectButton(int ix, int iy, 
    int isizeX, int isizeY, 
    color icolor, 
    color ihighlight, 
    boolean iExist, 
    String iText, 
    String iToolTipText 
    ) {
    x = ix;
    y = iy;

    sizeX = isizeX;
    sizeY = isizeY;    

    basecolor = icolor;
    highlightcolor = ihighlight;
    currentcolor = basecolor;
    Exists = iExist;

    Text = iText;
    ToolTipText = iToolTipText;
  } // constr 

  void display() {
    if (Exists) {
      stroke (ButtonStrokeColor); 
      strokeWeight(0); 
      fill(currentcolor, 30);
      rect(x, y, sizeX, sizeY);        
      if (Text != "") {
        //
        fill(0, 102, 153);
        textAlign(CENTER);
        textSize(16) ;
        text(Text, (x + (sizeX / 2.0)), (y + (sizeY / 2.0))+5);
        textAlign(LEFT);
      } // if (Text != "")
    } // if exists
  } // method display
} // class

class Button {
  int x, y;
  int sizeX;
  int sizeY;  
  color basecolor, highlightcolor;
  color currentcolor;
  boolean Exists  = false;  
  String Text     = "";
  String ToolTipText = ""; 
  //  String Tag = "";
  //  int Tag2 = 0;
  //  int TagMark = 0; 
  color ButtonStrokeColor = color (255, 255, 255);

  void update() {
    if (over()) {
      // Mouse over 
      currentcolor = highlightcolor;
    } else {
      // not Mouse over 
      currentcolor = basecolor;
    }
  } // update 

  void toolTip() {
    if (over()) {
      if (!ToolTipText.equals("")) {
        if (millis() - timeSinceLastMouseMoved > 800) {
          fill(colYellow);
          noStroke();
          textSize (12);
          float tw = textWidth(ToolTipText);
          float xLeft = mouseX-(tw/2); 
          float xRight = mouseX-(tw/2) + tw; 
          float xLeftText = mouseX; 
          if (xRight>=width) { 
            xLeft= width-tw-2;
            xLeftText= xLeft + tw/2;
          } 
          if (xLeft< 2) 
          { 
            xLeft=2;
            xLeftText= 2 + tw / 2;
          }
          rect (xLeft, mouseY+32, tw+4, 20);
          textAlign(CENTER);
          fill(0);
          text(ToolTipText, xLeftText, mouseY+44);
          textAlign(LEFT);
          textSize(16);
        } //  if
      } // if
    } // if
  } // func 

  boolean pressed() {
    if (over()) {
      return true;
    } else {
      return false;
    }
  }  // pressed; 

  boolean over() {
    if (overRect(x, y, sizeX, sizeY) ) {
      return true;
    } else {
      return false;
    }
  } // over 

  boolean overRect(int x, int y, 
    int width, int height) {
    if (mouseX >= x && mouseX <= x+width &&
      mouseY >= y && mouseY <= y+height) {
      return true;
    } else {
      return false;
    }
  } // overRect
  //
} // class
//
1 Like

ok well, thats gonna require alot of changes then haha. How would you have handled the screen for the questions. i have an individual variable for each question for round 1 and 2 and each answer for round 1 and 2 that alone is 120 variables?

Your code got so many variables! You should definitely read these 2 articles below: :open_book:

  1. Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays
  2. Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes
3 Likes

That sounds complicate.

In my opinion you would have one class CardWithQuestion and an array of that class. Or an 2D array, so you would have a board for round 1 and one board for round 2 etc.

Now define it in setup and use it in draw()

set all Strings into the cells in setup() (!)


Cell[][] grid = new Cell[3][100];
int round=0;

void setup() { 
  size(1200, 900);

  // ROUND: 
  for (int j2 = 0; j2 < 3; j2++) { 
    int k=0;
    // GRID: 
    for (int i = 0; i < 10; i++) {  // x...
      for (int j = 0; j < 10; j++) { // y....
        int size1=70; 
        grid[j2][k] = new Cell(i*size1+115, 
          j*size1+115, 
          "A");
        k++;
      }
    }
  }

  grid[0][4].colorCell = color(255, 2, 2); //red
}

void draw() { 
  round = 0;  
  for (int j = 0; j < 100; j++) {
    grid[round][j].display();
  }
}

// ==============================================================================

class Cell {

  float x, y; 
  color colorCell = color(255); // white  
  String str1="A";
  Cell(float xTemp, float yTemp, 
    String stringTemp) {
    x=xTemp; 
    y=yTemp;
    str1=stringTemp;
  } // Constr 

  void display() {
    rectMode(CENTER);
    fill(colorCell); 
    rect(x, y, 55, 55);

    fill(0);
    text(str1, x, y);
  }
}//class
//

Is there a way i can download this example you showed me so i can tinker with it and see how it operates in p5.js?

I know! haha im learning as I go since this is my first project. I learned how to create variables about 5 videos before i learned about,classes, functions, and arrays. So I started typing and ran with it haha.

goto loop already showed some good links.

As I showed in my 2nd example I would store question and answer directly into the cell of the grid.

Yeah, it’s not p5 but java processing

to run it:

download processing and run it in the IDE

https://www.processing.org/download/

Here is an example of how I’d do it:

store your Questions / Answer (I know in Jeopardy it’s the other way round) in the cell.


Cell[][] grid = new Cell[3][6*6];  // 3 rounds and 6*6 board   !!!!!!!!!! 
int round=0;  // current round !!!!! To do: change this 

int selected=4;   // current cell selected !!! This cell is RED. To do: change this 

// states / unique numbers 
final int normal=0; // show grid 
final int showQuestion=1; 
final int showAnswer=2; 
int state=normal;  // current state / screen !!!!!!

// YOUR DATA  ******************************************************************

String[] coverRound1 = 
  {
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000", 
  "$100", 
  "$200", 
  "$300", 
  "$400", 
  "$700", 
  "$1000"
};

String[] questionsRound1 = 
  {
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where ", 
  "What ", 
  "Who ", 
  "Where " 
};

String[] answersRound1 = 
  {
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary ", 
  "Henry ", 
  "1979 ", 
  "Mary "
};

void setup() { 
  size(1200, 900);

  background(90); 

// NOW WE READ THE DATA INTO THE cells of the grid....

  // ROUND: 
  for (int j2 = 0; j2 < 3; j2++) { 
    int k=0;
    // GRID: 
    for (int i = 0; i < 6; i++) {  // x...
      for (int j = 0; j < 6; j++) { // y....
        int size1=70; 

        if (j2==0) { 
          // Round 1 
          grid[j2][k] = new Cell(i*size1+115, 
            j*size1+115, 
            coverRound1[k], 
            questionsRound1 [k], 
            answersRound1[k]);
        } else if (j2==1) {
          // to do !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ROUND 2 
          grid[j2][k] = new Cell(i*size1+115, 
            j*size1+115, 
            coverRound1[k], 
            questionsRound1 [k], 
            answersRound1[k]);
          // to do !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }

        k++;
      }
    }
  }
  grid[0][selected].colorCell = color(255, 2, 2); //red
  textAlign(CENTER);
}

void draw() { 

  background(90); 

  switch (state) {

  case normal:
    round = 0;  
    for (int j = 0; j < 6*6; j++) {
      grid[round][j].display();
    }
    break; 

  case showQuestion:
    grid[round][selected].displayQuestion();
    break;

  case showAnswer:
    grid[round][selected].displayAnswer();
    break;
  }//switch
  //

  textAlign(LEFT);
  fill(255); 
  text("HELP"
    +"\n"
    +"Return show Question"
    +"\n"
    +"Space show Answer"
    +"\n"
    +"Space or Escape to go back.", 
    width-300, 100);
  textAlign(CENTER);
}//func draw

// -------------------------------------------------------------------------------

void keyPressed() {
  switch(key) {

  case RETURN:
  case ENTER:
    state=showQuestion; 
    break;

  case ' ':
    // Answer or go back
    // (Answer is allowed only when question is displayed!!!!!! (Or answer))
    if (state==showQuestion || state==showAnswer) { 
      if ( state==showAnswer)
        state=normal; // go back 
      else 
      state=showAnswer;  // show Answer state 
    }
    break;

  case ESC:
    state=normal;
    key=0; // kill ESC
    break;
  }//switch 
  //
}// func

// ==============================================================================

class Cell {

  float x, y; 
  color colorCell = color(255); // white

  String strCover="$100";
  String strQuestion="A";
  String strAnswer="A";

  Cell(float xTemp, float yTemp, 
    String strCoverTemp, 
    String strQuestionTemp, 
    String strAnswerTemp) {

    x=xTemp; 
    y=yTemp;
    strCover=strCoverTemp;
    strQuestion=strQuestionTemp;
    strAnswer=strAnswerTemp;
  } // Constr 

  void display() {
    rectMode(CENTER);
    fill(colorCell); 
    rect(x, y, 55, 55);

    fill(0);
    textAlign(CENTER);
    text(strCover, 
      x, y);
  }

  void displayQuestion() {
    rectMode(CENTER);
    fill(colorCell); 
    rect(width/2, height/2, 
      500, 555);

    fill(0);
    textAlign(CENTER);
    text(strQuestion, 
      width/2, height/2);
  }

  void displayAnswer() {
    rectMode(CENTER);
    fill(0, 0, 255); 
    rect(width/2, height/2, 
      500, 555);

    fill(0);
    textAlign(CENTER);
    text(strAnswer, 
      width/2, height/2);
  }
  //
}//class
//
1 Like

Sorry for being so new to this but all of this is way above my head haha. i tried pasting this into p5.js just to see how this functions, but i believe you originally said its not p5 id need to do this in a separate editor?
did you run this code and it functioned for you ?

Yeah it runs. But it’s not in p5.

It’s in processing java.

As I said download the processing program (if you like a “separate editor” but it’s rather an IDE with a programming language processing java. An IDE is an editor that additionally let’s you compile and run your programs) and run it therein.

https://www.processing.org/download/

Instead of running it, you can also read it and implement it in p5 - or modify it so that it works in p5.

processing java and p5 are pretty similar on some levels.

Chrisir

haha thats also above my skills at this time. ill just download processing and go from there. so i can try to learn how to rewrite this whole code in p5 with my specific parameters

2 Likes

actually when you stay with p5.js
you should work there as
https://editor.p5js.org
( as you might get more easy help as when using PDE p5.js Mode. )


so all comment shown in JAVA
you should not take literally, only structurally.

learn about

  • variables
  • functions
  • arrays
  • ( later also class and array or class )
    and the code might get snappy soon.

but all that was not your question

  • it should have been after 1000 lines ? how to make it better ?
    now after 2000 lines it hurts more.

generally there should be only the

function mousePressed() {

}

what again was the question?
in “Round 1” on click get a question
in “Round 2” NOT?


example for button array of class as grid
https://editor.p5js.org/kll/sketches/nIgaLm90P

2 Likes

but just a start could be ONE BUTTON structured so the second one gets very easy
https://editor.p5js.org/kll/sketches/5hBxVwuAP

First of all, thanks for the reply. The program i linked works if you click round 1 and attempt to click a point value to show you a question. You can click the top left box which is a 200 dollar question for category 1, it takes you to the question and then click answer and it takes you to the answer. The problem is that the mousepressed function i made for the answer button is still active when the round 1 game board is up so when you try to click the category 3 800 dollar question you actually are hitting the answer button for that question since its in the same location. So i know now that i could have simplified all of my coding and used arrays and create classes but i didnt at the time. so instead of startin over i wanted to know if there was an easy fix to basically make this game work without the mousePressed functions overlaying each other. if that makes any sense. I have been doing this for about 4 days now from just what i learned watching the coding train youtube channel. I have been having a hard time wrapping my head around coding this whole game since its my first project and i have only known about p5 for 4 days haha.

so you need logic:

if ( over( ) && ( state == 'x' ) ) { }

yea currently i dont have states coded in, i have been changing screens using if statements in function draw with variables so if var title is true then it shows the title screen. if board is true it shows the board

does not matter how you call it

if ( over( ) && r )   { }

yea, i have that code repeated multiple times for each of the clicks for the question squares and then for the answer rect but somehow they are still overlapping, i even set the if() to include !board so it shouldnt work when board is true. im thinking the reason its still working is because to get back to the board i have to set board back to true to get back to my board.
idk maybe i need to just redo the whole thing. im still just fuzzy on exactly how i would class everything and organize the arrays. then ontop of that still make it look on the nicer side for the family haha.