Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. import time
  2. import random
  3. from datetime import datetime
  4. from datetime import timedelta
  5.  
  6. class Tetromino():
  7.  
  8. colours = ['red', 'blue', 'orange', 'magenta', 'green'];
  9. types = ['a', 'b', 'c', 'd', 'e'];
  10.  
  11. def __init__(self):
  12. self.x = 4;
  13. self.y = 5;
  14. self.rotation = 0;
  15. randIndex = random.randrange(0,len(Tetromino.types))
  16. self.type = Tetromino.types[randIndex];
  17. self.colour = Tetromino.colours[randIndex];
  18.  
  19. def moveLeft(self):
  20. if(self.x > 1):
  21. self.x -= 1;
  22.  
  23. def moveRight(self):
  24. if(self.x < 10):
  25. self.x += 1;
  26.  
  27. def rotateCW(self):
  28. if(self.rotation == 3):
  29. self.rotation = -1;
  30.  
  31. self.rotation += 1;
  32.  
  33. def rotateACW(self):
  34. if(self.rotation == 0):
  35. self.rotation = 4;
  36.  
  37. self.rotation -= 1;
  38.  
  39. class Game():
  40.  
  41. def __init__(self):
  42. self.currentPiece = Tetromino();
  43. self.gameLoop();
  44.  
  45.  
  46. def gameLoop(self):
  47. while(True):
  48. if(self.currentPiece == None):
  49. self.currentPiece = Tetromino();
  50.  
  51. timeout = 1 # [seconds];
  52. timeout_start = time.time();
  53.  
  54. while time.time() < timeout_start + timeout:
  55. self.movement();
  56. self.rotation();
  57.  
  58. self.currentPiece.y += 1;
  59. print(self.currentPiece.type + ", y=" + str(self.currentPiece.y) + ", r=" + str(self.currentPiece.rotation) + ", x=" + str(self.currentPiece.x));
  60. if(self.currentPiece.y > 20):
  61. self.currentPiece = None;
  62.  
  63. def movement(self):
  64. ran = random.randint(1,2);
  65. if(ran == 1):
  66. self.currentPiece.moveLeft();
  67. else:
  68. self.currentPiece.moveRight();
  69.  
  70. #time.sleep(.1)
  71. #print("");
  72.  
  73. def rotation(self):
  74. ran = random.randint(1,2);
  75. if(ran == 1):
  76. self.currentPiece.rotateACW();
  77. else:
  78. self.currentPiece.rotateCW();
  79.  
  80. #time.sleep(.1)
  81. #print("");
  82.  
  83. def main():
  84. game = Game();
  85.  
  86. main();
  87.  
  88.  
  89.  
  90.  
  91. d, y=6, r=1, x=9
  92. d, y=7, r=3, x=1
  93. d, y=8, r=3, x=4
  94. d, y=9, r=1, x=9
  95. d, y=10, r=2, x=4
  96. d, y=11, r=0, x=4
  97. d, y=12, r=3, x=10
  98. d, y=13, r=2, x=7
  99. d, y=14, r=3, x=8
  100. d, y=15, r=0, x=7
  101. d, y=16, r=3, x=3
  102. d, y=17, r=0, x=8
  103. d, y=18, r=3, x=9
  104. d, y=19, r=3, x=9
  105. d, y=20, r=2, x=10
  106. d, y=21, r=2, x=10
  107. b, y=6, r=0, x=3
  108. b, y=7, r=1, x=4
  109. b, y=8, r=2, x=1
  110. b, y=9, r=1, x=5
  111. b, y=10, r=1, x=4
  112. b, y=11, r=2, x=1
  113. b, y=12, r=1, x=9
  114. b, y=13, r=0, x=8
  115. b, y=14, r=1, x=2
  116. b, y=15, r=2, x=5
  117. b, y=16, r=3, x=4
  118. b, y=17, r=1, x=3
  119. b, y=18, r=1, x=8
  120. b, y=19, r=0, x=8
  121. b, y=20, r=0, x=5
  122. b, y=21, r=0, x=4
  123. a, y=6, r=2, x=10
  124. a, y=7, r=1, x=1
  125. a, y=8, r=2, x=9
  126. a, y=9, r=1, x=7
  127. a, y=10, r=2, x=2
  128. a, y=11, r=0, x=2
  129. a, y=12, r=1, x=2
  130. a, y=13, r=3, x=4
  131. a, y=14, r=1, x=4
  132. a, y=15, r=1, x=6
  133. a, y=16, r=2, x=5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement