2024.9.29
玩了好几天游戏。
感觉有点灵感了。还想继续玩游戏。
2024.10.4
今天练习阿斯汤加练完从早上10点睡到下午2点.跑到单位玩游戏玩到晚上10点多.
现在回家突然有了灵感
顺便说一句,因为后弯不好,明天加练一次.
然后去丈母娘家.
加油吧
第一章、追求可以外调的函数draw_rec2
我在self的基础上如何让它的变量能够被外部调用.
def draw_rec2(self, other_rec):
x = other_rec.out_x
y = other_rec.out_y
width_r = other_rec.out_width
height_r = other_rec.out_height
turtle.penup()
turtle.goto(x, y)
turtle.dot(6, "yellow")
turtle.goto(width_r/ 2 + x, height_r/2 + y)
turtle.pendown()
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.right(90)
turtle.forward(width_r)
turtle.right(90)
turtle.forward(height_r)
turtle.hideturtle()
turtle.done()
在这个代码前self 后面加了一个other_rec利用他来作为输入的入口.也是为了扣题上所说的.
但实际的问题却很头疼.
1 statement expected,found py:dedemt
2 Method ‘draw_rec2’ may be ‘static’
不管了实际试一下看看如何
class Rectangle2D:
def __init__(self, x, y, width, height):
self.__x = x
self.__y = y
self.__width = width
self.__height = height
def get_area(self):
return self.__width * self.__height
def get_perimeter(self):
return (self.__width + self.__height) * 2
def out_x(self):
return self.__x
def out_y(self):
return self.__y
def out_width(self):
return self.__width
def out_height(self):
return self.__height
# 他内带绘画矩形,直接调用的self
def draw_rec1(self):
turtle.penup()
turtle.goto(self.__x, self.__y)
turtle.dot(6, "blue")
turtle.goto(self.__x-self.__width / 2