乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 50|回复: 3

[编程交流] 基于标志的程序

[复制链接]

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-5 23:59:51 | 显示全部楼层 |阅读模式
你好
 
我想知道旗子驱动的脚本流是什么。我写道:
 
  1. (defun C:TEST ()
  2. (setq        door nil;_T is open, nil is closed
  3. window nil ;_T is open, nil is closed
  4. driving        T;_T is driving nil is not
  5. )
  6. (if (not door)
  7.    (if        (not window)
  8.      (if driving
  9. (princ "\nYour door and window are closed, drive saftly!")
  10. (princ "\nYour door and window are closed, you might start driving")
  11. )
  12.      (princ "your window is open, and you are not driving, such a waste!")
  13.      )
  14.      (princ "the car cant start until you close the door")
  15.    )
  16.    
  17. (princ)
  18. )

 
现在,我最好不要在门开着的时候开车,但如果用户选择我必须自费开车怎么办?
 
谢谢
谢伊
 
谢谢
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 00:26:19 | 显示全部楼层
对不起,有什么问题?
回复

使用道具 举报

0

主题

375

帖子

385

银币

限制会员

铜币
-7
发表于 2022-7-6 00:59:03 | 显示全部楼层
你可以这样写:
  1. (defun C:TEST ()
  2. (setq door nil;_T is open, nil is closed
  3.        window nil ;_T is open, nil is closed
  4.        driving T;_T is driving nil is not
  5. )
  6. (if door
  7. (if window
  8.    (if driving
  9.      (princ "\nStop it right now, you #$@*")
  10.      (princ "\nPut your belt!  Don't forget the door!!")
  11.      )
  12.    (if driving
  13.      (princ "\nSami, one day you'll die!")
  14.      (princ "\nClose the door and start your engine!!!")
  15.      )
  16. )
  17. (if window
  18.    (if driving
  19.      (princ "\nYou know, this car has air conditioning...")
  20.      (princ "\nFinaly, we can go! Just close the window, please")
  21.      )
  22.    (if driving
  23.      (princ "\nYour door and window are closed, drive saftly!")
  24.      (princ "\nYour door and window are closed, you might start driving")
  25.      )
  26.    )
  27. )
  28. (princ)
  29. )
但每增加一个选项,代码的大小就会翻倍。
 
这可能是另一种选择:
  1. (defun C:TEST ()
  2. ;driving     1
  3. ;open door   2
  4. ;open window 4
  5. (if
  6.    (setq i (getint "\nEnter a number: "))
  7.    (if (<= 0 i 7)
  8.      (princ
  9.        (strcat "\nYour car is "
  10.          (if (= 1 (logand i 1)) " " "not ")
  11.          "moving. The door is "
  12.          (if (= 2 (logand i 2)) "open " "closed ")
  13.          "and the window is "
  14.          (if (= 4 (logand i 4)) "open!" "closed!")
  15.        )
  16.      )
  17.    )
  18. )
  19. (princ)
  20. )

 
谢谢
谢伊
回复

使用道具 举报

218

主题

699

帖子

483

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1090
发表于 2022-7-6 01:17:50 | 显示全部楼层
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-10 21:00 , Processed in 0.579220 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表