diff --git a/tictactoe/App.xaml b/tictactoe/App.xaml
index 3e5aaf9..14023e2 100644
--- a/tictactoe/App.xaml
+++ b/tictactoe/App.xaml
@@ -5,11 +5,10 @@
StartupUri="MainWindow.xaml">
-
diff --git a/tictactoe/MainWindow.xaml b/tictactoe/MainWindow.xaml
index 3b1a085..d0f3f52 100644
--- a/tictactoe/MainWindow.xaml
+++ b/tictactoe/MainWindow.xaml
@@ -22,31 +22,31 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/tictactoe/TicTacToeViewModel.cs b/tictactoe/TicTacToeViewModel.cs
index f8b7a50..935e3e9 100644
--- a/tictactoe/TicTacToeViewModel.cs
+++ b/tictactoe/TicTacToeViewModel.cs
@@ -3,24 +3,94 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Microsoft.VisualBasic;
namespace TicTacToe
{
partial class TicTacToeViewModel : ObservableObject
{
[ObservableProperty]
- char[][] grid = new char[][] {
- new char[] { ' ', ' ', ' ' },
- new char[] { ' ', ' ', ' ' },
- new char[] { ' ', ' ', ' ' },
- };
+ char field1 = ' ';
- char currentTurn = 'O';
+ [ObservableProperty]
+ char field2 = ' ';
+
+ [ObservableProperty]
+ char field3 = ' ';
+
+ [ObservableProperty]
+ char field4 = ' ';
+
+ [ObservableProperty]
+ char field5 = ' ';
+
+ [ObservableProperty]
+ char field6 = ' ';
+
+ [ObservableProperty]
+ char field7 = ' ';
+
+ [ObservableProperty]
+ char field8 = ' ';
+
+ [ObservableProperty]
+ char field9 = ' ';
+
+ char currentTurn;
public TicTacToeViewModel()
{
+ currentTurn = 'O';
+ }
+ [RelayCommand]
+ public void OnFieldClick(string index)
+ {
+ // Karlkodning
+ switch (index)
+ {
+ case "1": if (Field1 == ' ') Field1 = currentTurn; else return; break;
+ case "2": if (Field2 == ' ') Field2 = currentTurn; else return; break;
+ case "3": if (Field3 == ' ') Field3 = currentTurn; else return; break;
+ case "4": if (Field4 == ' ') Field4 = currentTurn; else return; break;
+ case "5": if (Field5 == ' ') Field5 = currentTurn; else return; break;
+ case "6": if (Field6 == ' ') Field6 = currentTurn; else return; break;
+ case "7": if (Field7 == ' ') Field7 = currentTurn; else return; break;
+ case "8": if (Field8 == ' ') Field8 = currentTurn; else return; break;
+ case "9": if (Field9 == ' ') Field9 = currentTurn; else return; break;
+ }
+
+ if (currentTurn == 'O') currentTurn = 'X';
+ else currentTurn = 'O';
+
+ char[][] wins = new char[][]
+ {
+ new char[] { Field1, Field2, Field3 },
+ new char[] { Field4, Field5, Field6 },
+ new char[] { Field7, Field8, Field9 },
+ new char[] { Field1, Field5, Field9 },
+ new char[] { Field3, Field5, Field7 },
+ };
+
+ foreach (var win in wins)
+ {
+ if (win[0] != ' ' && win[0] == win[1] && win[1] == win[2])
+ {
+ MessageBox.Show($"{win[0]} VANDT!!!!");
+ Field1 = ' ';
+ Field2 = ' ';
+ Field3 = ' ';
+ Field4 = ' ';
+ Field5 = ' ';
+ Field6 = ' ';
+ Field7 = ' ';
+ Field8 = ' ';
+ Field9 = ' ';
+ }
+ }
}
}
}