www.codingmarch.com
游戏分享:手把手教你用
Python
编写
俄罗斯方块(十)
2017.12.28
这是俄罗斯方块的最后一章了
经历了这么多游戏
编写了这么多代码
你的心中是否有所收获呢
温故而知新
在一段时间的学习之后
也要懂得总结与回顾
从底板坐标转换为像素坐标
437.
def
convertToPixelCoords(boxx,
boxy):
438.
#
Convert
the
given
xy
coordinates
of
the
board
to
xy
439.
#
coordinates
of
the
location
on
the
screen.
440.
return
(XMARGIN
+
(boxx
*
BOXSIZE)),
(TOPMARGIN
+
(boxy
*
BOXSIZE))
该辅助函数将板的坐标转换为像素坐标。
此功能与前一游戏程序中使用的其他
“转换坐标”功能相同。
在屏幕上绘制底板或任何地方的方块
443.
def
drawBox(boxx,
boxy,
color,
pixelx=None,
pixely=None):
444.
#
draw
a
single
box
(each
tetromino
piece
has
four
boxes)
445.
#
at
xy
coordinates
on
the
board.
Or,
if
pixelx
&
pixely
446.
#
are
specified,
draw
to
the
pixel
coordinates
stored
in
447.
#
pixelx
&
pixely
(this
is
used
for
the
"Next"
piece).
448.
if
color
==
BLANK:
449.
return