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 Player2 [10]string
var P1index int
var P2index int
var Ball [10][30]string
var BallDirection [10][30]string
var BallSpeed int
@ -21,8 +22,8 @@ var GameOver bool = false
var LastPressedKey rune
func main() {
// SpawnEverything()
loop2()
SpawnEverything()
Loop()
}
func SpawnEverything() {
@ -85,35 +86,10 @@ func SpawnPlayers() {
}
func Loop() {
i = 5
j = 5
P1index=3
for GameOver == false {
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' {
}
}
}
P2index=3
func loop2() {
for !GameOver {
c:=getch()
switch {
@ -121,17 +97,38 @@ func loop2() {
return
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}):
fmt.Println("S pressed")
// "S" Key
if P1index!=7 {
gameBoard[P1index][0] = " "
P1index++
gameBoard[P1index + 2][0] = "|"
PrintBoard()
}
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}):
fmt.Println("K pressed")
// "K" Key)
if P2index!=7 {
gameBoard[P2index][29] = " "
P2index++
gameBoard[P2index + 2][29] = "|"
PrintBoard()
}
default:
GameOver = true
}