Compare commits
23 commits
Author | SHA1 | Date | |
---|---|---|---|
|
f87e6dd836 | ||
|
c8020398a9 | ||
|
3df378dd21 | ||
|
b14c6d2660 | ||
|
4ed1f12107 | ||
|
76a43c94b4 | ||
|
d3ab01ff02 | ||
|
3249c2d2e9 | ||
|
bc04eaf0c8 | ||
|
562623c713 | ||
|
7bdebab0f5 | ||
|
5b284ee2bb | ||
|
32508d1738 | ||
|
ab0589ddf2 | ||
|
01306f9ee0 | ||
|
8d147ad1df | ||
|
3b266b2169 | ||
|
0ca1eca5a3 | ||
|
0068baa68e | ||
|
4a03d31439 | ||
|
aec64b7408 | ||
|
bdcb1dbe55 | ||
|
985dc40ab1 |
4 changed files with 63 additions and 16 deletions
24
README.md
24
README.md
|
@ -1,5 +1,23 @@
|
||||||
## Memory Game
|
# Memory Game
|
||||||
|
### Benjamin Zimmerman
|
||||||
|
|
||||||
This is my final project (option 1) for ITSE-1479.
|
---
|
||||||
Instead of using the provided cardback.png image, I used a photo of one of my turtles as the card back.
|
|
||||||
|
|
||||||
|
Info for users:
|
||||||
|
- This is my final project (option 1) for ITSE-1479 (Intro to Scripting Languages)
|
||||||
|
- It is a memory game with a graphical interface.
|
||||||
|
- You can click on a card to flip it. Match 2 cards correctly and the cards will stay flipped. Match all cards to win.
|
||||||
|
- Scoring:
|
||||||
|
- When you make an incorrect match, you lose 1 point.
|
||||||
|
- When you make a correct match, you gain 5 points.
|
||||||
|
|
||||||
|
Technical info:
|
||||||
|
- This program is written in Python 3, using the turtle module for graphics, and the pygame module for sound and music.
|
||||||
|
- Instead of using the provided cardback.png image, I used a photo of one of my turtles as the card back.
|
||||||
|
- Notable game behavior: If you make an incorrect match, the cards will flip back over after 1 second. However, if you click on a card while the incorrect match is still face up, nothing will happen.
|
||||||
|
- Just wait until the cards flip back over.
|
||||||
|
|
||||||
|
Future plans:
|
||||||
|
- Change the game behavior to a queue of cards to flip over, 1 pair at a time.
|
||||||
|
- Expand the game to include a stopwatch.
|
||||||
|
- Expand score to include number of correct and incorrect matches.
|
||||||
|
|
10
audio.py
10
audio.py
|
@ -25,7 +25,7 @@ class Audio:
|
||||||
# no_match sound is from https://freesound.org/people/distillerystudio/sounds/327738/
|
# no_match sound is from https://freesound.org/people/distillerystudio/sounds/327738/
|
||||||
Audio.no_match_sound = mixer.Sound('audio/no_match.wav')
|
Audio.no_match_sound = mixer.Sound('audio/no_match.wav')
|
||||||
|
|
||||||
# game_success_sound is from https://freesound.org/people/jimhancock/sounds/376318/
|
# game_success_sound is TMNT turtle Michaelangelo saying "Cowabunga!"
|
||||||
Audio.game_success_sound = mixer.Sound('audio/game_success.wav')
|
Audio.game_success_sound = mixer.Sound('audio/game_success.wav')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -34,8 +34,12 @@ class Audio:
|
||||||
mixer.music.set_volume(0.5)
|
mixer.music.set_volume(0.5)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def stop_background_music():
|
def pause_music():
|
||||||
mixer.music.stop()
|
mixer.music.pause()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def unpause_background_music():
|
||||||
|
mixer.music.unpause()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def click():
|
def click():
|
||||||
|
|
Binary file not shown.
45
main.py
45
main.py
|
@ -1,3 +1,5 @@
|
||||||
|
from tkinter import PhotoImage
|
||||||
|
|
||||||
from audio import Audio
|
from audio import Audio
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -16,6 +18,14 @@ try:
|
||||||
screen = turtle.Screen()
|
screen = turtle.Screen()
|
||||||
turtle.bgcolor('#46a38d')
|
turtle.bgcolor('#46a38d')
|
||||||
screen.setup(WIDTH, HEIGHT)
|
screen.setup(WIDTH, HEIGHT)
|
||||||
|
screen.title('Turtle Match - Benjamin Zimmerman')
|
||||||
|
|
||||||
|
success_t = turtle.Turtle()
|
||||||
|
success_t.hideturtle()
|
||||||
|
success_t.penup()
|
||||||
|
turtle.register_shape('success_turtle', turtle.Shape('image', PhotoImage(file='images/turtle.png')))
|
||||||
|
success_t.shape('success_turtle')
|
||||||
|
success_t.goto(-379, 0)
|
||||||
|
|
||||||
Audio.start_audio()
|
Audio.start_audio()
|
||||||
Audio.play_background_music()
|
Audio.play_background_music()
|
||||||
|
@ -59,21 +69,24 @@ try:
|
||||||
cards[i].goto(x, y)
|
cards[i].goto(x, y)
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
|
matches = 0
|
||||||
game_is_running = True
|
game_is_running = True
|
||||||
|
end_routine_done = False
|
||||||
clicked_cards = []
|
clicked_cards = []
|
||||||
|
|
||||||
|
|
||||||
def clicked_card(x, y):
|
def clicked_card(x, y):
|
||||||
"""
|
"""
|
||||||
:return: The card which was clicked
|
Appends the card which was clicked on to the list clicked_cards.
|
||||||
"""
|
"""
|
||||||
Audio.click()
|
|
||||||
global clicked_cards
|
global clicked_cards
|
||||||
for card in cards:
|
|
||||||
if card.is_mouse_over(x, y):
|
|
||||||
if len(clicked_cards) == 2:
|
if len(clicked_cards) == 2:
|
||||||
clicked_cards = []
|
return None
|
||||||
|
for card in cards:
|
||||||
|
if card.is_mouse_over(x, y) and card.shape()[:10] != 'card_front':
|
||||||
card.to_front()
|
card.to_front()
|
||||||
clicked_cards.append(card)
|
clicked_cards.append(card)
|
||||||
|
Audio.click()
|
||||||
|
|
||||||
|
|
||||||
def update_score():
|
def update_score():
|
||||||
|
@ -85,18 +98,30 @@ try:
|
||||||
|
|
||||||
while game_is_running:
|
while game_is_running:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
if not end_routine_done:
|
||||||
|
if matches >= 8:
|
||||||
|
success_t.showturtle()
|
||||||
|
Audio.pause_music()
|
||||||
|
Audio.game_success()
|
||||||
|
time.sleep(3.1)
|
||||||
|
Audio.unpause_background_music()
|
||||||
|
end_routine_done = True
|
||||||
if len(clicked_cards) == 2:
|
if len(clicked_cards) == 2:
|
||||||
if clicked_cards[0] != clicked_cards[1]:
|
if clicked_cards[0] == clicked_cards[1]:
|
||||||
|
time.sleep(0.5)
|
||||||
|
clicked_cards[0].hideturtle()
|
||||||
|
clicked_cards[1].hideturtle()
|
||||||
|
score += 5
|
||||||
|
update_score()
|
||||||
|
Audio.match_made()
|
||||||
|
matches += 1
|
||||||
|
else:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
clicked_cards[0].to_back()
|
clicked_cards[0].to_back()
|
||||||
clicked_cards[1].to_back()
|
clicked_cards[1].to_back()
|
||||||
score -= 1
|
score -= 1
|
||||||
update_score()
|
update_score()
|
||||||
Audio.no_match()
|
Audio.no_match()
|
||||||
else:
|
|
||||||
score += 5
|
|
||||||
update_score()
|
|
||||||
Audio.match_made()
|
|
||||||
clicked_cards = []
|
clicked_cards = []
|
||||||
screen.update()
|
screen.update()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue