yt.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. YTSectors, err = BigBang(YTConfig{
  69. Sectors: 3000,
  70. Turns: 500,
  71. Holds: 10,
  72. PortReset: 1,
  73. DaysExpire: 30,
  74. Lottery: 12345,
  75. })
  76. if err != nil {
  77. log.Printf("BigBang() => %v", err)
  78. } else {
  79. for idx, sector := range YTSectors {
  80. log.Printf("IDX: %d = YTSector{Sector: %d, Planet: %v, Port: %v, Fighters: %d, FighterOwner: %d, Mines: %d, Sectors: %v, Players: %v}",
  81. idx, sector.Sector, sector.Planet, sector.Port, sector.Fighters, sector.FighterOwner, sector.Mines, sector.Sectors, sector.Players)
  82. }
  83. }
  84. abort:
  85. d.Write(door.Clrscr)
  86. var YtFont door.ColorFont = FontCyberWar()
  87. var yt []string
  88. var output []string
  89. var l int
  90. // Ok, that's wider then I was expecting! Yikes!
  91. if door.Width < 138 {
  92. yt = []string{"Yankee", "Trader", "2022"}
  93. } else {
  94. yt = []string{"Yankee Trader", "2022"}
  95. }
  96. for _, msg := range yt {
  97. output, l = YtFont.Output(msg)
  98. var center string
  99. if l < door.Width {
  100. center = strings.Repeat(" ", (door.Width-l)/2)
  101. } else {
  102. log.Println("[", msg, "]:", l, "Width:", door.Width)
  103. }
  104. for _, line := range output {
  105. d.Write(center + line + door.Reset + door.CRNL)
  106. }
  107. d.Write(door.CRNL)
  108. }
  109. d.Write(door.CRNL)
  110. d.Key()
  111. message = fmt.Sprintf("Returning to the %s BBS..."+door.CRNL, d.Config.BBSID)
  112. d.Write(message)
  113. d.WaitKey(1, 0)
  114. var left time.Duration = d.TimeLeft()
  115. message = fmt.Sprintf("You had %0.2f minutes remaining!"+door.CRNL, left.Minutes())
  116. d.Write(message)
  117. }