You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 5 година
пре 5 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "sort"
  6. "time"
  7. "util"
  8. )
  9. type Class struct {
  10. Name string
  11. HitDie int
  12. StatPriority []string
  13. }
  14. type Player struct {
  15. Name string
  16. Class Class
  17. Stats map[string]int
  18. }
  19. func stats() []int {
  20. rolls := make([]int, 6)
  21. for i := 0; i < 6; i++ {
  22. thisRoll := util.Roll(4, 6)
  23. for k, v := range thisRoll {
  24. // fmt.Println(thisRoll)
  25. for v == 1 {
  26. // fmt.Println("Replacing 1")
  27. newv := util.Roll(1, 6)
  28. thisRoll[k] = newv[0]
  29. v = newv[0]
  30. }
  31. }
  32. sort.Ints(thisRoll)
  33. top3 := make([]int, 3)
  34. copy(top3, thisRoll[1:])
  35. rolls[i] = util.Sum(top3)
  36. }
  37. return rolls
  38. }
  39. func main() {
  40. rand.Seed(time.Now().UnixNano()) // Keep this the first line in main()
  41. barb := Class{"Barbarian", 12, []string{"Int", "Wis", "Cha", "Dex", "Con", "Str"}}
  42. fmt.Println("=== Generated D&D character ===")
  43. rolls := stats()
  44. fmt.Println("Rolls: ", rolls)
  45. sort.Ints(rolls)
  46. ply := Player{util.Namegen(), barb, make(map[string]int)}
  47. for k, v := range barb.StatPriority {
  48. ply.Stats[v] = rolls[k]
  49. }
  50. fmt.Printf("%s - %s\n", ply.Name, ply.Class.Name)
  51. fmt.Printf("Str: %d\tInt: %d\nDex: %d\tWis: %d\nCon: %d\tCha: %d\n",
  52. ply.Stats["Str"],
  53. ply.Stats["Int"],
  54. ply.Stats["Dex"],
  55. ply.Stats["Wis"],
  56. ply.Stats["Con"],
  57. ply.Stats["Cha"])
  58. }