Created
March 3, 2016 08:51
-
-
Save NorbiPeti/be7e5ec1f5c51635113c to your computer and use it in GitHub Desktop.
Amőba
This file contains hidden or 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 Amőba | |
{ | |
public partial class Form1 : Form | |
{ | |
private bool X = false; | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void ButtonClick(object sender, EventArgs e) | |
{ | |
var btn = ((Button)sender); | |
if (btn.Text.Length > 0) | |
return; | |
if (X) | |
btn.Text = "X"; | |
else | |
btn.Text = "O"; | |
//Oszlopok | |
Check(topleftbtn, leftbtn, bottomleftbtn); | |
Check(topbtn, centerbtn, bottombtn); | |
Check(toprightbtn, rightbtn, bottomrightbtn); | |
//Sorok | |
Check(topleftbtn, topbtn, toprightbtn); | |
Check(leftbtn, centerbtn, rightbtn); | |
Check(bottomleftbtn, bottombtn, bottomrightbtn); | |
//Átlók | |
Check(topleftbtn, centerbtn, bottomrightbtn); | |
Check(toprightbtn, centerbtn, bottomleftbtn); | |
bool f = true; | |
foreach (Button button in this.Controls.Cast<Control>().Where(c => c.GetType() == typeof(Button)).Cast<Button>()) | |
if (button.Text.Length == 0) | |
f = false; | |
if(f) | |
{ | |
MessageBox.Show("Döntetlen"); | |
Reset(); | |
} | |
X = !X; | |
} | |
private void Reset() | |
{ | |
foreach (Button btn in this.Controls.Cast<Control>().Where(c => c.GetType() == typeof(Button)).Cast<Button>()) | |
btn.Text = ""; | |
} | |
private void Check(Button b1, Button b2, Button b3) | |
{ | |
if (b1.Text.Length > 0 && b1.Text == b2.Text && b2.Text == b3.Text) | |
{ | |
MessageBox.Show("Nyert: " + b1.Text); | |
Reset(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment