xxxxxxxxxx
591
var imagemFundo;
function preload(){
fontMenu = loadFont('Bouncy-Thin-PERSONAL_USE_ONLY.otf');
imagemEducadora = loadImage("foto_joyce.PNG")
imagemProgramadora = loadImage("foto_natalia.PNG");
imagemFundo = loadImage("fundo4.png");
fundoCarta = loadImage("fundoCarta.png");
}
var tabuleiroAtivo=false
EscolhaMenu = 0;
EscolhaDif = 0;
//variaveis logica
var cartasComparacao = ['1', '1', '2', '2', '3', '3', '4', '4', '5', '5', '6', '6', '7', '7', '8', '8']
let cartas = []
let cartasMedio = []
const numLinhas = 4
const numColunas = 4
let versoImage
let frenteImage = []
let frenteImage1 = []
let frenteImageMedio = []
let frenteImage1Medio = []
let imagesDeck = []
let imagesDeckMedio = []
let flippedCartas = []
let flippedCartasMedio = []
let delayStartFC = null
let numTent = 0
// Tile Object
// --------------------------
class Carta {
constructor(x, y, faceUpImage, v) {
this.x = x
this.y = y
this.width = 100
this.versoImage = versoImage
this.faceUpImage = faceUpImage
this.isFaceUp = false
this.value = v
}
render() {
fill(0, 0, 0)
rect(this.x, this.y, this.width, this.width)
if (this.isFaceUp === true) {
image(this.faceUpImage, this.x, this.y, this.width, this.width)
} else {
image(this.versoImage, this.x, this.y, 100, 100)
}
}
setIsFaceUp(isFaceUp) {
this.isFaceUp = isFaceUp
}
isUnderMouse(x, y) {
return x >= this.x && x <= this.x + this.width &&
y >= this.y && y <= this.y + this.width
}
}
// Game functions
// --------------------------
//facil
function createCartas() {
for (let i = 0; i < numColunas; i++) {
for (let j = 0; j < numLinhas; j++) {
cartas.push(new Carta(i * 100 + 50, j * 100+50, imagesDeck.pop(), cartasComparacao.pop() ))
}
}
}
//medio
function createCartasMedio() {
for (let i = 0; i < numColunas; i++) {
for (let j = 0; j < numLinhas; j++) {
cartasMedio.push(new Carta(i * 100 + 50, j * 100+50, imagesDeckMedio.pop(), cartasComparacao.pop() ))
}
}
}
function updateGameLogic() {
if (delayStartFC && (frameCount - delayStartFC) > 30) {
for (let i = 0; i < cartas.length; i++) {
if (!cartas[i].isMatch && cartas[i].isFaceUp) {
cartas[i].setIsFaceUp(false)
}
}
flippedCartas = []
delayStartFC = null
}
}
//medio
function updateGameLogicMedio() {
if (delayStartFC && (frameCount - delayStartFC) > 30) {
for (let i = 0; i < cartasMedio.length; i++) {
if (!cartasMedio[i].isMatch && cartasMedio[i].isFaceUp) {
cartasMedio[i].setIsFaceUp(false)
}
}
flippedCartasMedio = []
delayStartFC = null
}
}
function loadfrenteImage() {
frenteImage[0] = loadImage("facil/1.png")
frenteImage[1] = loadImage("facil/2.png")
frenteImage[2] = loadImage("facil/3.png")
frenteImage[3] = loadImage("facil/4.png")
frenteImage[4] = loadImage("facil/5.png")
frenteImage[5] = loadImage("facil/6.png")
frenteImage[6] = loadImage("facil/7.png")
frenteImage[7] = loadImage("facil/8.png")
}
function loadfrenteImage1() {
frenteImage1[0] = loadImage("facil/1.1.png")
frenteImage1[1] = loadImage("facil/2.1.png")
frenteImage1[2] = loadImage("facil/3.1.png")
frenteImage1[3] = loadImage("facil/4.1.png")
frenteImage1[4] = loadImage("facil/5.1.png")
frenteImage1[5] = loadImage("facil/6.1.png")
frenteImage1[6] = loadImage("facil/7.1.png")
frenteImage1[7] = loadImage("facil/8.1.png")
}
function loadfrenteImageMedio() {
frenteImageMedio[0] = loadImage("medio/1.png")
frenteImageMedio[1] = loadImage("medio/2.png")
frenteImageMedio[2] = loadImage("medio/3.png")
frenteImageMedio[3] = loadImage("medio/4.png")
frenteImageMedio[4] = loadImage("medio/5.png")
frenteImageMedio[5] = loadImage("medio/6.png")
frenteImageMedio[6] = loadImage("medio/7.png")
frenteImageMedio[7] = loadImage("medio/8.png")
}
function loadfrenteImage1Medio() {
frenteImage1Medio[0] = loadImage("medio/1.1.png")
frenteImage1Medio[1] = loadImage("medio/2.1.png")
frenteImage1Medio[2] = loadImage("medio/3.1.png")
frenteImage1Medio[3] = loadImage("medio/4.1.png")
frenteImage1Medio[4] = loadImage("medio/5.1.png")
frenteImage1Medio[5] = loadImage("medio/6.1.png")
frenteImage1Medio[6] = loadImage("medio/7.1.png")
frenteImage1Medio[7] = loadImage("medio/8.1.png")
}
function createImagesDeck(imagesES, imagesPT) {
for (let i = 0; i < frenteImage.length; i++) {
imagesDeck.push(imagesES[i])
imagesDeck.push(imagesPT[i])
}
}
//medio
function createImagesDeckMedio(imagesESMedio, imagesPTMedio) {
for (let i = 0; i < frenteImageMedio.length; i++) {
imagesDeckMedio.push(imagesESMedio[i])
imagesDeckMedio.push(imagesPTMedio[i])
}
//imagesDeck.sort(function() {
// return 0.5 - random()
//})
}
function drawScoringMessage() {
let foundAllMatches = true
for (let i = 0; i < cartas.length; i++) {
foundAllMatches = foundAllMatches && cartas[i].isMatch
}
if (foundAllMatches) {
fill(255, 255, 255)
text("Você encontrou todos em " + numTent + " tentativas", 20, 360)
}
}
//botao voltar
var xMinBotaoVoltar = 400
var larguraBotaoVoltar = 80
var xMaxBotaoVoltar = (xMinBotaoVoltar) + larguraBotaoVoltar
var alturaBotaoVoltar = 20
var yMinBotaoVoltar1 = 480
var yMaxBotaoVoltar1 = yMinBotaoVoltar1 + alturaBotaoVoltar
//botoes Menu
var xMinBotao = 150
var larguraBotao = 200
var xMaxBotao = xMinBotao + larguraBotao
var alturaBotao = 60
var yMinBotao1 = 200
var yMaxBotao1 = yMinBotao1 + alturaBotao
var yMinBotao2 = 280
var yMaxBotao2 = yMinBotao2 + alturaBotao
var yMinBotao3 = 120
var yMaxBotao3 = yMinBotao3 + alturaBotao
//botoes dificuldade
var xMinBotaoDif = 150
var larguraBotaoDif = 200
var xMaxBotaoDif = xMinBotaoDif + larguraBotaoDif
var alturaBotaoDif = 60
var yMinBotaoDif1 = 120
var yMaxBotaoDif1 = yMinBotaoDif1 + alturaBotao
var yMinBotaoDif2 = 200
var yMaxBotaoDif2 = yMinBotaoDif2 + alturaBotao
var yMinBotaoDif3 = 280
var yMaxBotaoDif3 = yMinBotaoDif3 + alturaBotao
var tela = 0;
// funcionamento botao Voltar
function Voltar(texto, yMinVoltar, yMaxVoltar, opcao){
if(mouseX > xMinBotaoVoltar && mouseX<xMaxBotaoVoltar && mouseY > yMinVoltar && mouseY < yMaxVoltar){
fill(0);
if(mouseIsPressed){
tela = 0;
EscolhaMenu = 0;
}
}
else{
noFill();
}
rect(xMinBotaoVoltar, yMinVoltar, larguraBotaoVoltar, alturaBotaoVoltar, 15);
textSize(14);
fill(color(255,255,255));
text(texto, xMinBotaoVoltar+35 , yMinVoltar+15)
}
function mouseClicked(){
if(tabuleiroAtivo){
for (let i = 0; i < cartas.length; i++) {
if (cartas[i].isUnderMouse(mouseX, mouseY)) {
if (flippedCartas.length < 2 && !cartas[i].isFaceUp) {
cartas[i].setIsFaceUp(true)
flippedCartas.push(cartas[i])
if (flippedCartas.length === 2) {
numTent++
console.log(flippedCartas[0].value+ " ? "+ flippedCartas[1].value)
if (flippedCartas[0].value === flippedCartas[1].value) {
flippedCartas[0].isMatch = true
flippedCartas[1].isMatch = true
}
delayStartFC = frameCount
}
}
}
}
}
//Medio
if(tabuleiroAtivo){
for (let i = 0; i < cartasMedio.length; i++) {
if (cartasMedio[i].isUnderMouse(mouseX, mouseY)) {
if (flippedCartasMedio.length < 2 && !cartasMedio[i].isFaceUp) {
cartasMedio[i].setIsFaceUp(true)
flippedCartasMedio.push(cartasMedio[i])
if (flippedCartasMedio.length === 2) {
numTent++
console.log(flippedCartasMedio[0].value+ " ? "+ flippedCartasMedio[1].value)
if (flippedCartasMedio[0].value === flippedCartasMedio[1].value) {
flippedCartasMedio[0].isMatch = true
flippedCartasMedio[1].isMatch = true
}
delayStartFC = frameCount
}
}
}
}
}
if (tela ==3){
if(EscolhaDif==5){
tela = 5;
tabuleiroAtivo = true;
}
if(EscolhaDif==6){
tela = 6;
tabuleiroAtivo = true;
}
if(EscolhaDif==7){
tela = 7;
}
}
if (tela ==0){
if(EscolhaMenu==1){
tela = 1;
}
if(EscolhaMenu==2){
tela = 2;
}
if(EscolhaMenu==3){
tela = 3;
}
}
}
//botao Menu
function menuBotao(texto, yMin, yMax, opcao){
if(mouseX > xMinBotao && mouseX<xMaxBotao && mouseY > yMin && mouseY < yMax){
fill(0);
EscolhaMenu = opcao;
}
else{
noFill();
}
rect(xMinBotao, yMin, larguraBotao, alturaBotao, 15);
textSize(26);
fill(color(255,255,255));
text(texto, xMinBotao + 100, yMin + 40)
}
//botaoDificuldade
function DifBotao(textoDif, yMinDif, yMaxDif, opcaoDif){
if(mouseX > xMinBotaoDif && mouseX<xMaxBotaoDif && mouseY > yMinDif && mouseY < yMaxDif){
fill(0);
EscolhaDif = opcaoDif;
}
else{
noFill();
}
rect(xMinBotaoDif, yMinDif, larguraBotaoDif, alturaBotaoDif, 15);
textSize(26);
fill(color(255,255,255));
text(textoDif, xMinBotaoDif + 100, yMinDif + 40)
}
function telaCreditos(){
background(imagemFundo);
fill(255);
textSize(40);
fill(255);
stroke(0,0,0)
strokeWeight(2)
fill(255);
text("Creditos", 250, 80);
textSize(20);
text("Joyce Lima", 300, 140);
textSize(16);
text("Função: Educadora", 300, 160);
textSize(14);
fill(255);
text("Licenciando em Língua Espanhola pela Universidade Estadual da Paraíba", 180, 180, 300);
image(imagemEducadora, 50, 130, 110, 120);
fill(255);
textSize(20);
text("Natália Tertuliano", 300, 300);
textSize(16);
text("Função: Programadora", 300, 320);
textSize(14);
fill(255);
text("Estudante do Bacharelado em Ciência e Tecnologia na Universidade Federal do Rio Grande do Norte", 180, 340, 300);
image(imagemProgramadora, 50, 280, 110, 120);
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0);
}
function telaInstrucoes(){
background(imagemFundo);
textFont(fontMenu);
textSize(32);
fill(255);
text("instrucciones", 150, 60)
textSize(20);
fill(255);
stroke(0,0,0)
strokeWeight(2)
text(" O jogador deve memorizar as palavras em espanhol e suas traduções, e após o embaralhamento das cartas, deve selecionar as combinações.",30, 90, 410);
textSize(14);
fill(255);
//facil
text("Queso = Queijo", 80, 210)
text("Mora = Amora", 80, 230)
text("Escalera = Escada", 80, 250)
text("Mango = Manga", 80, 270)
text("Helado = Sorvete", 80, 290)
text("Silla = Cadeira", 80, 310)
text("Perrito Quente = Cachorro Quente", 10, 330,135)
text("Manzana = Maçã", 80, 365)
//medio
text("Queso = Queijo", 230, 210)
text("Mango = Manga", 230, 230)
text("Helado = Sorvete", 230, 250)
text("Perrito Quente = Cachorro Quente", 160,265, 135)
text("Cepillo = escova", 230, 300)
text("Bolígrafos = Canetas", 230, 320)
text("Fresa = Morango", 230, 340)
text("Durazno = Pêssego", 230, 360)
//dificil
text("Remolacha = Beterraba", 390, 210)
text("Galettas = Bolacha", 390, 230)
text("Sandía = Melancia", 390, 250)
text("Vasos = Óculos", 390,270)
text("Cubiertas = Talheres", 390, 290)
text("Alubias = Feijão", 390, 310)
text("Ordenador = Computador", 350, 330, 100)
text("Corpiño = Sutiã", 395, 367)
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0);
}
function telaJogar(){
if(tela==3){
background(imagemFundo);
textSize(36);
fill(color(255,255,255));
textFont(fontMenu);
textStyle(BOLD);
text("Dificultad", 250, 75);
textAlign(CENTER);
textFont(fontMenu);
EscolhaDif = 0
DifBotao("Fácil",yMinBotaoDif1, yMaxBotaoDif1, 5 );
DifBotao("Medio",yMinBotaoDif2, yMaxBotaoDif2, 6);
DifBotao("Difícil",yMinBotaoDif3, yMaxBotaoDif3, 7);
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0);
}
}
function facil(){
background(imagemFundo);
textFont(fontMenu);
textSize(32);
fill(255);
fill(255);
stroke(0,0,0)
strokeWeight(2)
text("Tentativas:", 120,30);
updateGameLogic()
for (let i = 0; i < cartas.length; i++) {
cartas[i].render()
}
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0);
}
function medio(){
background(imagemFundo);
textFont(fontMenu);
textSize(32);
fill(255);
fill(255);
stroke(0,0,0)
strokeWeight(2)
text("Tentativas:", 120,30);
updateGameLogicMedio()
for (let i = 0; i < cartasMedio.length; i++) {
cartasMedio[i].render()
}
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0);
}
function dificil(){
background(imagemFundo);
textFont(fontMenu);
textSize(32);
fill(255);
text("Tentativas:", 120,30);
text("Tempo:", 360,30);
image(fundoCarta, 30, 50, 100, 100);
image(fundoCarta, 140, 50, 100, 100);
image(fundoCarta, 250, 50, 100, 100);
image(fundoCarta, 360, 50, 100, 100);
image(fundoCarta, 30, 160, 100, 100);
image(fundoCarta, 140, 160, 100, 100);
image(fundoCarta, 250, 160, 100, 100);
image(fundoCarta, 360, 160, 100, 100);
image(fundoCarta, 30, 270, 100, 100);
image(fundoCarta, 140, 270, 100, 100);
image(fundoCarta, 250, 270, 100, 100);
image(fundoCarta, 360, 270, 100, 100);
image(fundoCarta, 30, 380, 100, 100);
image(fundoCarta, 140, 380, 100, 100);
image(fundoCarta, 250, 380, 100, 100);
image(fundoCarta, 360, 380, 100, 100);
Voltar("Volver",yMinBotaoVoltar1, yMaxBotaoVoltar1, 0)
}
function setup() {
createCanvas(500, 500);
versoImage = loadImage("fundoCarta.png")
loadfrenteImage()
loadfrenteImage1()
createImagesDeck(frenteImage, frenteImage1)
createCartas()
//medio
loadfrenteImageMedio()
loadfrenteImage1Medio()
createImagesDeckMedio(frenteImageMedio, frenteImage1Medio)
createCartasMedio()
}
function draw() {
if(tela==0){
background(imagemFundo);
image(nomeDaVar,0,0,400,400);
textSize(36);
fill(color(255,255,255));
fill(255);
stroke(0,0,0)
strokeWeight(2)
textFont(fontMenu);
textStyle(BOLD);
text("Juego Del Memoria", 250, 75);
textAlign(CENTER);
textFont(fontMenu);
EscolhaMenu = -1
menuBotao("Instrucciones",yMinBotao1, yMaxBotao1, 1);
menuBotao("Creditos",yMinBotao2, yMaxBotao2, 2);
menuBotao("Jugar",yMinBotao3, yMaxBotao3, 3);
}
if(tela ==1){
telaInstrucoes();
}
if(tela ==2){
telaCreditos();
}
if(tela ==3){
telaJogar();
}
if(tela ==5){
facil();
}
if(tela ==6){
medio();
}
if(tela ==7){
dificil();
}
}