mecze soe by dodac jakas fizyke pilki ale nie moge nic wymyslic

This commit is contained in:
knmarcin 2018-11-21 22:28:10 +01:00
parent 63d9932607
commit 9984e8af4d
2 changed files with 68 additions and 42 deletions

BIN
Pong

Binary file not shown.

106
Pong.go
View File

@ -28,7 +28,7 @@ func main() {
SpawnEverything() SpawnEverything()
for !GameOver { for !GameOver {
Ball() Ball()
Loop()
} }
} }
func SpawnEverything() { func SpawnEverything() {
@ -73,7 +73,7 @@ func PrintBoard() {
func SpawnBall() { func SpawnBall() {
x = 4 x = 4
y = 14 y = 14
gameBoard[x][y] = "o" gameBoard[x][y] = " "
} }
func SpawnPlayers() { func SpawnPlayers() {
for i = 0; i < 10; i++ { for i = 0; i < 10; i++ {
@ -95,6 +95,7 @@ func Loop() {
P2index=3 P2index=3
for !GameOver { for !GameOver {
c:=getch() c:=getch()
switch { switch {
case bytes.Equal(c, []byte{3}): case bytes.Equal(c, []byte{3}):
@ -139,33 +140,33 @@ func Loop() {
} }
} }
func Ball() {
BallX = 2
BallY = 14
BallDirX = 4
BallDirY = 0
for BallX!=BallDirX && BallY!=BallDirY { func Ball() {
BallX = 7
BallY = 14
BallDirX = 8
BallDirY = 1
for BallX!=BallDirX || BallY!=BallDirY {
if BallX>BallDirX { if BallX>BallDirX {
gameBoard[BallX][BallY] = " " gameBoard[BallX][BallY] = " "
BallX-- BallX--
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
}
if BallY>BallDirY { if BallY>BallDirY {
gameBoard[BallX][BallY] = " " gameBoard[BallX][BallY] = " "
BallY-- BallY--
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
if BallY<BallDirY { if BallY<BallDirY {
gameBoard[BallX][BallY] = " " gameBoard[BallX][BallY] = " "
BallY++ BallY++
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
}
} }
if BallX < BallDirX { if BallX < BallDirX {
gameBoard[BallX][BallY] = " " gameBoard[BallX][BallY] = " "
@ -173,21 +174,6 @@ func Ball() {
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) 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 BallX==BallDirX {
if BallY < BallDirY { if BallY < BallDirY {
@ -196,18 +182,58 @@ func Ball() {
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
if BallY > BallDirY { if BallY > BallDirY {
gameBoard[BallX][BallY] = " " gameBoard[BallX][BallY] = " "
BallY-- BallY--
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
} }
}
if gameBoard[BallX][BallY-1] == " " {
GameOver = true
fmt.Print("Game Over!\n")
}
}
}
func TickBall() {
BallX = 4
BallY = 14
for !GameOver {
if GoesUP {
if BallX < 9 {
BallX++
if GoesLEFT {
BallY--
}
if Bally == 9 {
GoesUP = false
}
}
if !GoesUP {
if BallX > 1 {
BallX--
if GoesLeft {
BallY++
}
}
} }
} }
} }
}
func Parallelize(functions ...func()) { func Parallelize(functions ...func()) {
var waitGroup sync.WaitGroup var waitGroup sync.WaitGroup
waitGroup.Add(len(functions)) waitGroup.Add(len(functions))