Concept
For this assignment, I decided to recreate a popular game called “Cards against humanity.” In this game, each participant is presented with a black card containing a humorous or absurd prompt. The objective is for players to select from a set of white cards, each bearing a comical response, aiming to match the prompt with the funniest, most unexpected, or outrageous answer.
Sketch
Code highlight
function generateCards() { let randomIndex = floor(random(blackCardTexts.length)); blackCardText = blackCardTexts[randomIndex]; whiteCardOptions = []; while (whiteCardOptions.length < 3) { randomIndex = floor(random(whiteCardTexts.length)); let selectedCard = whiteCardTexts[randomIndex]; if (selectedCard.trim() !== "" && !whiteCardOptions.includes(selectedCard)) { whiteCardOptions.push(selectedCard); } } cardsGenerated = true; displayInitialText = false; // Update the variable to switch to displaying cards }
The function generateCards() is responsible for displaying the cards with random prompts from the csv files. First, I generate a random index to pick a prompt at random from the blackCardsTexts array which holds all the possible prompts in my game. Next, I initialize an empty array whiteCardOptions to store the white card responses to display on the 3 white cards. To ensure they are all distinct responses, I use a while loop which continues until whiteCardOptions array has 3 distinct responses. I did this by:
1. generating a another random index (randomIndex) from the whiteCardTexts array.
2. extracting the white card response at this random index and storing it in a variable called selectedCard.
3. checking if selectedCard is not empty (i.e., it contains text) and if it’s not already included in the whiteCardOptions array. This is the step that ensures I only add valid and unique responses to the white cards.
Reflection
I had the most fun working on this assignment so far because I tried to recreate a game that I love playing with my friends. While I’m quite happy with the outcome and how the core mechanics of the game function, I think there is definitely room for improvement, particularly in terms of the aesthetics of the sketch. For this project, my primary focus was recreating the fundamental concept and gameplay of the game rather than emphasizing the visual design.
Nonetheless, I’m still pretty satisfied with what I’ve been able to create. Reading some of these responses made me chuckle as well (even though I wrote them myself), and that’s ultimately what this game is all about—laughter and amusement.