Game for Gettysburg

by Sheralyn Woon

Inspired by an earlier project on the PCB Puzzle, I wanted to use the same concept to develop a game for an online site that teaches 5th graders about the civil war.

The embroidery process and writing code in Processing was challenging.  The various pieces had to fit properly. When pieces were sewn separately, the sizes of the items were not of the same scale. To fit everything, all items were put into a hoop at the same time and sewed together at one time. (This took over 4 hrs). When testing the pieces, the snaps and velcro sometimes don’t snap together properly, giving strange readings. The velcro readings evened out after a while of repeated attachment and removal. Writing the code was also difficult for a first-timer.

I want to keep working on the coding for processing to add a timer and allow 2 players to play simultaneously.

Code:

import processing.serial.*;
Serial myPort;        // The serial port

//variables for collecting and storing information
int ARRAYX = 2;
int ARRAYY = 3;
int [][] sensorArray = new int[ARRAYX][ARRAYY];

int flag = 0;
boolean inGame = false;
boolean prompt = false;
int characterPrompt = 0;
boolean instructions = true;
boolean wonGame = false;
boolean endGame = false;

//variables for drawing information on the screen
int spacing = 100;
PFont font;
PFont fontA;

void setup () {
//set the window size:
size(600, 400);
//initialize the font variables
font = loadFont(“SansSerif-20.vlw”);
textFont(font);

fontA = loadFont(“SansSerif-48.vlw”);

// list all the available serial ports
println(Serial.list());
// open the appropriate port
myPort = new Serial(this, Serial.list()[0], 9600);
// don’t generate a serialEvent() until you get an exclamation mark character
myPort.bufferUntil(‘!’);
// set inital background:
background(0);
}

void draw () {
background(0);
//draw buttonNEXT
fill (255);
rect(520, 350, 50, 30);
text(“NEXT”, 520, 350);
//draw buttonEXIT
fill (255);
rect(450, 350, 50,30);
text(“EXIT” , 450, 350);

if (inGame==false)
{
if (instructions==true)
{
//draw instructions
text(“Stick the right clothes onto the right character.”, 75, 100);
}

else if (prompt==true)
{
// draw prompt
if (characterPrompt == 0)
{
text(“Mary Tepe”, width/2, height/2);
}
else if (characterPrompt == 1)
{
text(“Jenny Wade”, width/2, height/2);
}
else if (characterPrompt == 2)
{
text(“General Lee”, width/2, height/2);
}
else if (characterPrompt == 3)
{
text(“General Meade”, width/2, height/2);
}
}
else if (wonGame==true)
{
text(“You’re right!”, width/2, height/2);
}
}
else if (inGame==true & wonGame == false)
{
if (characterPrompt == 0)
{
if (testIfMary() == true)
{
text(“You’re right!”, width/2, height/2);
wonGame=true;
inGame = false;
}
else
text(“That’s not Mary, keep trying.”, 200, height/2);
}

if (characterPrompt == 1)
{
if (testIfJenny() == true)
{
text(“You’re right!”, width/2, height/2);
wonGame=true;
inGame = false;
}
else
text(“That’s not Jenny, keep trying.”, 200, height/2);
}

if (characterPrompt == 2)
{
if (testIfGeneralL() == true)
{
text(“You’re right!”, width/2, height/2);
wonGame=true;
inGame = false;
}
else
text(“That’s not Gen. Lee, keep trying.”, 200, height/2);
}

if (characterPrompt == 3)
{
if (testIfGeneralM() == true)
{
text(“You’re right!”, width/2, height/2);
wonGame=true;
inGame = false;
}
else
text(“That’s not Gen Meade, keep trying.”, 200, height/2);
}
}
}

void mousePressed() {
//test if over area
if (( mouseX> 519 & mouseX< 571) & (mouseY>349 & mouseY<381))
{
if (instructions==true)
{
instructions = false;
inGame=false;
prompt=true;
characterPrompt = int(random(4));
//characterPrompt = 0;
}
else if (prompt== true)
{
prompt = false;
inGame= true;
}
else if (wonGame== true)
{
wonGame= false;
prompt=true;
characterPrompt = int(random(4));
}

}

else if (( mouseX> 449 & mouseX< 501 ) & (mouseY>349  & mouseY<381))
{
println(“clicked exit”);
exit();
}
}

void serialEvent (Serial myPort) {
//store a batch of data into variable “inString”
//batches are separated by exclamation mark characters
String inString = myPort.readStringUntil(‘!’);
//split the data into rows (rows separated by new line characters)
String[] incomingArrayRows = splitTokens(inString, “\n”);
//loop through all of the rows
for (int i=0;i<ARRAYX;i++)
{
//split each row into entries (entries separated by tab characters)
String[] incomingArrayEntries = splitTokens(incomingArrayRows[i], “\t”);
//loop through all of these entries
for (int j=0;j<ARRAYY;j++)
{
//store entries in the “sensorArray” variable
sensorArray[i][j]=int(incomingArrayEntries[j]);
//print the entries to the terminal, separated by tab characters
print(sensorArray[i][j]);
print(‘\t’);
}
//print a new line after each row
println();
}
//print a new line after each batch of data
println();
}

void printArray()
{
for (int i=0;i<ARRAYX;i++)
{
for (int j=0;j<ARRAYY;j++)
{
print(sensorArray[i][j]);
print(‘\t’);
}
//print a new line after each row
println();
}
println();
}

boolean testIfMary()
{
int hat = sensorArray[0][1];
int clothes = sensorArray[0][0];
int other = sensorArray[0][2];

if ((hat>10 & hat <29) & (clothes>10 & clothes<29)  & (other>10 & other<29))
{
return true;
}
else
return false;
}

boolean testIfJenny()
{
int hat = sensorArray[0][1];
int clothes = sensorArray[0][0];
int other = sensorArray[0][2];

if ((hat>30 & hat <60) & (clothes>30 & clothes<60)  & (other>30 & other<60))
{
return true;
}
else
return false;
}

boolean testIfGeneralM()
{
int hat = sensorArray[1][2];
int clothes = sensorArray[1][0];
int other = sensorArray[1][1];

if ((hat>10 & hat<60) & (clothes>10 & clothes<60)  & (other>10 & other<60))
{
return true;
}
else
return false;
}

boolean testIfGeneralL()
{
int hat = sensorArray[1][2];
int clothes = sensorArray[1][0];
int other = sensorArray[1][1];

if ((hat>200 & hat<300) & (clothes>200 & clothes<300)  & (other>200 & other<300))
{
return true;
}
else
return false;
}