diff --git a/README.md b/README.md index a571cf6..9056128 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ -# Submarine-ladders-Python +# python制作海底飞行棋(含源码) -python制作海底飞行棋(含源码) \ No newline at end of file +飞行棋玩过吗?玩过python制作的海底飞行棋玩过吗?额。。。。。。 + +今天就来教制作海底飞行棋 + +# 核心玩法 + +两名玩家通过→和←操控游戏角色,最终全部到达终点,(本游戏适合全年龄段,不要太较真)谁的分数越高谁就获胜 + +# 主要代码思想 + +实现游戏角色移动,分数,分数判断 + +在游戏中,设立三个游戏状态 + +- start 开始 +- running 运行 +- game——over 游戏结束 + +三个状态都很重要,对于制作游戏有很大帮助 + +要依次根据玩家操作变换 + +其次就是鼠标和键盘的按下事件 + +没有这一步,游戏就变成了动画片,不能控制,就看着它运行 + +而且这一步很容易报错,因为代码量多 + +最后就是完成所有的调用 + +一切完成后就OK了 \ No newline at end of file diff --git a/src/images/Patrickstar.png b/src/images/Patrickstar.png new file mode 100644 index 0000000..fc95b89 Binary files /dev/null and b/src/images/Patrickstar.png differ diff --git a/src/images/Spongebob.png b/src/images/Spongebob.png new file mode 100644 index 0000000..50c30e5 Binary files /dev/null and b/src/images/Spongebob.png differ diff --git a/src/images/bg.jpg b/src/images/bg.jpg new file mode 100644 index 0000000..6d955e5 Binary files /dev/null and b/src/images/bg.jpg differ diff --git a/src/images/bg.png b/src/images/bg.png new file mode 100644 index 0000000..cc27a6f Binary files /dev/null and b/src/images/bg.png differ diff --git a/src/images/bullet_tip.png b/src/images/bullet_tip.png new file mode 100644 index 0000000..efad89e Binary files /dev/null and b/src/images/bullet_tip.png differ diff --git a/src/images/dial0.png b/src/images/dial0.png new file mode 100644 index 0000000..19a8387 Binary files /dev/null and b/src/images/dial0.png differ diff --git a/src/images/dial1.png b/src/images/dial1.png new file mode 100644 index 0000000..8bb8b8e Binary files /dev/null and b/src/images/dial1.png differ diff --git a/src/images/dial2.png b/src/images/dial2.png new file mode 100644 index 0000000..4cd6b68 Binary files /dev/null and b/src/images/dial2.png differ diff --git a/src/images/dial3.png b/src/images/dial3.png new file mode 100644 index 0000000..fa78f70 Binary files /dev/null and b/src/images/dial3.png differ diff --git a/src/images/end.jpg b/src/images/end.jpg new file mode 100644 index 0000000..94b32f3 Binary files /dev/null and b/src/images/end.jpg differ diff --git a/src/images/end1.png b/src/images/end1.png new file mode 100644 index 0000000..65f3b22 Binary files /dev/null and b/src/images/end1.png differ diff --git a/src/images/end2.png b/src/images/end2.png new file mode 100644 index 0000000..877a977 Binary files /dev/null and b/src/images/end2.png differ diff --git a/src/images/font1.ttf b/src/images/font1.ttf new file mode 100644 index 0000000..aa7a22a Binary files /dev/null and b/src/images/font1.ttf differ diff --git a/src/images/gameover.png b/src/images/gameover.png new file mode 100644 index 0000000..88db078 Binary files /dev/null and b/src/images/gameover.png differ diff --git a/src/images/hero.png b/src/images/hero.png new file mode 100644 index 0000000..ca9c296 Binary files /dev/null and b/src/images/hero.png differ diff --git a/src/images/hotdog.png b/src/images/hotdog.png new file mode 100644 index 0000000..4c380ee Binary files /dev/null and b/src/images/hotdog.png differ diff --git a/src/images/start.png b/src/images/start.png new file mode 100644 index 0000000..2085d59 Binary files /dev/null and b/src/images/start.png differ diff --git a/src/images/time_tip.png b/src/images/time_tip.png new file mode 100644 index 0000000..c50bca3 Binary files /dev/null and b/src/images/time_tip.png differ diff --git a/src/index.py b/src/index.py new file mode 100644 index 0000000..49e6c1c --- /dev/null +++ b/src/index.py @@ -0,0 +1,108 @@ +# coding:utf-8 +import pygame,sys,os,easygui,random,time +from pygame.locals import * +from sys import exit +from func import fillText,drawPlayer,addScore_s,addScore_p,drawStep +pygame.init() +# 窗口定位 +os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (100, 30) +# 设置一个长宽窗口 +canvas = pygame.display.set_mode((1025, 689)) +canvas.fill([255, 255, 255]) +# 设置窗口标题 +pygame.display.set_caption("飞行棋") + +# 图片加载 +start = pygame.image.load('images/start.png') +bg = pygame.image.load('images/bg.png') +end1 = pygame.image.load('images/end1.png') +end2 = pygame.image.load('images/end2.png') +gameover = pygame.image.load('images/gameover.png') +spongebob = 'spongebob' +patrickstar = 'patrickstar' + + +#设定游戏状态和玩家分数 +state = 'START' +score_s = 0 +score_p = 0 +#判断哪位玩家移动 +turn = True +#控制玩家到达位置 +sum_s = 0 +sum_p = 0 +#控制玩家移动步数 +step_s = 0 +step_p = 0 +#表示到达终点 +final = 0 +#创建游戏控制 +def gameControl(): + global step_s,step_p,score_s,score_p,final,sum_s,sum_p,turn + #随机生成行进步数 + step_s = random.randint(1,4) + step_p = random.randint(1,4) + #游戏开始状态 + if state == 'START': + canvas.blit(start,(0,0)) + elif state == 'READY': + canvas.blit(bg,(0,0)) + drawPlayer(spongebob,sum_s) + drawPlayer(patrickstar,sum_p) + drawStep(1,(-10,300)) + fillText(score_s ,(30,150)) + fillText(score_p ,(860,150)) + elif state == 'RUNNING': + canvas.blit(bg,(0,0)) + if turn == True:#表示海绵宝宝移动 + sum_s = sum_s + step_s + if sum_s < 14: + drawStep(step_s,(-10,300)) + score_s = addScore_s(sum_s) + else: + canvas.blit(gameover,(40,340)) + final = 1 + elif turn == False:#表示派大星移动 + sum_p = sum_p + step_p + if sum_p < 14: + drawStep(step_p,(-10,300)) + score_p = addScore_p(sum_p) + else: + canvas.blit(gameover,(40,340)) + final = 1 + drawPlayer(spongebob,sum_s) + drawPlayer(patrickstar,sum_p) + fillText(score_s,(30,150)) + fillText(score_p,(860,150)) + #游戏结束状态 + elif state == 'END': + if score_s >= score_p : + canvas.blit(end2,(0,0)) + else: + canvas.blit(end1,(0,0)) + +gameControl() +# 根据用户的操作切换游戏状态 +while True: + for event in pygame.event.get(): + if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE: + pygame.quit() + sys.exit() + elif event.type == MOUSEBUTTONDOWN and event.button == 1: + if state == 'START': + state = 'READY' + gameControl() + if state == 'READY': + state = 'RUNNING' + elif event.type == KEYDOWN and event.key == K_LEFT and turn == True: + gameControl() + turn = False + elif event.type == KEYDOWN and event.key == K_RIGHT and turn == False: + gameControl() + turn = True + elif final == 1: + pygame.time.delay(1500) + pygame.display.update() + state = 'END' + gameControl() + pygame.display.update() \ No newline at end of file