Prawie dziala

This commit is contained in:
knmarcin 2018-11-24 09:56:03 +01:00
parent d1076fc4a2
commit 9784f10b59
2 changed files with 33 additions and 83 deletions

BIN
Pong

Binary file not shown.

112
Pong.go
View File

@ -27,10 +27,14 @@ var GoesUP bool = true
var GoesLEFT bool = true var GoesLEFT bool = true
func main() { func main() {
i = 5
j = 5
P1index=3
P2index=3
SpawnEverything() SpawnEverything()
for !GameOver { for !GameOver {
MovePlayers()
TickBall() TickBall()
} }
} }
func SpawnEverything() { func SpawnEverything() {
@ -90,14 +94,7 @@ func SpawnPlayers() {
gameBoard[i][29] = Player2[i] gameBoard[i][29] = Player2[i]
} }
} }
func Loop() { func MovePlayers() {
i = 5
j = 5
P1index=3
P2index=3
for !GameOver {
c:=getch() c:=getch()
switch { switch {
case bytes.Equal(c, []byte{3}): case bytes.Equal(c, []byte{3}):
@ -137,71 +134,12 @@ func Loop() {
PrintBoard() PrintBoard()
} }
default: default:
GameOver = true fmt.Print(" ")
time.Sleep(40*time.Nanosecond)
} }
}
} }
func Ball() {
BallX = 7
BallY = 14
BallDirX = 8
BallDirY = 1
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 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)
}
}
if gameBoard[BallX][BallY-1] == " " {
GameOver = true
fmt.Print("Game Over!\n")
}
}
}
func TickBall() { func TickBall() {
BallX = 4 BallX = 4
@ -217,29 +155,35 @@ func TickBall() {
BallY-- BallY--
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1 * time.Second) time.Sleep(40*time.Millisecond)
} }
if !GoesLEFT { if !GoesLEFT {
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(40*time.Millisecond)
} }
if BallX == 0 { if BallX == 0 {
PrintBoard() PrintBoard()
GoesUP = false GoesUP = false
} }
if BallY == 1 { if BallY == 1 {
if gameBoard[BallX+1][BallY-1] == "|" { if gameBoard[BallX][0] == "|" {
GoesLEFT = false GoesLEFT = false
} else { } else {
fmt.Print("Game Over") fmt.Print("Game Over")
GameOver = true GameOver = true
} }
} }
if BallY == 29 { if BallY == 28 {
GoesLEFT = true if gameBoard[BallX][29] == "|" {
GoesLEFT = true
} else {
GameOver=true
fmt.Print("Game Over")
}
} }
} }
} }
@ -254,18 +198,18 @@ func TickBall() {
BallY-- BallY--
gameBoard[BallX][BallY] = "o" gameBoard[BallX][BallY] = "o"
PrintBoard() PrintBoard()
time.Sleep(1* time.Second) time.Sleep(40*time.Millisecond)
} }
if !GoesLEFT { if !GoesLEFT {
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(40*time.Millisecond)
} }
if BallY == 1 { if BallY == 1 {
if gameBoard[BallX][BallY -1] == "|" { if gameBoard[BallX][0] == "|" {
GoesLEFT = false GoesLEFT = false
} else { } else {
fmt.Print("Game Over") fmt.Print("Game Over")
@ -273,14 +217,19 @@ func TickBall() {
} }
} }
if BallY == 29 { if BallY == 28 {
GoesLEFT = true if gameBoard[BallX][29] == "|" {
GoesLEFT = true
} else {
GameOver=true
fmt.Print("GameOver")
}
} }
if BallX == 9 { if BallX == 9 {
GoesUP = true GoesUP = true
} }
if BallY == 0 { if BallY == 1 {
GoesLEFT = false GoesLEFT = false
} }
if BallY == 29 { if BallY == 29 {
@ -306,3 +255,4 @@ func Parallelize(functions ...func()) {
}(function) }(function)
} }
} }