We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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);
}
}
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
thanks
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:
the function
question()
won't work:in the function
Question() {
you have a variable q but it's declared asQ
(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 arrayString[] 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:
instead use a 2Dimensional array:
String[][] CQ;
- see tutorials for thathttps://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
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?
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?
Does it run?
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):
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 ?
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
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.
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 rowsfor 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
i will try this, i am not as familiar with
class
I just edited my post, it's better now. Hit F5 to get it.
there is a tutorial on classes / objects
https://github.com/Kango/Processing-snippets/wiki/Variables,-Arrays-and-object-oriented-programming
https://www.processing.org/tutorials/objects/
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
Show your attempt
Have you read the two links?
Basically you put the String answer and question and point into the class
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;
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 arethe 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
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
P.S,
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.
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
and questions
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:
and
both pairs of files should work, but you can't mix them
thanks, i have got it to work, here is the code for finished product :
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
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?
ok thx
ok