EDN Admin
Well-known member
Hello,
First of all, Im posting this question in the C# forum because this program just "happens" to be in WPF. Theres no XAML code in trhe MainWindow besides the window itself (with the size, the title, and all that) and a Grid without any elements or properties
called gridPrincipal.
Ive been trying to make a strange game in WPF ( http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a70e42cb-73d2-4aea-be37-0ea366029581" target="_blank" title="Strange WPF Game first thread here ) with a character (2 meanings) that moves
around a map and earns some stuff. The actual map is a 20 by 20 grid of TextBlocks (more details in the link above refered). Just moving the character is being hard,
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/409094b6-e08d-4c64-b7f6-2300e94bdb2f" target="_blank" title="TIE
sometimes I get the strange TIException , when it is actually a NullReferenceException, ArgumentExeption or ArgumentNullERxception.
However, now I get no exception and everything seems to be working fine, but when the app runs the symbol "#" (at position (0,19)) should be lower and it appears awckward (like if the character "@" overlapped the "#"). If I click in the right arrow key the
character moves correctly to the (3, 2) position (it should be represented in the (2, 2) position before the key was pressed). Afterwords it moves normally unless the x value is lower than or equals 2 (as in the beginning), in which case the character moves
back to the (0, 19) position (the odd character reappears), again as when the program started.
I simply dont know whats wrong. I never made a game before, so I guess the code must be just too strange for the compiler. If you were pacient enough to read all this I strongly recommend to read the other threads as well before helping me. Anyway,
here is the code:
MainWindow.xaml.cs:
<pre class="prettyprint /// <summary> /// Interaction logic for MainWindow.xaml /// </summary>
public partial class MainWindow : Window
{
internal TextBlock[,] mapa0tb, mapa1tb;
internal Mapa mapaIntro;
internal Jogador jog1;
private byte x;
private byte y;
public MainWindow()
{
mapa0tb = new TextBlock[20, 20];
mapa1tb = new TextBlock[20, 20];
// mapa0tb[2, 2].Text = "@";
// jog1 = new Jogador(mapaIntro, 2, 2);
mapaIntro = new Mapa(out jog1, 2, 2, mapa0tb, "(0;19 ,#)", "(2 ,3, #");
x = jog1.Posicao[0];
y = jog1.Posicao[1];
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
gridPrincipal = mapaIntro.Carrega();
//mapa0tb[2, 2].Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
Content = gridPrincipal;
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
jog1.Mover(e, ref x, ref y);
}
}
public static partial class Util
{
} [/code]
Mapa.cs:
<pre class="prettyprint public class Mapa : IDisposable
{
private bool disposed = false;
private CoordStringCor[] valSubst;
internal string[,] valores;
private byte[] posicaoInicJog = new byte[2];
private Mapa()
{
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
if (MapaBase[x, y].Text == "@")
{
posicaoInicJog[0] = x;
posicaoInicJog[1] = y;
}
}
}
}
public Mapa(string[,] valores)
{
}
public Mapa(out Jogador jog, byte xPos, byte yPos, TextBlock[,] mapaBase, params CoordStringCor[] valoresSubst)
{
valSubst = valoresSubst;
MapaBase = mapaBase;
/* muda o array mas não muda cada um dos seus valores individuais.
* Abaixo encontra-se a solução para esse problema.
* No entanto, a igualdade é necessária para assegurar que a array não é nula.*/
/*
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
MapaBase[x, y] = new TextBlock();
}
}*/
jog = new Jogador(this, 2, 2);
jog.MapaAtual = this;
jog.Posicao = new byte[2];
jog.Posicao[0] = xPos;
jog.Posicao[1] = yPos;
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
MapaBase[x, y] = new TextBlock();
if (x == xPos && y == yPos)
{
MapaBase[x, y].Text = "@";
break;
}
/*if (MapaBase[x, y] != null && MapaBase[x, y].Text == "@")
{
posicaoInicJog[0] = x;
posicaoInicJog[1] = y;
}*/
MapaBase[x, y].Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
// TargetInvocationException (acima), na realidade uma NullReferenceException
// Erro eliminado! OK!!
}
if (x == xPos)
{
break;
}
}
}
public TextBlock[,] MapaBase
{
get;
set;
}
public byte[] PosicaoDoJogador
{
get;
set;
}
public Grid Carrega()
{
Grid grid = new Grid();
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
if (MapaBase[x, y] == null)
{
MapaBase[x, y] = new TextBlock();
MapaBase[x, y].Text = " ";
MapaBase[x, y].VerticalAlignment = VerticalAlignment.Bottom;
MapaBase[x, y].HorizontalAlignment = HorizontalAlignment.Left;
MapaBase[x, y].Margin = new Thickness(x * 15 + 15, 0, 0, y * 15 + 15);
MapaBase[x, y].FontSize = 14;
MapaBase[x, y].Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
}
/*else
{*/
foreach (CoordStringCor cs in valSubst)
{
if (cs.X == x && cs.Y == y)
{
MapaBase[x, y].Text = cs.Substituidor;
}
}
//}
grid.Children.Add(MapaBase[x, y]); // grid.Children.Contains(MapaBase[2, 2]) ?
}
}
return grid;
}
/*public void Recarrega()
{
Grid grid = new Grid();
return;
}*/ // incompleto
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
// valSubst.Dispose();
valSubst = null;
valores = null;
MapaBase = null;
/*((IDisposable)(object)valSubst).Dispose();
((IDisposable)(object)valores).Dispose();
((IDisposable)(object)MapaBase).Dispose();*/
}
// Call the appropriate methods to clean up
// unmanaged resources here.
// If disposing is false,
// only the following code is executed.
// CloseHandle(handle);
// handle = IntPtr.Zero;
// Note disposing has been done.
disposed = true;
}
}
~Mapa()
{
Dispose(false);
}
}
/**
*
* <summary>Representa um valor a substituir num mapa.</summary>
* <example>(2, 3, "#")</example>
*/
public class CoordStringCor
{
public CoordStringCor(byte x, byte y, string subst)
{
X = x;
Y = y;
Substituidor = subst;
Cor = Color.FromRgb(255, 255, 255);
}
public CoordStringCor(byte x, byte y, string subst, Color cor)
{
X = x;
Y = y;
Substituidor = subst;
Cor = cor;
}
public CoordStringCor(string sCoordString)
{
CoordStringCor c = ((CoordStringCor)sCoordString);
X = c.X;
Y = c.Y;
Substituidor = c.Substituidor;
Cor = Color.FromRgb(255, 255, 255);
}
public byte X
{
get;
set;
}
public byte Y
{
get;
set;
}
public string Substituidor
{
get;
private set;
}
public Color Cor
{
get;
set;
}
public override string ToString()
{
return "(" + X + ", " + Y + ", "" + Substituidor + "")";
}
public static implicit operator CoordStringCor(string scs)
{
return scs.ToCoordStringCor();
}
}
public static partial class Util
{
internal static CoordStringCor ToCoordStringCor(this string scsc)
{
try
{
scsc = scsc.Replace((, uabcd);
scsc = scsc.Replace(), uabcd);
scsc = scsc.Replace(", uabcd);
scsc = scsc.Replace( , uabcd);
// por alguma razão, u0000 introduz um 0 em vez do caracter nulo
string s = "";
for (int i = 0; i < scsc.Length; i++)
{
if (scsc.ToCharArray() != uabcd) // se um espaço fosse usado como comparação, os espaços postos de propósito seriam eliminados
{
s += scsc.ToCharArray();
}
}
string[] array = s.Split(,, ;
return new CoordStringCor(Convert.ToByte(array[0]), Convert.ToByte(array[1]), array[2]);
}
catch (Exception e)
{
MessageBox.Show(""" + e.Message + """, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
return new CoordStringCor(Convert.ToByte(10), Convert.ToByte(10), " ");
}
}[/code]
Jogador.cs:
<pre class="prettyprint public class Jogador
{
// private byte[] posicaoInic = new byte[2];
private byte[] posicao = new byte[2];
internal bool jogMovido = false;
internal bool jogCriado = false;
private Mapa mapaAtual;
protected Jogador()
{
Local = new TextBlock();
Local.VerticalAlignment = VerticalAlignment.Bottom;
Local.HorizontalAlignment = HorizontalAlignment.Left;
Local.Margin = new Thickness(10, 0, 0, 10);
Local.Text = "@";
// Posicao = Local.Margin;
}
public Jogador(ref Mapa mapa, params byte[] posicao)
{
mapaAtual = mapa;
mapa.MapaBase[posicao[0], posicao[1]] = new TextBlock();
mapa.MapaBase[posicao[0], posicao[1]].Text = "@";
this.posicao[0] = posicao[0];
this.posicao[1] = posicao[1];
}
public Jogador(Mapa mapa, params byte[] posicao)
{
mapaAtual = mapa;
mapa.MapaBase[posicao[0], posicao[1]] = new TextBlock();
mapa.MapaBase[posicao[0], posicao[1]].Text = "@";
this.posicao[0] = posicao[0];
this.posicao[1] = posicao[1];
}
public byte[] Posicao
{
get
{
return posicao;
}
set
{
jogCriado = true;
posicao = value;
}
}
/*
public Thickness Posicao
{
get
{
return Local.Margin;
}
set
{
Local.Name = "textblock" + value.Left + value.Top;
}
}*/
public Thickness PosicaoAnterior
{
get
{
return Local.Margin;
}
set
{
Local.Name = "textblock" + value.Left + value.Top;
}
}
public TextBlock Local
{
get;
private set;
}
internal Mapa MapaAtual
{
get
{
return mapaAtual;
}
set
{
mapaAtual = value;
}
}
public void Mover(KeyEventArgs e, ref byte x, ref byte y)
{
try
{
if (jogCriado)
{
if (e.Key == Key.Up && y < 19 && mapaAtual.MapaBase[x, y + 1].Text != "#")
{
if (mapaAtual.MapaBase[x, y + 1].Text == "€")
{
}
mapaAtual.MapaBase[x, y].Text = " ";
y++;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Down && y != 0 && mapaAtual.MapaBase[x, y - 1].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
y--;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Right && x < 19 && mapaAtual.MapaBase[x + 1, y].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
x++;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Left && x != 0 && mapaAtual.MapaBase[x - 1, y].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
x--;
mapaAtual.MapaBase[x, y].Text = "@";
}
}
}
catch (Exception erro)
{
MessageBox.Show(""" + erro.Message + """, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
// mapaAtual.Recarrega();
jogMovido = true;
}
}
}
public static partial class Util
{
public static bool IsParede(this TextBlock l)
{
switch (l.Text.ToString())
{
case "@":
case " ":
return true;
case "#":
default:
return false;
}
}
private static bool IsParede(this TextBlock l, Brush jCor)
{
return !((l.Text.ToString() == " " || l.Text.ToString() == "@") && jCor != l.Foreground);
}
public static TextBlock[,] PosTesouro(this TextBlock[,] mapa)
{
return null;
}
}[/code]
<br/>
Jogo.cs:
<pre class="prettyprint public class Jogo
{
Jogo jogo1 = new Jogo();
Jogo jogo2 = new Jogo();
Jogo jogo3 = new Jogo();
Jogo jogo4 = new Jogo();
Jogo jogo5 = new Jogo();
Jogo jogo6 = new Jogo();
private Jogo()
{
}
}[/code]
Thanks for at least reading and I hope you help, <hr class="sig João Miguel
View the full article
First of all, Im posting this question in the C# forum because this program just "happens" to be in WPF. Theres no XAML code in trhe MainWindow besides the window itself (with the size, the title, and all that) and a Grid without any elements or properties
called gridPrincipal.
Ive been trying to make a strange game in WPF ( http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/a70e42cb-73d2-4aea-be37-0ea366029581" target="_blank" title="Strange WPF Game first thread here ) with a character (2 meanings) that moves
around a map and earns some stuff. The actual map is a 20 by 20 grid of TextBlocks (more details in the link above refered). Just moving the character is being hard,
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/409094b6-e08d-4c64-b7f6-2300e94bdb2f" target="_blank" title="TIE
sometimes I get the strange TIException , when it is actually a NullReferenceException, ArgumentExeption or ArgumentNullERxception.
However, now I get no exception and everything seems to be working fine, but when the app runs the symbol "#" (at position (0,19)) should be lower and it appears awckward (like if the character "@" overlapped the "#"). If I click in the right arrow key the
character moves correctly to the (3, 2) position (it should be represented in the (2, 2) position before the key was pressed). Afterwords it moves normally unless the x value is lower than or equals 2 (as in the beginning), in which case the character moves
back to the (0, 19) position (the odd character reappears), again as when the program started.
I simply dont know whats wrong. I never made a game before, so I guess the code must be just too strange for the compiler. If you were pacient enough to read all this I strongly recommend to read the other threads as well before helping me. Anyway,
here is the code:
MainWindow.xaml.cs:
<pre class="prettyprint /// <summary> /// Interaction logic for MainWindow.xaml /// </summary>
public partial class MainWindow : Window
{
internal TextBlock[,] mapa0tb, mapa1tb;
internal Mapa mapaIntro;
internal Jogador jog1;
private byte x;
private byte y;
public MainWindow()
{
mapa0tb = new TextBlock[20, 20];
mapa1tb = new TextBlock[20, 20];
// mapa0tb[2, 2].Text = "@";
// jog1 = new Jogador(mapaIntro, 2, 2);
mapaIntro = new Mapa(out jog1, 2, 2, mapa0tb, "(0;19 ,#)", "(2 ,3, #");
x = jog1.Posicao[0];
y = jog1.Posicao[1];
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
gridPrincipal = mapaIntro.Carrega();
//mapa0tb[2, 2].Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
Content = gridPrincipal;
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
jog1.Mover(e, ref x, ref y);
}
}
public static partial class Util
{
} [/code]
Mapa.cs:
<pre class="prettyprint public class Mapa : IDisposable
{
private bool disposed = false;
private CoordStringCor[] valSubst;
internal string[,] valores;
private byte[] posicaoInicJog = new byte[2];
private Mapa()
{
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
if (MapaBase[x, y].Text == "@")
{
posicaoInicJog[0] = x;
posicaoInicJog[1] = y;
}
}
}
}
public Mapa(string[,] valores)
{
}
public Mapa(out Jogador jog, byte xPos, byte yPos, TextBlock[,] mapaBase, params CoordStringCor[] valoresSubst)
{
valSubst = valoresSubst;
MapaBase = mapaBase;
/* muda o array mas não muda cada um dos seus valores individuais.
* Abaixo encontra-se a solução para esse problema.
* No entanto, a igualdade é necessária para assegurar que a array não é nula.*/
/*
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
MapaBase[x, y] = new TextBlock();
}
}*/
jog = new Jogador(this, 2, 2);
jog.MapaAtual = this;
jog.Posicao = new byte[2];
jog.Posicao[0] = xPos;
jog.Posicao[1] = yPos;
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
MapaBase[x, y] = new TextBlock();
if (x == xPos && y == yPos)
{
MapaBase[x, y].Text = "@";
break;
}
/*if (MapaBase[x, y] != null && MapaBase[x, y].Text == "@")
{
posicaoInicJog[0] = x;
posicaoInicJog[1] = y;
}*/
MapaBase[x, y].Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
// TargetInvocationException (acima), na realidade uma NullReferenceException
// Erro eliminado! OK!!
}
if (x == xPos)
{
break;
}
}
}
public TextBlock[,] MapaBase
{
get;
set;
}
public byte[] PosicaoDoJogador
{
get;
set;
}
public Grid Carrega()
{
Grid grid = new Grid();
for (byte x = 0; x < MapaBase.GetLength(0); x++)
{
for (byte y = 0; y < MapaBase.GetLength(1); y++)
{
if (MapaBase[x, y] == null)
{
MapaBase[x, y] = new TextBlock();
MapaBase[x, y].Text = " ";
MapaBase[x, y].VerticalAlignment = VerticalAlignment.Bottom;
MapaBase[x, y].HorizontalAlignment = HorizontalAlignment.Left;
MapaBase[x, y].Margin = new Thickness(x * 15 + 15, 0, 0, y * 15 + 15);
MapaBase[x, y].FontSize = 14;
MapaBase[x, y].Foreground = new SolidColorBrush(Color.FromRgb(0xff, 0xff, 0xff));
}
/*else
{*/
foreach (CoordStringCor cs in valSubst)
{
if (cs.X == x && cs.Y == y)
{
MapaBase[x, y].Text = cs.Substituidor;
}
}
//}
grid.Children.Add(MapaBase[x, y]); // grid.Children.Contains(MapaBase[2, 2]) ?
}
}
return grid;
}
/*public void Recarrega()
{
Grid grid = new Grid();
return;
}*/ // incompleto
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
// Check to see if Dispose has already been called.
if (!this.disposed)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{
// Dispose managed resources.
// valSubst.Dispose();
valSubst = null;
valores = null;
MapaBase = null;
/*((IDisposable)(object)valSubst).Dispose();
((IDisposable)(object)valores).Dispose();
((IDisposable)(object)MapaBase).Dispose();*/
}
// Call the appropriate methods to clean up
// unmanaged resources here.
// If disposing is false,
// only the following code is executed.
// CloseHandle(handle);
// handle = IntPtr.Zero;
// Note disposing has been done.
disposed = true;
}
}
~Mapa()
{
Dispose(false);
}
}
/**
*
* <summary>Representa um valor a substituir num mapa.</summary>
* <example>(2, 3, "#")</example>
*/
public class CoordStringCor
{
public CoordStringCor(byte x, byte y, string subst)
{
X = x;
Y = y;
Substituidor = subst;
Cor = Color.FromRgb(255, 255, 255);
}
public CoordStringCor(byte x, byte y, string subst, Color cor)
{
X = x;
Y = y;
Substituidor = subst;
Cor = cor;
}
public CoordStringCor(string sCoordString)
{
CoordStringCor c = ((CoordStringCor)sCoordString);
X = c.X;
Y = c.Y;
Substituidor = c.Substituidor;
Cor = Color.FromRgb(255, 255, 255);
}
public byte X
{
get;
set;
}
public byte Y
{
get;
set;
}
public string Substituidor
{
get;
private set;
}
public Color Cor
{
get;
set;
}
public override string ToString()
{
return "(" + X + ", " + Y + ", "" + Substituidor + "")";
}
public static implicit operator CoordStringCor(string scs)
{
return scs.ToCoordStringCor();
}
}
public static partial class Util
{
internal static CoordStringCor ToCoordStringCor(this string scsc)
{
try
{
scsc = scsc.Replace((, uabcd);
scsc = scsc.Replace(), uabcd);
scsc = scsc.Replace(", uabcd);
scsc = scsc.Replace( , uabcd);
// por alguma razão, u0000 introduz um 0 em vez do caracter nulo
string s = "";
for (int i = 0; i < scsc.Length; i++)
{
if (scsc.ToCharArray() != uabcd) // se um espaço fosse usado como comparação, os espaços postos de propósito seriam eliminados
{
s += scsc.ToCharArray();
}
}
string[] array = s.Split(,, ;
return new CoordStringCor(Convert.ToByte(array[0]), Convert.ToByte(array[1]), array[2]);
}
catch (Exception e)
{
MessageBox.Show(""" + e.Message + """, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
return new CoordStringCor(Convert.ToByte(10), Convert.ToByte(10), " ");
}
}[/code]
Jogador.cs:
<pre class="prettyprint public class Jogador
{
// private byte[] posicaoInic = new byte[2];
private byte[] posicao = new byte[2];
internal bool jogMovido = false;
internal bool jogCriado = false;
private Mapa mapaAtual;
protected Jogador()
{
Local = new TextBlock();
Local.VerticalAlignment = VerticalAlignment.Bottom;
Local.HorizontalAlignment = HorizontalAlignment.Left;
Local.Margin = new Thickness(10, 0, 0, 10);
Local.Text = "@";
// Posicao = Local.Margin;
}
public Jogador(ref Mapa mapa, params byte[] posicao)
{
mapaAtual = mapa;
mapa.MapaBase[posicao[0], posicao[1]] = new TextBlock();
mapa.MapaBase[posicao[0], posicao[1]].Text = "@";
this.posicao[0] = posicao[0];
this.posicao[1] = posicao[1];
}
public Jogador(Mapa mapa, params byte[] posicao)
{
mapaAtual = mapa;
mapa.MapaBase[posicao[0], posicao[1]] = new TextBlock();
mapa.MapaBase[posicao[0], posicao[1]].Text = "@";
this.posicao[0] = posicao[0];
this.posicao[1] = posicao[1];
}
public byte[] Posicao
{
get
{
return posicao;
}
set
{
jogCriado = true;
posicao = value;
}
}
/*
public Thickness Posicao
{
get
{
return Local.Margin;
}
set
{
Local.Name = "textblock" + value.Left + value.Top;
}
}*/
public Thickness PosicaoAnterior
{
get
{
return Local.Margin;
}
set
{
Local.Name = "textblock" + value.Left + value.Top;
}
}
public TextBlock Local
{
get;
private set;
}
internal Mapa MapaAtual
{
get
{
return mapaAtual;
}
set
{
mapaAtual = value;
}
}
public void Mover(KeyEventArgs e, ref byte x, ref byte y)
{
try
{
if (jogCriado)
{
if (e.Key == Key.Up && y < 19 && mapaAtual.MapaBase[x, y + 1].Text != "#")
{
if (mapaAtual.MapaBase[x, y + 1].Text == "€")
{
}
mapaAtual.MapaBase[x, y].Text = " ";
y++;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Down && y != 0 && mapaAtual.MapaBase[x, y - 1].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
y--;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Right && x < 19 && mapaAtual.MapaBase[x + 1, y].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
x++;
mapaAtual.MapaBase[x, y].Text = "@";
}
if (e.Key == Key.Left && x != 0 && mapaAtual.MapaBase[x - 1, y].Text != "#")
{
mapaAtual.MapaBase[x, y].Text = " ";
x--;
mapaAtual.MapaBase[x, y].Text = "@";
}
}
}
catch (Exception erro)
{
MessageBox.Show(""" + erro.Message + """, "Erro", MessageBoxButton.OK, MessageBoxImage.Error);
}
finally
{
// mapaAtual.Recarrega();
jogMovido = true;
}
}
}
public static partial class Util
{
public static bool IsParede(this TextBlock l)
{
switch (l.Text.ToString())
{
case "@":
case " ":
return true;
case "#":
default:
return false;
}
}
private static bool IsParede(this TextBlock l, Brush jCor)
{
return !((l.Text.ToString() == " " || l.Text.ToString() == "@") && jCor != l.Foreground);
}
public static TextBlock[,] PosTesouro(this TextBlock[,] mapa)
{
return null;
}
}[/code]
<br/>
Jogo.cs:
<pre class="prettyprint public class Jogo
{
Jogo jogo1 = new Jogo();
Jogo jogo2 = new Jogo();
Jogo jogo3 = new Jogo();
Jogo jogo4 = new Jogo();
Jogo jogo5 = new Jogo();
Jogo jogo6 = new Jogo();
private Jogo()
{
}
}[/code]
Thanks for at least reading and I hope you help, <hr class="sig João Miguel
View the full article