mirror of
https://github.com/gabehf/go-battleship.git
synced 2026-03-07 13:38:15 -08:00
fixed some silly mistakes and bugs
This commit is contained in:
parent
0045790ec4
commit
23cc2b374f
4 changed files with 11 additions and 5 deletions
|
|
@ -173,7 +173,7 @@ func (b Board) shipExistsAt(coords []Point) bool {
|
||||||
func (b *Board) PlaceShip(s Ship, p Point, vertical bool) (Ship, error) {
|
func (b *Board) PlaceShip(s Ship, p Point, vertical bool) (Ship, error) {
|
||||||
switch vertical {
|
switch vertical {
|
||||||
case true:
|
case true:
|
||||||
if p.Row+rune(s.Length) > 'j' {
|
if p.Row+rune(s.Length-1) > 'j' {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for i := 0; i < s.Length; i++ {
|
for i := 0; i < s.Length; i++ {
|
||||||
|
|
@ -189,7 +189,7 @@ func (b *Board) PlaceShip(s Ship, p Point, vertical bool) (Ship, error) {
|
||||||
}
|
}
|
||||||
return s, nil
|
return s, nil
|
||||||
case false:
|
case false:
|
||||||
if p.Col+s.Length > 10 {
|
if p.Col+s.Length-1 > 10 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
for i := 0; i < s.Length; i++ {
|
for i := 0; i < s.Length; i++ {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func PrintLogo() {
|
||||||
cprint.Printf["Magenta"]("| $$$$$$ | $$$$$$$$ | $$ | $$$$$$$/\n")
|
cprint.Printf["Magenta"]("| $$$$$$ | $$$$$$$$ | $$ | $$$$$$$/\n")
|
||||||
cprint.Printf["Magenta"](" \\____ $$| $$__ $$ | $$ | $$____/ \n")
|
cprint.Printf["Magenta"](" \\____ $$| $$__ $$ | $$ | $$____/ \n")
|
||||||
cprint.Printf["Magenta"](" /$$ \\ $$| $$ | $$ | $$ | $$ \n")
|
cprint.Printf["Magenta"](" /$$ \\ $$| $$ | $$ | $$ | $$ \n")
|
||||||
cprint.Printf["Magenta"](" $$$$$$/| $$ | $$ /$$$$$$| $$ \n")
|
cprint.Printf["Magenta"]("| $$$$$$/| $$ | $$ /$$$$$$| $$ \n")
|
||||||
cprint.Printf["Magenta"](" \\______/ |__/ |__/|______/|__/ \n")
|
cprint.Printf["Magenta"](" \\______/ |__/ |__/|______/|__/ \n")
|
||||||
cprint.Printf["Red"]("Press ctrl + c at any time to quit.\n\n")
|
cprint.Printf["Red"]("Press ctrl + c at any time to quit.\n\n")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
main.go
7
main.go
|
|
@ -30,7 +30,7 @@ import (
|
||||||
"github.com/ghfarrell/go-battleship/player"
|
"github.com/ghfarrell/go-battleship/player"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PlayerGoesFirst() bool {
|
func PlayerGoesFirst() (b bool) {
|
||||||
var playerGuess int
|
var playerGuess int
|
||||||
for {
|
for {
|
||||||
cprint.Printf["Cyan"]("Time to determine who goes first! Guess a number 1-6: ")
|
cprint.Printf["Cyan"]("Time to determine who goes first! Guess a number 1-6: ")
|
||||||
|
|
@ -50,13 +50,16 @@ func PlayerGoesFirst() bool {
|
||||||
cprint.Printf["Cyan"]("The AI guessed %d, so the winner is...\n", aiGuess)
|
cprint.Printf["Cyan"]("The AI guessed %d, so the winner is...\n", aiGuess)
|
||||||
if math.Abs(float64(r-playerGuess)) < math.Abs(float64(r-aiGuess)) {
|
if math.Abs(float64(r-playerGuess)) < math.Abs(float64(r-aiGuess)) {
|
||||||
cprint.Printf["Cyan"]("You! You will make your strike first.\n")
|
cprint.Printf["Cyan"]("You! You will make your strike first.\n")
|
||||||
|
b = true
|
||||||
} else if math.Abs(float64(r-playerGuess)) == math.Abs(float64(r-aiGuess)) {
|
} else if math.Abs(float64(r-playerGuess)) == math.Abs(float64(r-aiGuess)) {
|
||||||
cprint.Printf["Cyan"]("You... via tiebreaker!\nYou both guessed %d, but I like you more than the AI.\n", playerGuess)
|
cprint.Printf["Cyan"]("You... via tiebreaker!\nYou both guessed %d, but I like you more than the AI.\n", playerGuess)
|
||||||
|
b = true
|
||||||
} else {
|
} else {
|
||||||
cprint.Printf["Cyan"]("The AI! Too bad! They will strike first.\n")
|
cprint.Printf["Cyan"]("The AI! Too bad! They will strike first.\n")
|
||||||
|
b = false
|
||||||
}
|
}
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func playerWin() {
|
func playerWin() {
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,9 @@ func (a *AI) getGuess() (c board.Point) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AI) Guess(p *Player, debug bool) bool {
|
func (a *AI) Guess(p *Player, debug bool) bool {
|
||||||
|
board.ClearScreen()
|
||||||
|
p.PrintEnemy()
|
||||||
|
p.PrintFriendly()
|
||||||
c := a.getGuess()
|
c := a.getGuess()
|
||||||
a.Guesses = append(a.Guesses, c)
|
a.Guesses = append(a.Guesses, c)
|
||||||
cprint.Printf["White"]("Now the AI's time to strike...\n")
|
cprint.Printf["White"]("Now the AI's time to strike...\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue