Angry Transformers Jenga
This code simulates a game of Jenga, but with a twist: the blocks are angry transformers that attack each other when they're knocked over.
Rules:
* The game starts with a tower of blocks, each block representing an angry transformer.
* Players take turns removing one block from the tower and placing it on top.
* If a player knocks over any blocks, the angry transformers on those blocks attack each other.
* The player who knocks over the most angry transformers loses the game.
Code:
```python
import random
transformers = ["Optimus Prime", "Megatron", "Bumblebee", "Starscream", "Soundwave", "Shockwave"]
def build_tower():
tower = []
for i in range(5):
row = []
for j in range(3):
row.append(random.choice(transformers))
tower.append(row)
return tower
def remove_block(tower, player):
print("Player {}'s turn".format(player))
while True:
row = int(input("Choose a row (1-5): ")) - 1
if row < 0 or row >= 5:
print("Invalid row. Please choose a number between 1 and 5.")
continue
column = int(input("Choose a column (1-3): ")) - 1
if column < 0 or column >= 3:
print("Invalid column. Please choose a number between 1 and 3.")
continue
if tower[row][column] == None:
print("There is no block in that position. Please choose a different position.")
continue
break
block = tower[row][column]
tower[row][column] = None
return block, row, column
def attack(block1, block2):
print("{} attacks {}!".format(block1, block2))
if block1 == "Optimus Prime":
if block2 == "Megatron":
return "Optimus Prime wins!"
else:
return "Megatron wins!"
elif block1 == "Megatron":
if block2 == "Optimus Prime":
return "Megatron wins!"
else:
return "Optimus Prime wins!"
else:
if block1 > block2:
return "{} wins!".format(block1)
else:
return "{} wins!".format(block2)
def game_over(player1_score, player2_score):
print("Game over!")
if player1_score > player2_score:
print("Player 1 wins!")
elif player2_score > player1_score:
print("Player 2 wins!")
else:
print("Tie!")
def main():
# Build the tower
tower = build_tower()
print("Tower built!")
# Players
player1_score = 0
player2_score = 0
while True:
# Player 1's turn
block1, row1, column1 = remove_block(tower, 1)
# Check for attacks
if row1 > 0 and tower[row1 - 1][column1] != None:
attack(block1, tower[row1 - 1][column1])
player1_score += 1
tower[row1 - 1][column1] = None
if row1 < 4 and tower[row1 + 1][column1] != None:
attack(block1, tower[row1 + 1][column1])
tower[row1 - 1][column1] = None
player1_score += 1
if column1 > 0 and tower[row1][column