-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.py
38 lines (27 loc) · 1.04 KB
/
data.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
from os.path import *
from Tkinter import PhotoImage
# modified from Super Mario pygame version. Adapted it to a class
class Data(object):
def __init__(self):
self.dirPath = normpath(join(abspath(dirname(__file__)), "data"))
def filePath(self, fileName):
return join(self.dirPath, fileName)
def load(self, fileName):
return open(self.filePath(fileName), "r")
def loadImage(self, fileName):
return PhotoImage(file=self.filePath(fileName))
def loadSmallerImage(self, fileName, X, Y):
return PhotoImage(file=self.filePath(fileName)).subsample(X, Y)
def loadBiggerImage(self, fileName, X, Y):
return PhotoImage(file=self.filePath(fileName)).zoom(X, Y)
@staticmethod
def testFilePath():
data = Data()
assert (data.filePath("mario.gif")
== "/Users/chenlian/Dropbox/2014fall/15112/termProject/GamePart/data/mario.gif")
print "Passed!"
@staticmethod
def testAll():
Data.testFilePath()
if __name__ == '__main__':
Data.testAll()