-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathview.py
More file actions
114 lines (97 loc) · 4.04 KB
/
view.py
File metadata and controls
114 lines (97 loc) · 4.04 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import audio
import visual
import pygame
class View:
"""
The class used to relate the visual and audio components before passing
into the game model.
Attributes:
visual -> Visual class with functions to display objects on the screen
audio -> Audio class with functions to play audio files
show_home_screen -> boolean for displaying the home screen
show_instructions -> boolean for displaying the instructions
show_credits -> boolean for displaying the credits
game_on -> boolean to determine whether to display the game
"""
def __init__(self,map):
"""Initalize the View class with default variable values"""
self.visual = visual.VisualView(map)
self.audio = audio.Audio()
self.show_home_screen = True
self.show_instructions = False
self.show_credits = False
self.game_on = False
def update_screen(self,screen):
"""Updates screen that is displayed in game window
This function takes in a screen name as a string, refreshes the game
window and calls a function to displays the correct screen.
Keyword arguments:
screen -> a string of text that indicates a screen to display
('home_screen','instructions','credits','game')
Return values: None
"""
self.visual.clear_screen()
self.display_correct_screen(screen)
self.visual.close_screen()
self.visual.refresh_screen()
def display_correct_screen(self,screen):
"""Calls function to display screen
This function takes in a screen name as a string and draws the
appropriate screen
Keyword arguments:
screen -> a string of text that indicates a screen to display
('home_screen','instructions','credits','game')
Return values: None
"""
if screen == 'home_screen':
self.visual.draw_home_screen()
elif screen == 'instructions':
self.visual.draw_instructions()
elif screen == 'credits':
self.visual.draw_credits()
elif screen == 'game':
self.visual.draw_screen()
def play_echo(self,distance,direction,sound):
"""Calls function to play echo
Keyword arguments:
distance -> integer value for distance to wall
direction -> string with direction being pinged
sound -> sound file to play
Return values: None
"""
self.audio.echo(distance,direction,sound)
def play_footsteps(self,current_time,previous_time,delay,count):
"""Plays footstep audio
Keyword arguments:
current_time -> integer with current time in milliseconds
previous_time -> integer with previous time that footstep audio was
played in milliseconds
delay -> integer indicating milliseconds to wait between playing
footstep audio
count -> integer referencing which footstep audio file to play
Return values: None
"""
if current_time - previous_time >= delay:
previous_time = current_time
if count < 5:
count += 1
self.audio.footstep_audio(count)
else:
count = 0
def say_and_display(self,string,audio_engine):
"""Displays string at the top of the page and reads the text aloud
Keyword arguments:
string -> string to say and displays
audio_engine -> engine to speak text that can have variables like rate,
volume and volume_to_distance
Return values: None
"""
self.visual.clear_screen()
self.display_correct_screen('game')
self.visual.draw_paragraph(string,32,pygame.Rect((self.visual.margin, self.visual.margin-24, self.visual.width - self.visual.margin*2, 160)))
self.visual.close_screen()
self.visual.refresh_screen()
self.audio.string_to_speach(string,audio_engine)
print('trying to display screen')
if __name__ == "__main__":
pass