Skip to content

Commit

Permalink
Merge pull request eesast#221 from Grange007/dev
Browse files Browse the repository at this point in the history
fix: 🐛 fix bullet display bug
  • Loading branch information
Grange007 authored Apr 13, 2024
2 parents 4bdacd2 + 0aac0ea commit 2bcbc4c
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 60 deletions.
5 changes: 3 additions & 2 deletions logic/Client/View/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public MainPage()
HeightRequest = unitHeight,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
Margin = new Thickness(unitWidth * (49 - j), unitHeight * (49 - i), 0, 0),
//Margin = new Thickness(unitWidth * (49 - j), unitHeight * (49 - i), 0, 0),
Margin = new Thickness(unitWidth * (j), unitHeight * (i), 0, 0),
HorizontalTextAlignment = TextAlignment.Center,
VerticalTextAlignment = TextAlignment.Center,
Padding = 0,
Expand Down Expand Up @@ -85,7 +86,7 @@ public MainPage()
{
CircleLabel bulletinfo = new()
{
CLDiameter = unitWidth * 1,
CLDiameter = unitWidth * 0.4,
HorizontalOptions = LayoutOptions.Start,
VerticalOptions = LayoutOptions.Start,
CLBackgroundColor = Colors.Black,
Expand Down
96 changes: 51 additions & 45 deletions logic/Client/ViewModel/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,13 @@ private void Refresh(object sender, EventArgs e)
foreach (var data in listOfHome)
{
DrawHome(data);
if (data.TeamId == (long)PlayerTeam.Red)
// if (data.TeamId == (long)PlayerTeam.Red)
if (data.TeamId == 0)
{
RedPlayer.Team = data.TeamId;
}
else if (data.TeamId == (long)PlayerTeam.Blue)
// else if (data.TeamId == (long)PlayerTeam.Blue)
else if (data.TeamId == 1)
{
BluePlayer.Team = data.TeamId;
}
Expand All @@ -499,7 +501,8 @@ private void Refresh(object sender, EventArgs e)
for (int i = 0; i < listOfShip.Count; i++)
{
MessageOfShip data = listOfShip[i];
if (data.TeamId == (long)PlayerTeam.Red)
// if (data.TeamId == (long)PlayerTeam.Red)
if (data.TeamId == 0)
{
Ship ship = new Ship
{
Expand All @@ -519,7 +522,8 @@ private void Refresh(object sender, EventArgs e)
RedPlayer.Ships[i] = ship;
else RedPlayer.Ships.Add(ship);
}
else if (data.TeamId == (long)PlayerTeam.Blue)
// else if (data.TeamId == (long)PlayerTeam.Blue)
else if (data.TeamId == 1)
{
Ship ship = new Ship
{
Expand Down Expand Up @@ -845,7 +849,7 @@ Show the error message
AttackMsg attackMsg = new AttackMsg();
attackMsg.PlayerId = playerID;
attackMsg.TeamId = teamID;
attackMsg.Angle = 0;
attackMsg.Angle = lastMoveAngle;
client.Attack(attackMsg);
});

Expand Down Expand Up @@ -940,46 +944,48 @@ Show the error message

// PureDrawMap(GameMap.GameMapArray);
//ReactToCommandline();
installer.Data.ConfigData d = new();
ip = d.Commands.IP;
port = d.Commands.Port;
playerID = d.Commands.LaunchID;
teamID = Convert.ToInt64(d.Commands.TeamID);
shipTypeID = Convert.ToInt32(d.Commands.ShipType);
playbackFile = d.Commands.PlaybackFile;
playbackSpeed = d.Commands.PlaybackSpeed;

if (playbackFile == "")
{
try
{
string[] comInfo = new string[5];
comInfo[0] = ip;
comInfo[1] = port;
comInfo[2] = Convert.ToString(playerID);
comInfo[3] = Convert.ToString(teamID);
comInfo[4] = Convert.ToString(shipTypeID);
ConnectToServer(comInfo);
OnReceive();
}
catch
{
OnReceive();
}
}
else
{
Playback(playbackFile, playbackSpeed);
}
//installer.Data.ConfigData d = new();
//ip = d.Commands.IP;
//port = d.Commands.Port;
//playerID = Convert. ToInt64(d.Commands.PlayerID);
//teamID = Convert.ToInt64(d.Commands.TeamID);
//shipTypeID = Convert.ToInt32(d.Commands.ShipType);
//playbackFile = d.Commands.PlaybackFile;
//playbackSpeed = d.Commands.PlaybackSpeed;
Playback("E:\\program\\Project\\THUAI7\\logic\\Client\\114514.thuai7.pb", 2.0);
//if (playbackFile == "")
//{
// try
// {
// string[] comInfo = new string[5];
// comInfo[0] = ip;
// comInfo[1] = port;
// comInfo[2] = Convert.ToString(playerID);
// comInfo[3] = Convert.ToString(teamID);
// comInfo[4] = Convert.ToString(shipTypeID);
// ConnectToServer(comInfo);
// OnReceive();
// }
// catch
// {
// OnReceive();
// }
//}
//else
//{
// Playback(playbackFile, playbackSpeed);
//}
// 连接Server,comInfo[]的格式:0-ip 1- port 2-playerID 3-teamID 4-ShipType
ConnectToServer(new string[]{
"localhost",
"8888",
"1",
"0",
"1"
});
d.Commands.Launched = true;

//ConnectToServer(new string[]{
// "localhost",
// "8888",
// "1",
// "0",
// "1"
//});
//d.Commands.Launched = true;


// 连接Server,comInfo[]的格式:0-ip 1- port 2-playerID (>2023则为观察者模式)
//ConnectToServer(new string[]{
Expand All @@ -993,7 +999,7 @@ Show the error message
timerViewModel.Tick += new EventHandler(Refresh);
timerViewModel.Start();

OnReceive();
//OnReceive();
}
}
}
39 changes: 26 additions & 13 deletions logic/Client/ViewModel/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,12 @@ private void DrawShip()
long team_id = data.TeamId;
switch (team_id)
{
case (long)PlayerTeam.Red:
case 0:
System.Diagnostics.Debug.WriteLine("shipinfo.color = red");
shipinfo.Color = Colors.DarkRed;
break;

case (long)PlayerTeam.Blue:
case 1:
System.Diagnostics.Debug.WriteLine("shipinfo.color = blue");

shipinfo.Color = Colors.DarkBlue;
Expand Down Expand Up @@ -318,7 +318,9 @@ private void DrawBullet()
{
for (int i = 0; i < BulletCircList.Count; i++)
{
BulletCircList[i].Color = Colors.Transparent;
//BulletCircList[i].Color = Colors.Transparent;
BulletCircList[i].X = 51;
BulletCircList[i].Y = 51;
BulletCircList[i].Text = "";
}
System.Diagnostics.Debug.WriteLine(String.Format("listOfBullet.Count:{0}", listOfBullet.Count));
Expand All @@ -331,14 +333,17 @@ private void DrawBullet()
bulletinfo.X = point.X;
bulletinfo.Y = point.Y;
long team_id = data.TeamId;
System.Diagnostics.Debug.WriteLine(String.Format("bulletinfo.X:{0}", bulletinfo.X));
System.Diagnostics.Debug.WriteLine(String.Format("bulletinfo.Y:{0}", bulletinfo.Y));
//System.Diagnostics.Debug.WriteLine(String.Format("Bullet{0}.Teamid:{1}", i, data.TeamId));
switch (team_id)
{
case (long)PlayerTeam.Red:
case 0:
System.Diagnostics.Debug.WriteLine("bulletinfo.color = red");
bulletinfo.Color = Colors.DarkRed;
break;

case (long)PlayerTeam.Blue:
case 1:
System.Diagnostics.Debug.WriteLine("bulletinfo.color = blue");
bulletinfo.Color = Colors.DarkBlue;
break;
Expand Down Expand Up @@ -541,12 +546,14 @@ private void DrawHome(MessageOfHome data)
MapPatchesList[index].Text = Convert.ToString(hp);
switch (team_id)
{
case (long)PlayerTeam.Red:
// case (long)PlayerTeam.Red:
case 0:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.RedHome];
MapPatchesList[index].TextColor = Colors.White;
break;

case (long)PlayerTeam.Blue:
// case (long)PlayerTeam.Blue:
case 1:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.BlueHome];
MapPatchesList[index].TextColor = Colors.White;
break;
Expand All @@ -568,12 +575,14 @@ private void DrawFactory(MessageOfFactory data)
MapPatchesList[index].Text = Convert.ToString(hp);
switch (team_id)
{
case (long)PlayerTeam.Red:
// case (long)PlayerTeam.Red:
case 0:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Factory];
MapPatchesList[index].TextColor = Colors.Red;
break;

case (long)PlayerTeam.Blue:
// case (long)PlayerTeam.Blue:
case 1:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Factory];
MapPatchesList[index].TextColor = Colors.Blue;
break;
Expand All @@ -595,12 +604,14 @@ private void DrawCommunity(MessageOfCommunity data)
MapPatchesList[index].Text = Convert.ToString(hp);
switch (team_id)
{
case (long)PlayerTeam.Red:
// case (long)PlayerTeam.Red:
case 0:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Community];
MapPatchesList[index].TextColor = Colors.Red;
break;

case (long)PlayerTeam.Blue:
// case (long)PlayerTeam.Blue:
case 1:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Community];
MapPatchesList[index].TextColor = Colors.Blue;
break;
Expand All @@ -622,12 +633,14 @@ private void DrawFort(MessageOfFort data)
MapPatchesList[index].Text = Convert.ToString(hp);
switch (team_id)
{
case (long)PlayerTeam.Red:
// case (long)PlayerTeam.Red:
case 0:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Fort];
MapPatchesList[index].TextColor = Colors.Red;
break;

case (long)PlayerTeam.Blue:
// case (long)PlayerTeam.Blue:
case 1:
MapPatchesList[index].PatchColor = PatchColorDict[MapPatchType.Fort];
MapPatchesList[index].TextColor = Colors.Blue;
break;
Expand Down

0 comments on commit 2bcbc4c

Please sign in to comment.