Print garbage sent/received on one line
This commit is contained in:
parent
5c15b730b8
commit
0e4db5d746
5 changed files with 18 additions and 23 deletions
|
@ -60,4 +60,4 @@ The following libraries are used to build netris:
|
|||
|
||||
Tetris is a registered trademark of the Tetris Holding, LLC.
|
||||
|
||||
netris is no way affiliated with Tetris Holding, LLC.
|
||||
netris is in no way affiliated with Tetris Holding, LLC.
|
||||
|
|
|
@ -271,7 +271,7 @@ func handleTitle() {
|
|||
}
|
||||
|
||||
for _, m := range p.Mino {
|
||||
if titleMatrixR.Block(p.X+m.X, p.Y+m.Y) != mino.BlockNone {
|
||||
if !titleMatrixR.ValidPoint(p.X+m.X, p.Y+m.Y) || titleMatrixR.Block(p.X+m.X, p.Y+m.Y) != mino.BlockNone {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -465,12 +465,17 @@ func (g *Game) handleDistributeMatrixes() {
|
|||
|
||||
g.WriteAllL(&GameCommandGameOver{Winner: winner})
|
||||
|
||||
g.WriteMessage("Game over - winner: " + winner)
|
||||
g.WriteMessage("Garbage sent/received:")
|
||||
for _, p := range players {
|
||||
g.WriteMessage(p.Name + " - " + strconv.Itoa(p.totalGarbageSent) + "/" + strconv.Itoa(p.totalGarbageReceived))
|
||||
var garbageMessage strings.Builder
|
||||
for i, p := range players {
|
||||
if i > 0 {
|
||||
garbageMessage.WriteString(", ")
|
||||
}
|
||||
|
||||
garbageMessage.WriteString(fmt.Sprintf("%s %d/%d", p.Name, p.totalGarbageSent, p.totalGarbageReceived))
|
||||
}
|
||||
|
||||
g.WriteMessage(fmt.Sprintf("Winner: %s - Garbage sent/received: %s", winner, garbageMessage.String()))
|
||||
|
||||
if len(g.Players) < 2 {
|
||||
g.WriteMessage("Game will start when there are at least two players")
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ type Matrix struct {
|
|||
|
||||
func I(x int, y int, w int) int {
|
||||
if x < 0 || x >= w || y < 0 {
|
||||
log.Fatalf("failed to calculate matrix index %d %d %d", x, y, w)
|
||||
log.Panicf("failed to retrieve index for %d,%d width %d: invalid coordinates", x, y, w)
|
||||
}
|
||||
|
||||
return (y * w) + x
|
||||
|
@ -452,8 +452,8 @@ func (m *Matrix) DrawActivePieceL() {
|
|||
}
|
||||
|
||||
func (m *Matrix) Block(x int, y int) Block {
|
||||
if x < 0 || x >= m.W || y < 0 || y >= m.H+m.B {
|
||||
return BlockGarbage
|
||||
if y >= m.H+m.B {
|
||||
log.Panicf("failed to retrieve block at %d,%d: invalid y coordinate", x, y)
|
||||
}
|
||||
|
||||
index := I(x, y, m.W)
|
||||
|
@ -886,6 +886,10 @@ func (m *Matrix) HardDropPiece() {
|
|||
m.finishLandingPiece()
|
||||
}
|
||||
|
||||
func (m *Matrix) ValidPoint(x int, y int) bool {
|
||||
return x >= 0 && x < m.W && y >= 0 && y < m.H+m.B
|
||||
}
|
||||
|
||||
func (m *Matrix) Replace(newmtx *Matrix) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
|
|
@ -64,20 +64,6 @@ func NewMino(points string) Mino {
|
|||
return m
|
||||
}
|
||||
|
||||
func (m Mino) Equal(other Mino) bool {
|
||||
if len(m) != len(other) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(m); i++ {
|
||||
if !m.HasPoint(other[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (m Mino) String() string {
|
||||
sort.Sort(m)
|
||||
|
||||
|
|
Loading…
Reference in a new issue