Checklists length and act accordingly

i want to make my jeopardy game able to load up as many questions and columns that you want without going into the code all together, could you give me some tips/solutions. i am open to any and all changes that you may suggest. Here is the code;

String[] Cat;

if (Cat.length()==1) {
  String[] C1Q;
}
if (Cat.length()==2) {
  String[] C2Q;
}
if (Cat.length()==3) {
  String[] C3Q;
}
if (Cat.length()==4) {
  String[] C4Q;
}
if (Cat.length()==5) {
  String[] C5Q;
}
if (Cat.length()==6) {
  String[] C6Q;
}
if (Cat.length()==7) {
  String[] C7Q;
}
if (Cat.length()==8) {
  String[] C8Q;
}
if (Cat.length==9) {
  String[] C9Q;
}
if (Cat.length()==10) {
  String[] C10Q;
}

PFont digits;  //brings in font name
IntList click;
int Q;
int C;
int c=0;
int x=0; 
int y=0;
int possScore=0;
int teem=1;
int attempt=1;
int t1Score=0;
int t2Score=0;
int ans=2;
int arrow=1;

void setup() {
  Cat=loadStrings("categories.txt");
  if (Cat.length()==1) {
    C1Q=loadStrings("C1Q.txt");
  }
  if (Cat.length()==2) {
    C2Q=loadStrings("C2Q.txt");
  }
  if (Cat.length()==3) {
    C3Q=loadStrings("C3Q.txt");
  }
  if (Cat.length()==4) {
    C4Q=loadStrings("C4Q.txt");
  }
  if (Cat.length()==5) {
    C5Q=loadStrings("C5Q.txt");
  }
  if (Cat.length()==6) {
    C1Q=loadStrings("C6Q.txt");
  }
  if (Cat.length()==7) {
    C2Q=loadStrings("C7Q.txt");
  }
  if (Cat.length()==8) {
    C3Q=loadStrings("C8Q.txt");
  }
  if (Cat.length()==9) {
    C4Q=loadStrings("C9Q.txt");
  }
  if (Cat.length()==10) {
    C5Q=loadStrings("C10Q.txt");
  }
  fullScreen();
  background(128, 128, 128);      //sets color to blue
  digits = loadFont("AvenirNext-Regular-25.vlw");  //brings in font
  textFont(digits);  //assines font to name
  click=new IntList();
  click.append(0);
  click.append(1);
  click.append(2);
  click.append(3);
  click.append(4);
  textAlign(CENTER);
}

void draw() {
  fill(128, 128, 128);
  stroke(0);
  rect(0, 0, width, height);
  if (x==0&&y==0) {
    gamebord();
  } else {
    Question();
  }
  fill(255, 213, 0);
  if (arrow==1) {
    text("<--", (width/2), 25);
  }
  text("Teem 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
  if (arrow==2) {
    text("-->", (width/2), 25);
  }
  text("Teem 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
}

void gamebord() {
  fill (0);
  rect(45, 45, width-90, height-90);  //makes fields
  for (int i=0; i<Cat.length(); i++)   //sets x positions
  {
    for (int j=0; j<C1Q.length(); j++) //sets y positions
    {
      fill(6, 12, 233);
      stroke(0);
      rect((j*((width-100)/Cat.length()))+55, (i*((height-100)/C1Q.length()))+55, (width/Cat.length())-30, (height/C1Q.length())-30);  //makes tiles 
      noStroke();
      if (convert(i, j)!=30) {
        if (!click.hasValue(convert(i, j))) {
          fill(255, 213, 0);
          text(i, (j*((width-100)/Cat.length()))+(width/8), (i*((height-100)/C1Q.length()))+(height/7));//puts numbers on tiles
        } else {
          fill(255, 213, 0);
          text(Cat[j], (j*((width-100)/Cat.length()))+(width/8), (0*((height-100)/C1Q.length()))+(height/7));
        }
      }
    }
  }
}

int convert(int row, int col) {
  return (row*Cat.length())+col;
}

int question(int row,int col){
  return ;
}

void Question() {
  fill(6, 12, 233);
  rect(45, 45, width-90, height-90);
  fill(255);
  if (x==0) {
    if (y==1) {
      q=0;
      possScore=1;
    }
    if (y==2) {
      q=1;
      possScore=2;
    }
    if (y==3) {
      q=2;
      possScore=3;
    }
    if (y==4) {
      q=3;
      possScore=4;
    }
    if (y==5) {
      q=4;
      possScore=5;
    }
    text(C1Q[q], width/2, height/2);
  }
  if (x==1) {
    if (y==1) {
      q=0;
      possScore=1;
    }
    if (y==2) {
      q=1;
      possScore=2;
    }
    if (y==3) {
      q=2;
      possScore=3;
    }
    if (y==4) {
      q=3;
      possScore=4;
    }
    if (y==5) {
      q=4;
      possScore=5;
    }
    text(C2Q[q], width/2, height/2);
  }
  if (x==2) {
    if (y==1) {
      q=0;
      possScore=1;
    }
    if (y==2) {
      q=1;
      possScore=2;
    }
    if (y==3) {
      q=2;
      possScore=3;
    }
    if (y==4) {
      q=3;
      possScore=4;
    }
    if (y==5) {
      q=4;
      possScore=5;
    }
    text(C3Q[q], width/2, height/2);
  }
  if (x==3) {
    if (y==1) {
      q=0;
      possScore=1;
    }
    if (y==2) {
      q=1;
      possScore=2;
    }
    if (y==3) {
      q=2;
      possScore=3;
    }
    if (y==4) {
      q=3;
      possScore=4;
    }
    if (y==5) {
      q=4;
      possScore=5;
    }
    text(C4Q[q], width/2, height/2);
  }
  if (x==4) {
    if (y==1) {
      q=0;
      possScore=1;
    }
    if (y==2) {
      q=1;
      possScore=2;
    }
    if (y==3) {
      q=2;
      possScore=3;
    }
    if (y==4) {
      q=3;
      possScore=4;
    }
    if (y==5) {
      q=4;
      possScore=5;
    }
    text(C5Q[q], width/2, height/2);
  }
  q=10;
  score();
}

void score() {
  if (teem==1) {
    if (attempt==1) {
      if (ans==3) {
        t1Score+=possScore;
        possScore=0;
        attempt=1;
        teem=2;
        arrow=2;
        ans=2;
        click.append(convert(y, x));
        click.sort();
        c=0;
        x=0;
        y=0;
      }
      if (ans==1) {
        attempt=2;
        teem=2;
        arrow=2;
      }
    }
    if (attempt==2) {
      if (ans==2) {
        t2Score+=possScore;
        possScore=0;
        attempt=1;
        ans=2;
        click.append(convert(y, x));
        click.sort();
        c=0;
        x=0;
        y=0;
      }
      if (ans==0) {
        possScore=0;
        attempt=1;
        ans=2;
        c=0;
        x=0;
        y=0;
      }
    }
  }
  if (teem==2) {
    if (attempt==1) {
      if (ans==3) {
        t2Score+=possScore;
        possScore=0;
        attempt=1;
        teem=1;
        arrow=1;
        ans=2;
        click.append(convert(y, x));
        click.sort();
        c=0;
        x=0;
        y=0;
      }
      if (ans==1) {
        attempt=2;
        teem=1;
        arrow=1;
      }
    }
    if (attempt==2) {
      if (ans==2) {
        t1Score+=possScore;
        possScore=0;
        attempt=1;
        ans=2;
        click.append(convert(y, x));
        click.sort();
        c=0;
        x=0;
        y=0;
      }
      if (ans==0) {
        possScore=0;
        attempt=1;
        ans=2;
        c=0;
        x=0;
        y=0;
      }
    }
  }
}

void mouseReleased() //moves tiles when mouse is relessed
{
  int row = (mouseY-55)/((height-100)/C1Q.length());
  int col = (mouseX-50)/((width-100)/Cat.length());
  if (!click.hasValue(convert(row, col))&&c!=1) {
    c=1;
    x=col;
    y=row;
  }
}

void keyPressed() {
  if (key=='y'||key=='Y') {
    ans+=1;
  }
  if (key=='n'||key=='N') {
    ans-=1;
  }
  if (key=='r'||key=='R') {
    click.clear();
    t1Score=0;
    t2Score=0;
    teem=1;
    arrow=1;
    click.append(0);
    click.append(1);
    click.append(2);
    click.append(3);
    click.append(4);
  }
}
Tagged:

Answers

  • sorry, don't know how to use markdowns yet

  • it's pretty easy

    go back edit your post: click on the gear and on "Edit"

    then empty line before and after the code

    select entire code with the mouse

    hit ctrl-o

  • edited November 2017

    I don't think that code ever ran, did it?

    Did you ever run your code?

    It's better to make the code runnable first and work from there. Otherwise errors accumulate.

    Remarks:

    this can't be outside a function I guess:

     if (Cat.length()==1) { String[] C1Q; } if (Cat.length()==2) { String[] C2Q; } 
     if (Cat.length()==3) { String[] C3Q; } if (Cat.length()==4) { String[] C4Q; }
     if (Cat.length()==5) { String[] C5Q; } if (Cat.length()==6) { String[] C6Q; }
     if (Cat.length()==7) { String[] C7Q; } if (Cat.length()==8) { String[] C8Q; } 
     if (Cat.length==9) { String[] C9Q; } if (Cat.length()==10) { String[] C10Q; }
    

    the function question() won't work:

    int question(int row, int col) { 
      return ; // ????????????????????????????????????????????????
    }
    

    in the function Question() { you have a variable q but it's declared as Q (capital)

    This : Cat.length() must be Cat.length without () (the version of length with () is for the length of Strings, but you try to use it for an array String[] Cat;). Same for C1Q.length etc. etc.

    Remark

    We can't run your code, because we don't have the files "categories.txt", "C1Q.txt" etc....

    just post the content of "categories.txt" and "C1Q.txt" so we can run it

    Bigger issues

    This is not a good data structure:

    String[] C1Q;
    String[] C2Q;
    String[] C3Q;
    String[] C4Q;
    String[] C5Q;
    String[] C6Q;
    String[] C7Q;
    String[] C8Q;
    String[] C9Q;
    String[] C10Q;
    

    instead use a 2Dimensional array: String[][] CQ; - see tutorials for that

    https://www.processing.org/tutorials/2darray/

    The function Question() { where you evaluate the grid of questions is not good.

    too much redundancy there. When you work with CQ[][] you can simplify

    I know, this sounds much but I can lead you through.

    Best, Chrisir

  • yes, i changed it though

  • i did fix the "teem" already

  • edited November 2017

    Thanks for formatting your initial post.

    The game field is fixed, isn't it?

    Jeopardy has always same number of columns and of rows, right?

    So if you don't have enough questions, leave the other fields empty?

    Question

    Do you load questions and answers?

  • edited November 2017

    yes, i have text documents that it pulls the questions and categories from them.

  • Can you post some content so we can run your code?

  • edited November 2017
        String[] C1Q;
        String[] C2Q;
        String[] C3Q;
        String[] C4Q;
        String[] C5Q;
        String[] Cat;
    
        PFont digits;  //brings in font name
        IntList click;
        int q;
        int c=0;
        int x=0; 
        int y=0;
        int possScore=0;
        int teem=1;
        int attempt=1;
        int t1Score=0;
        int t2Score=0;
        int ans=2;
        int arrow=1;
    
        void setup() {
          C1Q=loadStrings("C1Q.txt");
          C2Q=loadStrings("C2Q.txt");
          C3Q=loadStrings("C3Q.txt");
          C4Q=loadStrings("C4Q.txt");
          C5Q=loadStrings("C5Q.txt");
          Cat=loadStrings("categories.txt");
          fullScreen();
          background(128, 128, 128);      //sets color to blue
          digits = loadFont("AvenirNext-Regular-25.vlw");  //brings in font
          textFont(digits);  //assines font to name
          click=new IntList();
          click.append(0);
          click.append(1);
          click.append(2);
          click.append(3);
          click.append(4);
          textAlign(CENTER);
        }
    
        void draw() {
          fill(128, 128, 128);
          stroke(0);
          rect(0, 0, width, height);
          if (x==0&&y==0) {
            gamebord();
          } else {
            Question();
          }
          fill(255, 213, 0);
          if (arrow==1) {
            text("<--", (width/2), 25);
          }
          text("Teem 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
          if (arrow==2) {
            text("-->", (width/2), 25);
          }
          text("Teem 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
        }
    
        void gamebord() {
          fill (0);
          rect(45, 45, width-90, height-90);  //makes fields
          for (int i=0; i<6; i++)   //sets x positions
          {
            for (int j=0; j<5; j++) //sets y positions
            {
              fill(6, 12, 233);
              stroke(0);
              rect((j*((width-100)/5))+55, (i*((height-100)/6))+55, (width/5)-30, (height/6)-30);  //makes tiles 
              noStroke();
              if (convert(i, j)!=30) {
                if (!click.hasValue(convert(i, j))) {
                  fill(255, 213, 0);
                  text(i, (j*((width-100)/5))+(width/8), (i*((height-100)/6))+(height/7));//puts numbers on tiles
                } else {
                  fill(255, 213, 0);
                  text(Cat[j], (j*((width-100)/5))+(width/8), (0*((height-100)/6))+(height/7));
                }
              }
            }
          }
        }
    
        int convert(int row, int col) {
          return row*5+col;
        }
    
        void Question() {
          fill(6, 12, 233);
          rect(45, 45, width-90, height-90);
          fill(255);
          if (x==0) {
            if (y==1) {
              q=0;
              possScore=1;
            }
            if (y==2) {
              q=1;
              possScore=2;
            }
            if (y==3) {
              q=2;
              possScore=3;
            }
            if (y==4) {
              q=3;
              possScore=4;
            }
            if (y==5) {
              q=4;
              possScore=5;
            }
            text(C1Q[q], width/2, height/2);
          }
          if (x==1) {
            if (y==1) {
              q=0;
              possScore=1;
            }
            if (y==2) {
              q=1;
              possScore=2;
            }
            if (y==3) {
              q=2;
              possScore=3;
            }
            if (y==4) {
              q=3;
              possScore=4;
            }
            if (y==5) {
              q=4;
              possScore=5;
            }
            text(C2Q[q], width/2, height/2);
          }
          if (x==2) {
            if (y==1) {
              q=0;
              possScore=1;
            }
            if (y==2) {
              q=1;
              possScore=2;
            }
            if (y==3) {
              q=2;
              possScore=3;
            }
            if (y==4) {
              q=3;
              possScore=4;
            }
            if (y==5) {
              q=4;
              possScore=5;
            }
            text(C3Q[q], width/2, height/2);
          }
          if (x==3) {
            if (y==1) {
              q=0;
              possScore=1;
            }
            if (y==2) {
              q=1;
              possScore=2;
            }
            if (y==3) {
              q=2;
              possScore=3;
            }
            if (y==4) {
              q=3;
              possScore=4;
            }
            if (y==5) {
              q=4;
              possScore=5;
            }
            text(C4Q[q], width/2, height/2);
          }
          if (x==4) {
            if (y==1) {
              q=0;
              possScore=1;
            }
            if (y==2) {
              q=1;
              possScore=2;
            }
            if (y==3) {
              q=2;
              possScore=3;
            }
            if (y==4) {
              q=3;
              possScore=4;
            }
            if (y==5) {
              q=4;
              possScore=5;
            }
            text(C5Q[q], width/2, height/2);
          }
          q=10;
          score();
        }
    
        void score() {
          if (teem==1) {
            if (attempt==1) {
              if (ans==3) {
                t1Score+=possScore;
                possScore=0;
                attempt=1;
                teem=2;
                arrow=2;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==1) {
                attempt=2;
                teem=2;
                arrow=2;
              }
            }
            if (attempt==2) {
              if (ans==2) {
                t2Score+=possScore;
                possScore=0;
                attempt=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==0) {
                possScore=0;
                attempt=1;
                ans=2;
                c=0;
                x=0;
                y=0;
              }
            }
          }
          if (teem==2) {
            if (attempt==1) {
              if (ans==3) {
                t2Score+=possScore;
                possScore=0;
                attempt=1;
                teem=1;
                arrow=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==1) {
                attempt=2;
                teem=1;
                arrow=1;
              }
            }
            if (attempt==2) {
              if (ans==2) {
                t1Score+=possScore;
                possScore=0;
                attempt=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==0) {
                possScore=0;
                attempt=1;
                ans=2;
                c=0;
                x=0;
                y=0;
              }
            }
          }
        }
    
        void mouseReleased() //moves tiles when mouse is relessed
        {
          int row = (mouseY-55)/((height-100)/6);
          int col = (mouseX-50)/((width-100)/5);
          if (!click.hasValue(convert(row, col))&&c!=1) {
            c=1;
            x=col;
            y=row;
          }
        }
    
        void keyPressed() {
          if (key=='y'||key=='Y') {
            ans+=1;
          }
          if (key=='n'||key=='N') {
            ans-=1;
          }
          if (key=='r'||key=='R') {
            click.clear();
            t1Score=0;
            t2Score=0;
            teem=1;
            arrow=1;
            click.append(0);
            click.append(1);
            click.append(2);
            click.append(3);
            click.append(4);
          }
        }
    
  • Does it run?

    text documents that it pulls the questions and categories from them.

    Could you post the content of categories.txt and some text documents that it pulls the questions and categories from ?

  • you can make the text documents with gibberish in them, the ones that i have are for spanish

  • are they like this (I know, Jeopardy provides answers but never mind):

    How far is the distance moon to earth? 
    When died George Washington?
    How old is the earth? 
    

    or are any answers / any other data included?

  • nope that's it

  • It looks great!

  • I wrote a lot to improve, but it already works and looks great!

    What are your questions?

  • i want to make it see how many categories and questions you have and act accordingly.

  • ah.

    So, when there are 3 categories in your text file, 3 columns and

    when there 2 questions have only 2 fields (or rows)?

    Please explain.

    Next question

    Do these represent different columns ?

      C1Q=loadStrings("C1Q.txt");
      C2Q=loadStrings("C2Q.txt");
      C3Q=loadStrings("C3Q.txt");
      C4Q=loadStrings("C4Q.txt");
      C5Q=loadStrings("C5Q.txt");
    

    Please explain what they do

    I have to go, see you

  • yes, i want the code to find the number of Columns and the number of questions and make the right questions go to the right columns. to your other question, C1Q=loadStrings("C1Q.txt"); that would be the first column questions and so on and so forth.

  • When you use loadStrings you get an array

    It’s length is in .length

    numCateg=....length;

    Calculate the width of one column by colWidth=width/ numCateg;

  • I did that, i still have the problem of pulling the questions.

  • What do you mean?

    When you click on a field, the question is displayed?

  • i have to cancel out the catagories

  • ??

    I still don’t understand.....

    In my opinion you need a state system for your sketch.

    Basically it tells you the situation the program is in. Like situation show grid, situation show question, receiving answer, give feedback etc.

    If you want me to I can probably provide a sketch for you

    Shall I?

  • Why not stick to the number of columns and rows in the game??

    Quote from Wikipedia::

    The Jeopardy! and Double Jeopardy! rounds each feature six categories, each of which contains five clues, which are ostensibly valued by difficulty.

  • Why don’t you try a full text file like

    Category 1, category 2, category 3, .......
    Question 1, question 2, question 3,.....
    Question 11, question 12, ...
    .....
    

    Then make a class Cell and a grid of that class (eg array or ArrayList or 2D array)

    See tutorials objects and two dimensional arrays

  • because i want to make it more user friendly and have as many categories or questions as they want.

  • edited November 2017 Answer ✓

    have as many categories or questions as they want.

    Then the game will take much longer. This is not user-friendly.

    I already explained how to do it though:

    • try a full text file like above

    • use String lines[] loadstrings(....................);

    • use length to evaluate number of rows

    • for loop over lines and use split to split at comma (String[] componentsInOneLine=split(lines[i]);)

    • use componentsInOneLine.length to evaluate number of cols.

    here is an example of a grid with a class

    // demo 
    
    // Array of objects of the class 
    Cell[] grid; 
    
    int cols = 4; 
    int rows = 6;
    
    void setup() { 
      size(400, 400); 
      grid = new Cell[cols*rows];
      int k=0; 
      for (int i = 0; i < cols; i++) { 
        for (int j = 0; j < rows; j++) { 
          // Initialize each object
          grid[k] = new Cell(i*20+22, j*20+22, 20, 20, k);
          k++;
        }
      }
    }
    
    void draw() { 
      background(0); 
      for (int i = 0; i < cols*rows; i++) { 
        grid[i].display();
      }
    }
    
    // =============================================
    
    // A Cell class 
    class Cell { 
      float x, y; // x,y location
      float w, h; // width and height 
      String text=""+char(int(random('a', 'z')));
      int tag;
    
      // Cell Constructor
      Cell(float tempX, float tempY, 
        float tempW, float tempH, 
        int tempTag) { 
        x = tempX; 
        y = tempY; 
        w = tempW; 
        h = tempH;
        tag= tempTag;
      }
    
      void display() { 
        stroke(255); 
        // Color 
        fill(0); 
        rect(x, y, w, h);
        fill(255);
        textAlign(CENTER, CENTER);
        text(text, 
          x+w/2, y+h/2);
      }
    }
    // 
    
  • i will try this, i am not as familiar with class

  • alright, i may be stupid but, how will i alter the cells to have categories on some and questions on the others? pls use this code for the demonstration.thx

  • edited November 2017
        String[] Cat;
        String[] Questions;
        PFont digits;  //brings in font name
        IntList click;
        int numC;
        int numQ;
        int Q;
        int C;
        int c=0;
        int x=0; 
        int y=0;
        int possScore=0;
        int team=1;
        int attempt=1;
        int t1Score=0;
        int t2Score=0;
        int ans=2;
        int arrow=1;
    
        void setup() {
          Cat=loadStrings("categories.txt");
          Questions=loadStrings("questions.txt");
          numC=Cat.length;
          numQ=((Questions.length)/numC);
          fullScreen();
          background(128, 128, 128);      //sets color to blue
          digits = loadFont("AvenirNext-Regular-25.vlw");  //brings in font
          textFont(digits);  //assines font to name
          click=new IntList();
          for (int i=0; i<numC; i++) {
            click.append(i);
          }
          textAlign(CENTER);
        }
    
        void draw() {
          fill(128, 128, 128);
          stroke(0);
          rect(0, 0, width, height);
          if (x==0&&y==0) {
            gamebord();
          } else {
            Question();
          }
          fill(255, 213, 0);
          if (arrow==1) {
            text("<--", (width/2), 25);
          }
          text("team 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
          if (arrow==2) {
            text("-->", (width/2), 25);
          }
          text("team 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
        }
    
        void gamebord() {
          fill (0);
          rect(45, 45, width-90, height-90);  //makes fields
          for (int i=0; i<numC; i++)   //sets x positions
          {
            for (int j=0; j<numQ; j++) //sets y positions
            {
              fill(6, 12, 233);
              stroke(0);
              rect((j*((width-100)/numC))+55, (i*((height-100)/numQ))+55, (width/numC)-30, (height/numQ)-30);  //makes tiles 
              noStroke();
              if (convert(i, j)!=Questions.length) {
                if (!click.hasValue(convert(i, j))) {
                  fill(255, 213, 0);
                  text(i, (j*((width-100)/numC))+(width/numQ+(numQ*1.25)), (i*((height-100)/numQ))+(height/(numC*1.25)));//puts numbers on tiles
                } else {
                  fill(255, 213, 0);
                  text(Cat[j], (j*((width-100)/numC))+(width/(numQ*1.25)), (0*((height-100)/numQ))+(height/(numC*1.25)));//puts words on the tiles
                }
              }
            }
          }
        }
    
        int convert(int row, int col) {
          return (row*numC)+col;
        }
    
        int question(int row, int col) {
          int p=(row*numC)+col;
          int m=0;
    
          for (int i=1; i<=numC; i++) {
            if (p==numC*i) {
              m+=1;
            }
          }
          p+=m;
          println(p);
          return p;
        }
    
        void Question() {
          fill(6, 12, 233);
          rect(45, 45, width-90, height-90);
          fill(255);
          text(Questions[question(y, x)], width/2, height/2);
          possScore=y;
          score();
        }
    
        void score() {
          if (team==1) {
            if (attempt==1) {
              if (ans==3) {
                t1Score+=possScore;
                possScore=0;
                attempt=1;
                team=2;
                arrow=2;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==1) {
                attempt=2;
                team=2;
                arrow=2;
              }
            }
            if (attempt==2) {
              if (ans==2) {
                t2Score+=possScore;
                possScore=0;
                attempt=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==0) {
                possScore=0;
                attempt=1;
                ans=2;
                c=0;
                x=0;
                y=0;
              }
            }
          }
          if (team==2) {
            if (attempt==1) {
              if (ans==3) {
                t2Score+=possScore;
                possScore=0;
                attempt=1;
                team=1;
                arrow=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==1) {
                attempt=2;
                team=1;
                arrow=1;
              }
            }
            if (attempt==2) {
              if (ans==2) {
                t1Score+=possScore;
                possScore=0;
                attempt=1;
                ans=2;
                click.append(convert(y, x));
                click.sort();
                c=0;
                x=0;
                y=0;
              }
              if (ans==0) {
                possScore=0;
                attempt=1;
                ans=2;
                c=0;
                x=0;
                y=0;
              }
            }
          }
        }
    
        void mouseReleased() //moves tiles when mouse is relessed
        {
          int row = (mouseY-55)/((height-100)/numQ);
          int col = (mouseX-50)/((width-100)/numC);
          if (!click.hasValue(convert(row, col))&&c!=1) {
            c=1;
            x=col;
            y=row;
          }
        }
    
        void keyPressed() {
          if (key=='y'||key=='Y') {
            ans+=1;
          }
          if (key=='n'||key=='N') {
            ans-=1;
          }
          if (key=='r'||key=='R') {
            click.clear();
            t1Score=0;
            t2Score=0;
            team=1;
            arrow=1;
            for (int i=0; i<numC; i++) {
              click.append(i);
            }
          }
        }
    
  • Show your attempt

    Have you read the two links?

    Basically you put the String answer and question and point into the class

  • edited November 2017

    i did try, i wanted to compare what i did and what you were thinking. at the moment i am having problems with the uploading and checking the questions and categories. here is what i have so far that works sometimes;

            PFont digits;
            Cell[] grid;
            String[] Cat;
            String[] Questions;
            int numQ;
            int cols; 
            int rows;
            IntList click;
            IntList categories;
            int Q;
            int C;
            int c=0;
            int x=0; 
            int y=0;
            int possScore=0;
            int team=1;
            int attempt=1;
            int t1Score=0;
            int t2Score=0;
            int ans=2;
            int arrow=1;
    
            void setup() { 
              fullScreen();;
              background(128, 128, 128);
              grid = new Cell[cols*rows];
              click=new IntList();
              categories=new IntList();
              Cat=loadStrings("categories.txt");
              Questions=loadStrings("questions.txt");
              rows=Cat.length;
              cols=(Questions.length)/rows;
              numQ=Questions.length;
              digits = loadFont("AvenirNext-Regular-25.vlw");  //brings in font
              textFont(digits, (width/(cols*rows))/1.5);  //assines font to name
              int k=0;
              for (int i = 0; i < cols; i++) { 
                for (int j = 0; j < rows; j++) { 
                if (j==0) {
                    categories.append(k);
                    grid[k] = new Cell((i*((width-100)/cols))+55, (j*((height-100)/rows))+55, (width/cols)-30, (height/rows)-30, k, Cat[i]);
                  } else {
                    grid[k] = new Cell((i*((width-100)/cols))+55, (j*((height-100)/rows))+55, (width/cols)-30, (height/rows)-30, k, " "+j+" ");
                  }
                  k++;
                }
              }
              textAlign(CENTER);
            }
    
            void draw() {
              background(128, 128, 128); 
              fill(0);
              if (x==0&&y==0) {
                gamebord();
              } else {
                Question();
              }
              fill(255, 213, 0);
              if (arrow==1) {
                text("<--", (width/2), 25);
              }
              text("team 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
              if (arrow==2) {
                text("-->", (width/2), 25);
              }
              text("team 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
            }
    
            int convert(int row, int col) {
              return (col*rows)+row;
            }
    
            void mouseReleased() //moves tiles when mouse is relessed
            {
              int row = (mouseY-55)/((height-100)/rows);
              int col = (mouseX-50)/((width-100)/cols);
              int p=convert(row, col);
              if (!click.hasValue(p)&&!categories.hasValue(p)&&c!=1&&(row*col)<30) {
                c=1;
                x=col;
                y=row;
              }
            }
    
            void keyPressed() {
              if (key=='y'||key=='Y') {
                ans+=1;
              }
              if (key=='n'||key=='N') {
                ans-=1;
              }
              if (key=='r'||key=='R') {
                click.clear();
                t1Score=0;
                t2Score=0;
                team=1;
                arrow=1;
              }
            }
    
            void gamebord() {
              rect(45, 45, width-90, height-90);
              for (int i = 0; i < cols*rows; i++) { 
                grid[i].display();
              }
            }
    
            void Question() {
              fill(6, 12, 233);
              rect(45, 45, width-90, height-90);
              fill(255);
              text(Questions[convert(y, x)], width/2, height/2);
              possScore=y;
              score();
            }
    
            void score() {
              if (team==1) {
                if (attempt==1) {
                  if (ans==3) {
                    t1Score+=possScore;
                    possScore=0;
                    attempt=1;
                    team=2;
                    arrow=2;
                    ans=2;
                    click.append(convert(y, x));
                    click.sort();
                    c=0;
                    x=0;
                    y=0;
                  }
                  if (ans==1) {
                    attempt=2;
                    team=2;
                    arrow=2;
                  }
                }
                if (attempt==2) {
                  if (ans==2) {
                    t2Score+=possScore;
                    possScore=0;
                    attempt=1;
                    ans=2;
                    click.append(convert(y, x));
                    click.sort();
                    c=0;
                    x=0;
                    y=0;
                  }
                  if (ans==0) {
                    possScore=0;
                    attempt=1;
                    ans=2;
                    c=0;
                    x=0;
                    y=0;
                  }
                }
              }
              if (team==2) {
                if (attempt==1) {
                  if (ans==3) {
                    t2Score+=possScore;
                    possScore=0;
                    attempt=1;
                    team=1;
                    arrow=1;
                    ans=2;
                    click.append(convert(y, x));
                    click.sort();
                    c=0;
                    x=0;
                    y=0;
                  }
                  if (ans==1) {
                    attempt=2;
                    team=1;
                    arrow=1;
                  }
                }
                if (attempt==2) {
                  if (ans==2) {
                    t1Score+=possScore;
                    possScore=0;
                    attempt=1;
                    ans=2;
                    click.append(convert(y, x));
                    click.sort();
                    c=0;
                    x=0;
                    y=0;
                  }
                  if (ans==0) {
                    possScore=0;
                    attempt=1;
                    ans=2;
                    c=0;
                    x=0;
                    y=0;
                  }
                }
              }
            }
    
            // =============================================
    
            // A Cell class 
            class Cell { 
              float x, y; // x,y location
              float w, h; // width and height 
              int tag;
              String text;
    
              // Cell Constructor
              Cell(float tempX, float tempY, 
                float tempW, float tempH, 
                int tempTag, String num) { 
                x = tempX; 
                y = tempY; 
                w = tempW; 
                h = tempH;
                tag= tempTag;
                text=num;
              }
    
              void display() { 
                fill(6, 12, 233);
                stroke(0);
                rect(x, y, w, h);
                if (!click.hasValue(tag)) {
                  fill(255, 213, 0);
                  textAlign(CENTER);
                  text(text, x+w/2, y+h/2);
                }
              }
            }
    
  • P.S. if you have a better way of doing the void score(), pls help. it is vary long and doesn't work at times.

  • that's how far I got

    main changes:

    a state system as described above: you know on which screen you are

    the class Cell has more stuff in it; especially also the text for the categories and questions

    I got rid of some IntList (click etc.) and integrated it in the class as well (the cell knows now whether it's a category or not and whether it's been clicked or not)

    Chrisir

    // https : // forum.processing.org/two/discussion/comment/109696#Comment_109696
    
    PFont digits;
    
    Cell[] grid;
    
    int cols; 
    int rows;
    
    final int stateGameBoard=0;
    final int stateQuestion=1;
    int state= stateGameBoard; 
    
    //int c=0;   // what is c ????
    int x=0; 
    int y=0;
    
    int possScore=0;
    int team=1;
    int attempt=1;
    int t1Score=0;
    int t2Score=0;
    int ans=2;
    int arrow=1;
    
    // -----------------------------------------------------------------------------
    // CORE functions
    
    void setup() { 
      fullScreen();
      background(128, 128, 128);
    
      // the loading : 
      loadData();
    
      digits = createFont("AvenirNext-Regular-25.vlw", 12);  //brings in font
      //  textFont(digits, (width/(cols*rows))/1.5);  //assines font to name
      textFont(digits, 14);  //assines font to name
      textAlign(CENTER);
    }
    
    void draw() {
    
      // depending on state 
      switch (state) { 
    
      case stateGameBoard:
    
        background(128, 128, 128); 
        fill(0);
        gameboard();
        fill(255, 213, 0);
        if (arrow==1) {
          text("<--", (width/2), 25);
        } else if (arrow==2) {
          text("-->", (width/2), 25);
        }
        text("team 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
        text("team 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
    
        break; 
    
      case stateQuestion: 
        background(128, 128, 128); 
        fill(0);
        Question();
        break;
        //
      }//switch
      //
    }//func 
    
    
    // ----------------------------------------------------------------------------
    // Input functions
    
    void mousePressed() {
    
      // depending on state 
      switch (state) { 
    
      case stateGameBoard:
    
        //moves tiles when mouse is pressed (released)
        int row = (mouseY-55)/((height-100)/rows);
        int col = (mouseX-50)/((width-100)/cols);
        int p=convert(row, col);
        Cell currentCell=grid[p];
    
        if (!currentCell.hasBeenClicked &&
          !currentCell.isCategory &&
          (row*col)<30  ) {  // why   (row*col)<30   ???????
          //   c=1;
          x=col;
          y=row;
          state=stateQuestion;
          currentCell.hasBeenClicked=true;
        }//if
        break; 
    
      case stateQuestion: 
        state=stateGameBoard;
        break;
      } //switch 
      //
    } //func 
    
    void keyPressed() {
    
      // depending on state 
      switch (state) { 
    
      case stateGameBoard:
    
        if (key=='y'||key=='Y') {
          ans+=1;
        } else if (key=='n'||key=='N') {
          ans-=1;
        } else if (key=='r'||key=='R') {
          //  click.clear();
          t1Score=0;
          t2Score=0;
          team=1;
          arrow=1;
        }  // if...else if...
        break; 
    
      case stateQuestion:
        if (key==' ') {
          state=stateGameBoard;
        }//if   
        break;
      } //switch 
      //
    } //func 
    
    // -----------------------------------------------------------------
    // other functions 
    
    void gameboard() {
      rect(45, 45, width-90, height-90);
      for (int i = 0; i < cols*rows; i++) { 
        grid[i].display();
      }
    }
    
    int convert(int row, int col) {
      return (col*rows)+row;
    }
    
    void Question() {
      fill(6, 12, 233);
      rect(45, 45, width-90, height-90);
      fill(255);
      // text(Questions[convert(y, x)], width/2, height/2);
      text(grid[convert(y, x)].question, width/2, height/2);
      text("Hit space to go back ", width/2, height-133);
      possScore=y;
      score();
    }
    
    void score() {
      if (team==1) {
        if (attempt==1) {
          if (ans==3) {
            t1Score+=possScore;
            possScore=0;
            attempt=1;
            team=2;
            arrow=2;
            ans=2;
    
            //c=0;
            x=0;
            y=0;
          }
          if (ans==1) {
            attempt=2;
            team=2;
            arrow=2;
          }
        }
        if (attempt==2) {
          if (ans==2) {
            t2Score+=possScore;
            possScore=0;
            attempt=1;
            ans=2;
    
            //c=0;
            x=0;
            y=0;
          }
          if (ans==0) {
            possScore=0;
            attempt=1;
            ans=2;
            //c=0;
            x=0;
            y=0;
          }
        }
      }
      if (team==2) {
        if (attempt==1) {
          if (ans==3) {
            t2Score+=possScore;
            possScore=0;
            attempt=1;
            team=1;
            arrow=1;
            ans=2;
    
            //c=0;
            x=0;
            y=0;
          }
          if (ans==1) {
            attempt=2;
            team=1;
            arrow=1;
          }
        }
        if (attempt==2) {
          if (ans==2) {
            t1Score+=possScore;
            possScore=0;
            attempt=1;
            ans=2;
    
            //c=0;
            x=0;
            y=0;
          }
          if (ans==0) {
            possScore=0;
            attempt=1;
            ans=2;
            //c=0;
            x=0;
            y=0;
          }
        }
      }
    }
    void loadData() {
      String[] Cat;
      String[] Questions;
    
      Cat=loadStrings("categories.txt");
      cols = Cat.length;  
    
      Questions=loadStrings("questions.txt");
      int QuestionsNumberOfCol = split(Questions[0], ',').length;
    
      // validate: categories against questions
      if (cols != QuestionsNumberOfCol) {
        println ("Number of Categories does not match the number of columns of the questions");
        exit();
        return;
      } 
    
      // preparation: 
      // distribute questions on grid of questions 
      // QuestionsGrid is a 2D grid, but the first index is Y, then X
      String[][]QuestionsGrid = new String [ Questions.length ] [ QuestionsNumberOfCol ]  ;
      // loop over lines 
      for (int i = 0; i < Questions.length; i++) { 
        QuestionsGrid[i] = split(Questions[i], ',');
        println ("Line "
          +i
          +": ");
        printArray(QuestionsGrid[i]);
        // validate: questions must be the same numbers in every row
        if ( QuestionsGrid[i].length != QuestionsNumberOfCol ) {
          println ("\n\nNumber of columns of the questions is not always the same: Line: "+i+". Program terminates. #########");
          exit();
          return;
        }
      }
    
      // ???????????????????????????????
      // rows=Cat.length;
      // cols=(Questions.length)/rows;
    
      rows =  Questions.length+1; 
    
      grid = new Cell[cols*rows];
    
      int k=0;
      for (int i = 0; i < cols; i++) { // X
        for (int j = 0; j < rows; j++) {  // Y
          if (j==0) {
            // we enter a category into the grid
            grid[k] = new Cell((i*((width-33)/cols))+55, (j*((height-45)/rows))+55, (width/cols)-66, (height/rows)-30, k, Cat[i], "", true);
          } else {
            // we enter a Question into the grid (swappng x and y for QuestionsGrid since QuestionsGrid is [y][x])
            grid[k] = new Cell((i*((width-33)/cols))+55, (j*((height-45)/rows))+55, (width/cols)-66, (height/rows)-30, k, " "+j+" ", QuestionsGrid[j-1] [i], false );
          }
          k++;
        }
      }
    }
    
    // =============================================
    
    // A Cell class 
    class Cell { 
      float x, y; // x,y location
      float w, h; // width and height 
    
      int tag;
    
      String text; // text for cell is closed
      String question="";
    
      // flags 
      boolean isCategory=false; 
      boolean hasBeenClicked=false; 
    
      // Cell Constructor
      Cell(float tempX, float tempY, 
        float tempW, float tempH, 
        int tempTag, 
        String num, 
        String tempQuestion, 
        boolean tempisCategory) { 
        x = tempX; 
        y = tempY; 
        w = tempW; 
        h = tempH;
        tag= tempTag;
        text=num;
        question =  tempQuestion;
        isCategory=tempisCategory;
      }
    
      void display() { 
        fill(6, 12, 233);
        stroke(0);
        rect(x, y, w, h);
        //if (!click.hasValue(tag)) {
        fill(255, 213, 0);
        textAlign(CENTER);
        textSize(12);
        String strHasBeenClicked = "";
        if (hasBeenClicked)
          strHasBeenClicked=" (X)";
        text(text+strHasBeenClicked, x+w/2, y+h/2);
        //}
      }
    }
    //
    
  • could you show me what you save for the categories and questions. i am trying to run the code and i am having a little trouble with the way i do it; categories.txt:Close 1;Close 2;Close 3;Questions;Miscellaneous; questions.txt:The word is, Coat.;The word is, Blouse.;The word is Boots.;The word is, Socks.;The word is, Shirt.;The word is, T-Shirt.;The word is, Jacket.;The word is, Skirt.;The word is, Cap.;The word is, Jeans.;The word is, Pants.;The word is, Shorts.;The word is, Sweat Shirt.;The word is, Sweater.;The word is, Suit.;The phrase is, How Can I Help You.;The phrase is, How Dose It Fit.;The phrase is, It Fits Well.;The phrase is, It Fits Poorly.;The phrase is, How Much.;The word is, Both.;The word is, his.;The word is, These.;The word is, That.;The phrase is, Excuse Me.;;=enter key, sorry the thing won't allow extra lines

  • edited November 2017

    P.S,

    int c=0;

    is checking if the mouse has been pressed, i made it up on the fly to stop the user from accidentally clicking somewhere on the screen and it change questions.

  • nevermind about this question, i figured it out.

    could you show me what you save for the categories and questions. i am trying to run the code and i am having a little trouble with the way i do it;

  • edited November 2017

    i realize that i have gone all this time without saying thank you for what you have done for me. So... Thank you Thank you Thank you

  • one test data was

    categories

    State
    Rhyme
    

    and questions

    Col 0 Question 0,Col 1 Question 0
    Col 0 Question 1,Col 1 Question 1
    Col 0 Question 2,Col 1 Question 2
    Col 0 Question 3,Col 1 Question 3
    Col 0 Question 4,Col 1 Question 2
    Col 0 Question 3,Col 1 Question 3
    Col 0 Question 4,Col 1 Question 2
    Col 0 Question 5,Col 1 Question 3
    Col 0 Question 5,Col 1 Question 3
    

    as you can see, as many columns in file questions as we have categories.

    as you can see, same amount of columns in each line in file questions

    both is mandatory

    other set:

    State
    Rhyme
    President
    Coins
    Wars
    Religions
    

    and

    Col 0 Question 0,Col 1 Question 0,Col 2 Question 0,Col 3 Question 0,Col 4 Question 0,A
    Col 0 Question 1,Col 1 Question 1,Col 2 Question 1,Col 3 Question 1,Col 4 Question 1,V 
    Col 0 Question 2,Col 1 Question 2,Col 2 Question 2,Col 3 Question 2,Col 4 Question 2,C
    Col 0 Question 3,Col 1 Question 3,Col 2 Question 3,Col 3 Question 3,Col 4 Question 3,h
    Col 0 Question 4,Col 1 Question 2,Col 2 Question 2,Col 3 Question 2,Col 4 Question 2,he
    Col 0 Question 3,Col 1 Question 3,Col 2 Question 3,Col 3 Question 3,Col 4 Question 3,x
    Col 0 Question 4,Col 1 Question 2,Col 2 Question 2,Col 3 Question 2,Col 4 Question 2,w
    Col 0 Question 5,Col 1 Question 3,Col 2 Question 3,Col 3 Question 3,Col 4 Question 3,1
    Col 0 Question 5,Col 1 Question 3,Col 2 Question 3,Col 3 Question 3,Col 4 Question 3,x
    
  • both pairs of files should work, but you can't mix them

  • edited November 2017

    thanks, i have got it to work, here is the code for finished product :

                PFont digits;
    
                Cell[] grid;
    
                int cols; 
                int rows;
    
                final int stateGameBoard=0;
                final int stateQuestion=1;
                int state= stateGameBoard; 
                final int team1=0;
                final int team2=1;
                int team=team1;
    
                int p;
                int x=0; 
                int y=0;
                int attempt=1;
                int possScore=0;
                int t1Score=0;
                int t2Score=0;
                int ans=2;
                int arrow=1;
    
                // -----------------------------------------------------------------------------
                // CORE functions
    
                void setup() { 
                  fullScreen();
                  background(128, 128, 128);
    
                  // the loading : 
                  loadData();
    
                  digits = createFont("AvenirNext-Regular-25.vlw", 12);  //brings in font
                  //  textFont(digits, (width/(cols*rows))/1.5);  //assines font to name
                  textFont(digits, (width/(cols*rows))/1.5);  //assines font to name
                  textAlign(CENTER);
                }
    
                void draw() {
    
                  // depending on state 
                  switch (state) { 
    
                  case stateGameBoard:
    
                    background(128, 128, 128); 
                    fill(0);
                    gameboard();
                    break; 
                  case stateQuestion: 
                    background(128, 128, 128); 
                    fill(0);
                    Question();
                    break;
                    //
                  }//switch
                  textSize((width/(cols*rows))/1.5);
                  fill(255, 213, 0);
                  switch(team) {
                  case team1:
                    text("<--", (width/2), 25);
                    break;
                  case team2:
                    text("-->", (width/2), 25);
                    break;
                  }
                  text("team 1= "+t1Score, (0*((width-100)/5))+(width/8), 25);
                  text("team 2= "+t2Score, (4*((width-100)/5))+(width/8), 25);
                  //
                }//func 
    
    
                // ----------------------------------------------------------------------------
                // Input functions
    
                void mouseReleased() {
    
                  // depending on state 
                  switch (state) { 
    
                  case stateGameBoard:
                    //moves tiles when mouse is pressed (released)
                    int row = (mouseY-55)/((height-100)/rows);
                    int col = (mouseX-50)/((width-100)/cols);
                    p=convert(row, col);
                    Cell currentCell=grid[p];
    
                    if (!currentCell.hasBeenClicked && !currentCell.isCategory) {
                      x=col;
                      y=row;
                      state=stateQuestion;
                    }//if
                    break;
                  } //switch 
                  //
                } //func 
    
                void keyReleased() {
                  // depending on state 
                  switch (state) { 
                  case stateQuestion:
                    if (key=='y'||key=='Y') {
                      ans+=1;
                    } else if (key=='n'||key=='N') {
                      ans-=1;
                    }
                    break;
    
                  case stateGameBoard:
                    if (key=='r'||key=='R') {
                      t1Score=0;
                      t2Score=0;
                      team=team1;
                      for (int i = 0; i < cols*rows; i++) { 
                        grid[i].hasBeenClicked=false;
                      }
                    }  // if...else if...
                    break;
                  } //switch 
                  //
                } //func 
    
                // -----------------------------------------------------------------
                // other functions 
    
                void gameboard() {
                  rect(45, 45, width-90, height-90);
                  for (int i = 0; i < cols*rows; i++) { 
                    grid[i].display();
                  }
                }
    
                int convert(int row, int col) {
                  return (col*rows)+row;
                }
    
                void Question() {
                  fill(6, 12, 233);
                  rect(45, 45, width-90, height-90);
                  fill(255);
                  textSize(grid[convert(y, x)].question.length()*2.5);
                  text(grid[convert(y, x)].question, width/2, height/2);
                  possScore=y;
                  score();
                }
    
                void score() {
                  switch(team) {
                  case team1:
    
                    if (attempt==1) {
                      if (ans==3) {
                        t1Score+=possScore;
                        possScore=0;
                        attempt=1;
                        team=team2;
                        state=stateGameBoard;
                        grid[p].hasBeenClicked=true;
                        ans=2;
                        x=0;
                        y=0;
                      }
                      if (ans==1) {
                        attempt=2;
                        team=team2;
                        state=stateQuestion;
                      }
                    }
                    if (attempt==2) {
                      if (ans==2) {
                        t1Score+=possScore;
                        possScore=0;
                        attempt=1;
                        state=stateGameBoard;
                        grid[p].hasBeenClicked=true;
                        ans=2;
                        x=0;
                        y=0;
                      }
                      if (ans==0) {
                        possScore=0;
                        attempt=1;
                        ans=2;
                        state=stateGameBoard;
                        x=0;
                        y=0;
                      }
                    }
                    break;
    
                  case team2:
                    if (attempt==1) {
                      if (ans==3) {
                        t2Score+=possScore;
                        possScore=0;
                        attempt=1;
                        team=team1;
                        state=stateGameBoard;
                        grid[p].hasBeenClicked=true;
                        ans=2;
                        x=0;
                        y=0;
                      }
                      if (ans==1) {
                        attempt=2;
                        team=team1;
                        state=stateQuestion;
                      }
                    }
                    if (attempt==2) {
                      if (ans==2) {
                        t2Score+=possScore;
                        possScore=0;
                        attempt=1;
                        ans=2;
                        state=stateGameBoard;
                        grid[p].hasBeenClicked=true;
                        x=0;
                        y=0;
                      }
                      if (ans==0) {
                        possScore=0;
                        attempt=1;
                        state=stateGameBoard;
                        ans=2;
                        x=0;
                        y=0;
                      }
                    }
                    break;
                  }
                }
    
                void loadData() {
                  String[] Cat;
                  String[] Questions;
    
                  Cat=loadStrings("categories.txt");
                  cols = Cat.length;  
    
                  Questions=loadStrings("questions.txt");
                  int QuestionsNumberOfCol = split(Questions[0], ',').length;
    
                  // validate: categories against questions
                  if (cols != QuestionsNumberOfCol) {
                    println ("Number of Categories does not match the number of columns of the questions");
                    exit();
                    return;
                  } 
    
                  // preparation: 
                  // distribute questions on grid of questions 
                  // QuestionsGrid is a 2D grid, but the first index is Y, then X
                  String[][]QuestionsGrid = new String [ Questions.length ] [ QuestionsNumberOfCol ]  ;
                  // loop over lines 
                  for (int i = 0; i < Questions.length; i++) { 
                    QuestionsGrid[i] = split(Questions[i], ',');
                    println ("Line "+i+": ");
                    printArray(QuestionsGrid[i]);
                    // validate: questions must be the same numbers in every row
                    if ( QuestionsGrid[i].length != QuestionsNumberOfCol ) {
                      println ("\n\nNumber of columns of the questions is not always the same: Line: "+i+". Program terminates. #########");
                      exit();
                      return;
                    }
                  }
                  rows =  Questions.length+1; 
                  grid = new Cell[cols*rows];
                  int k=0;
                  for (int i = 0; i < cols; i++) { // X
                    for (int j = 0; j < rows; j++) {  // Y
                      if (j==0) {
                        // we enter a category into the grid
                        grid[k] = new Cell((i*((width-100)/cols))+55, (j*((height-100)/rows))+55, (width/cols)-30, (height/rows)-30, k, Cat[i], "", true);
                      } else {
                        // we enter a Question into the grid (swappng x and y for QuestionsGrid since QuestionsGrid is [y][x])
                        grid[k] = new Cell((i*((width-100)/cols))+55, (j*((height-100)/rows))+55, (width/cols)-30, (height/rows)-30, k, " "+j+" ", QuestionsGrid[j-1] [i], false );
                      }
                      k++;
                    }
                  }
                }
    
                // =============================================
    
                // A Cell class 
                class Cell { 
                  float x, y; // x,y location
                  float w, h; // width and height 
                  int tag;
                  String text; // text for cell is closed
                  String question="";// flags
                  boolean isCategory=false; 
                  boolean hasBeenClicked=false; // Cell Constructor
                  Cell(float tempX, float tempY, float tempW, float tempH, int tempTag, String num, String tempQuestion, boolean tempisCategory) { 
                    x = tempX; 
                    y = tempY; 
                    w = tempW; 
                    h = tempH;
                    tag= tempTag;
                    text=num;
                    question =  tempQuestion;
                    isCategory=tempisCategory;
                  }
    
                  void display() { 
                    fill(6, 12, 233);
                    stroke(0);
                    rect(x, y, w, h);
                    //if (!click.hasValue(tag)) {
                    fill(255, 213, 0);
                    textAlign(CENTER);
                    textSize((width/(cols*rows))/2);
                    if (!hasBeenClicked) {
                      text(text, x+w/2, y+h/2);
                    }
                    //}
                  }
                }
    
  • so, just out of curiosity, how would you have it open up another window with the errors of the println(error here);

  • what kind of errors are these, who will you show them to?

    The programmer (yourself) or the user/player?

    Because when it's the player, you should a message to him in the main window.

    you could also write a log file to the hard drive using saveStrings or so

    you can also open a 2nd window, maybe look at GUI libraries

  • for (int i = 0; i < Questions.length; i++) { QuestionsGrid[i] = split(Questions[i], ','); println ("Line "+i+": "); printArray(QuestionsGrid[i]); // validate: questions must be the same numbers in every row if ( QuestionsGrid[i].length != QuestionsNumberOfCol ) { println ("\n\nNumber of columns of the questions is not always the same: Line: "+i+". Program terminates. #########"); exit(); return; }

    have it on a new window instead of a println

  • That‘s terminating the program. So it’s a Message for the programmer not the player.

    Um.

    Make a new state and just display the message in the main window instead of the jeopardy grid?

Sign In or Register to comment.