Skip to content
Snippets Groups Projects
Commit f1cabfc8 authored by s2032074's avatar s2032074
Browse files

init() problem solved, simple test for block added

parent 132d11c0
No related branches found
No related tags found
No related merge requests found
{
"python.pythonPath": "D:\\Apps\\anaconda3\\python.exe"
"python.pythonPath": "D:\\Apps\\anaconda3\\python.exe",
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
]
}
\ No newline at end of file
# Block object which will be used in a corsi-blocks test
'''Block object which will be used in a corsi-blocks test'''
#pygame is the library for drawing
import sys
import pygame
import keyboard
class Block:
'''Block class defines the main functions that can be done with the block'''
#Constructor to initiate a block (square)
#x and y -- coordinates of the top left corner
#length -- the length of one side of the square
def __init__(self, x, y, length):
self.x = x
self.y = y
self.x_coord = x
self.y_coord = y
self.length = length
\ No newline at end of file
def draw_block(self, screen):
'''function for drawing a block with initialized parameters'''
pygame.draw.rect(screen, (0, 0, 0),
(self.x_coord, self.y_coord, self.length, self.length),0)
#this class will be tested, thus, we need this main method
#as it sets the environment where we are going to test
def main():
'''This is MAAAAIN'''
pygame.init()
width = 1000
height = 800
pygame.display.set_mode((width, height))
screen = pygame.display.get_surface()
screen.fill((255,255,255))
while True:
block1 = Block(100, 100, 50)
block1.draw_block(screen)
pygame.display.update()
try:
if keyboard.is_pressed('q'):
pygame.quit()
sys.exit()
except:
break
#class functions testing
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment