Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
pygame_lesson1_2
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fb172b7b
authored
Dec 28, 2020
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
a0d54ae9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
0 deletions
snake.py
老八和马牛逼.py
贪吃蛇吃粑粑.py
snake.py
deleted
100644 → 0
View file @
a0d54ae9
老八和马牛逼.py
0 → 100644
View file @
fb172b7b
import
random
import
random
# 英雄角色类
class
Hero
(
object
):
def
__init__
(
self
,
name
):
self
.
level
=
1
self
.
hp
=
458
self
.
attack
=
58
self
.
name
=
name
self
.
max_hp
=
self
.
hp
#亚瑟对后羿发起攻击,造成了40点伤害,后羿剩多少血(阵亡)
def
cure
(
self
):
self
.
hp
+=
67
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了吃屎术,回复"
,
67
,
"点屎量,当前屎量是"
,
self
.
hp
)
def
combat
(
self
,
enemy
):
# 攻击
info1
=
self
.
name
+
'对'
+
enemy
.
name
+
'发起屎蛋子攻击,'
info2
=
'造成'
+
str
(
self
.
attack
)
+
'点伤害,'
enemy
.
hp
-=
self
.
attack
if
enemy
.
hp
>
0
:
info3
=
enemy
.
name
+
'还剩'
+
str
(
enemy
.
hp
)
+
'屎量'
info
=
info1
+
info2
+
info3
print
(
info
)
else
:
info3
=
enemy
.
name
+
'已嗝屁,游戏结束'
info
=
info1
+
info2
+
info3
print
(
info
)
exit
()
class
Player
(
Hero
):
def
__init__
(
self
,
name
,
hero_type
):
super
()
.
__init__
(
name
)
self
.
hp
=
279
self
.
attack
=
87
self
.
hero_type
=
hero_type
print
(
self
.
name
,
"创建成功,当前英雄的类型是:"
,
self
.
hero_type
)
print
(
self
.
name
,
'等级、血量、攻击力是'
,
self
.
level
,
self
.
hp
,
self
.
attack
)
def
cure
(
self
):
blood
=
random
.
randint
(
1
,
80
)
self
.
hp
+=
blood
if
self
.
hp
>
self
.
max_hp
:
self
.
hp
=
self
.
max_hp
print
(
self
.
name
+
"使用了吃屎术,回复"
,
blood
,
"点屎量,当前屎量是"
,
self
.
hp
)
superman
=
Hero
(
"马牛逼"
)
batman
=
Player
(
"老八"
,
'吃屎人'
)
print
(
'-'
*
40
)
print
(
' 战斗开始'
)
while
True
:
print
(
'-'
*
48
)
choice
=
input
(
'请输入1(超级无敌大屎蛋子)或2(超级无敌吃屎):'
)
if
choice
==
'q'
:
print
(
'游戏结束'
)
break
elif
choice
==
'1'
:
batman
.
combat
(
superman
)
elif
choice
==
'2'
:
batman
.
cure
()
else
:
print
(
"输入有误~"
)
continue
num
=
random
.
randint
(
1
,
2
)
if
num
==
1
:
superman
.
cure
()
else
:
superman
.
combat
(
batman
)
\ No newline at end of file
贪吃蛇吃粑粑.py
0 → 100644
View file @
fb172b7b
import
pygame
import
pygame
from
pygame
import
locals
#初始化pygame,为使用硬件做准备
pygame
.
init
()
#载入图片
background
=
pygame
.
image
.
load
(
'bg.png'
)
#背景图
head_right
=
pygame
.
image
.
load
(
'right.png'
)
#贪吃蛇的头
apple
=
pygame
.
image
.
load
(
'apple.png'
)
#苹果
body
=
pygame
.
image
.
load
(
'body.png'
)
#贪吃蛇身体
#创建一个窗口
screen
=
pygame
.
display
.
set_mode
((
660
,
480
))
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
locals
.
QUIT
:
#接收到退出事件后退出程序
exit
()
#将背景图画上去
screen
.
blit
(
background
,(
0
,
0
))
#将贪吃蛇蛇头画上去
screen
.
blit
(
head_right
,(
240
,
120
))
#将苹果画上去
screen
.
blit
(
apple
,(
300
,
270
))
#将贪吃蛇身子画上去
screen
.
blit
(
body
,(
210
,
120
))
screen
.
blit
(
body
,(
180
,
120
))
screen
.
blit
(
body
,(
150
,
120
))
#刷新画面
pygame
.
display
.
update
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment