How To Do IN OOPS instead of displaying Trees in a list

Joined
Dec 5, 2022
Messages
2
Reaction score
0
def draw_forest(win):

therow = 0
trees = 0
y = 14
tree_num = 1

list_of_trees = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

while therow < 10:
x = 14
while trees < 15:
tree = Tree(Point(x,y), "0_tree.png", tree_num)


image = Image(tree.get_point(), tree.get_image())
image.draw(win)
x += 29
tree_num += 1
trees += 1




y += 29
trees = 0
therow += 1

list_of_trees = [list_of_trees] * therow
print(list_of_trees)
return list_of_trees


How to display the following using onject oriented projramming.
 
Joined
Dec 10, 2022
Messages
73
Reaction score
22
The question is kind of broad.
What id Tree() and where does Image() come from? What is Point()?

A basic example of oop

Python:
# import randint
from random import randint

# Define a class
class MyClass:
    def __init__(self, num):
        self.num = num

    def __repr__(self):
        return f'{self.num}'


# Do a for loop with range of 10
for i in range(10):
    # Create and print obect from Myclass class
    print(MyClass(randint(1, 50)))

output
Code:
24
1
47
48
1
34
5
13
41
41
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top