-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsong.py
99 lines (81 loc) · 2.81 KB
/
song.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
MULTIPLIER_MIN = 1
MULTIPLIER_MAX = 5
HIT_SCORE = 10
NOTE_STREAK = 5
DEFAULT_SPEED = 5
DEFAULT_SPACING = 100
MIN_DIFFICULTY = 1
MAX_DIFFICULTY = 5
class Song:
def __init__(self, name, speed, spacing, difficulty):
self.songName = name
self.songChart = name + ".txt"
self.songMP3 = name + ".mp3"
self.chartSpeed = speed
self.chartSpacing = spacing
self.difficulty = difficulty
self.score = 0
self.notesHit = 0
self.multiplier = MULTIPLIER_MIN
self.totalNotesHit = 0
self.totalNotesMissed = 0
self.verifyParameters()
# Check if parameters are valid, and fix them if they are not
def verifyParameters(self):
if self.chartSpeed <= 0:
self.chartSpeed = DEFAULT_SPEED
if self.chartSpacing <= 0:
self.chartSpacing = DEFAULT_SPACING
if self.difficulty > MAX_DIFFICULTY:
self.difficulty = MAX_DIFFICULTY
elif self.difficulty < MIN_DIFFICULTY:
self.difficulty = MIN_DIFFICULTY
# Get name of song
def getName(self):
return self.songName
# Get file name for chart
def getChart(self):
return self.songChart
# Get mp3 file for song
def getMP3(self):
return self.songMP3
# Determines the speed of the chart
def getChartSpeed(self):
return self.chartSpeed
# Determines the spacing of notes in the chart
def getChartSpacing(self):
return self.chartSpacing
# Increment the score and adjust multiplier if necessary
def noteHit(self):
self.score = self.score + (HIT_SCORE * self.multiplier)
self.notesHit = self.notesHit + 1
self.totalNotesHit = self.totalNotesHit + 1
if self.notesHit >= NOTE_STREAK * self.multiplier and self.multiplier < MULTIPLIER_MAX:
self.notesHit = 0
self.multiplier = self.multiplier + 1
# Reset multiplier and dock points
def noteMiss(self):
self.totalNotesMissed = self.totalNotesMissed + 1
if self.score < 0:
self.score = 0
self.notesHit = 0
self.multiplier = MULTIPLIER_MIN
# Set everything back to default values
def reset(self):
self.score = 0
self.notesHit = 0
self.multiplier = MULTIPLIER_MIN
self.totalNotesHit = 0
self.totalNotesMissed = 0
# Returns the current score
def getScore(self):
return str(self.score)
# Returns the current mutliplier
def getMultiplier(self):
return str(self.multiplier)
# Returns the difficulty of the song
def getDifficulty(self):
return self.difficulty
# Returns the number of notes hit and missed in the song
def getSummary(self):
return (str(self.totalNotesHit), str(self.totalNotesMissed))