-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path__init__.py
82 lines (68 loc) · 2.79 KB
/
__init__.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
from os.path import join, exists
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill, intent_handler
from .zork import ZorkInterpreter, install_zork_data
class ZorkSkill(MycroftSkill):
def __init__(self):
super(ZorkSkill, self).__init__()
self.room = None
self.playing = False
self.zork = None
self.interpreter = join(self.root_dir, 'frotz/dfrotz')
self.data = join(self.file_system.path, 'zork/DATA/ZORK1.DAT')
self.save_file = join(self.file_system.path, 'save.qzl')
if not exists(self.data):
self.log.info('Installing Zork data to %s', self.file_system.path)
install_zork_data(self.file_system.path)
@intent_handler(IntentBuilder('PlayZork').require('Play').require('Zork'))
def play_zork(self, Message):
"""Starts zork and activates the converse part.
Converse then handles the actual gameplay.
"""
if not self.zork:
self.zork = ZorkInterpreter(self.interpreter,
self.data,
self.save_file)
# Issue look command to get initial description
self.zork.cmd('look')
self.room, description = self.zork.read()
self.speak(description, expect_response=True)
self.playing = True
def leave_zork(self):
self.speak_dialog('LeavingZork')
self.playing = False
self.zork.save()
self.log.info('Zork savegame has been created')
def converse(self, message):
"""Pass sentence on to the frotz zork interpreter.
The commands "quit" and "exit" will immediately exit the game.
"""
utterances = message.data['utterances']
if utterances:
utterance = utterances[0]
if self.playing:
if "quit" in utterance or utterance == "exit":
self.leave_zork()
return True
else:
# Send utterance to zork interpreter and then
# speak response
self.zork.cmd(utterance)
self.room, description = self.zork.read()
if description != "":
self.speak(description, expect_response=True)
return True
return False
@intent_handler(IntentBuilder('DeleteSave').require('Delete')
.require('Zork').require('Save'))
def delete_save(self, Message):
if self.zork.delete_save():
self.speak_dialog('SaveDeleted')
else:
self.speak_dialog('NoSave')
def stop(self, message=None):
"""Stop playing."""
if self.playing:
self.leave_zork()
def create_skill():
return ZorkSkill()