Browse Source

Update to dice, included doc files

Apollo 1 year ago
parent
commit
72876d2c08

+ 54 - 0
dice.go

@@ -0,0 +1,54 @@
+package main
+
+import (
+	"fmt"
+	"math/rand"
+	"strconv"
+	"strings"
+)
+
+type Dice struct {
+	Number uint // Number of dice to roll
+}
+
+// Perform the rolls without the Pips
+func (d *Dice) Roll() (total, wild int, rolls []int) {
+	var die int
+	for range make([]byte, d.Number-1) {
+		die = rand.Intn(6) + 1
+		total += die
+		rolls = append(rolls, die)
+	}
+	wild = rand.Intn(6) + 1
+	return
+}
+
+// Returns the text form for this Dice
+//
+// Without the Pips
+func (d *Dice) String() string {
+	return fmt.Sprintf("%dD", d.Number)
+}
+
+func NewDice(D uint) *Dice {
+	return &Dice{
+		Number: D,
+	}
+}
+
+func NewDiceFromString(text string) (*Dice, error) {
+	var (
+		number int
+		err    error
+	)
+	if strings.Contains(text, "D") {
+		text = strings.ReplaceAll(text, "D", "")
+	}
+	number, err = strconv.Atoi(text)
+	if err != nil {
+		return nil, err
+	}
+	return &Dice{
+		Number: uint(number),
+	}, nil
+}

BIN
docs/D6_Character_Sheet.pdf


BIN
docs/D6_Gamemasters_Aid_Screen.pdf


BIN
docs/D6_How_The_Game_Works.pdf


BIN
docs/D6_Legend_And_Conversion_OGL.pdf


BIN
docs/D6_Magic.pdf


BIN
docs/D6_Player_Book_And_GM_Guide.pdf


BIN
docs/D6_Reference_Sheet.pdf


BIN
docs/D6_System_Book.pdf


BIN
docs/OpenD6_And_OGL_-_Rules_Of_Thumb.pdf


+ 1 - 0
docs/where.txt

@@ -0,0 +1 @@
+https://ogc.rpglibrary.org/index.php?title=OpenD6

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module git.red-green.com/david/opend6-go
+
+go 1.20

+ 31 - 0
main.go

@@ -0,0 +1,31 @@
+package main
+
+import "fmt"
+
+func main() {
+	D, err := NewDiceFromString("3D")
+	if err != nil {
+		fmt.Println("Err:", err)
+		return
+	}
+	var (
+		total int
+	)
+	t, w, r := D.Roll()
+	total += t
+	total += w
+	fmt.Printf("Rolled: %d %v\n", t, r)
+	fmt.Printf("Wild:   %d\n", w)
+	if w == 6 {
+		for {
+			_, w, _ := D.Roll()
+			fmt.Printf("Wild:   %d\n", w)
+			if w == 6 {
+				total += w
+			} else {
+				break
+			}
+		}
+	}
+	fmt.Printf("Final:  %d\n", total)
+}