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> /// </summary>
public partial class App : Application public partial class App : Application
{ {
} }
} }

View File

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

View File

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