Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import random
- from datetime import datetime
- from datetime import timedelta
- class Tetromino():
- colours = ['red', 'blue', 'orange', 'magenta', 'green'];
- types = ['a', 'b', 'c', 'd', 'e'];
- def __init__(self):
- self.x = 4;
- self.y = 5;
- self.rotation = 0;
- randIndex = random.randrange(0,len(Tetromino.types))
- self.type = Tetromino.types[randIndex];
- self.colour = Tetromino.colours[randIndex];
- def moveLeft(self):
- if(self.x > 1):
- self.x -= 1;
- def moveRight(self):
- if(self.x < 10):
- self.x += 1;
- def rotateCW(self):
- if(self.rotation == 3):
- self.rotation = -1;
- self.rotation += 1;
- def rotateACW(self):
- if(self.rotation == 0):
- self.rotation = 4;
- self.rotation -= 1;
- class Game():
- def __init__(self):
- self.currentPiece = Tetromino();
- self.gameLoop();
- def gameLoop(self):
- while(True):
- if(self.currentPiece == None):
- self.currentPiece = Tetromino();
- timeout = 1 # [seconds];
- timeout_start = time.time();
- while time.time() < timeout_start + timeout:
- self.movement();
- self.rotation();
- self.currentPiece.y += 1;
- print(self.currentPiece.type + ", y=" + str(self.currentPiece.y) + ", r=" + str(self.currentPiece.rotation) + ", x=" + str(self.currentPiece.x));
- if(self.currentPiece.y > 20):
- self.currentPiece = None;
- def movement(self):
- ran = random.randint(1,2);
- if(ran == 1):
- self.currentPiece.moveLeft();
- else:
- self.currentPiece.moveRight();
- #time.sleep(.1)
- #print("");
- def rotation(self):
- ran = random.randint(1,2);
- if(ran == 1):
- self.currentPiece.rotateACW();
- else:
- self.currentPiece.rotateCW();
- #time.sleep(.1)
- #print("");
- def main():
- game = Game();
- main();
- d, y=6, r=1, x=9
- d, y=7, r=3, x=1
- d, y=8, r=3, x=4
- d, y=9, r=1, x=9
- d, y=10, r=2, x=4
- d, y=11, r=0, x=4
- d, y=12, r=3, x=10
- d, y=13, r=2, x=7
- d, y=14, r=3, x=8
- d, y=15, r=0, x=7
- d, y=16, r=3, x=3
- d, y=17, r=0, x=8
- d, y=18, r=3, x=9
- d, y=19, r=3, x=9
- d, y=20, r=2, x=10
- d, y=21, r=2, x=10
- b, y=6, r=0, x=3
- b, y=7, r=1, x=4
- b, y=8, r=2, x=1
- b, y=9, r=1, x=5
- b, y=10, r=1, x=4
- b, y=11, r=2, x=1
- b, y=12, r=1, x=9
- b, y=13, r=0, x=8
- b, y=14, r=1, x=2
- b, y=15, r=2, x=5
- b, y=16, r=3, x=4
- b, y=17, r=1, x=3
- b, y=18, r=1, x=8
- b, y=19, r=0, x=8
- b, y=20, r=0, x=5
- b, y=21, r=0, x=4
- a, y=6, r=2, x=10
- a, y=7, r=1, x=1
- a, y=8, r=2, x=9
- a, y=9, r=1, x=7
- a, y=10, r=2, x=2
- a, y=11, r=0, x=2
- a, y=12, r=1, x=2
- a, y=13, r=3, x=4
- a, y=14, r=1, x=4
- a, y=15, r=1, x=6
- a, y=16, r=2, x=5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement