Makey Makey: Don't Tap the White Tile

by makerspace_burch in Circuits > Electronics

6700 Views, 90 Favorites, 0 Comments

Makey Makey: Don't Tap the White Tile

556361ac50e1b669240002c4.jpeg

Hi there, our creative friends! We are a group of 3 students from International Burch University, Sarajevo. We are having competition at our university in making Makey Makey projects. We decided to do this project because we think it is very interesting. We hope you will like it. :D

Needed Components

11117505_10204900368084092_796374592_n.jpg
11350236_10204900368484102_742501718_n.jpg
11354966_10204900368564104_608103926_n.jpg
11356344_10204900368604105_597732510_n.jpg
11270089_10204900368884112_1353979555_n.jpg
11292676_10204900368804110_1986642523_n.jpg

- Makey Makey
- 9 jumpers
- 5 two sided clamps
- 5x10 cm cardboard
- some aluminum foil
- sellotape

Making Software Part - Code Logic

Create an array for one column of tiles. Create same size array for black tiles. When creating column of tiles, check black tiles array. If box number is equal to tile number make tile back color black else make tile back color white. After drawing the table, get character input from user. If character equals the black input play piano key remove last row. Move rows one block down. Create new row, put the new row as last row, else plat fail sound.

Writing the Code

HERE COMES THE CODE FOR THE GAME. It is done in C#.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data; using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { Random rnd = new Random();

int[] tiles = new int[4] { 2 ,1,0,3 };
Panel[] row = new Panel[4];
Panel[][] rows = new Panel[4][];
SoundPlayer a = new SoundPlayer(WindowsFormsApplication1.Properties.Resources._1);
SoundPlayer b = new SoundPlayer(WindowsFormsApplication1.Properties.Resources._2);
SoundPlayer c = new SoundPlayer(WindowsFormsApplication1.Properties.Resources._3);
SoundPlayer d = new SoundPlayer(WindowsFormsApplication1.Properties.Resources._4);
SoundPlayer f = new SoundPlayer(WindowsFormsApplication1.Properties.Resources._5);
Random r = new Random();

//List tilesP = new List ();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

// this.Shuffle(tiles);
//this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;

int FormHeight = this.Size.Height;
int FormWidth = this.Size.Width;

for (int i = 0; i < 4; i++) {
Panel[] p = new Panel[4];
for (int j = 0; j < 4; j++)
{

row[j] = new Panel();

row[j].Size = new Size(FormWidth / 4, FormHeight / 4);
row[j].Location = new Point((i * FormWidth / 4), (j * FormHeight / 4));
row[j].BackColor = Color.White;
if (j == tiles[i]) row[j].BackColor = Color.Black;
row[j].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(row[j]);
p[j] = row[j];
}
rows[i] = p;
}

//draw the tiles
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {

int FormHeight = this.Size.Height;
int FormWidth = this.Size.Width;

switch (keyData)
{
case Keys.A:
{
if (tiles[3] == 0)
{
a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();

a.Play();

Random r = new Random();
int inr = r.Next(0, 4);

int[] s = new int[4];
Array.Copy(tiles, s, 4);

for (int i = 3; i > 0; i--)
{
tiles[i] = s[i - 1];
}
tiles[0] = inr;

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++) {

Control p = this.GetChildAtPoint(new Point((i * FormWidth / 4), (j * FormHeight / 4))); rows[i][j] = (Panel)p;

}}

for (int i = 0; i < 4; i++)
{

for (int j = 0; j < 4; j++)
{

rows[i][j].Location = new Point((i * FormWidth / 4), ((j + 1) * FormHeight / 4));

}}

for (int i = 0; i < 4; i++)
{
rows[i][0] = new Panel();
rows[i][0].Size = new Size(FormWidth / 4, FormHeight / 4);
rows[i][0].Location = new Point((i * FormWidth / 4), (0 * FormHeight / 4));
rows[i][0].BackColor = Color.White;
if (i == inr) rows[i][0].BackColor = Color.Black;
rows[i][0].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(rows[i][0]);
}}
else
{

a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();
f.Play();

}
return true;

}
case Keys.S: {
if (tiles[3] == 1)
{

a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();

b.Play();

int inr = r.Next(0, 4);

int[] s = new int[4];
Array.Copy(tiles, s, 4);

for (int i = 3; i > 0; i--)

{
tiles[i] = s[i - 1];
} tiles[0] = inr;

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

Control p = this.GetChildAtPoint(new Point((i * FormWidth / 4), (j * FormHeight / 4))); rows[i][j] = (Panel)p;

}
}

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

rows[i][j].Location = new Point((i * FormWidth / 4), ((j + 1) * FormHeight / 4));

}
}

for (int i = 0; i < 4; i++)
{
rows[i][0] = new Panel();
rows[i][0].Size = new Size(FormWidth / 4, FormHeight / 4);
rows[i][0].Location = new Point((i * FormWidth / 4), (0 * FormHeight / 4));
rows[i][0].BackColor = Color.White;
if (i == inr) rows[i][0].BackColor = Color.Black;
rows[i][0].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(rows[i][0]);
}}
else {
a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();

f.Play();
}

return true;
}
case Keys.D:
{
if (tiles[3] == 2)
{

a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();

c.Play();

Random r = new Random();
int inr = r.Next(0, 4);

int[] s = new int[4];
Array.Copy(tiles, s, 4);

for (int i = 3; i > 0; i--)
{
tiles[i] = s[i - 1];
}
tiles[0] = inr;
for (int i = 0; i < 4; i++)

{
for (int j = 0; j < 4; j++)
{

Control p = this.GetChildAtPoint(new Point((i * FormWidth / 4), (j * FormHeight / 4))); rows[i][j] = (Panel)p;

}}
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

rows[i][j].Location = new Point((i * FormWidth / 4), ((j + 1) * FormHeight / 4));
}}

for (int i = 0; i < 4; i++)
{
rows[i][0] = new Panel();

rows[i][0].Size = new Size(FormWidth / 4, FormHeight / 4);
rows[i][0].Location = new Point((i * FormWidth / 4), (0 * FormHeight / 4));

rows[i][0].BackColor = Color.White;

if (i == inr) rows[i][0].BackColor = Color.Black;
rows[i][0].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(rows[i][0]);
} }
else
{
a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();

f.Play();
}

return true;
} // up arrow key pressed
case Keys.F: {
if (tiles[3] == 3)
{

a.Stop();
b.Stop();

c.Stop();
d.Stop();
f.Stop();

d.Play();

Random r = new Random();
int inr = r.Next(0, 4);

int[] s = new int[4];
Array.Copy(tiles, s, 4);

for (int i = 3; i > 0; i--)
{
tiles[i] = s[i - 1];
}
tiles[0] = inr;

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

Control p = this.GetChildAtPoint(new Point((i * FormWidth / 4), (j * FormHeight / 4)));
rows[i][j] = (Panel)p;
}}

for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{

rows[i][j].Location = new Point((i * FormWidth / 4), ((j + 1) * FormHeight / 4));

}}

for (int i = 0; i < 4; i++)
{
rows[i][0] = new Panel();
rows[i][0].Size = new Size(FormWidth / 4, FormHeight / 4);
rows[i][0].Location = new Point((i * FormWidth / 4), (0 * FormHeight / 4));
rows[i][0].BackColor = Color.White;
if (i == inr) rows[i][0].BackColor = Color.Black;
rows[i][0].BorderStyle = BorderStyle.FixedSingle;
this.Controls.Add(rows[i][0]);
} }
else
{
a.Stop();
b.Stop();
c.Stop();
d.Stop();
f.Stop();
f.Play();

}
return true;

} }

return base.ProcessCmdKey(ref msg, keyData);
}
void Shuffle(T[] array)
{
int n = array.Length; for (int i = 0; i < n; i++)
{
// NextDouble returns a random number between 0 and 1.
// ... It is equivalent to Math.random() in Java.
int r = i + (int)(rnd.NextDouble() * (n - i));
T t = array[r];
array[r] = array[i];
array[i] = t;
} } } }

Hardware Part - Connecting All Components

11291769_10204900526208045_1664330632_n.jpg
11262347_10204900525968039_2145489947_n.jpg
11350376_10204900525688032_1201444853_n.jpg
11281751_10204900525528028_999132977_n.jpg
11311000_10204900525368024_261645704_n.jpg
11263227_10204900525328023_297932944_n.jpg

Final Product

Makey Makey: Don't Tap The White Tile

After doing all hardware and software work, we enjoyed playing the game. We hope you will like it too.