精华内容
下载资源
问答
  • 主要介绍了python3实现弹弹球小游戏,图形用户界面tkinter,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • 本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下from tkinter import *from tkinter import messageboximport randomimport timefrom PIL import Image, ImageTkimport sysclass ...

    本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下

    from tkinter import *

    from tkinter import messagebox

    import random

    import time

    from PIL import Image, ImageTk

    import sys

    class Game:

    def __init__(self):

    self.tk = Tk()

    self.times = 0

    sw = self.tk.winfo_screenwidth()

    sh = self.tk.winfo_screenheight()

    image = Image.open(r'02.jpg')

    background_image = ImageTk.PhotoImage(image)

    ww = background_image.width()

    wh = background_image.height()

    x = (sw-ww)/2

    y = (sh-wh)/2

    self.tk.geometry("%dx%d+%d+%d" % (ww, wh, x, y))

    self.tk.title('欢迎进入弹弹弹')

    background_label = Label(self.tk, image=background_image)

    background_label.place(x=0, y=0, relwidth=1, relheight=1)

    self.tk.resizable(False, False)

    self.tk.wm_attributes("-topmost", 1) # at top

    btn1 = Button(self.tk, text='减少难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test1)

    btn2 = Button(self.tk, text='增加难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test2)

    btn1.place(x=380, y=10, width=80, height=30)

    btn2.place(x=500, y=10, width=80, height=30)

    self.canvas = Canvas(self.tk, width=500, height=400,

    bd=0, highlightthickness=0, background='#FFFFFF')

    self.canvas.place(x=190, y=90, width=500, height=400)

    self.tk.update()

    self.xunhuan()

    def xunhuan(self):

    try:

    paddle = Paddle(self.canvas, 'green', 100)

    ball = Ball(self.canvas, paddle, '#D11C43', 0)

    while True:

    if ball.hit_bottom == False:

    ball.draw()

    paddle.draw()

    else:

    b = messagebox.askyesno(

    '失败', message="您的分数为:" + str(ball.score)+"\n是否重新开始游戏?")

    if bool(b) is True:

    paddle.canvas.delete(paddle.id)

    self.sever()

    else:

    sys.exit()

    self.tk.update_idletasks()

    self.tk.update()

    time.sleep(0.01+self.times)

    except:

    sys.exit('游戏已退出!')

    def sever(self):

    self.xunhuan()

    def test1(self):

    self.times += 0.001

    def test2(self):

    self.times -= 0.001

    class Ball:

    def __init__(self, canvas, paddle, color, score):

    self.score = 0

    self.canvas = canvas

    self.paddle = paddle

    self.id = canvas.create_oval(

    20, 20, 35, 35, fill=color, outline='green')

    self.canvas.move(self.id, 245, 100)

    startx = [-3, -2, -1, 1, 2, 3]

    random.shuffle(startx)

    self.x = startx[0]

    self.y = -3

    self.canvas_height = self.canvas.winfo_height()

    self.canvas_width = self.canvas.winfo_width()

    self.hit_bottom = False

    b = messagebox.askyesno('game', '游戏是否开始?')

    if bool(b) is True:

    self.draw()

    else:

    sys.exit()

    def draw(self):

    self.canvas.move(self.id, self.x, self.y)

    pos = self.canvas.coords(self.id)

    if pos[1] <= 0 or self.hit_paddle(pos) == True:

    self.y = -self.y

    if pos[0] <= 0 or pos[2] >= self.canvas_width:

    self.x = -self.x

    if pos[3] >= self.canvas_height:

    self.hit_bottom = True

    def hit_paddle(self, pos):

    paddle_pos = self.canvas.coords(self.paddle.id)

    if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]:

    if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]:

    self.score += 1

    return True

    return False

    class Paddle:

    def __init__(self, canvas, color, width):

    self.canvas = canvas

    self.id = canvas.create_rectangle(0, 0, width, 10, fill=color)

    self.x = 0

    self.y = 0

    self.canvas.move(self.id, 200, 300)

    self.canvas_width = self.canvas.winfo_width()

    self.canvas.bind_all("", self.turn_left)

    self.canvas.bind_all("", self.turn_right)

    def draw(self):

    pos = self.canvas.coords(self.id)

    if pos[0] + self.x >= 0 and pos[2] + self.x <= self.canvas_width:

    self.canvas.move(self.id, self.x, 0)

    def turn_left(self, event):

    self.x = -4

    def turn_right(self, event):

    self.x = 4

    def main():

    game = Game()

    if __name__ == '__main__':

    main()

    d2027654819f59cb71a81e879c752120.png

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

    展开全文
  • 本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下from tkinter import *from tkinter import messageboximport randomimport timefrom PIL import Image, ImageTkimport sysclass ...

    本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下

    from tkinter import *

    from tkinter import messagebox

    import random

    import time

    from PIL import Image, ImageTk

    import sys

    class Game:

    def __init__(self):

    self.tk = Tk()

    self.times = 0

    sw = self.tk.winfo_screenwidth()

    sh = self.tk.winfo_screenheight()

    image = Image.open(r'02.jpg')

    background_image = ImageTk.PhotoImage(image)

    ww = background_image.width()

    wh = background_image.height()

    x = (sw-ww)/2

    y = (sh-wh)/2

    self.tk.geometry("%dx%d+%d+%d" % (ww, wh, x, y))

    self.tk.title('欢迎进入弹弹弹')

    background_label = Label(self.tk, image=background_image)

    background_label.place(x=0, y=0, relwidth=1, relheight=1)

    self.tk.resizable(False, False)

    self.tk.wm_attributes("-topmost", 1) # at top

    btn1 = Button(self.tk, text='减少难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test1)

    btn2 = Button(self.tk, text='增加难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test2)

    btn1.place(x=380, y=10, width=80, height=30)

    btn2.place(x=500, y=10, width=80, height=30)

    self.canvas = Canvas(self.tk, width=500, height=400,

    bd=0, highlightthickness=0, background='#FFFFFF')

    self.canvas.place(x=190, y=90, width=500, height=400)

    self.tk.update()

    self.xunhuan()

    def xunhuan(self):

    try:

    paddle = Paddle(self.canvas, 'green', 100)

    ball = Ball(self.canvas, paddle, '#D11C43', 0)

    while True:

    if ball.hit_bottom == False:

    ball.draw()

    paddle.draw()

    else:

    b = messagebox.askyesno(

    '失败', message="您的分数为:" + str(ball.score)+"\n是否重新开始游戏?")

    if bool(b) is True:

    paddle.canvas.delete(paddle.id)

    self.sever()

    else:

    sys.exit()

    self.tk.update_idletasks()

    self.tk.update()

    time.sleep(0.01+self.times)

    except:

    sys.exit('游戏已退出!')

    def sever(self):

    self.xunhuan()

    def test1(self):

    self.times += 0.001

    def test2(self):

    self.times -= 0.001

    class Ball:

    def __init__(self, canvas, paddle, color, score):

    self.score = 0

    self.canvas = canvas

    self.paddle = paddle

    self.id = canvas.create_oval(

    20, 20, 35, 35, fill=color, outline='green')

    self.canvas.move(self.id, 245, 100)

    startx = [-3, -2, -1, 1, 2, 3]

    random.shuffle(startx)

    self.x = startx[0]

    self.y = -3

    self.canvas_height = self.canvas.winfo_height()

    self.canvas_width = self.canvas.winfo_width()

    self.hit_bottom = False

    b = messagebox.askyesno('game', '游戏是否开始?')

    if bool(b) is True:

    self.draw()

    else:

    sys.exit()

    def draw(self):

    self.canvas.move(self.id, self.x, self.y)

    pos = self.canvas.coords(self.id)

    if pos[1] <= 0 or self.hit_paddle(pos) == True:

    self.y = -self.y

    if pos[0] <= 0 or pos[2] >= self.canvas_width:

    self.x = -self.x

    if pos[3] >= self.canvas_height:

    self.hit_bottom = True

    def hit_paddle(self, pos):

    paddle_pos = self.canvas.coords(self.paddle.id)

    if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]:

    if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]:

    self.score += 1

    return True

    return False

    class Paddle:

    def __init__(self, canvas, color, width):

    self.canvas = canvas

    self.id = canvas.create_rectangle(0, 0, width, 10, fill=color)

    self.x = 0

    self.y = 0

    self.canvas.move(self.id, 200, 300)

    self.canvas_width = self.canvas.winfo_width()

    self.canvas.bind_all("", self.turn_left)

    self.canvas.bind_all("", self.turn_right)

    def draw(self):

    pos = self.canvas.coords(self.id)

    if pos[0] + self.x >= 0 and pos[2] + self.x <= self.canvas_width:

    self.canvas.move(self.id, self.x, 0)

    def turn_left(self, event):

    self.x = -4

    def turn_right(self, event):

    self.x = 4

    def main():

    game = Game()

    if __name__ == '__main__':

    main()

    20191125143734188.jpg

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • 本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下from tkinter import *from tkinter import messageboximport randomimport timefrom PIL import Image, ImageTkimport sysclass ...

    本文实例为大家分享了python3实现弹弹球小游戏的具体代码,供大家参考,具体内容如下

    from tkinter import *

    from tkinter import messagebox

    import random

    import time

    from PIL import Image, ImageTk

    import sys

    class Game:

    def __init__(self):

    self.tk = Tk()

    self.times = 0

    sw = self.tk.winfo_screenwidth()

    sh = self.tk.winfo_screenheight()

    image = Image.open(r'02.jpg')

    background_image = ImageTk.PhotoImage(image)

    ww = background_image.width()

    wh = background_image.height()

    x = (sw-ww)/2

    y = (sh-wh)/2

    self.tk.geometry("%dx%d+%d+%d" % (ww, wh, x, y))

    self.tk.title('欢迎进入弹弹弹')

    background_label = Label(self.tk, image=background_image)

    background_label.place(x=0, y=0, relwidth=1, relheight=1)

    self.tk.resizable(False, False)

    self.tk.wm_attributes("-topmost", 1) # at top

    btn1 = Button(self.tk, text='减少难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test1)

    btn2 = Button(self.tk, text='增加难度', background='#FFFF67',

    activebackground='#3EC23B', command=self.test2)

    btn1.place(x=380, y=10, width=80, height=30)

    btn2.place(x=500, y=10, width=80, height=30)

    self.canvas = Canvas(self.tk, width=500, height=400,

    bd=0, highlightthickness=0, background='#FFFFFF')

    self.canvas.place(x=190, y=90, width=500, height=400)

    self.tk.update()

    self.xunhuan()

    def xunhuan(self):

    try:

    paddle = Paddle(self.canvas, 'green', 100)

    ball = Ball(self.canvas, paddle, '#D11C43', 0)

    while True:

    if ball.hit_bottom == False:

    ball.draw()

    paddle.draw()

    else:

    b = messagebox.askyesno(

    '失败', message="您的分数为:" + str(ball.score)+"\n是否重新开始游戏?")

    if bool(b) is True:

    paddle.canvas.delete(paddle.id)

    self.sever()

    else:

    sys.exit()

    self.tk.update_idletasks()

    self.tk.update()

    time.sleep(0.01+self.times)

    except:

    sys.exit('游戏已退出!')

    def sever(self):

    self.xunhuan()

    def test1(self):

    self.times += 0.001

    def test2(self):

    self.times -= 0.001

    class Ball:

    def __init__(self, canvas, paddle, color, score):

    self.score = 0

    self.canvas = canvas

    self.paddle = paddle

    self.id = canvas.create_oval(

    20, 20, 35, 35, fill=color, outline='green')

    self.canvas.move(self.id, 245, 100)

    startx = [-3, -2, -1, 1, 2, 3]

    random.shuffle(startx)

    self.x = startx[0]

    self.y = -3

    self.canvas_height = self.canvas.winfo_height()

    self.canvas_width = self.canvas.winfo_width()

    self.hit_bottom = False

    b = messagebox.askyesno('game', '游戏是否开始?')

    if bool(b) is True:

    self.draw()

    else:

    sys.exit()

    def draw(self):

    self.canvas.move(self.id, self.x, self.y)

    pos = self.canvas.coords(self.id)

    if pos[1] <= 0 or self.hit_paddle(pos) == True:

    self.y = -self.y

    if pos[0] <= 0 or pos[2] >= self.canvas_width:

    self.x = -self.x

    if pos[3] >= self.canvas_height:

    self.hit_bottom = True

    def hit_paddle(self, pos):

    paddle_pos = self.canvas.coords(self.paddle.id)

    if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]:

    if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]:

    self.score += 1

    return True

    return False

    class Paddle:

    def __init__(self, canvas, color, width):

    self.canvas = canvas

    self.id = canvas.create_rectangle(0, 0, width, 10, fill=color)

    self.x = 0

    self.y = 0

    self.canvas.move(self.id, 200, 300)

    self.canvas_width = self.canvas.winfo_width()

    self.canvas.bind_all("", self.turn_left)

    self.canvas.bind_all("", self.turn_right)

    def draw(self):

    pos = self.canvas.coords(self.id)

    if pos[0] + self.x >= 0 and pos[2] + self.x <= self.canvas_width:

    self.canvas.move(self.id, self.x, 0)

    def turn_left(self, event):

    self.x = -4

    def turn_right(self, event):

    self.x = 4

    def main():

    game = Game()

    if __name__ == '__main__':

    main()

    20191125143734188.jpg

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

    本文标题: python3实现弹弹球小游戏

    本文地址: http://www.cppcns.com/jiaoben/python/288602.html

    展开全文
  • JavaScript 弹弹球小游戏(二)

    千次阅读 2015-04-24 14:58:40
    新版弹弹球小游戏,在上一次的基础上,做了改进,可以任意添加小球,而且跑动时可以互不干扰 var step = 10; function createBall() { //添加到DIV var div = document.getElementById...



    新版弹弹球小游戏,在上一次的基础上,做了改进,可以任意添加小球,而且跑动时可以互不干扰


    <html>
    
    	<head>
    		<meta charset="utf-8">
    		<title></title>
    		<script type="text/javascript">
    			var step = 10;
    
    			function createBall() {
    				//添加到DIV
    				var div = document.getElementById("showDiv");
    				//创建球对象
    				var img = document.createElement("img");
    				img.src = "img/qlz.jpg";
    				img.style.height = "10px";
    				img.style.position = "absolute";
    				img.style.left = parseInt(Math.random() * 59) * 10 + "px";
    				img.style.top = parseInt(Math.random() * 39) * 10 + "px";
    				img.xflag = true;
    				img.yflag = true;
    				//将球添加到DIV
    				div.appendChild(img);
    			}
    
    			function moveBall() {
    				window.setInterval(function() {
    					//获取所有的球
    					var balls = document.getElementsByTagName("img");
    					//遍历小球
    					for (var i = 0; i < balls.length; i++) {
    						var ball = balls[i];
    						var x = parseInt(ball.style.left);
    						var y = parseInt(ball.style.top);
    						//判断X的大小
    						if (ball.xflag) {
    							ball.style.left = x + step + "px";
    							if (x >= 590) {
    								ball.xflag = false;
    							}
    						} else {
    							ball.style.left = x - step + "px";
    							if (x <= 20) {
    								ball.xflag = true;
    							}
    						}
    						//判断Y的大小
    						if (ball.yflag) {
    							ball.style.top = y + step + "px";
    							if (y >= 390) {
    								ball.yflag = false;
    							}
    						} else {
    							ball.style.top = y - step + "px";
    							if (y <= 20) {
    								ball.yflag = true;
    							}
    						}
    					}
    				}, 40);
    			}
    		</script>
    	</head>
    
    	<body οnlοad="moveBall();">
    		<div id="showDiv" style="border: solid 2px;height: 400px;width: 600px;"></div>
    		<input type="button" value="新增一个小球" οnclick="createBall();" />
    	</body>
    
    </html>

    游戏效果图如下:


    展开全文
  • c语言 弹弹球小游戏

    2018-07-14 21:11:00
    2、 3、条形木块 */ typedef struct Point { int x; int y; } Point; //数据模型 typedef struct Ball { //坐标 Point point; //形状,普通 火球 激光 int shape; //水平方向 r:1 l:-1 : 'l' 'r' int ...
  • 单机版弹球游戏 var step = 20; var qiuXFlag = true; var qiuYFlag = true; var intervalId = 0; function qiuMove() { intervalId = window.setInterval(function() { //根据按键...
  • 我对她说,等着,马上为你量身定做一个去,你爱玩游戏,整好今天周末给你做个小小的游戏,让你耍一耍~哈哈哈哈,我太机智了。 效果如下: css部分代码: <style> #main{ width: 600px; ...
  • 小球弹跳小游戏

    2019-04-07 21:02:50
    C语言简单入门小游戏,小球弹跳。适合C语言初学者,刚入门能找点乐子
  • 弹力小球游戏

    2015-12-02 11:02:17
    flash弹力小球,有源代码,代码里有详细的解释。希望对各位有所帮助。
  • flash 弹力小球游戏

    2011-11-14 11:48:21
    一款弹力小球的游戏,里面很好的讲述了小球精确碰撞的代码!有兴趣的可以下载试试!!
  • 弹跳小球游戏

    2019-01-11 17:49:13
    #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main() { int i,j; int x=0; int y=5; int velocity_x=1; int velocity_y=1; int left=0; int right=20;... int top=0...
  • java游戏弹跳小球

    2011-03-23 22:26:00
    java游戏作业,是设计弹跳小球在一个正方形中跳动的列子,
  • 小球游戏和代码

    2015-11-14 16:03:50
    简单的小球游戏,刚学FLASH的可以看看,代码也比较简单
  • 小球砖块游戏

    2012-12-11 21:22:04
    编写的简单java的小球砖块游戏,运用GUI界面
  • 小球弹跳游戏

    2018-03-27 09:27:54
    #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;windows.h&gt; int main() { int i, j; int x = 0; int y = 5; int velocity_x = 1;... int right = 20...
  • C语言实现小球游戏 编译环境:vs2019 需求: 小球在控制台界面内不停移动,碰到边界则改变方向,控制棍子接住小球,得分加一,小球没有被接住则游戏结束。 思路: _getch()函数接收a、d两个字符控制控制棍子移动,...
  • C++游戏小球发子弹

    2015-04-25 00:59:50
    在Windows下通过VS2010,C++,开发的游戏,可以控制小球的移动,然后发射子弹,得分数
  • 【c语言】小游戏程序——弹跳小球

    万次阅读 多人点赞 2018-09-04 15:46:56
    现在说一下其中一个最简单的程序:弹跳小球 ———————————————LINE———————————————— 首先我们知道,在窗口的坐标系原点是在窗口左上角的,如图所示 然后我们如果想在这个坐标...
  • unity3D(2018.3)实现开小球游戏游戏运行时,点击鼠标左键,生成绿色小球,并朝红色方块飞来。点击鼠标右键,红色方块跳起。当红色方块与绿色小球相撞时,绿色小球被开。
  • 弹弹小球游戏

    2019-05-08 23:07:59
    a = [100] #每个‘反弹落地’过程经过的路程,第1次只有落地(100米) h = 100 #每个‘反弹落地’过程,反弹的高度,第1次为100米 print('第1次从%s米高落地,走过%s米,之后又反弹至%s米。' % (h, a[0], h/2)) ...
  • flash简单的基础小游戏——弹力小球。flash简单的基础小游戏,适合flash的初学者使用和参考,内有碰撞检测等
  • Pygame 弹跳小球【小游戏】 #!/usr/bin/env Python # coding=utf-8 #解决gbk编码问题 import pygame import os WINDOW_W, WINDOW_H = 640, 480 # 窗体尺寸 FPS = 50 # 帧率,即每秒刷新多少次 g = 9.8 * 100 # ...
  • VB小游戏开发,可直接使用。文档包含源程序,本游戏为小球动态在界面跳动。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 524
精华内容 209
关键字:

弹弹球小游戏