Created
February 15, 2018 13:19
-
-
Save afelipems/37737f63abb7bfb427d773b63571cd3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace GuessGame.cs | |
{ | |
class Difficult | |
{ | |
public int difficultFactor { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace GuessGame.cs | |
{ | |
public partial class FormInitial : Form | |
{ | |
Difficult difficult = new Difficult(); | |
GuessNumber guessnumb = new GuessNumber(); | |
public FormInitial() | |
{ | |
InitializeComponent(); | |
} | |
private void Form1_Load(object sender, EventArgs e) | |
{ | |
labelCount.Text = "0"; | |
} | |
private void label1_Click(object sender, EventArgs e) | |
{ | |
} | |
private void checkBoxEasy_CheckedChanged(object sender, EventArgs e) | |
{ | |
checkBoxMedium.Checked = false; | |
checkBoxHard.Checked = false; | |
difficult.difficultFactor = 1; | |
} | |
private void checkBoxMedium_CheckedChanged(object sender, EventArgs e) | |
{ | |
checkBoxEasy.Checked = false; | |
checkBoxHard.Checked = false; | |
difficult.difficultFactor = 2; | |
} | |
private void checkBoxHard_CheckedChanged(object sender, EventArgs e) | |
{ | |
checkBoxEasy.Checked = false; | |
checkBoxMedium.Checked = false; | |
difficult.difficultFactor = 3; | |
} | |
private void btStart_Click(object sender, EventArgs e) | |
{ | |
labelCount.Text = "10"; | |
guessnumb.SetValue(difficult.difficultFactor); | |
var value = difficult.difficultFactor; | |
switch (value) | |
{ | |
case 1: | |
MessageBox.Show("Você deverá adivinhar um número entre 1 e 20."); | |
break; | |
case 2: | |
MessageBox.Show("Você deverá adivinhar um número entre 1 e 50."); | |
break; | |
case 3: | |
MessageBox.Show("Você deverá adivinhar um número entre 1 e 100."); | |
break; | |
} | |
} | |
private void label1_Click_1(object sender, EventArgs e) | |
{ | |
} | |
private void label3_Click(object sender, EventArgs e) | |
{ | |
} | |
public static bool IsNumeric(string s) | |
{ | |
float output; | |
return float.TryParse(s, out output); | |
} | |
private void btnGuess_Click(object sender, EventArgs e) | |
{ | |
var chances = Convert.ToInt32(labelCount.Text); | |
var chute = 0; | |
if (IsNumeric(textBox1.Text)) | |
{ | |
chute = Convert.ToInt32(textBox1.Text); | |
} | |
var OkLimit = ((difficult.difficultFactor == 1 && chute >= 1 && chute <= 20) || | |
(difficult.difficultFactor == 2 | |
&& chute >= 21 && chute <= 50) || | |
(difficult.difficultFactor == 3 && chute >= 51 && chute <= 100)); | |
var difference = Math.Abs(chute - guessnumb.value); | |
var fraction = (decimal) difference / (decimal) chute; | |
var MuitoFrio = fraction >= 0.7M; | |
var Frio = fraction >= 0.5M && fraction < 0.7M; | |
var Morno = fraction >= 0.35M && fraction < 0.5M; | |
var Quente = fraction >= 0.15M && fraction < 0.35M; | |
var MuitoQuente = fraction > 0 && fraction < 0.15M; | |
if (!OkLimit) | |
{ | |
MessageBox.Show("Por favor, insira um valor válido"); | |
} | |
else | |
{ | |
if (MuitoFrio) | |
{ | |
MessageBox.Show("Seu palpite é frio! Ainda está muito longe."); | |
} | |
if (Frio) | |
{ | |
MessageBox.Show("Seu palpite é frio, mas nem tanto."); | |
} | |
if (Morno) | |
{ | |
MessageBox.Show("Meio termo, nem quente nem frio."); | |
} | |
if (Quente) | |
{ | |
MessageBox.Show("Seu palpite está quente, mas não o suficiente"); | |
} | |
if (MuitoQuente) | |
{ | |
MessageBox.Show("Você está quase acertando!"); | |
} | |
if (difference == 0) | |
{ | |
MessageBox.Show("Parabéns! Você acertou o número depois de " + (11 - chances) + " tentativas"); | |
} | |
if (labelCount.Text == "0") | |
{ | |
MessageBox.Show("Lamento, mas você não conseguiu adivinhar o número " + guessnumb.value + | |
" que estava pensando."); | |
Close(); | |
} | |
else | |
{ | |
chances--; | |
labelCount.Text = chances.ToString(); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace GuessGame.cs | |
{ | |
class GuessNumber: Difficult | |
{ | |
Random rnd = new Random(); | |
public int value { get; private set; } | |
public int SetValue(int factor) | |
{ | |
switch (factor) | |
{ | |
case 1: | |
value = rnd.Next(1, 20); | |
break; | |
case 2: | |
value = rnd.Next(1, 50); | |
break; | |
case 3: | |
value = rnd.Next(1, 100); | |
break; | |
} | |
return value; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace GuessGame.cs | |
{ | |
public static class Extension | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment