yt.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "red-green/door"
  6. "strings"
  7. "time"
  8. )
  9. /*
  10. Yankee Trader has:
  11. CONFIG
  12. Max Number of sectors.
  13. Turns per day.
  14. Max number of holds.
  15. Number of Ports needed to reset the game.
  16. Number of days before a player is expired.
  17. Number of lottery plays per day.
  18. From yt-init:
  19. Sector map (what sectors go to what).
  20. Port information (sector, buying, selling, amounts...)
  21. MAINT -- The "old" maint is run as an event. I'd like to have it so
  22. it runs when a player plays. This might be tricky -- do I want it to
  23. run XX days of maint, if it hasn't been played in XX days?
  24. Ports need to be updated with their buying/selling amounts.
  25. Planets produce -- this would need to be updated.
  26. Xannor - attacks, and planet genesis.
  27. Wanderer - planet genesis (if missing).
  28. */
  29. func main() {
  30. var d door.Door = door.Door{}
  31. d.Init("yt2000")
  32. var message string
  33. var err error
  34. var key int
  35. _ = err
  36. d.Write(door.Clrscr + "\x1b[?1000h")
  37. d.Write(door.Reset + door.CRNL)
  38. // slow output here
  39. for _, line := range ANSIYtopen() {
  40. if door.Unicode {
  41. for _, c := range line {
  42. d.Write(string(c))
  43. // time.Sleep(time.Duration(5) * time.Millisecond)
  44. key = d.WaitKey(0, 5*1000)
  45. if key != -1 {
  46. d.Write(door.Reset + door.CRNL)
  47. goto abort
  48. }
  49. }
  50. } else {
  51. // Line gets mangled. Treat as bytes.
  52. var buff []byte = make([]byte, 1)
  53. for _, c := range []byte(line) {
  54. buff[0] = c
  55. d.Write(string(buff)) // string(c)
  56. // time.Sleep(time.Duration(5) * time.Millisecond)
  57. key = d.WaitKey(0, 5*1000)
  58. if key != -1 {
  59. d.Write(door.Reset + door.CRNL)
  60. goto abort
  61. }
  62. }
  63. }
  64. // d.Write(door.CRNL)
  65. }
  66. d.Write(door.Reset + door.CRNL)
  67. d.WaitKey(2, 0)
  68. abort:
  69. d.Write(door.Clrscr)
  70. var YtFont door.ColorFont = FontCyberWar()
  71. var yt []string
  72. var output []string
  73. var l int
  74. // Ok, that's wider then I was expecting! Yikes!
  75. if door.Width < 138 {
  76. yt = []string{"Yankee", "Trader", "2022"}
  77. } else {
  78. yt = []string{"Yankee Trader", "2022"}
  79. }
  80. for _, msg := range yt {
  81. output, l = YtFont.Output(msg)
  82. var center string
  83. if l < door.Width {
  84. center = strings.Repeat(" ", (door.Width-l)/2)
  85. } else {
  86. log.Println("[", msg, "]:", l, "Width:", door.Width)
  87. }
  88. for _, line := range output {
  89. d.Write(center + line + door.Reset + door.CRNL)
  90. }
  91. d.Write(door.CRNL)
  92. }
  93. d.Write(door.CRNL)
  94. d.Key()
  95. message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
  96. d.Write(message)
  97. d.WaitKey(1, 0)
  98. var left time.Duration = d.TimeLeft()
  99. message = fmt.Sprintf("You had %0.2f minutes remaining!"+door.CRNL, left.Minutes())
  100. d.Write(message)
  101. }