xxxxxxxxxx
193
// Trying to add functionality to select
// your own card
card=[];
BINGO="BINGO";
cellwidth=0;
cellheight=0;
hudsize=50; // Area for reset/ new buttons
var seed=0;
var cardnum=0;
var change=-1;
var input;
function setup() {
createCanvas(800, 800);
input=createInput()
input.position(width/2, height-40);
initializeCard();
cellwidth=(width-100)/5;
cellheight=(height-hudsize)/6
}
function draw() {
background(220);
showCard();
showButtons();
}
function touchStarted(){
// circle(width-30, ch-30, cellwidth-10);
//circle(25, ch-30, cellwidth-10);
if(dist(width-30, ch-30, mouseX, mouseY) < (cellwidth-10)/4)
{
for(c of card)
{
c.selected=false;
}
card[12].selected=true;
}
else if(dist(25, ch-30, mouseX, mouseY) < (cellwidth-10)/4)
{
card=[];
initializeCard();
//setup();
}
else
{
for(c of card)
{
if(dist(c.x+cellwidth/2, c.y+cellheight/2, mouseX, mouseY) < cellwidth/4)
{
c.selected=!c.selected;
}
}
}
}
function initializeCard(){
if(input.value())
{
cardnum=input.value();
}
else{
cardnum=floor(random(1000000));
}
randomSeed(cardnum);
B=[];
I=[];
N=[];
G=[];
O=[];
selection=[]; // These are our randomly selected numbers
// Please don't judge me for what I'm about to do.
for(var i=1; i<16; i++) // Load the arrays with digits 1-75
{
B.push(i);
I.push(i+15);
N.push(i+30);
G.push(i+45);
O.push(i+60);
}
shuffle(B,1); //Shuffle up those digits
shuffle(I,1);
shuffle(N,1);
shuffle(G,1);
shuffle(O,1);
for(var i=0; i<25; i++)
{
if(i<5)
selection[i]=B.pop();
else if(i <10)
selection[i]=I.pop();
else if(i <15)
selection[i]=N.pop();
else if(i<20)
selection[i]=G.pop();
else
selection[i]=O.pop();
}
// It's over now. It's been done. It can't hurt you anymore
count=0;
cw=(width-100)/5;
ch=(height-hudsize)/6;
for(var i=0; i<5; i++)
{
x=50+(i*cw);
for(var j=0; j<5; j++)
{
y=ch+(j*ch);
card.push(new cell(x,y, selection[count]));
count++;
}
}
card[12].value="FREE";
card[12].selected=true;
}
function showCard(){
noFill();
cw=width;
ch=(height);
offset=0;
rect(0, 0, cw, height);
textSize(25);
fill(0);
text("Card Number: " + cardnum, 10, 25);
textSize(20);
text("Type desired card number.", width/8+20, height-30);
text("Leave blank for random card.", width/8+20, height -10);
for(var i=0; i<5; i++)
{
textSize(50);
fill(0);
x=100 + (i*cellwidth)
text(BINGO[i], x, 100);
stroke(0);
//line(x+offset, 0, x+offset, height/2-5);
// y=ch+(i*ch/6);
//line(0, y, cw, y);
}
// Show cells values and put DOBS on selected cells
for(c of card)
{
noFill();
rect(c.x, c.y, (width-100)/5, (height-hudsize)/6);
//circle(c.x+cellwidth/2, c.y+cellheight/2, cellwidth);
if(c.selected)
{
fill('red');
circle(c.x+cellwidth/2, c.y+cellheight/2, cellwidth-10);
}
fill(0);
textSize(50);
if(c.value=="FREE")
{
textSize(30);
text(c.value, c.x+cellwidth/2-30, c.y+cellheight/2+5);
}
else{
text(c.value, c.x+cellwidth/2-8, c.y+cellheight/2+5);
}
}
//**************************************
}
function showButtons()
{
fill('skyblue');
textSize(24)
circle(25, ch-30, cellwidth-10);
fill(0);
text("NEW", 10, ch-40);
text("CARD", 10, ch-18);
fill('skyblue');
textSize(24)
circle(width-30, ch-30, cellwidth-10);
fill(0);
text("Clear", width-65, ch-40);
text("CARD", width-65, ch-18);
}