using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace HogerLager
{
public partial class frmHogerLager : Form
{
int raadGetal;
int turn = 0;
public frmHogerLager()
{
InitializeComponent();
}
private void frmHogerLager_Load(object sender, EventArgs e)
{
newGame();
}
private void newGame()
{
Random rnd = new Random();
raadGetal = rnd.Next(1, 100);
lblBoodschap.Text = "Begin";
turn = 0;
label1.Text = Convert.ToString(turn);
}
private void btnEvalueer_Click(object sender, EventArgs e)
{
// Methode om te zien of de input een geldige integer is.
bool isNumeric;
isNumeric = int.TryParse(txtInput.Text, out raadGetal);
if (isNumeric)
{// Is een getal!
turn++;
checkTurn();
int input = Convert.ToInt32(txtInput.Text);
if (raadGetal > input)
{ lblBoodschap.Text = ("Hoger"); }
else if (raadGetal < input)
{ lblBoodschap.Text = ("Lager"); }
else if (raadGetal == input)
{
lblBoodschap.Text = "Proficiat!";
}
else
{ lblBoodschap.Text = "Err"; }
}
else
{
MessageBox.Show("Voer een geldige integer in");
}
}
private void checkTurn()
{
if (turn == 10)
{
MessageBox.Show("Game OVer!");
newGame();
}
else {
label1.Text = Convert.ToString(turn);
}
}
private void btnNieuwSpel_Click(object sender, EventArgs e)
{
newGame();
}
private void btnStop_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
|