Compare commits

...

4 Commits

3 changed files with 41 additions and 23 deletions

10
game.go
View File

@ -19,10 +19,10 @@ func gameinit() {
// Quit the screen
quit(&game)
fmt.Println("\nDebug time: Trash")
for i, t := range game.trash {
fmt.Println("Trash: ", i, t)
}
// fmt.Println("\nDebug time: Trash")
// for i, t := range game.trash {
// fmt.Println("Trash: ", i, t)
// }
// Give closure
if game.gameover == 1 {
@ -165,7 +165,7 @@ func (game *Game) keyboardProcessor() {
}
func quit(game *Game) {
game.screen.Clear()
// game.screen.Clear()
maybePanic := recover()
game.screen.Fini()
if maybePanic != nil {

View File

@ -43,21 +43,28 @@ func (game *Game) moveRobots() {
// After all the moves, lets check if any of the rowboz collided with anything
for i, r := range game.robots {
// Check if it collides with anything.
// Hit a player? Game over!
if game.onPlayer(r) {
game.gameover = 1
return
}
if game.onRobot(i, r) || game.onTrash(r) {
// Robots mingling? Trash!
if game.onRobot(i, r) {
trash := r
// delete robot
// Delete robot
game.deleteRobot(i)
// create trash
game.addTrash(trash)
// Create trash
game.addTrash(r)
}
// Hugging Trash? More trash!
if game.onTrash(r) {
// Delete robot
game.deleteRobot(i)
}
@ -65,9 +72,9 @@ func (game *Game) moveRobots() {
}
func (game *Game) onRobot(index int, pos Position) bool {
var found bool
var found bool = false
for i, r := range game.robots {
if index != i && pos.x == r.x && pos.y == r.y {
if index != i && pos == r {
found = true
}
}
@ -77,16 +84,27 @@ func (game *Game) onRobot(index int, pos Position) bool {
// TODO: improve this
func (game *Game) deleteRobot(robot int) {
var rowboz []Position
// The following would work, if it wasn't for the fact you are iterating through an array,
// and deleting elements form that same array. So deleting item #15 isn't going to work
// when the array has been reduced to 13 elements.
// if robot < len(game.robots) {
// game.robots = append(game.robots[:robot], game.robots[robot+1:]...)
// }
for i, r := range game.robots {
if robot != i {
rowboz = append(rowboz, r)
}
}
// This isn't going to work for the same reason,
// and it adds the issue that random robots will get deleted.
// var rowboz []Position
game.robots = nil
game.robots = rowboz
// for i, r := range game.robots {
// if robot != i {
// rowboz = append(rowboz, r)
// }
// }
// game.robots = nil
// game.robots = rowboz
// Conclusion: I need to find a different way to do this properly while iterating to that same array.
game.player.score++

View File

@ -9,7 +9,7 @@ func (game *Game) drawTrash() {
func (game *Game) onTrash(pos Position) bool {
var found bool
for _, t := range game.trash {
if t.x == pos.x && t.y == pos.y {
if t == pos {
found = true
}
}