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.

116
Pong.go
View File

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