Musze wymyslic jak zrobic by dzialaly rownolegle te dwie funkcje i poprawic fizyke pilki, bo prawie jej nie ma.
This commit is contained in:
parent
cebed38d25
commit
63d9932607
93
Pong.go
93
Pong.go
@ -6,6 +6,8 @@ import (
|
||||
"os/exec"
|
||||
"bytes"
|
||||
"github.com/pkg/term"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var gameBoard [10][30]string
|
||||
@ -15,23 +17,25 @@ var Player1 [10]string
|
||||
var Player2 [10]string
|
||||
var P1index int
|
||||
var P2index int
|
||||
var Ball [10][30]string
|
||||
var BallDirection [10][30]string
|
||||
var BallSpeed int
|
||||
var GameOver bool = false
|
||||
var LastPressedKey rune
|
||||
var BallX, BallY int
|
||||
var BallDirX, BallDirY int
|
||||
|
||||
func main() {
|
||||
SpawnEverything()
|
||||
for !GameOver {
|
||||
Ball()
|
||||
Loop()
|
||||
}
|
||||
}
|
||||
|
||||
func SpawnEverything() {
|
||||
CreateBoard()
|
||||
SpawnPlayers()
|
||||
SpawnBall()
|
||||
PrintBoard()
|
||||
Loop()
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user