Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
|
6c6d84c644 |
4 changed files with 16 additions and 63 deletions
24
README.md
24
README.md
|
@ -1,23 +1,5 @@
|
||||||
# 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 TMNT turtle Michaelangelo saying "Cowabunga!"
|
# game_success_sound is from https://freesound.org/people/jimhancock/sounds/376318/
|
||||||
Audio.game_success_sound = mixer.Sound('audio/game_success.wav')
|
Audio.game_success_sound = mixer.Sound('audio/game_success.wav')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -34,12 +34,8 @@ class Audio:
|
||||||
mixer.music.set_volume(0.5)
|
mixer.music.set_volume(0.5)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def pause_music():
|
def stop_background_music():
|
||||||
mixer.music.pause()
|
mixer.music.stop()
|
||||||
|
|
||||||
@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,5 +1,3 @@
|
||||||
from tkinter import PhotoImage
|
|
||||||
|
|
||||||
from audio import Audio
|
from audio import Audio
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -18,14 +16,6 @@ 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()
|
||||||
|
@ -69,24 +59,21 @@ 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):
|
||||||
"""
|
"""
|
||||||
Appends the card which was clicked on to the list clicked_cards.
|
:return: The card which was clicked
|
||||||
"""
|
"""
|
||||||
|
Audio.click()
|
||||||
global clicked_cards
|
global clicked_cards
|
||||||
if len(clicked_cards) == 2:
|
|
||||||
return None
|
|
||||||
for card in cards:
|
for card in cards:
|
||||||
if card.is_mouse_over(x, y) and card.shape()[:10] != 'card_front':
|
if card.is_mouse_over(x, y):
|
||||||
|
if len(clicked_cards) == 2:
|
||||||
|
clicked_cards = []
|
||||||
card.to_front()
|
card.to_front()
|
||||||
clicked_cards.append(card)
|
clicked_cards.append(card)
|
||||||
Audio.click()
|
|
||||||
|
|
||||||
|
|
||||||
def update_score():
|
def update_score():
|
||||||
|
@ -98,30 +85,18 @@ 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