diff --git a/Pong b/Pong index 309454f..3dc116e 100755 Binary files a/Pong and b/Pong differ diff --git a/Pong.go b/Pong.go index 1e5d431..9a29aa8 100644 --- a/Pong.go +++ b/Pong.go @@ -28,7 +28,7 @@ func main() { SpawnEverything() for !GameOver { Ball() - Loop() + } } func SpawnEverything() { @@ -73,7 +73,7 @@ func PrintBoard() { func SpawnBall() { x = 4 y = 14 - gameBoard[x][y] = "o" + gameBoard[x][y] = " " } func SpawnPlayers() { for i = 0; i < 10; i++ { @@ -95,6 +95,7 @@ func Loop() { P2index=3 for !GameOver { + c:=getch() switch { case bytes.Equal(c, []byte{3}): @@ -136,36 +137,36 @@ func Loop() { default: GameOver = true } - } -} + } +} + func Ball() { - BallX = 2 + BallX = 7 BallY = 14 - BallDirX = 4 - BallDirY = 0 + BallDirX = 8 + BallDirY = 1 - for BallX!=BallDirX && BallY!=BallDirY { + 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 BallYBallDirY { + 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] = " " @@ -196,18 +182,58 @@ func Ball() { 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 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()) { var waitGroup sync.WaitGroup waitGroup.Add(len(functions))