当前位置:网站首页>PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)
PyGame game: "Changsha version" millionaire started, dare you ask? (multiple game source codes attached)
2022-06-28 09:43:00 【Gu muzia】
Introduction

![]()
Speaking of the computer games I loved to play in my childhood , What do you think ?

The most national is Jinshan typewriter , Then there's minesweeping 、 The battle of hearts , The most popular stand-alone game is 《 MONOPOLY Here & Now: The World Edition 》.
Hee hee Typing games —— Minesweeping is a game that has been written for everyone before ~SO be left over 《 MONOPOLY Here & Now: The World Edition 》 game .
Today, I'd like to show you my skills ——
As a classic strong hand chess game ,“ MONOPOLY Here & Now: The World Edition ” The series has been flourishing for more than ten years , from 2 Dai became popular ,3
Dai became a big brother ,4 Dai created the peak of turn based games ,5 Generation opens the network online battle …… so far , Chinese tycoons
I'm afraid there are few highlights that can surpass the millionaire series .
And roll the dice 、 Open the treasure chest 、 Jumping lattice , Become the majority 80、90 Post childhood memory , Several friends crowded together , Waiting to roll the dice
Buy land and build houses , Sun Xiaomei 、 October 、 Jinbeibei 、 Sharon bath 、 Mrs. Qian 、 Princess Sarah …… These lovely game characters ,
Accompanied us to spend one happy time after another . All right. , The nonsense is a little too much , I can't stop for a moment .
Come on, come on Let's get started !

Text
One 、 Big rich weng And brigade
Hey ! Yuanxiao , Do you have any friends coming to Changsha ?

Today's 《 MONOPOLY Here & Now: The World Edition 》 The game is based on the famous scenic spots in Changsha 、 You can see , The map is inlaid with 8 It's from Changsha
Iconic location , Press From top to bottom 、 The sequence from left to right is west railway station 、 The Windows of the world 、 May day square 、 Orange Island 、 plant
garden 、 The museum 、 Yuelu Academy 、 Yuelu Mountain . When players reach these Place time , The corresponding special event will be triggered .
Two 、 Special events
1) The special events triggered are as follows :
West Station : Players will stop for a day when passing the west station , That's one You can't roll dice in this round , In return , The player GPA rising 0.2.
The Windows of the world : Players will play for a day when they pass through the window of the world , That is, one round cannot Dice .
May day square : Players will experience the business of helping to recharge the field once they pass through the May day square , Money increases 500,GPA falling 1.0.
Orange Island : Players pass Orange Island will be thirsty to buy tea with Yan , gold Less money 100.
Botanical garden : Players will buy tickets to watch the performance when they pass through the botanical garden , Money minus Less 200.
The museum : When the player passes the museum, he suddenly remembers that he dropped something in the window of the world , That is, directly to the window of the world , And a round
No dice .
Yuelu Mountain : Players will see the most beautiful scenery when they pass Yuelu Mountain , body 、 The heart is inspired ,GPA rising 0.3.
2) The rules of the game :
As a monopoly game ,“ A trip to Changsha ” The traditional millionaire tour is preserved The mechanism of the play , That is to earn money by buying land and building houses , Some play
When the family runs out of money Cloth goes bankrupt , Game over .
On this basis , In order to reflect more diverse elements plain , The strength of each character in the game is in addition to property , There is another balance
The amount standard ——GPA. When a player's GPA achieve 4.0 when , Game over , The player wins ;GPA achieve 1.0 when ,
Game over , The player failed . This game can support 2~4 How people play , For players 4 A cute The role of the game !
3、 ... and 、 Code demonstration
1) Environmental materials


2) Running environment
Environmental installation The running environment used in this paper :Python3.7、Pycharm Community Edition 2020、Pygame The game module has its own module Connect import
No installation required .( If you need to install the package 、 If you have an activation code or encounter problems, you can send a private message to me !)
Module installation :pip install -i https://pypi.douban.com/simple/ + Module name
3) The main program
import pygame
import sys
import time
from draw import Button, draw_text, draw_mapstatus, draw_player
from game import *
from player import Player
pygame.init()
screen_size = (1080, 680) # The first is the width , The second is height
role_size = (60, 60)
screen = pygame.display.set_mode(screen_size)
pygame.display.set_caption(" MONOPOLY Here & Now: The World Edition —— A trip to Changsha ")
map_screen = pygame.image.load('image/ Map .bmp')
stop_picture = pygame.image.load('image/ prohibit .jpg')
stop_picture = pygame.transform.scale(stop_picture, (20, 20))
lose_sound = pygame.mixer.Sound('sound/ Failure .wav') # Load sound effects
win_sound = pygame.mixer.Sound('sound/ victory .wav')
up_sound = pygame.mixer.Sound('sound/ upgrade .wav')
click_sound = pygame.mixer.Sound('sound/ Key .wav')
chances_sound = pygame.mixer.Sound('sound/ event .wav')
picture_dice = []
for i in range(6):
picture_dice.append(pygame.image.load('image/dice/%d.jpg'%(i+1)))
map_screen = pygame.transform.scale(map_screen, screen_size)
screen.blit(map_screen, (0, 0))
play_button = Button(screen, ' Start the game ') # Draw the start game button
play_button.draw_button()
status = 0 # Control the progress of the game 0: The game has not started 1: Select the number of games 2: Dice 3: Players walk 4: Triggering event 5: Buy land and build houses 6: Game over
cur_player = 0 # Current player
dice_answer = 1 # The result of rolling the dice
player = []
role = []
local_init = [0, 20, 12, 32] # The original position of the four players
map_status = []
for i in range(8):
map_status.append(Map(i)) # Store property information , Including the owner 、 value 、 Rent, etc
while True:
if status == 0: # The game has not started
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
(mouse_x, mouse_y) = event.pos
#print(mouse_x, mouse_y)
if click_button(mouse_x, mouse_y, 0):
click_sound.play()
num_player_button = Button(screen, ' Please enter the number of players (2~4)')
num_player_button.draw_button()
draw_text(screen, (540, 440), ' Operation guide : Press ↑ Dice 、 Buy real estate ',
50, 'STXINGKA.TTF', pygame.Color('gold'))
status = 1
pygame.display.update()
elif status == 1: # Select the number of games
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if 258 <= event.key <= 260 or 50 <= event.key <= 52: # Load the appropriate number of roles
click_sound.play()
role.append(pygame.image.load('image/role/ Small e.jpg'))
role.append(pygame.image.load('image/role/ Pikachu .jpg'))
if event.key == 259 or event.key == 51:
role.append(pygame.image.load('image/role/ Up to duck .jpg'))
elif event.key == 260 or event.key == 52:
role.append(pygame.image.load('image/role/ Up to duck .jpg'))
role.append(pygame.image.load('image/role/ Small yellow chicken .jpg'))
screen.blit(map_screen, (0, 0))
for i in range(len(role)): # Initialize the gamer
role[i] = pygame.transform.scale(role[i], role_size)
player.append(Player(i))
player[i].local = local_init[i]
draw_player(screen, player, role, stop_picture)
status = 2
elif status == 2: # Dice
for i in range(6): # Draw dice animation
screen.blit(picture_dice[i], (500, 400))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == 273:
dice_answer = get_dice()
status = 3
pygame.display.update()
elif status == 3: # Players walk
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
for i in range(dice_answer):
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
player[cur_player].local = (player[cur_player].local + 1) % 40
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
click_sound.play()
pygame.display.update()
time.sleep(0.5)
if Special(player[cur_player].local): # Determine whether to trigger a special event
status = 4
else: # A common location , Judge whether you need to buy land or pay rent
local = player[cur_player].local
if map_status[local2order(local)].owner == -1:
chances_sound.play()
draw_text(screen, (800, 340), ' Whether to buy this land ?(¥%d)' % map_status[local2order(local)].value1, 30,
'STXINGKA.TTF', pygame.Color('grey'))
status = 5
elif map_status[local2order(local)].owner == cur_player and map_status[local2order(local)].level == 1:
chances_sound.play()
draw_text(screen, (800, 340), ' Whether to cover the building ?(¥%d)' % map_status[local2order(local)].value2, 30,
'STXINGKA.TTF', pygame.Color('grey'))
status = 5
elif map_status[local2order(local)].owner == cur_player and map_status[local2order(local)].level == 2:
cur_player = (cur_player + 1) % len(player) # The next player rolls the dice
while player[cur_player].stop == 1:
player[cur_player].stop = 0
cur_player = (cur_player + 1) % len(player)
status = 2
else:
if map_status[local2order(local)].level == 1:
player[cur_player].money -= map_status[local2order(local)].rent1
player[map_status[local2order(local)].owner].money += map_status[local2order(local)].rent1
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' Pay rent (¥%d)' % map_status[local2order(local)].rent1, 30,
'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif map_status[local2order(local)].level == 2:
player[cur_player].money -= map_status[local2order(local)].rent2
player[map_status[local2order(local)].owner].money += map_status[local2order(local)].rent2
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' Pay rent (¥%d)' % map_status[local2order(local)].rent2, 30,
'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
cur_player = (cur_player + 1) % len(player) # The next player rolls the dice
while player[cur_player].stop == 1:
player[cur_player].stop = 0
cur_player = (cur_player + 1) % len(player)
if not game_over(player) == 0:
if game_over(player) > 0:
win_sound.play()
else:
lose_sound.play()
status = 6
else:
status = 2
pygame.display.update()
elif status == 4: # Trigger a special event
if player[cur_player].local == 5: #C floor
player[cur_player].money -= 100
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' Go shopping in Orange Island , money -100', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 11: # Purple exercises
player[cur_player].money += 100
if full_somewhere(35, player):
player[cur_player].gpa += 0.2
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' West Station , Grade point +0.2', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
else:
player[cur_player].local = 35
player[cur_player].stop = 1
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' The museum ', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 15: # Roma building
if cur_player == 0:
player[0].stop = 1
player[0].gpa += 0.2
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (750, 340), ' Study for a day , Grade point +0.2', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 19: # The main building
player[cur_player].gpa += 0.3
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (750, 340), ' Watch the scenery of Yuelu Mountain , Grade point +0.3', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 25: # Xinqing
player[cur_player].money -= 200
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' Go to the botanical garden to see the performance , money -200', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 31: # Second school gate
player[cur_player].money += 500
player[cur_player].gpa -= 1.0
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (750, 340), ' Wuyi Square business , money +500, Grade point -1.0', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 35: # school hospital
player[cur_player].stop = 1
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' The Windows of the world ', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
elif player[cur_player].local == 39: # The library
if not cur_player == 2:
player[cur_player].stop = 1
player[cur_player].gpa += 0.2
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_mapstatus(screen, player, map_status)
draw_player(screen, player, role, stop_picture)
draw_text(screen, (800, 340), ' Soak in the west railway station for a day , Grade point +0.2', 30, 'STXINGKA.TTF', pygame.Color('grey'))
chances_sound.play()
cur_player = (cur_player + 1) % len(player) # The next player rolls the dice
while player[cur_player].stop == 1:
player[cur_player].stop = 0
cur_player = (cur_player + 1) % len(player)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
if not game_over(player) == 0:
if game_over(player) > 0:
win_sound.play()
else:
lose_sound.play()
status = 6
else:
status = 2
elif status == 5: # Buy land and build houses
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == 273:
if map_status[local2order(player[cur_player].local)].level == 0:
player[cur_player].money -= map_status[local2order(player[cur_player].local)].value1
map_status[local2order(player[cur_player].local)].owner = cur_player
map_status[local2order(player[cur_player].local)].level = 1
elif map_status[local2order(player[cur_player].local)].level == 1:
player[cur_player].money -= map_status[local2order(player[cur_player].local)].value2
map_status[local2order(player[cur_player].local)].level = 2
cur_player = (cur_player + 1) % len(player) # The next player rolls the dice
while player[cur_player].stop == 1:
player[cur_player].stop = 0
cur_player = (cur_player + 1) % len(player)
status = 2
screen.blit(map_screen, (0, 0))
screen.blit(picture_dice[dice_answer - 1], (500, 400))
draw_player(screen, player, role, stop_picture)
draw_mapstatus(screen, player, map_status)
up_sound.play()
if not game_over(player) == 0:
if game_over(player) > 0:
win_sound.play()
else:
lose_sound.play()
status = 6
pygame.display.update()
elif status == 6: # Game over
if game_over(player) > 0:
draw_text(screen, (540, 340), ' Game over ,%s victory ' % player[game_over(player)-1].name,
50, 'STXINGKA.TTF', pygame.Color('darkgreen'))
draw_text(screen, (540, 440), ' Another round ',
50, 'STXINGKA.TTF', pygame.Color('darkgreen'))
else :
draw_text(screen, (540, 340), ' Game over ,%s Failure ' % player[- game_over(player) - 1].name,
50, 'STXINGKA.TTF', pygame.Color('darkgreen'))
draw_text(screen, (540, 440), ' Another round ',
50, 'STXINGKA.TTF', pygame.Color('darkgreen'))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
(mouse_x, mouse_y) = event.pos
if click_button(mouse_x, mouse_y, 1):
player = []
role = []
map_status = []
for i in range(8):
map_status.append(Map(i))
cur_player = 0
click_sound.play()
screen.blit(map_screen, (0, 0))
num_player_button = Button(screen, ' Please enter the number of players (2~4)')
num_player_button.draw_button()
draw_text(screen, (540, 440), ' Operation guide : Press ↑ Dice 、 Buy real estate ',
50, 'STXINGKA.TTF', pygame.Color('gold'))
status = 1
pygame.display.update()
4) Player character
class Player: # Player class
def __init__(self, order):
self.money = 3000
self.gpa = 3.0
self.local = 0
self.stop = 0
if order == 0:
self.name = ' Small E'
elif order == 1:
self.name = ' Pikachu '
elif order == 2:
self.name = ' Up to duck '
elif order == 3:
self.name = ' Small yellow chicken '
5) Omit ......
There are so many codes : As the old rule, I can get it for free !( See the end of the article )
Four 、 Effect display
1) Initial interface
Click the left mouse button “ Start the game ” that will do !

2) Select the game number interface
Keyboard entry 2~4 The number of !

3) follow-up ......
Press keyboard “↑” Key roll 、 Press keyboard “↑” Key to buy land ( The operation of upgrading real estate is the same 、 Click the left mouse button “ Another round ” Restart the game !

summary
All right. ~ A simple, interesting and fun 《 Changsha trip millionaire 》 The little game is officially over . Hurry to find me and play with the material
play ~ Don't just focus on this game ~ You are welcome to read more in previous issues !
Complete material 、 Installation environment 、 The source code can be seen at the end of the text !
Recommended reading in the past ——
Objective 1.0 Super Marie
project 1.2 Heart card battle game
project 1.1 Mine clearance
project 1.2 Contra
A summary of the article ——
project 1.0 Python—2021 | Summary of existing articles | Continuous updating , Just read this article directly
( More + The source code is summarized in the article !! Welcome to ~)

边栏推荐
- The digital human industry is about to break out. What is the market pattern?
- 当面试官让你用两种方式写BinarySort
- Matplotlib属性及注解
- 1182:合影效果
- JDBC connection database (MySQL) steps
- Divide and rule classic Hanoi
- bad zipfile offset (local header sig)
- Write a simple timeline
- What is online account opening? Is it safe to open an account online now?
- Calcul des frais d'achat et de vente d'actions
猜你喜欢

Explain final, finally, and finalize

Bridge mode

Music website design based on harmonyos (portal page)

Dbeaver连接人大金仓KingbaseES V8(超详细图文教程)

Calculation of stock purchase and sale expenses

代理模式(Proxy)

PMP考试重点总结六——图表整理

The digital human industry is about to break out. What is the market pattern?

PMP examination key summary VIII - monitoring process group (2)

Composite pattern
随机推荐
缓存之王Caffeine Cache,性能比Guava更强
PMP needs to master its own learning methods
多线程-并发并行-线程进程
组合模式(Composite Pattern)
A classic JVM class loaded interview question class singleton{static singleton instance = new singleton(); private singleton() {}
MySQL基础知识点总结
June 27, 2022: give a 01 string with a length of N. now please find two intervals so that the number of 1 is equal and the number of 0 is equal in the two intervals. The two intervals can intersect bu
Machine virtuelle 14 installer win7 (tutoriel)
Boundary value analysis method for learning basic content of software testing (2)
Basic knowledge of hard disk (head, track, sector, cylinder)
The digital human industry is about to break out. What is the market pattern?
Understanding the IO model
JVM系列(2)——垃圾回收
浅谈小程序对传媒行业数字化的影响
==和eqauls()的区别
再见!IE浏览器,这条路由Edge替IE继续走下去
创建多线程的方法---1创建Thread类的子类及多线程原理
Matplotlib attribute and annotation
Key summary V of PMP examination - execution process group
手机号、邮箱正则验证[通俗易懂]