2 more step:
-c- for the canvas use a grid layout of ( 9 ) rectangles,
with some changed numbers can make it
9 by 1 | 1 by 9 | 3 by 3
as they have to be clicked it must be again a class
( i use my own example from
see / open >example
)
-d-
now the Set class need a show
start with just printing the info
card id, col , shape , num
later use it to select 3 colors, 3 shapes, 3 counts
-e- inside the 9 rectangles must now call
myrects[i].drawit(open[i]);
and inthere call:
sets[index].show();
might look like
example
// https://discourse.processing.org/t/make-the-game-called-sets/7761
// https://en.wikipedia.org/wiki/Set_(card_game)
// good question: random N out of M ( no repeat )
// v01 sets[27] with 3 int
// open[9] unique numbers 0 .. 26
// v02 selectable grid show
// sets vars
int m = 27, n = 9;
int[] open = new int[n];
MySet[] sets = new MySet[m];
// grid vars
int x = 20, y = x, w = 0, h = w; // w,h auto fit to canvas
int grid = 9, many = 9;//grid*grid; // many = n !
MyRect[] myrects= new MyRect[many];
class MySet {
int col;
int shape;
int num;
int id;
MySet(int col, int shape, int num, int id) {
this.col = col;
this.shape= shape;
this.num = num;
this.id = id;
}
void show(){
fill(0,0,0); // info
noStroke();
text(id+": "+col+","+shape+","+num,10,20);
int loop = 0, big =25;
if ( col == 0 ) fill(200,0,0);
if ( col == 1 ) fill(0,200,0);
if ( col == 2 ) fill(0,0,200);
if ( num == 0 ) loop = 1;
if ( num == 1 ) loop = 2;
if ( num == 2 ) loop = 3;
if ( shape == 0 ) for ( int i = 0; i < loop; i++ ) ellipse(w/2,h/4+30*i+big/2,big,big);
if ( shape == 1 ) for ( int i = 0; i < loop; i++ ) rect(w/2-big/2,h/4+30*i,big,big);
if ( shape == 2 ) for ( int i = 0; i < loop; i++ ) triangle(w/2-big/2, h/4+30*i, w/2,h/4+30*i+big, w/2+big/2,h/4+30*i);
}
}
class MyRect {
int x, y; //, w, h; from global
boolean selected=false;
MyRect (int x, int y) {
this.x = x;
this.y = y;
}
void drawit(int index) {
stroke(0, 0, 200);
if ( selected ) fill(200, 0, 200);
else fill(0, 200, 200);
rect(x, y, w, h);
// show cards in it
push();
translate(x,y);
sets[index].show();
pop();
}
boolean over() {
return( x < mouseX && mouseX < x+w && y < mouseY && mouseY < y+h );
}
void sel() {
if ( over() ) {
if ( selected && mousePressed && mouseButton == RIGHT) selected=false;
if ( !selected && mousePressed && mouseButton == LEFT) selected=true;
}
}
}
void setup_grid() {
// use x,y,grid as master and auto adjust rectangles (w,h) to window:
w = ( width - 2 * x ) / grid;
h = ( height - 2 * y ) ;// / grid;
for (int i = 0; i < many; i++) myrects[i]=new MyRect(x+(i%grid)*w, y+(floor(i/grid))*h);
println("use: mouse LEFT to select, mouse RIGHT to deselect");
}
void draw_grid() {
for (int i = 0; i < many; i++) {
myrects[i].drawit(open[i]); // draw each rect with open cards
myrects[i].sel(); // check if mousebutton and over this for color
}
}
void setup_sets() {
println("sets: "+sets.length);
int c=0, s=0, n=0;
for (int i=0; i < m; i++) {
c=i%3; // 1+i%3;
s=floor(i/3)%3;
n=floor(i/9)%3; // +1
sets[i] = new MySet(c, s, n, i);
}
for (MySet set : sets) println("id "+nf(set.id, 2)+" col "+set.col+" shape "+set.shape+" num "+set.num);
}
void make_open() {
// function to create a array ( of n ) with random numbers ( 0 .. m ) ( no repeat )
IntList choice = new IntList();
for ( int i = 0; i < m; i++ ) choice.append(i);
choice.shuffle();
for ( int i = 0; i < n; i++ ) open[i]=choice.get(i);
println("i open "+n+" cards for you");
println(open);
}
void setup() {
size(800, 200);
setup_grid();
setup_sets();
make_open();
println("use: key [s] for reshuffle");
}
void draw() {
background(200, 200, 0);
draw_grid();
}
void keyPressed() {
if ( key == 's' ) make_open(); // reshuffle
}
i have no intention to make a GAME out of it,
( you say you have a game “framework” already )
but anyhow can not think of further feature ( memory … )
of the array sets, as the creation / and the draw job is so easy
so i replace it just by a function
sets_show(int id)
pls find:
example v03
// https://discourse.processing.org/t/make-the-game-called-sets/7761
// https://en.wikipedia.org/wiki/Set_(card_game)
// v01 sets[27] with 3 int
// open[9] unique numbers 0 .. 26
// v02 selectable grid show
// v03 obviously the sets array of MySet is a dummy as it can be created easy, is not changed and has no further job as MEMORY, make
// sets_show(index);
// deselect all at reshuffle
// sets vars
int m = 27, n = 9;
int[] open = new int[n];
// grid vars
int x = 20, y = x, w = 0, h = w; // w,h auto fit to canvas
int grid = n, many = grid * 1;//grid*grid; // many = n !
MyRect[] myrects= new MyRect[many];
// v03
void sets_show(int id) {
int big =25, col, shape, num;
// make the set
col = id%3;
shape = floor(id/3)%3;
num = floor(id/9)%3;
// make the show
fill(0, 0, 0); // print info
noStroke();
text(id+": "+col+","+shape+","+num, 10, 20);
if ( col == 0 ) fill(200, 0, 0);
else if ( col == 1 ) fill(0, 200, 0);
else if ( col == 2 ) fill(0, 0, 200);
for ( int i = 0; i <= num; i++ ) {
if ( shape == 0 ) ellipse(w/2, h/4+30*i+big/2, big, big);
else if ( shape == 1 ) rect(w/2-big/2, h/4+30*i, big, big);
else if ( shape == 2 ) triangle(w/2-big/2, h/4+30*i, w/2, h/4+30*i+big, w/2+big/2, h/4+30*i);
}
}
class MyRect {
int x, y; //, w, h; from global
boolean selected=false;
MyRect (int x, int y) {
this.x = x;
this.y = y;
}
void drawit(int index) {
stroke(0, 0, 100);
if ( selected ) fill(0, 200, 200);
else fill(200, 200, 200);
rect(x, y, w, h);
push(); // show cards in it
translate(x, y);
sets_show(index); // index comes down from open[i] list
pop();
}
boolean over() {
return( x < mouseX && mouseX < x+w && y < mouseY && mouseY < y+h );
}
void sel() {
if ( over() ) {
if ( selected && mousePressed && mouseButton == RIGHT) selected=false;
if ( !selected && mousePressed && mouseButton == LEFT) selected=true;
}
}
void reset() {
selected=false;
}
}
void setup_grid() { // use x,y,grid as master and auto adjust rectangles (w,h) to window:
w = ( width - 2 * x ) / grid;
h = ( height - 2 * y ) ;// / grid; // here only one row
for (int i = 0; i < many; i++) myrects[i]=new MyRect(x+(i%grid)*w, y+(floor(i/grid))*h);
}
void draw_grid() {
for (int i = 0; i < many; i++) {
myrects[i].drawit(open[i]); // draw each rect with open cards
myrects[i].sel(); // check if mousebutton and over this for color
}
}
void make_open() { // function to create a array ( of n ) with random numbers ( 0 .. m ) ( no repeat )
IntList choice = new IntList();
for ( int i = 0; i < m; i++ ) choice.append(i);
choice.shuffle();
for ( int i = 0; i < n; i++ ) open[i]=choice.get(i); // just take first n of the shuffled list
println("shuffle and i open the first "+n+" cards ( out of "+m+" ) for you:");
for ( int i =0; i <n; i++) print(", "+open[i]);
println(": good luck !");
}
void setup() {
size(800, 200);
setup_grid();
println("use: mouse LEFT to select, mouse RIGHT to deselect");
println("use: key [s] for reshuffle");
make_open();
}
void draw() {
background(200, 200, 0);
draw_grid();
}
void keyPressed() {
if ( key == 's' ) {
make_open(); // reshuffle
for (int i = 0; i < many; i++) myrects[i].reset(); // v03
}
}
for test show all unshuffled