Js 写了一个 “狼吃羊” 小游戏。

2019-04-14 15:00:03 +08:00
 hahaayaoyaoyao

https://github.com/ZTFtrue/wolf-eat-sheep

不知道游戏逻辑怎么写,我都是用 if else 做判断。

4380 次点击
所在节点    JavaScript
14 条回复
strpbrk
2019-04-14 15:02:40 +08:00
不就是用 if else 么
hahaayaoyaoyao
2019-04-14 16:21:19 +08:00
@strpbrk 我之前看到有人嘲笑游戏用 if else 写。
inoki
2019-04-14 16:24:27 +08:00
@hahaayaoyaoyao 太吾绘卷?😂
hahaayaoyaoyao
2019-04-14 16:30:19 +08:00
@inoki 是的😂
xeaglex
2019-04-14 16:49:33 +08:00
比如状态机编程?
Biwood
2019-04-14 16:59:23 +08:00
@hahaayaoyaoyao 嘲笑的不是 if else,嘲笑的是满屏只有 if else,不懂什么叫函数封装,什么叫抽象。
话说你这代码确实有点吓人,还是多读一些优秀源码吧。
whoami9894
2019-04-14 17:12:01 +08:00
想起我最开始上学习的 VB 课,最后的大作业一个游戏就是这样的风格

```vb
If keyascii = 119 Then
Image1.Top = Image1.Top - 200
End If
If keyascii = 115 Then
Image1.Top = Image1.Top + 200
End If
If keyascii = 97 Then
Image1.Left = Image1.Left - 200
End If
If keyascii = 100 Then
Image1.Left = Image1.Left + 200
End If
If keyascii = 32 Then
If Image3(4).Visible = False Then
Call m3
Else
Call m1
WindowsMediaPlayer1.Enabled = False
Image3(i).Visible = False
i = i + 1
If i = 5 Then i = 0
If Abs((Image1.Left + Image1.Width / 2) - (Image2.Left + Image2.Width / 2)) <= Image2.Width / 3 And Abs((Image1.Top + Image1.Height / 2) - (Image2.Top + Image2.Height / 2)) <= (9 / 10) * Image2.Height Then
If Image2.Picture = Image4.Picture Then
p = 1
Else
a = a - 1
Label2.Caption = a
End If
Image2.Picture = Image4.Picture
End If
If Abs((Image1.Left + Image1.Width / 2) - (Image11.Left + Image11.Width / 2)) <= Image11.Width / 3 And Abs((Image1.Top + Image1.Height / 2) - (Image11.Top + Image11.Height / 2)) <= (9 / 10) * Image11.Height Then
If Image11.Picture = Image12.Picture Then
p = 1
Else
a = a - 1
Label2.Caption = a
End If
Image11.Picture = Image12.Picture
Timer1.Enabled = False
End If
If Abs((Image1.Left + Image1.Width / 2) - (Image7.Left + Image7.Width / 2)) <= Image7.Width / 3 And Abs((Image1.Top + Image1.Height / 2) - (Image7.Top + Image7.Height / 2)) <= (9 / 10) * Image7.Height Then
If Image7.Picture = Image13.Picture Then
p = 1
Else
a = a - 1
Label2.Caption = a
End If
Image7.Picture = Image13.Picture
End If
If Abs((Image1.Left + Image1.Width / 2) - (Image8.Left + Image8.Width / 2)) <= Image8.Width / 3 And Abs((Image1.Top + Image1.Height / 2) - (Image8.Top + Image8.Height / 2)) <= (9 / 10) * Image8.Height Then
If Image8.Picture = Image14.Picture Then
p = 1
Else
a = a - 1
Label2.Caption = a
End If
Image8.Picture = Image14.Picture
End If
If Abs((Image1.Left + Image1.Width / 2) - (Image9.Left + Image9.Width / 2)) <= Image9.Width / 3 And Abs((Image1.Top + Image1.Height / 2) - (Image9.Top + Image9.Height / 2)) <= (9 / 10) * Image9.Height Then
If Image9.Picture = Image15.Picture Then
p = 1
Else
a = a - 1
Label2.Caption = a
End If
Image9.Picture = Image15.Picture
Image9.Move 15000
Timer2.Enabled = True
End If
```
malaohu
2019-04-14 17:13:54 +08:00
我一个人玩的好累
hahaayaoyaoyao
2019-04-14 17:55:27 +08:00
@Biwood 给点具体指导,确实很差
zwh2698
2019-04-14 19:51:27 +08:00
我了你博客中那个套《桃花庵歌》的程序员,觉得你实在无聊的有才啊,https://timerd.ml 传送门给你 .
Senventise
2019-04-14 20:14:15 +08:00
没有获胜判断吗?
hahaayaoyaoyao
2019-04-14 20:39:48 +08:00
@zwh2698 佛祖?网上抄的
zwh2698
2019-04-14 23:24:58 +08:00
@hahaayaoyaoyao 是这个,好玩
hahaayaoyaoyao
2019-04-15 22:22:03 +08:00
@Senventise 是的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/555015

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX