Added gui version and basic scorehandler
This commit is contained in:
@ -5,8 +5,20 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Memory.Gui"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
Title="Memory"
|
||||
Width="800"
|
||||
Height="600"
|
||||
ResizeMode="NoResize">
|
||||
<Grid>
|
||||
|
||||
<Grid Name="StartScreen">
|
||||
<Label Content="Memory" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,180,0,0"/>
|
||||
<Button Content="Start" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,320,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
</Grid>
|
||||
<Grid Name="GameScreen" Visibility="Hidden" Margin="50, 100, 50, 50">
|
||||
</Grid>
|
||||
<Grid Name="FinishScreen" Visibility="Hidden">
|
||||
<Label Content="Game Finished" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,180,0,0"/>
|
||||
<Button Content="Restart" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,320,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -1,24 +1,89 @@
|
||||
using System.Text;
|
||||
using Memory.Data;
|
||||
using Memory.Logic;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Memory.Gui
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private Game? game;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
CreateGrid();
|
||||
}
|
||||
|
||||
private void StartGame(object sender, RoutedEventArgs args)
|
||||
{
|
||||
game = new(new ScoreHandler());
|
||||
StartScreen.Visibility = Visibility.Hidden;
|
||||
FinishScreen.Visibility = Visibility.Hidden;
|
||||
GameScreen.Visibility = Visibility.Visible;
|
||||
Redraw();
|
||||
}
|
||||
|
||||
private void FinishGame()
|
||||
{
|
||||
GameScreen.Visibility = Visibility.Hidden;
|
||||
FinishScreen.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void CreateGrid()
|
||||
{
|
||||
int columns = Game.GRIDSIZE;
|
||||
int rows = Game.DECKSIZE * 2 / Game.GRIDSIZE;
|
||||
for (int i = 0; i < columns; i++)
|
||||
{
|
||||
ColumnDefinition colDef = new()
|
||||
{
|
||||
Width = new(1, GridUnitType.Star)
|
||||
};
|
||||
GameScreen.ColumnDefinitions.Add(colDef);
|
||||
}
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
RowDefinition rowDef = new()
|
||||
{
|
||||
Height = new(1, GridUnitType.Star)
|
||||
};
|
||||
GameScreen.RowDefinitions.Add(rowDef);
|
||||
}
|
||||
}
|
||||
|
||||
private void Redraw()
|
||||
{
|
||||
GameScreen.Children.Clear();
|
||||
for (int i = 0; i < game.Cards.Count; i++)
|
||||
{
|
||||
Card card = game.Cards[i];
|
||||
if (!card.Completed)
|
||||
{
|
||||
Button button = new()
|
||||
{
|
||||
Content = card.Selected() ? card.ID : null,
|
||||
FontSize = 30,
|
||||
Background = new SolidColorBrush(card.Selected() ? Color.FromRgb(0, 255, 0) : Color.FromRgb(255, 0, 0))
|
||||
};
|
||||
Grid.SetColumn(button, i % Game.GRIDSIZE);
|
||||
Grid.SetRow(button, i / Game.GRIDSIZE);
|
||||
button.Click += (object sender, RoutedEventArgs args) =>
|
||||
{
|
||||
game.ClickCard(card);
|
||||
if (!game.IsFinished())
|
||||
{
|
||||
Redraw();
|
||||
}
|
||||
else
|
||||
{
|
||||
FinishGame();
|
||||
}
|
||||
};
|
||||
GameScreen.Children.Add(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,9 @@
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Memory.Data\Memory.Data.csproj" />
|
||||
<ProjectReference Include="..\Memory.Logic\Memory.Logic.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Reference in New Issue
Block a user