-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkshop.py
More file actions
223 lines (132 loc) · 3.42 KB
/
workshop.py
File metadata and controls
223 lines (132 loc) · 3.42 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# if, while, for, switch/case, functions, classes, exceptions, datatypes
# x = 23
# if x == 42:
# print 'the universe is fine'
# elif x == 23:
# print 'random string'
# else:
# print 'else'
# while x > 0:
# x -= 1
# print x
# for i in range(10):
# print i
# def fun1(p1, p2):
# print p1+p2
# fun1(1, 2)
# def throw1():
# raise Exception("some error")
# class MyEx(Exception):
# pass
# try:
# throw1()
# except Exception as e:
# print 'i have an exception::', e
#float, int, date, dict, list(vector)
# print 2.0
# print 2
# from datetime import datetime
# print datetime.now()
# print {1: 'value1', 2: 'value2'}
# print [1, 2, 3]
# x = {1: 'value1', 2: 'value2'}
# try:
# print x[10]
# except KeyError as ke:
# print 'i dont have the key: ', ke
# x[10] = ['this is dog', 10]
# print x[10]
# x = [1, 'a', 2, 3, 4]
# # print x[0]
# # print x[-1]
# # print x[:]
# y = x[:]
# y[0] = 42
# print x
# class BaseClass(object):
# def __init__(self):
# self.x = 42
# self.init2()
# print 'init base'
# def init2(self):
# self.x2 = self.x + 10
# print 'base init2'
# class Class1(BaseClass):
# def __init__(self, p):
# super(Class1, self).__init__()
# self.p = p
# def init2(self):
# print 'derived init2'
# c = Class1('this is p')
# b = BaseClass()
# print c.p
# x = (1, 2, 3)
# a1, a2, a3 = x
# print a1, a2
# a1, a2 = a2, a1
# print a1, a2
# x = lambda p: p+1
# print x(41)
# x = lambda: 42
# print x()
# def crash(n):
# if n == 0:
# return
# print n
# crash(n-1)
# crash(10)
# import os, sys
# import pygame
# from pygame.locals import *
# def load_image(name, colorkey=None):
# fullname = os.path.join('assets', name)
# try:
# image = pygame.image.load(fullname)
# except pygame.error as message:
# print 'Cannot load image:', fullname
# raise SystemExit, message
# image = image.convert()
# if colorkey is not None:
# if colorkey is -1:
# colorkey = image.get_at((0,0))
# image.set_colorkey(colorkey, RLEACCEL)
# return image, image.get_rect()
# class GameObject(pygame.sprite.Sprite):
# def __init__(self, name):
# super(GameObject, self).__init__()
# self.image, self.rect = load_image(name)
# def update(self):
# raise NotImplementedError('abstract method')
# class Ball(GameObject):
# def __init__(self):
# super(Ball, self).__init__('ball.gif')
# self.speed = [10, 10]
# def update(self):
# self.rect = self.rect.move(self.speed)
# if self.rect.top < 0 or self.rect.bottom > 480:
# self.speed[1] = -self.speed[1]
# if self.rect.left < 0 or self.rect.right > 640:
# self.speed[0] = -self.speed[0]
# # initialize
# pygame.init()
# screen = pygame.display.set_mode((640, 480))
# allsprites = pygame.sprite.RenderPlain([Ball()])
# background = pygame.Surface(screen.get_size()).convert()
# background.fill((163, 73, 164))
# def update():
# allsprites.update()
# def render():
# screen.blit(background, (0, 0))
# allsprites.draw(screen)
# pygame.display.flip()
# clock = pygame.time.Clock()
# def wait():
# clock.tick(30)
# while True:
# update()
# render()
# wait()
# def fun(*args, **kwargs):
# print args
# print kwargs
# fun(1, 2, param='p1')