# 引言：

Python是一种简单易学的编程语言，它的灵活性和强大的功能使得它成为了许多开发者的首选。在本文中，我们将使用Python编写三个小游戏，展示Python的魅力和游戏开发的乐趣。这些小游戏将带领你进入一个奇妙的游戏世界，让你体验到编程的乐趣和创造力。

# 第一部分：猜数字游戏

## 代码案例1：

``````import random

def guess_number():
number = random.randint(1, 100)
guess = 0
tries = 0

while guess != number:
guess = int(input("请输入一个1到100之间的数字："))
tries += 1

if guess < number:
print("猜小了！")
elif guess > number:
print("猜大了！")
else:
print("恭喜你，猜对了！")
print("你一共猜了", tries, "次。")

guess_number()
``````

# 第二部分：石头剪刀布游戏

## 代码案例2：

``````import random

def rock_paper_scissors():
choices = ["石头", "剪刀", "布"]
player_choice = input("请输入你的选择（石头、剪刀、布）：")
computer_choice = random.choice(choices)

print("你选择了：", player_choice)
print("计算机选择了：", computer_choice)

if player_choice == computer_choice:
print("平局！")
elif (player_choice == "石头" and computer_choice == "剪刀") or
(player_choice == "剪刀" and computer_choice == "布") or
(player_choice == "布" and computer_choice == "石头"):
print("你赢了！")
else:
print("你输了！")

rock_paper_scissors()
``````

# 第三部分：迷宫游戏

## 代码案例3：

``````import pygame

def maze_game():
pygame.init()
screen = pygame.display.set_mode((400, 400))
pygame.display.set_caption("迷宫游戏")

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
# 处理向上移动的逻辑
pass
elif keys[pygame.K_DOWN]:
# 处理向下移动的逻辑
pass
elif keys[pygame.K_LEFT]:
# 处理向左移动的逻辑
pass
elif keys[pygame.K_RIGHT]:
# 处理向右移动的逻辑
pass

screen.fill((255, 255, 255))
# 绘制迷宫和角色
pygame.display.flip()

pygame.quit()

maze_game()
``````

THE END