xxxxxxxxxx
//For this Excerise i created a game of chance, using the loop code.
//Click the sketch to revel an array of grey squares and within it features 5 red circles.
// if you spot all five, within your first click you win, if not try again.
//I made this game diffuclt so that the player becomes addicted to playing it until they see all five circles.
function setup() {
createCanvas(500, 500);
background(0,0,255);
fill (0);
textAlign(CENTER);
textFont("Verdana");
textSize(20);
text("Spot 5 red circles in one click!", width / 2, height / 2);
fill(0);
textSize(12.5);
text("Goodluck ;)", width / 2, height / 2 + 20);
}
function draw() {}
function mousePressed() {
background(0,0,255);
for (let i = 0; i < 200; i++) { // grey rectangles
let diameter = random(10, 60);
let x = random(0, width);
let y = random(0, height);
let hue = random(0, 255);
fill(245);
square (x, y, diameter);
}
for (let i = 1; i < 6; i++) { //red circles
let diameter = random(15, 35);
let x = random(1, width);
let y = random(1, height);
let hue = random(1, 255);
fill(255,0,0);
ellipse (x, y, diameter, diameter);
}
for (let i = 2; i < 200; i++) { //grey rectangles
let diameter = random(10, 55);
let x = random(2, width);
let y = random(2, height);
let hue = random(2, 255);
fill(225);
rect (x, y, diameter, diameter);
}
for (let i = 3; i < 100; i++) { // grey rectangles
let diameter = random(10, 45);
let x = random(3, width);
let y = random(3, height);
let hue = random(3, 255);
fill(200);
rect (x, y, diameter, diameter);
}
}