V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
hahaayaoyaoyao
V2EX  ›  JavaScript

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

  •  
  •   hahaayaoyaoyao · 2019-04-14 15:00:03 +08:00 · 4405 次点击
    这是一个创建于 2079 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    14 条回复    2019-04-15 22:22:03 +08:00
    strpbrk
        1
    strpbrk  
       2019-04-14 15:02:40 +08:00
    不就是用 if else 么
    hahaayaoyaoyao
        2
    hahaayaoyaoyao  
    OP
       2019-04-14 16:21:19 +08:00 via Android
    @strpbrk 我之前看到有人嘲笑游戏用 if else 写。
    inoki
        3
    inoki  
       2019-04-14 16:24:27 +08:00 via Android
    @hahaayaoyaoyao 太吾绘卷?😂
    hahaayaoyaoyao
        4
    hahaayaoyaoyao  
    OP
       2019-04-14 16:30:19 +08:00 via Android
    @inoki 是的😂
    xeaglex
        5
    xeaglex  
       2019-04-14 16:49:33 +08:00
    比如状态机编程?
    Biwood
        6
    Biwood  
       2019-04-14 16:59:23 +08:00
    @hahaayaoyaoyao 嘲笑的不是 if else,嘲笑的是满屏只有 if else,不懂什么叫函数封装,什么叫抽象。
    话说你这代码确实有点吓人,还是多读一些优秀源码吧。
    whoami9894
        7
    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
        8
    malaohu  
       2019-04-14 17:13:54 +08:00
    我一个人玩的好累
    hahaayaoyaoyao
        9
    hahaayaoyaoyao  
    OP
       2019-04-14 17:55:27 +08:00 via Android
    @Biwood 给点具体指导,确实很差
    zwh2698
        10
    zwh2698  
       2019-04-14 19:51:27 +08:00
    我了你博客中那个套《桃花庵歌》的程序员,觉得你实在无聊的有才啊,https://timerd.ml 传送门给你 .
    Senventise
        11
    Senventise  
       2019-04-14 20:14:15 +08:00 via Android
    没有获胜判断吗?
    hahaayaoyaoyao
        12
    hahaayaoyaoyao  
    OP
       2019-04-14 20:39:48 +08:00 via Android
    @zwh2698 佛祖?网上抄的
    zwh2698
        13
    zwh2698  
       2019-04-14 23:24:58 +08:00 via Android
    @hahaayaoyaoyao 是这个,好玩
    hahaayaoyaoyao
        14
    hahaayaoyaoyao  
    OP
       2019-04-15 22:22:03 +08:00
    @Senventise 是的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1152 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:42 · PVG 07:42 · LAX 15:42 · JFK 18:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.