fix some buggs

This commit is contained in:
Natlinux81
2022-03-08 00:15:09 +01:00
parent 5b465179f8
commit 0ff0576609
3 changed files with 101 additions and 43 deletions

View File

@@ -13,5 +13,6 @@ namespace MathColoringGame
/// </summary>
public partial class App : Application
{
}
}

View File

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MathColoringGame"
mc:Ignorable="d"
Title="MainWindow" Height="780" Width="650"
Title="MainWindow" Height="780" Width="900"
WindowStyle="None"
Background="Transparent"
AllowsTransparency="True"
@@ -24,7 +24,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="230"/>
<ColumnDefinition Width="460"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
@@ -89,8 +89,8 @@
FontSize="18"
FontWeight="Bold"
FontFamily="Comic Sans MS"
Content="End Turn" Click="BtnEndTurnClick"/>
Content="End Turn" Click="BtnEndTurnClick"/>
<Border Grid.Row="1"
Grid.Column="1"
Margin="15,40"
@@ -168,7 +168,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 1: "
Text="Result Round 1: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p1round1" Text="0"
@@ -185,7 +185,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 2: "
Text="Result Round 2: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p1round2"
@@ -203,7 +203,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 3: "
Text="Result Round 3: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p1round3"
@@ -221,7 +221,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 4: "
Text="Result Round 4: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p1round4"
@@ -239,7 +239,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 5: "
Text="Result Round 5: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p1round5"
@@ -279,7 +279,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 1: "
Text="Result Round 1: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p2round1"
@@ -297,7 +297,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 2: "
Text="Result Round 2: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p2round2"
@@ -315,7 +315,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 3: "
Text="Result Round 3: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p2round3"
@@ -333,7 +333,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 4: "
Text="Result Round 4: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p2round4"
@@ -351,7 +351,7 @@
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="Resuld Round 5: "
Text="Result Round 5: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="p2round5"
@@ -380,13 +380,31 @@
BorderThickness="0 "
FontSize="16"
Height="30"
FontFamily="Comic Sans MS"/>
</WrapPanel>
FontFamily="Comic Sans MS"/>
</WrapPanel>
<WrapPanel>
<TextBlock
Margin="10,30,0,0"
FontSize="16"
Text="dice Result: "
FontFamily="Comic Sans MS"/>
<TextBox x:Name="testbox"
Text="0"
Margin="0,29,0,0"
FontWeight="Bold"
Background="Transparent"
BorderThickness="0 "
FontSize="16"
Height="30"
FontFamily="Comic Sans MS"/>
</WrapPanel>
</StackPanel>
<Grid x:Name="Container"
Width="250"
Width="450"
Height="450"
VerticalAlignment="Top"
Margin="28"
@@ -411,7 +429,10 @@
<Button Click="Button_Click" Background="White" Grid.Row="15" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="16" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="17" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="18" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="19" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="20" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Row="1" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Row="2" Grid.Column="1" BorderBrush="Black"/>
@@ -430,7 +451,10 @@
<Button Click="Button_Click" Background="White" Grid.Row="15" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="16" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="17" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="18" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="19" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="White" Grid.Row="20" Grid.Column="1" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Column="2" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Row="1" Grid.Column="2" BorderBrush="Black"/>
<Button Click="Button_Click" Background="Red" Grid.Row="2" Grid.Column="2" BorderBrush="Black"/>
@@ -602,10 +626,23 @@
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>

View File

@@ -24,7 +24,8 @@ namespace MathColoringGame
int cellCounter;
int roundCounter;
int diceResult;
private MarkTyp[] mResults;
private bool mPlayer1Turn;
@@ -34,6 +35,7 @@ namespace MathColoringGame
{
cellCounter = 0;
roundCounter = 1;
// Create a new blanck aray of free cells
mResults = new MarkTyp[180];
@@ -57,8 +59,8 @@ namespace MathColoringGame
{
if (roundCounter >= 6)
{
CheckWinner();
Round.Text = "5";
Round.Text = "5";
CheckWinner();
ClearAll();
NewGame();
@@ -89,7 +91,7 @@ namespace MathColoringGame
// reset all fields
private void ClearAll()
{
Round.Text = "1";
Round.Text = "1";
p1round1.Text = "0";
p1round2.Text = "0";
@@ -150,7 +152,8 @@ namespace MathColoringGame
if (mPlayer1Turn && roundCounter == 1)
{
cellCounter++;
p1round1.Text = cellCounter.ToString();
p1round1.Text = cellCounter.ToString();
}
if (!(mPlayer1Turn) && roundCounter == 1)
{
@@ -236,7 +239,7 @@ namespace MathColoringGame
// Instantiate random number generator.
private readonly Random dice = new Random();
// shuffle the dices
private void BtnRollClick(object sender, RoutedEventArgs e)
{
@@ -245,6 +248,8 @@ namespace MathColoringGame
string finalImage1 = "DiceSix.png";
string finalImage2 = "DiceOne.png";
// Gernerate Numbers in Range
int number1 = dice.Next(1, 7);
int number2 = dice.Next(1, 7);
@@ -267,9 +272,9 @@ namespace MathColoringGame
case 5:
finalImage1 = "DiceFive.png";
break;
case 6:
case 6:
finalImage1 = "DiceSix.png";
break;
break;
default:
finalImage1 = "DiceSix.png";
break;
@@ -301,32 +306,45 @@ namespace MathColoringGame
break;
}
Dice2.ImageSource = new BitmapImage(new Uri("Images/" + finalImage2, UriKind.Relative));
diceResult = number1 * number2;
testbox.Text = diceResult.ToString();
}
// Handesl Cell click event
private void Button_Click(object sender, RoutedEventArgs e)
{
//cast the sender to Cell
var button = (Button)sender;
// bind the cells position in the array
var column = Grid.GetColumn(button);
var row = Grid.GetRow(button);
if (diceResult > 0 && diceResult != cellCounter)
{
//cast the sender to Cell
var button = (Button)sender;
var index = column + (row * 10);
// dont`t do anything if the cellalready has a value in it
if (mResults[index] != MarkTyp.Free)
return;
// bind the cells position in the array
var column = Grid.GetColumn(button);
var row = Grid.GetRow(button);
// set the cell value based on which players turn it is (Compact if else statement)
mResults[index] = mPlayer1Turn ? MarkTyp.Player1Red : MarkTyp.Player2Blue;
var index = column + (row * 10);
// set cell color to the result
button.Background = mPlayer1Turn ? Brushes.Red : Brushes.Blue;
// dont`t do anything if the cellalready has a value in it
if (mResults[index] != MarkTyp.Free)
return;
//count selectet cells per player
CountCells();
// set the cell value based on which players turn it is (Compact if else statement)
mResults[index] = mPlayer1Turn ? MarkTyp.Player1Red : MarkTyp.Player2Blue;
// set cell color to the result
button.Background = mPlayer1Turn ? Brushes.Red : Brushes.Blue;
//count selectet cells per player
CountCells();
}
}
// Handel count cells
@@ -334,6 +352,8 @@ namespace MathColoringGame
{
BtnStartRoll.Visibility = Visibility.Visible;
diceResult = 0;
// check how many cells the Player marks
PlayerResult();