func (g *Game) Move(block BlockType, x int, y int) error {
	if g.GameOver {
		return &ErrorGame{GameOver, "Cannot continue playing game in a game over state"}
	}

	var selectedBlock [][]BoardElement
	switch block {
	case A:
		selectedBlock = g.BlockA
	case B:
		selectedBlock = g.BlockB
	case C:
		selectedBlock = g.BlockC
	default:
		g.GameOver = true
		return &ErrorGame{IncorrectBlock, fmt.Sprintf("Incorrect block type specified (%d)", block)}
	}

	if isBlockEmpty(selectedBlock) {
		g.GameOver = true
		return &ErrorGame{IncorrectBlock, "Selected block is empty"}
	}

	error := g.placeBlock(x, y, selectedBlock)
	if error != nil {
		g.GameOver = true
		return error
	}

	emptyBlock := createContainer(5)
	switch block {
	case A:
		g.BlockA = emptyBlock
	case B:
		g.BlockB = emptyBlock
	case C:
		g.BlockC = emptyBlock
	}

	if isBlockEmpty(g.BlockA) && isBlockEmpty(g.BlockB) && isBlockEmpty(g.BlockC) {
		g.assignRandomBlocks()
	}

	if g.isGameOver() {
		g.GameOver = true
		return &ErrorGame{GameOver, "No other move is possible. Game over."}
	}

	return nil
}
// Move is used to select one of available blocks and place it on x,y position.
// In case the placement is not possible or block does not exist error is returned.
Move is used to select one of available blocks and place it on x,y position.
In case the placement is not possible or block does not exist error is returned.
// Move is used to select one of available blocks and place it on x y position . // In case the placement is not possible or block does not exist error is returned .
func (g *Game) Move(block BlockType, x int, y int) error {
	if g.GameOver {
		return &ErrorGame{GameOver, "Cannot continue playing game in a game over state"}
	}
	var selectedBlock [][]BoardElement
	switch block {
	case A:
		selectedBlock = g.BlockA
	case B:
		selectedBlock = g.BlockB
	case C:
		selectedBlock = g.BlockC
	default:
		g.GameOver = true
		return &ErrorGame{IncorrectBlock, fmt.Sprintf("Incorrect block type specified (%d)", block)}
	}
	if isBlockEmpty(selectedBlock) {
		g.GameOver = true
		return &ErrorGame{IncorrectBlock, "Selected block is empty"}
	}
	error := g.placeBlock(x, y, selectedBlock)
	if error != nil {
		g.GameOver = true
		return error
	}
	emptyBlock := createContainer(5)
	switch block {
	case A:
		g.BlockA = emptyBlock
	case B:
		g.BlockB = emptyBlock
	case C:
		g.BlockC = emptyBlock
	}
	if isBlockEmpty(g.BlockA) && isBlockEmpty(g.BlockB) && isBlockEmpty(g.BlockC) {
		g.assignRandomBlocks()
	}
	if g.isGameOver() {
		g.GameOver = true
		return &ErrorGame{GameOver, "No other move is possible. Game over."}
	}
	return nil
}
func ( g * Game ) Move ( block BlockType , x int , y int ) error { if g . GameOver { return & ErrorGame { GameOver , " " } } var selectedBlock [ ] [ ] BoardElement switch block { case A : selectedBlock = g . BlockA case B : selectedBlock = g . BlockB case C : selectedBlock = g . BlockC default : g . GameOver = true return & ErrorGame { IncorrectBlock , fmt . Sprintf ( " " , block ) } } if isBlockEmpty ( selectedBlock ) { g . GameOver = true return & ErrorGame { IncorrectBlock , " " } } error := g . placeBlock ( x , y , selectedBlock ) if error != nil { g . GameOver = true return error } emptyBlock := createContainer ( 5 ) switch block { case A : g . BlockA = emptyBlock case B : g . BlockB = emptyBlock case C : g . BlockC = emptyBlock } if isBlockEmpty ( g . BlockA ) && isBlockEmpty ( g . BlockB ) && isBlockEmpty ( g . BlockC ) { g . assignRandomBlocks ( ) } if g . isGameOver ( ) { g . GameOver = true return & ErrorGame { GameOver , " " } } return nil }
Move is used to select one of available blocks and place it on x,y position.
Move is used to select one of available blocks and place it on x y position .