Dodano drugiego gracza

This commit is contained in:
knmarcin 2018-11-18 19:56:48 +01:00
parent e36ce289d8
commit 62c896a08d
2 changed files with 35 additions and 38 deletions

BIN
Pong

Binary file not shown.

69
Pong.go
View File

@ -14,6 +14,7 @@ var i, j int
var Player1 [10]string var Player1 [10]string
var Player2 [10]string var Player2 [10]string
var P1index int var P1index int
var P2index int
var Ball [10][30]string var Ball [10][30]string
var BallDirection [10][30]string var BallDirection [10][30]string
var BallSpeed int var BallSpeed int
@ -21,8 +22,8 @@ var GameOver bool = false
var LastPressedKey rune var LastPressedKey rune
func main() { func main() {
// SpawnEverything() SpawnEverything()
loop2() Loop()
} }
func SpawnEverything() { func SpawnEverything() {
@ -85,35 +86,10 @@ func SpawnPlayers() {
} }
func Loop() { func Loop() {
i = 5 i = 5
j = 5
P1index=3 P1index=3
for GameOver == false { P2index=3
fmt.Scanf("%c", &LastPressedKey)
if LastPressedKey == 'w' {
if P1index != 0 {
P1index--
gameBoard[P1index][0] = "|"
gameBoard[P1index + 3][0] = " "
PrintBoard()
} else {
PrintBoard()
}
}
if LastPressedKey=='s' {
if P1index!=7 {
gameBoard[P1index][0] = " "
P1index++
gameBoard[P1index + 2][0] = "|"
PrintBoard()
} else {
PrintBoard()
}
}
if LastPressedKey=='r' {
}
}
}
func loop2() {
for !GameOver { for !GameOver {
c:=getch() c:=getch()
switch { switch {
@ -121,17 +97,38 @@ func loop2() {
return return
case bytes.Equal(c, []byte{119}): case bytes.Equal(c, []byte{119}):
fmt.Println("W pressed") // "W" Key
if P1index != 0 {
P1index--
gameBoard[P1index][0] = "|"
gameBoard[P1index + 3][0] = " "
PrintBoard()
}
case bytes.Equal(c, []byte{115}): case bytes.Equal(c, []byte{115}):
fmt.Println("S pressed") // "S" Key
if P1index!=7 {
gameBoard[P1index][0] = " "
P1index++
gameBoard[P1index + 2][0] = "|"
PrintBoard()
}
case bytes.Equal(c, []byte{105}): case bytes.Equal(c, []byte{105}):
fmt.Println("I pressed") // "I" Key
if P2index!=0 {
P2index--
gameBoard[P2index][29] = "|"
gameBoard[P2index + 3][29] = " "
PrintBoard()
}
case bytes.Equal(c, []byte{107}): case bytes.Equal(c, []byte{107}):
fmt.Println("K pressed") // "K" Key)
if P2index!=7 {
gameBoard[P2index][29] = " "
P2index++
gameBoard[P2index + 2][29] = "|"
PrintBoard()
}
default: default:
GameOver = true GameOver = true
} }