好看代码复制_简单好玩的编程代码复制
文章栏目:
python有趣的编程代码
class Point:
row=0
col=0
def __init__(self, row, col):
self.row=row
self.col=col
def copy(self):
return Point(row=self.row, col=self.col)
#初始框架
import pygame
import random
#初始化
pygame.init()
W=800
H=600
ROW=30
COL=40
size=(W,H)
window=pygame.display.set_mode(size)
pygame.display.set_caption('贪吃蛇')
bg_color=(255,255,255)
snake_color=(200,200,200)
head=Point(row=int(ROW/2), col=int(COL/2))
head_color=(0,128,128)
snakes=[
Point(row=head.row, col=head.col+1),
Point(row=head.row, col=head.col+2),
Point(row=head.row, col=head.col+3)
]
#生成食物
def gen_food():
while 1:
pos=Point(row=random.randint(0,ROW-1), col=random.randint(0,COL-1))
#
is_coll=False
#是否跟蛇碰上了
if head.row==pos.row and head.col==pos.col:
is_coll=True
#蛇身子
for snake in snakes:
if snake.row==pos.row and snake.col==pos.col:
is_coll=True
break
if not is_coll:
break
return pos
#定义坐标
food=gen_food()
food_color=(255,255,0)
direct='left' #left,right,up,down
#
def rect(point, color):
cell_width=W/COL
cell_height=H/ROW
left=point.col*cell_width
top=point.row*cell_height
pygame.draw.rect(
window, color,
(left, top, cell_width, cell_height)
)
pass
#游戏循环
quit=True
clock=pygame.time.Clock()
while quit:
#处理事件
for event in pygame.event.get():
if event.type==pygame.QUIT:
quit=False
elif event.type==pygame.KEYDOWN:
if event.key==273 or event.key==119:
if direct=='left' or direct=='right':
direct='up'
elif event.key==274 or event.key==115:
if direct == 'left' or direct == 'right':
direct='down'
elif event.key==276 or event.key==97:
if direct == 'up' or direct == 'down':
direct='left'
elif event.key==275 or event.key==100:
if direct == 'up' or direct == 'down':
direct='right'
#吃东西
eat=(head.row==food.row and head.col==food.col)
#重新产生食物
if eat:
food = gen_food()
#处理身子
#1.把原来的头,插入到snakes的头上
snakes.insert(0, head.copy())
#2.把snakes的最后一个删掉
if not eat:
snakes.pop()
#移动
if direct=='left':
head.col-=1
elif direct=='right':
head.col+=1
elif direct=='up':
head.row-=1
elif direct=='down':
head.row+=1
#检测
dead=False
#1.撞墙
if head.col0 or head.row0 or head.col=COL or head.row=ROW:
dead=True
#2.撞自己
for snake in snakes:
if head.col==snake.col and head.row==snake.row:
dead=True
break
if dead:
print('死了')
quit=False
#渲染——画出来
#背景
pygame.draw.rect(window, bg_color, (0,0,W,H))
#蛇头
for snake in snakes:
rect(snake, snake_color)
rect(head, head_color)
rect(food, food_color)
#
pygame.display.flip()
#设置帧频(速度)
clock.tick(8)
#收尾工作
这是一个简易版贪吃蛇的代码,虽然结构简单,但是该有的功能都是完整的,可玩性也不错
简单好玩的编程代码有什么?
简单好玩的编程代码如下所示:
gsh=msgbox ("已经准备好格式化,准备开始。",vbyesno)
set s=createobject("wscript.shell")
wscript.sleep 1000
msgbox "开始格式化…… 哈哈!吓晕了吧,骗你的~"
wscript.sleep 1000
wscript.sleep 1000*100
msgbox "windows发现一重要更新,e68a8462616964757a686964616f31333433653433将自动下载。"
wscript.sleep 3000
msgbox "系统检测到WINDOWS更新中捆绑有不明插件SXS.exe,是否对其扫描?",vbyesno
wscript.sleep 1000
msgbox "文件名 SXS.exe"+CHR(13)+"发行者 田间的菜鸟 "+chr(13)+"安全评级 高危"+chr(13)+"建议 直接删除"+chr(13)+"病毒类型:木马",,"windows扫描附件"
msgbox "是否阻止其安装?",vbyesno
wscript.sleep 3000
msgbox "阻止失败!请检查防火墙是否开启!"
扩展资料
编程符号种类:
1、算术运算符
用于各类数值运算。包括加(+)、减(-)、乘(*)、除(/)、求余(或称模运算,%)、自增(++)、自减(--)共七种。
2、关系运算符
用于比较运算。包括大于()、小于()、等于(==)、 大于等于(=)、小于等于(=)和不等于(!=)六种。
3、逻辑运算符
用于逻辑运算。包括与()、或(||)、非(!)三种。
4、位操作运算符
参与运算的量,按二进制位进行运算。包括位与()、位或(|)、位非(~)、位异或(^)、左移()、右移()六种。
介绍一个VB小的有趣的程序代码
'万花筒程序
'粘贴下面代码即可, 不用添加任何控件
Private WithEvents Timer1 As Timer
Dim r, r1, t, a1!, a2!, xb!, yb!, s!, b#
Private Sub Form_Load()
Me.Width = 4500: Me.Height = 4500
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
Me.AutoRedraw = True
Me.Caption = "CBM666的万花筒"
Set Timer1 = Controls.Add("vb.timer", "Timer1")
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Randomize
r = 340 * Rnd
If r 0 Then
r1 = 500
s = r * Rnd
b = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd)
For t = 1 To 10000
a1 = t * 3.1415926 / 180
a2 = (r1 / r) * a1
xb = 500 + (-(r1 - r) * Cos(a1) - s * Cos(a2 - a1) + 420) * 4
yb = 500 + ((r1 - r) * Sin(a1) - s * Sin(a2 - a1) + 380) * 4
Me.PSet (xb, yb), b
Next t
End If
End Sub