Musze wymyslic jak zrobic by dzialaly rownolegle te dwie funkcje i poprawic fizyke pilki, bo prawie jej nie ma.

This commit is contained in:
knmarcin 2018-11-20 23:15:57 +01:00
parent cebed38d25
commit 63d9932607
2 changed files with 91 additions and 4 deletions

BIN
Pong

Binary file not shown.

95
Pong.go
View File

@ -6,6 +6,8 @@ import (
"os/exec" "os/exec"
"bytes" "bytes"
"github.com/pkg/term" "github.com/pkg/term"
"sync"
"time"
) )
var gameBoard [10][30]string var gameBoard [10][30]string
@ -15,23 +17,25 @@ var Player1 [10]string
var Player2 [10]string var Player2 [10]string
var P1index int var P1index int
var P2index int var P2index int
var Ball [10][30]string
var BallDirection [10][30]string var BallDirection [10][30]string
var BallSpeed int var BallSpeed int
var GameOver bool = false var GameOver bool = false
var LastPressedKey rune var LastPressedKey rune
var BallX, BallY int
var BallDirX, BallDirY int
func main() { func main() {
SpawnEverything() SpawnEverything()
Loop() for !GameOver {
Ball()
Loop()
}
} }
func SpawnEverything() { func SpawnEverything() {
CreateBoard() CreateBoard()
SpawnPlayers() SpawnPlayers()
SpawnBall() SpawnBall()
PrintBoard() PrintBoard()
Loop()
} }
func getch() []byte { func getch() []byte {
@ -134,3 +138,86 @@ func Loop() {
} }
} }
} }
func Ball() {
BallX = 2
BallY = 14
BallDirX = 4
BallDirY = 0
for BallX!=BallDirX && BallY!=BallDirY {
if BallX>BallDirX {
gameBoard[BallX][BallY] = " "
BallX--
gameBoard[BallX][BallY] = "o"
PrintBoard()
if BallY>BallDirY {
gameBoard[BallX][BallY] = " "
BallY--
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
if BallY<BallDirY {
gameBoard[BallX][BallY] = " "
BallY++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
}
if BallX < BallDirX {
gameBoard[BallX][BallY] = " "
BallX++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
if BallY < BallDirY {
gameBoard[BallX][BallY] = " "
BallY++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
if BallY > BallDirY {
gameBoard[BallX][BallY] = " "
BallY--
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
}
if BallX==BallDirX {
if BallY < BallDirY {
gameBoard[BallX][BallY] = " "
BallY++
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
if BallY > BallDirY {
gameBoard[BallX][BallY] = " "
BallY--
gameBoard[BallX][BallY] = "o"
PrintBoard()
time.Sleep(1 * time.Second)
}
}
}
}
func Parallelize(functions ...func()) {
var waitGroup sync.WaitGroup
waitGroup.Add(len(functions))
defer waitGroup.Wait()
for _, function := range functions {
go func(copy func()) {
defer waitGroup.Done()
copy()
}(function)
}
}