Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
It's done finally...
Browse files Browse the repository at this point in the history
  • Loading branch information
Vassterak committed Nov 13, 2021
1 parent 5f38f7d commit 777fefb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion GameSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<Label Content="Hráč číslo 1 jméno: " Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Content="Hráč číslo 2 jméno: " Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Content="Velikost hráčů na hrací ploše: " Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<Label Content="Velikost hráčů na hrací ploše (v px): " Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBox x:Name="textBox_player1" Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" PreviewTextInput="textBox_player1_PreviewTextInput" Text="Hráč 1"/>
<TextBox x:Name="textBox_player2" Grid.Column="1" Grid.Row="4" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" PreviewTextInput="textBox_player2_PreviewTextInput" Text="Hráč 2" />
<TextBox x:Name="textBox_playerSize" Grid.Column="1" Grid.Row="5" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" PreviewTextInput="textBox_playerSize_PreviewTextInput" Text="80"/>
Expand Down
33 changes: 30 additions & 3 deletions Gorillas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ namespace WPF_Game_Gorillas
class Gorillas
{
private const int gravityCoeficient = 10; //9,81 rounded to 10
public int[] player1 = new int[2]; //angle and speed
public int[] player2 = new int[2]; //angle and speed
public string[] playersNames = new string[2];
public int[] player1 = new int[3]; //angle and speed, lives
public int[] player2 = new int[3]; //angle and speed, lives
public bool player1Starts = true;

private Canvas gameCanvas = new Canvas();
private List<Rectangle> skyscrapersList = new List<Rectangle>();
private Random rnd = new Random();
public Label gameStatusLabel;
public Label gameStatusLabel; //values is set outside the class
public Label[] playersLives = new Label[2];

//Players sprites
private Rectangle gorillaSprite1 = new Rectangle();
Expand Down Expand Up @@ -216,19 +218,44 @@ private void CollisionManagement() //I'm not able to use something like: myRecta
{
if(HasIntersection(GetGeometry(gameBullet), GetGeometry(gorillaSprite2)))
{
player2[2]--;
gameCanvas.Children.Remove(gameBullet);
gameStatusLabel.Content = "Zásah!";
playersLives[1].Content = "Počet životů: " + player2[2].ToString();
physicTimerUpdate.Stop();

if (player2[2] <= 0)
{
MessageBox.Show("Hráč: " + playersNames[0] + " vyhrál!");

foreach (Window killThatWindow in App.Current.Windows) //I was unable to find simpler version that was actually working...
{
if (killThatWindow.Title == "Gorillas - Game")
killThatWindow.Close();
}
}
}

}
else
{
if (HasIntersection(GetGeometry(gameBullet), GetGeometry(gorillaSprite1)))
{
player1[2]--;
gameCanvas.Children.Remove(gameBullet);
gameStatusLabel.Content = "Zásah!";
playersLives[0].Content = "Počet životů: " + player1[2].ToString();
physicTimerUpdate.Stop();

if (player1[2] <= 0)
{
MessageBox.Show("Hráč: " + playersNames[1] + " vyhrál!");
foreach (Window killThatWindow in App.Current.Windows) //I was unable to find simpler version that was actually working...
{
if (killThatWindow.Title == "Gorillas - Game")
killThatWindow.Close();
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions GorillasScreen.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ private void Window_SourceInitialized(object sender, EventArgs e)

player1Name.Content = ((GameSettings)Application.Current.MainWindow).textBox_player1.Text; //get values from other window
player2Name.Content = ((GameSettings)Application.Current.MainWindow).textBox_player2.Text;

player1Lives.Content = "Počet životů: " + ((GameSettings)Application.Current.MainWindow).textBox_gamesToWin.Text; //live values initialization on screen
player2Lives.Content = player1Lives.Content;

gorillasGame.gameStatusLabel = gameStatusLabel;

gorillasGame.playersLives[0] = player1Lives;
gorillasGame.playersLives[1] = player2Lives;
gorillasGame.player1[2] = gorillasGame.player2[2] =int.Parse(((GameSettings)Application.Current.MainWindow).textBox_gamesToWin.Text);
gorillasGame.playersNames[0] = player1Name.Content.ToString();
gorillasGame.playersNames[1] = player2Name.Content.ToString();

nextRoundButton.Content = "Hraje: " + player1Name.Content;
}

Expand Down

0 comments on commit 777fefb

Please sign in to comment.