Skip to content

Commit

Permalink
Comments formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
VedVid committed Nov 13, 2018
1 parent 6f4e302 commit 6b0c8b5
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 249 deletions.
18 changes: 9 additions & 9 deletions ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ freely, subject to the following restrictions:
package main

const (
//ai types
// Types of AI.
NoAI = iota
PlayerAI
DumbAI
PatherAI
)

func CreaturesTakeTurn(b Board, c Creatures) {
/*Function CreaturesTakeTurn is supposed to handle all enemy creatures
actions: movement, attacking, etc.
It takes Board and Creatures as arguments.
Iterates through all Creatures slice, and handles creature behavior:
if distance between creature and player is bigger than 1, creature
moves towards player. Else, it attacks.
It passed Creature's ai type as argument of MoveTowards to force
different behavior.*/
/* Function CreaturesTakeTurn is supposed to handle all enemy creatures
actions: movement, attacking, etc.
It takes Board and Creatures as arguments.
Iterates through all Creatures slice, and handles creature behavior:
if distance between creature and player is bigger than 1, creature
moves towards player. Else, it attacks.
It passed Creature's ai type as argument of MoveTowards to force
different behavior. */
var ai int
for _, v := range c {
ai = v.AIType
Expand Down
26 changes: 13 additions & 13 deletions combat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package main
import "fmt"

func (c *Creature) AttackTarget(t *Creature) {
/*Method Attack handles damage rolls for combat. Receiver "c" is attacker,
argument "t" is target. Critical hit is if attack roll is the same as receiver
attack attribute.
Println calls will remain here until message log will be implemented.*/
/* Method Attack handles damage rolls for combat. Receiver "c" is attacker,
argument "t" is target. Critical hit is if attack roll is the same as receiver
attack attribute.
Println calls will remain here until message log will be implemented. */
att := RandInt(c.Attack) //basic attack roll
att2 := 0 //critical bonus
def := t.Defense //opponent's defense
Expand All @@ -37,37 +37,37 @@ func (c *Creature) AttackTarget(t *Creature) {
att2 = RandInt(c.Attack)
}
switch {
case att < def: //attack score if lower than target defense
case att < def: // Attack score if lower than target defense.
if crit == false {
fmt.Println("Attack deflected!")
} else {
dmg = att2 //critical hit, but against heavily armored enemy
dmg = att2 // Critical hit, but against heavily armored enemy.
fmt.Println("Critical hit! <heavily armored enemy>")
}
case att == def: //attack score is equal to target defense
case att == def: // Attack score is equal to target defense.
if crit == false {
dmg = 1 //just a scratch...
dmg = 1 // It's just a scratch...
fmt.Println("Attack successful, but it is just a scratch...")
} else {
dmg = att
fmt.Println("Critical hit, but it barely bypassed opponent's armor.")
}
case att > def: //attack score is bigger than target defense
case att > def: // Attack score is bigger than target defense.
if crit == false {
dmg = att
fmt.Println("Successful attack!")
} else {
dmg = att + att2 //critical attack!
dmg = att + att2 // Critical attack!
fmt.Println("Critical attack!")
}
}
t.TakeDamage(dmg)
}

func (c *Creature) TakeDamage(dmg int) {
/*Method TakeDamage has *Creature as receiver and takes damage integer
as argument. dmg value is deducted from Creature current HP.
If HPCurrent is below zero after taking damage, Creature dies.*/
/* Method TakeDamage has *Creature as receiver and takes damage integer
as argument. dmg value is deducted from Creature current HP.
If HPCurrent is below zero after taking damage, Creature dies. */
c.HPCurrent -= dmg
if c.HPCurrent <= 0 {
c.Die()
Expand Down
11 changes: 6 additions & 5 deletions controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ package main
import blt "bearlibterminal"

func Controls(k int, p *Creature, b Board, c Creatures) bool {
/*Function Controls is input handler; it takes integer k
(keycodes are basically numbers, but creating new "type key int"
is not convenient) and Creature p (which is player);
Controls handle input, then returns integer value that depends
if player spent turn by action or not.*/
/* Function Controls is input handler.
It takes integer k (keycodes are basically numbers,
but creating new "type key int" is not convenient)
and Creature p (which is player).
Controls handle input, then returns integer value that depends
if player spent turn by action or not. */
var turnSpent bool
switch k {
case blt.TK_UP:
Expand Down
46 changes: 23 additions & 23 deletions err_.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,61 @@ import (
)

func LayerError(layer int) string {
/*Function LayerError is helper function that returns string
to error; it takes layer integer as argument and returns string.*/
/* Function LayerError is helper function that returns string
to error; it takes layer integer as argument and returns string. */
return "\n <layer: " + strconv.Itoa(layer) + ">"
}

func CoordsError(x, y int) string {
/*Function CoordsError is helper function that returns string
to error; it takes coords x, y as arguments and returns string,
with use global WindowSizeX and WindowSizeY constants.*/
/* Function CoordsError is helper function that returns string
to error; it takes coords x, y as arguments and returns string,
with use global WindowSizeX and WindowSizeY constants. */
txt := "\n <x: " + strconv.Itoa(x) + "; y: " + strconv.Itoa(y) +
"; map width: " + strconv.Itoa(WindowSizeX) + "; map height: " +
strconv.Itoa(WindowSizeY) + ">"
return txt
}

func CharacterLengthError(character string) string {
/*Function CharacterLengthError is helper function that returns string
to error; it takes character string as argument and returns string.
Character (as something's representation on map) is supposed to be
one-letter long.*/
/* Function CharacterLengthError is helper function that returns string
to error; it takes character string as argument and returns string.
Character (as something's representation on map) is supposed to be
one-letter long. */
txt := "\n <length: " + strconv.Itoa(utf8.RuneCountInString(character)) +
"; character: " + character + ">"
return txt
}

func PlayerAIError(ai int) string {
/*Function PlayerAIError is helper function that returns string to error;
it takes ai code (integer) as argument and returns string.
Player AI is supposed to be PlayerAI (defined in ai.go).
It's supposed to be warning, not error.*/
/* Function PlayerAIError is helper function that returns string to error;
it takes ai code (integer) as argument and returns string.
Player AI is supposed to be PlayerAI (defined in ai.go).
It's supposed to be warning, not error. */
txt := "\n <player ai code: " + strconv.Itoa(ai) + ">"
return txt
}

func InitialHPError(hp int) string {
/*Function InitialHPError is helper function that returns string to error;
it takes creature's HPMax as argument and returns string.
It will be warning instead of error sometimes - negative hp for newly created
creatures is unusual, but it is not bug per se.*/
/* Function InitialHPError is helper function that returns string to error;
it takes creature's HPMax as argument and returns string.
It will be warning instead of error sometimes - negative hp for newly created
creatures is unusual, but it is not bug per se. */
txt := "\n <fighter hp: " + strconv.Itoa(hp) + ">"
return txt
}

func InitialAttackError(attack int) string {
/*Function InitialAttackError is helper function that returns string
to error; it takes creature's attack value as argument and returns string.
Attack value should not be negative.*/
/* Function InitialAttackError is helper function that returns string
to error; it takes creature's attack value as argument and returns string.
Attack value should not be negative. */
txt := "\n <fighter attack: " + strconv.Itoa(attack) + ">"
return txt
}

func InitialDefenseError(defense int) string {
/*Function InitialDefenseError is helper function that returns string
to error; it takes creature's attack value as argument and returns string.
Defense value should not be negative.*/
/* Function InitialDefenseError is helper function that returns string
to error; it takes creature's attack value as argument and returns string.
Defense value should not be negative. */
txt := "\n <fighter defense: " + strconv.Itoa(defense) + ">"
return txt
}
32 changes: 16 additions & 16 deletions fov.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ package main
import "math"

const (
//values for handling field of view algorithm execution
FOVRays = 360 //whole area around player; it may not work properly with other values
FOVLength = 5 //sight range
// Values for handling field of view algorithm execution.
FOVRays = 360 // Whole area around player; it may not work properly with other values.
FOVLength = 5 // Sight range.
FOVStep = 1
)

Expand All @@ -44,12 +44,12 @@ func InitializeFOVTables() {
}

func CastRays(b Board, sx, sy int) {
/*Function castRays is simple raycasting function for turning tiles to
explored.
It casts (fovRays / fovStep) rays (bigger fovStep means faster but
more error-prone raycasting) from player to coordinates in fovLength range.
Source of algorithm:
http://www.roguebasin.com/index.php?title=Raycasting_in_python [20170712]*/
/* Function castRays is simple raycasting function for turning tiles to
explored.
It casts (fovRays / fovStep) rays (bigger fovStep means faster but
more error-prone raycasting) from player to coordinates in fovLength range.
Source of algorithm:
http://www.roguebasin.com/index.php?title=Raycasting_in_python [20170712] */
for i := 0; i < FOVRays; i += FOVStep {
rayX := sinBase[i]
rayY := cosBase[i]
Expand All @@ -73,13 +73,13 @@ func CastRays(b Board, sx, sy int) {
}

func IsInFOV(b Board, sx, sy, tx, ty int) bool {
/*Function isInFOV checks if target (tx, ty) is in fov of source (sx, sy).
Returns true if tx, ty == sx, sy; otherwise, it casts (FOVRays / fovStep)
rays (bigger fovStep means faster but more error-prone algorithm)
from source to tiles in fovLength range;
stops if cell has BlocksSight bool set to true.
Source of algorithm:
http://www.roguebasin.com/index.php?title=Raycasting_in_python [20170712].*/
/* Function isInFOV checks if target (tx, ty) is in fov of source (sx, sy).
Returns true if tx, ty == sx, sy; otherwise, it casts (FOVRays / fovStep)
rays (bigger fovStep means faster but more error-prone algorithm)
from source to tiles in fovLength range;
stops if cell has BlocksSight bool set to true.
Source of algorithm:
http://www.roguebasin.com/index.php?title=Raycasting_in_python [20170712]. */
if sx == tx && sy == ty {
return true
}
Expand Down
24 changes: 12 additions & 12 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ import (
)

const (
//colors
// Colors.
colorTile = "light gray"
colorTileDark = "dark gray"
)

type Tile struct {
/*Tiles are map cells - floors, walls, doors*/
// Tiles are map cells - floors, walls, doors.
BasicProperties
VisibilityProperties
Explored bool
CollisionProperties
}

/*Board is map representation, that uses 2d slice
to hold data of its every cell*/
/* Board is map representation, that uses 2d slice
to hold data of its every cell. */
type Board [][]*Tile

func NewTile(layer, x, y int, character, color, colorDark string,
alwaysVisible, explored, blocked, blocksSight bool) (*Tile, error) {
/*Function NewTile takes all values necessary by its struct,
and creates then returns Tile.*/
/* Function NewTile takes all values necessary by its struct,
and creates then returns Tile. */
var err error
if layer < 0 {
txt := LayerError(layer)
Expand All @@ -71,12 +71,12 @@ func NewTile(layer, x, y int, character, color, colorDark string,
}

func InitializeEmptyMap() Board {
/*Function InitializeEmptyMap returns new Board, filled with
generic (ie "empty") tiles.
It starts by declaring 2d slice of *Tile - unfortunately, Go seems to
lack simple way to do it, therefore it's necessary to use
the first for loop.
The second, nested loop initializes specific Tiles withing Board.*/
/* Function InitializeEmptyMap returns new Board, filled with
generic (ie "empty") tiles.
It starts by declaring 2d slice of *Tile - unfortunately, Go seems to
lack simple way to do it, therefore it's necessary to use
the first for loop.
The second, nested loop initializes specific Tiles withing Board. */
b := make([][]*Tile, WindowSizeX)
for i := range b {
b[i] = make([]*Tile, WindowSizeY)
Expand Down
30 changes: 15 additions & 15 deletions monsters.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ import (
)

const (
//colors
// Colors.
colorCreature = "green"
colorCreatureDark = "dark green"
)

const (
//special characters
// Special characters.
CorpseChar = "%"
)

type Creature struct {
/*Creatures are living objects that
moves, attacks, dies, etc.*/
/* Creatures are living objects that
moves, attacks, dies, etc. */
BasicProperties
VisibilityProperties
CollisionProperties
AIProperties
FighterProperties
}

/*Creatures holds every creature on map.*/
// Creatures holds every creature on map.
type Creatures []*Creature

func NewCreature(layer, x, y int, character, color, colorDark string,
alwaysVisible, blocked, blocksSight bool, ai, hp, attack,
defense int) (*Creature, error) {
/*Function NewCreture takes all values necessary by its struct,
and creates then returns pointer to Creature*/
/* Function NewCreture takes all values necessary by its struct,
and creates then returns pointer to Creature. */
var err error
if layer < 0 {
txt := LayerError(layer)
Expand Down Expand Up @@ -92,14 +92,14 @@ func NewCreature(layer, x, y int, character, color, colorDark string,
}

func (c *Creature) MoveOrAttack(tx, ty int, b Board, all Creatures) bool {
/*Method MoveOrAttack decides if Creature will move or attack other Creature;
It has *Creature receiver, and takes tx, ty (coords) integers as arguments,
and map of current level, and list of all Creatures.
Starts by target that is nil, then iterates through Creatures. If there is
Creature on targeted tile, that Creature becomes new target for attack.
Otherwise, Creature moves to specified Tile.
It's supposed to take player as receiver (attack / moving enemies is
handled differently - check ai.go and combat.go).*/
/* Method MoveOrAttack decides if Creature will move or attack other Creature;
It has *Creature receiver, and takes tx, ty (coords) integers as arguments,
and map of current level, and list of all Creatures.
Starts by target that is nil, then iterates through Creatures. If there is
Creature on targeted tile, that Creature becomes new target for attack.
Otherwise, Creature moves to specified Tile.
It's supposed to take player as receiver (attack / moving enemies is
handled differently - check ai.go and combat.go). */
var target *Creature
var turnSpent bool
for i, _ := range all {
Expand Down
Loading

0 comments on commit 6b0c8b5

Please sign in to comment.