From 30995e55d3c1484960c7fe91278deda00b8b91d9 Mon Sep 17 00:00:00 2001 From: jimdmm Date: Sat, 11 Jul 2026 14:47:29 -0300 Subject: [PATCH] =?UTF-8?q?refactor:=20retirando=20valida=C3=A7=C3=A3o=20d?= =?UTF-8?q?esnecess=C3=A1ria=20e=20alterando=20if/else=20para=20switch=20c?= =?UTF-8?q?ase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 47 +++++++++++++++++++++++++++++++++++++++++++++++ main.go | 38 ++++++++++++++++---------------------- 2 files changed, 63 insertions(+), 22 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d0a783 --- /dev/null +++ b/.gitignore @@ -0,0 +1,47 @@ +# Binários compilados +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Binário de teste, criado por 'go test -c' +*.test + +# Output de profiling do go tool cover +*.out + +# Dependências (se usar vendor) +/vendor/ + +# Arquivo de workspace do Go (a menos que queira versionar) +go.work +go.work.sum + +# Variáveis de ambiente / segredos +.env +.env.local +*.env + +# Build outputs comuns (ajuste conforme seu projeto) +/bin/ +/build/ +/dist/ + +# Arquivos de IDE / editor +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# Arquivos específicos do sistema operacional +.DS_Store +Thumbs.db + +# Logs +*.log + +# Arquivos de configuração local +config.local.yaml +config.local.json \ No newline at end of file diff --git a/main.go b/main.go index 87d9030..ca76ffa 100644 --- a/main.go +++ b/main.go @@ -9,14 +9,17 @@ import ( ) func main() { - numero, tentativas := 7, 3 + const TENTATIVAS = 3 + numero := 7 scanner := bufio.NewScanner(os.Stdin) fmt.Println("Bem-vindo ao jogo de adivinhação!") - fmt.Printf("Você tem %d tentativas para adivinhar o número entre 1 e 10.\n", tentativas) + fmt.Printf("Você tem %d tentativas para adivinhar o número entre 1 e 10.\n", TENTATIVAS) - for i := 0; i <= tentativas; i++ { - if i == tentativas { + tentativa := 0 + + for tentativa < TENTATIVAS { + if tentativa == TENTATIVAS { fmt.Println("Suas tentativas acabaram. O número correto era:", numero) break } @@ -27,26 +30,17 @@ func main() { if err != nil { fmt.Println("Deve ser informado um número.") - continue + continue // colocado para pular a proxima iteração e não contar a tentativa } - // talvez não necessite checar se o número é menor que um -// - if chuteInt < 1 { - fmt.Println("O número deve ser maior que 0.") - continue - } - - if chuteInt < numero { - fmt.Println("O número é maior") - } - - if chuteInt > numero { - fmt.Println("O número é menor") - } - - if chuteInt == numero { + switch { + case chuteInt < numero: + fmt.Println("O número é maior, tente novamente.") + case chuteInt > numero: + fmt.Println("O número é menor, tente novamente.") + default: fmt.Println("Parabéns! Você acertou o número!") - break } + + tentativa++ } }