Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Fix few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Team-on committed Nov 15, 2018
1 parent 406f812 commit c1db661
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
2 changes: 1 addition & 1 deletion BattleRoyale/BattleRoyale/ConnectWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ConnectWindow() {
private void Button_Click(object sender, RoutedEventArgs e) {
MainWindow.Ip = IpTextBox.Text;
new MainWindow().Show();
//this.Close();
this.Close();
}

private void Window_Loaded(object sender, RoutedEventArgs e) {
Expand Down
7 changes: 0 additions & 7 deletions BattleRoyale/BattleRoyale/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
Height="450" Width="800"

Loaded="Window_Loaded"
Closing="Window_Closing"
Closed="Window_Closed"
KeyDown="Window_KeyDown"
KeyUp="Window_KeyUp"

MouseMove="Window_MouseMove"
MouseLeftButtonDown="Window_MouseLeftButtonDown"
>
<Grid>
<Canvas x:Name="GameCanvas" Background="White">
Expand Down
75 changes: 40 additions & 35 deletions BattleRoyale/BattleRoyale/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace BattleRoyale {
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
//192.168.137.1
public static string Ip = "127.0.0.1";

Common.GameObjectState playerState;
Expand All @@ -33,46 +34,16 @@ public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();

pressedKeys = new List<Key>();
keysTimer = new Timer() {
AutoReset = true,
Enabled = true,
Interval = 200,
};

keysTimer.Elapsed += (a, b) => {
lock (keysLocker) {
foreach (var key in pressedKeys) {
switch (key) {
case Key.A:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveLeft));
break;
case Key.D:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveRight));
break;
case Key.S:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveBackward));
break;
case Key.W:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveForward));
break;
}
}
}
};

client = new TCPClient();
pressedKeys = new List<Key>();

this.Closing += (a, b) => {
client.Disconnect();
};
Closing += Window_Closing;
Closed += Window_Closed;
}

private void Window_Loaded(object sender, RoutedEventArgs e) {
AllocConsole();

client.Connect(Ip, 65000);

client.OnWorldUpdate += (states) => {
List<Image> newState = new List<Image>();

Expand Down Expand Up @@ -114,16 +85,50 @@ private void Window_Loaded(object sender, RoutedEventArgs e) {
}
}

if(currTag.TextureId != Common.TextureId.None)
if (currTag.TextureId != Common.TextureId.None)
GameCanvas.Children.Add(image);
}
});

};

client.Connect(Ip, 65000);

KeyDown += Window_KeyDown;
KeyUp += Window_KeyUp;
MouseMove += Window_MouseMove;
MouseLeftButtonDown +=Window_MouseLeftButtonDown;

keysTimer = new Timer() {
AutoReset = true,
Enabled = true,
Interval = 200,
};

keysTimer.Elapsed += (a, b) => {
lock (keysLocker) {
foreach (var key in pressedKeys) {
switch (key) {
case Key.A:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveLeft));
break;
case Key.D:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveRight));
break;
case Key.S:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveBackward));
break;
case Key.W:
client.SentPlayerAction(new Common.BasePlayerAction(Common.PlayerActionType.MoveForward));
break;
}
}
}
};
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {

client.Disconnect();
}

private void Window_Closed(object sender, EventArgs e) {
Expand Down

0 comments on commit c1db661

Please sign in to comment.