exit()
if event.type == pygame.KEYDOWN:
if event.key in self.keys.keys():
self.keysevent.key
if event.key == pygame.K_F11: # F11全屏
self.fullscreen = not self.fullscreen
if self.fullscreen:
self.screen = pygame.display.set_mode(self.size, pygame.FULLSCREEN, 32)
else:
self.screen = pygame.display.set_mode(self.size, 0, 32)
if event.type == pygame.KEYUP:
if event.key in self.keys_up.keys():
self.keys_upevent.key
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button in self.clicks.keys():
self.clicksevent.button
def run(self):
while True:
for event in pygame.event.get():
self.handle_input(event)
self.timer.tick(self.fps)
self.update(pygame.time.get_ticks())
self.draw(pygame.time.get_ticks())
def draw_score(self, color, rect=None):
score = self.score_font.render(str(self.score), True, color)
if rect is None:
r = self.screen.get_rect()
rect = score.get_rect(center=r.center)
self.screen.blit(score, rect)
def is_end(self):
return self.end
def update(self, current_time):
pass
def draw(self, current_time):
pass
class Test(Game):
def init(self, title, size, fps=30):
super(Test, self).init(title, size, fps)
self.bind_key(pygame.K_RETURN, self.press_enter)
def press_enter(self):
print(“press enter”)
def draw(self, current_time):
pass
def press_space(key):
print(“press space.”)
def click(x, y):
print(x, y)
def main():
print(hex2rgb(0xfcf040))
game = Test(“game”, (640, 480))
game.bind_key(pygame.K_SPACE, press_space)
game.bind_click(1, click)
game.run()
if name == ‘main’:
main()
import pygame
import game
ROWS = 17
SIDE = 30
SCREEN_WIDTH = ROWS * SIDE
SCREEN_HEIGHT = ROWS * SIDE
EMPTY = -1
BLACK = (0,0,0)
WHITE = (255, 255, 255)
DIRE = [(1, 0), (0, 1), (1, 1), (1, -1)]
class Gobang(game.Game):
def init(self, title, size, fps=15):
super(Gobang, self).init(title, size, fps)
self.board = [[EMPTY for i in range(ROWS)] for j in range(ROWS)]
self.select = (-1, -1)
self.black = True
self.draw_board()
self.bind_click(1, self.click)
def click(self, x, y):
if self.end:
return
i, j = y // SIDE, x // SIDE
if self.board[i][j] != EMPTY:
return
self.board[i][j] = BLACK if self.black else WHITE
self.draw_chess(self.board[i][j], i, j)
self.black = not self.black
chess = self.check_win()
if chess:
self.end = True
i, j = chess[0]
winer = “Black”
if self.board[i][j] == WHITE:
winer = “White”
pygame.display.set_caption(“五子棋 ---- %s win!” % (winer))
for c in chess:
i, j = c
self.draw_chess((100, 255, 255), i, j)
self.timer.tick(5)
def check_win(self):
for i in range(ROWS):
for j in range(ROWS):
win = self.check_chess(i, j)
if win:
return win
return None
def check_chess(self, i, j):
if self.board[i][j] == EMPTY:
return None
color = self.board[i][j]
for dire in DIRE:
x, y = i, j
chess = []
while self.board[x][y] == color:
chess.append((x, y))
x, y = x+dire[0], y+dire[1]
if x < 0 or y < 0 or x >= ROWS or y >= ROWS:
break
if len(chess) >= 5:
return chess
return None
def draw_chess(self, color, i, j):
center = (jSIDE+SIDE//2, iSIDE+SIDE//2)
pygame.draw.circle(self.screen, color, center, SIDE//2-2)
pygame.display.update(pygame.Rect(jSIDE, iSIDE, SIDE, SIDE))
def draw_board(self):
self.screen.fill((139, 87,66))
for i in range(ROWS):
start = (i*SIDE + SIDE//2, SIDE//2)
end = (iSIDE + SIDE//2, ROWSSIDE - SIDE//2)
pygame.draw.line(self.screen, 0x000000, start, end)
学好 Python 不论是就业还是做副业赚钱都不错,但要学会 Python 还是要有一个学习规划。最后大家分享一份全套的 Python 学习资料,给那些想学习 Python 的小伙伴们一点帮助!
一、Python所有方向的学习路线
Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
二、学习软件
工欲善其事必先利其器。学习Python常用的开发软件都在这里了,给大家节省了很多时间。
三、全套PDF电子书
书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。
四、入门学习视频
我们在看视频学习的时候,不能光动眼动脑不动手,比较科学的学习方法是在理解之后运用它们,这时候练手项目就很适合了。
五、实战案例
光学理论是没用的,要学会跟着一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。
六、面试资料
我们学习Python必然是为了找到高薪的工作,下面这些面试题是来自阿里、腾讯、字节等一线互联网大厂最新的面试资料,并且有阿里大佬给出了权威的解答,刷完这一套面试资料相信大家都能找到满意的工作。
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!