gamedice

package module
v0.0.0-...-a48026a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2022 License: Apache-2.0 Imports: 1 Imported by: 2

README

gamedice: Simple dice rolling

This package implements a simple dice roller for games like Dungeons & Dragons and other RPGs that use all kinds of dice (D4, D8, ..., D20, etc.).

TODO

  • add lexical parser for dice notation (maybe)
  • custom rand source

Usage

package main

import (
	"fmt"

	"github.com/Flokey82/gamedice"
)

func main() {
	fmt.Println(gamedice.Roll(3, gamedice.D4, gamedice.D12))
}

Documentation

Overview

Package gamedice is a pretty simple dice roller for games.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Roll

func Roll(modifier int, dd ...Dice) int

Roll rolls a number of dice and returns the sum of the results (plus the modifier).

func RollAdvantage

func RollAdvantage(modifier int, d Dice) int

RollAdvantage rolls a dice twice and returns the highest result (plus the modifier).

func RollDisadvantage

func RollDisadvantage(modifier int, d Dice) int

RollDisadvantage rolls a dice twice and returns the lowest result (plus the modifier).

Types

type Dice

type Dice int

Dice represents a dice.

const (
	D2   Dice = 2
	D4   Dice = 4
	D6   Dice = 6
	D8   Dice = 8
	D10  Dice = 10
	D12  Dice = 12
	D20  Dice = 20
	D100 Dice = 100
)

Various dice types.

func (Dice) Roll

func (d Dice) Roll() int

Roll rolls the given dice and returns the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL