Witam.
Program uruchamia się zaczynając od klasy game.cs, która wygląda tak:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 warcaby
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class GAME : Window
{
int game_time, round_bonus;
PLAYER player1 = new PLAYER();
PLAYER player2 = new PLAYER();
public GAME()
{
InitializeComponent();
}
private void game_time_textbox_TextChanged(object sender, TextChangedEventArgs e){}
private void round_bonus_textbox_TextChanged(object sender, TextChangedEventArgs e) { }
private void no_time_limit_checkBox_Checked(object sender, RoutedEventArgs e)
{
game_time_textbox.Text = "brak";
round_bonus_textbox.Text = "brak";
}
private void no_time_limit_checkBox_unChecked(object sender, RoutedEventArgs e)
{
game_time_textbox.Text = "";
round_bonus_textbox.Text = "";
}
private void temp_TextChanged(object sender, TextChangedEventArgs e){}
public void next_button_Click(object sender, RoutedEventArgs e)
{
if (no_time_limit_checkBox.IsChecked == true)
{
game_time = 0;
round_bonus = 0;
}
else
{
game_time = int.Parse(game_time_textbox.Text);
round_bonus = int.Parse(round_bonus_textbox.Text);
}
player1.create_name(p1_name_input.Text);
player2.create_name(p2_name_input.Text);
//PLAYER player1 = new PLAYER(p1_name_input.Text);
//PLAYER player2 = new PLAYER(p2_name_input.Text);
//temp.Text = player1.p1_name;
ROUND round = new ROUND(this.player1);
round.ShowDialog();
}
}
}
I dodatkowo game.cs.xaml:
<Window x:Class="warcaby.GAME"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:warcaby"
mc:Ignorable="d"
Title="MainWindow" Height="392.054" Width="525">
<Grid x:Name="grid_f_run" Margin="0,0,0,-8">
<TextBlock HorizontalAlignment="Left" Margin="99,50,0,0" TextWrapping="Wrap" Text="Czas gry" VerticalAlignment="Top" Height="40" Width="91" FontSize="22"/>
<TextBlock HorizontalAlignment="Left" Margin="99,95,0,0" TextWrapping="Wrap" Text="Premia za rundę" VerticalAlignment="Top" FontSize="22"/>
<TextBox x:Name="round_bonus_textbox" HorizontalAlignment="Left" Height="26" Margin="314,98,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="41" TextChanged="round_bonus_textbox_TextChanged" RenderTransformOrigin="0.483,-1.338"/>
<TextBox x:Name="game_time_textbox" HorizontalAlignment="Left" Height="23" Margin="314,67,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="41" TextChanged="game_time_textbox_TextChanged"/>
<Button x:Name="next_button" Content="Start" HorizontalAlignment="Left" Margin="231,311,0,0" VerticalAlignment="Top" Width="76" Height="31" Click="next_button_Click" />
<TextBlock x:Name="p1_name" HorizontalAlignment="Left" Margin="101,191,0,0" TextWrapping="Wrap" Text="Imię gracza nr 1" VerticalAlignment="Top" FontSize="22"/>
<TextBox x:Name="p2_name" HorizontalAlignment="Left" Height="32" Margin="101,239,0,0" TextWrapping="Wrap" Text="Imię gracza nr 2" VerticalAlignment="Top" Width="167" FontSize="22"/>
<TextBox x:Name="p1_name_input" HorizontalAlignment="Left" Height="23" Margin="294,197,0,0" TextWrapping="Wrap" Text="pierwszy" VerticalAlignment="Top" Width="120"/>
<TextBox x:Name="p2_name_input" HorizontalAlignment="Left" Height="23" Margin="294,248,0,0" TextWrapping="Wrap" Text="drugi" VerticalAlignment="Top" Width="120"/>
<CheckBox x:Name="no_time_limit_checkBox" Content="Brak limitu czasu" HorizontalAlignment="Left" Margin="223,140,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" Checked="no_time_limit_checkBox_Checked" Unchecked="no_time_limit_checkBox_unChecked">
<CheckBox.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<TranslateTransform/>
</TransformGroup>
</CheckBox.RenderTransform>
</CheckBox>
<TextBox x:Name="temp" HorizontalAlignment="Left" Height="23" Margin="87,311,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" TextChanged="temp_TextChanged"/>
</Grid>
</Window>
W klasie game.cs tworzę obiekty: player1 i player2, które swoją definicję mają w pliku player.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace warcaby
{
class PLAYER
{
private string name;
public string p1_name
{
get { return this.name; }
set { name = value; }
}
private PLAYER p;
public PLAYER player
{
get { return this.p; }
set { p = value; }
}
public PLAYER(){ }
public string create_name(string Name)
{
return name = Name;
}
}
}
Wróćmy teraz do pliku game.cs a konkretniej do ostatnich linijek:
ROUND round = new ROUND(this.player1);
Tworzę tutaj nowe okienko, które swoją definicję będzie miało w pliku round.cs i round.cs.xaml. Jak widać do konstruktora chcę przekazać obiekt player1. Cały plik round.cs wygląda tak:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes;
namespace warcaby
{
/// <summary>
/// Interaction logic for round.xaml
/// </summary>
public partial class ROUND : Window
{
public ROUND(PLAYER player1)
{
InitializeComponent();
p1_show_name_textbox.Text = player1.p1_name;
}
}
}
gdzie "p1_show_name_textbox.Text" to textbox umieszczony w okienku.
I teraz problem który mam: chcę przekazać do ROUND obiekt a następnie w textboksie wyświetlić pole name, ale kompilator krzyczy
Severity Code Description Project File Line Suppression State
Error CS0051 Inconsistent accessibility: parameter type 'PLAYER' is less accessible than method 'ROUND.ROUND(PLAYER)'
Nie rozumiem w czym robie błąd. Gdy chciałem w GAME przekazać do konstruktora nazwę jaką gracz wpisywał na ekranie to wystarczyło dać modyfikatory dostępu get i set, w przypadku przekazywania obiektów nie chce mi to działac.
Czy może ktoś podać jaki przykład, który pokaże jak poradzić sobie z przekazaniem obiektu ?