v.1.3
This commit is contained in:
parent
d0af8bdabc
commit
74e54e1d38
22 changed files with 31 additions and 25 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -18,7 +18,7 @@ namespace Bowling
|
||||||
}
|
}
|
||||||
public class Game1 : Game
|
public class Game1 : Game
|
||||||
{
|
{
|
||||||
private Color[] colors = { Color.White, Color.Red, Color.Black, Color.DeepSkyBlue, Color.DeepPink };
|
private Color[] colors = { Color.White/*, Color.Red, Color.Black, Color.DeepSkyBlue, Color.DeepPink*/ };
|
||||||
private GraphicsDeviceManager _graphics;
|
private GraphicsDeviceManager _graphics;
|
||||||
private SpriteBatch _spriteBatch;
|
private SpriteBatch _spriteBatch;
|
||||||
private static int gutter_height;
|
private static int gutter_height;
|
||||||
|
@ -67,7 +67,7 @@ namespace Bowling
|
||||||
gutter_height = 50;
|
gutter_height = 50;
|
||||||
ballStartPosition = new Vector2(10, gutter_top_y + (gutter_bottom_y - gutter_top_y) / 2 - 25);
|
ballStartPosition = new Vector2(10, gutter_top_y + (gutter_bottom_y - gutter_top_y) / 2 - 25);
|
||||||
random = new Random();
|
random = new Random();
|
||||||
ball = new Ball(ballStartPosition, Vector2.Zero, colors[random.Next(colors.Length)], Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
||||||
menu = new Menu();
|
menu = new Menu();
|
||||||
player2 = new Player();
|
player2 = new Player();
|
||||||
rowWidth = 80;
|
rowWidth = 80;
|
||||||
|
@ -138,6 +138,10 @@ namespace Bowling
|
||||||
{
|
{
|
||||||
ResetAll();
|
ResetAll();
|
||||||
}
|
}
|
||||||
|
else if (msg == "12")
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player2.Deserialize(msg);
|
player2.Deserialize(msg);
|
||||||
|
@ -224,7 +228,7 @@ namespace Bowling
|
||||||
{
|
{
|
||||||
player1.Score.Add(intermediateScore);
|
player1.Score.Add(intermediateScore);
|
||||||
intermediateScore = 0;
|
intermediateScore = 0;
|
||||||
ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
||||||
ball.LoadContent(Content);
|
ball.LoadContent(Content);
|
||||||
if (player1.Score.Count <= 20 && player1.Score.Count % 2 == 0)
|
if (player1.Score.Count <= 20 && player1.Score.Count % 2 == 0)
|
||||||
{
|
{
|
||||||
|
@ -357,7 +361,7 @@ namespace Bowling
|
||||||
|
|
||||||
private void ResetAll()
|
private void ResetAll()
|
||||||
{
|
{
|
||||||
ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
ball = new Ball(ballStartPosition, Vector2.Zero, Color.White, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
||||||
menu = new Menu();
|
menu = new Menu();
|
||||||
player1.Score.Clear();
|
player1.Score.Clear();
|
||||||
player2.Score.Clear();
|
player2.Score.Clear();
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,17 +7,17 @@ namespace Bowling_Server.Classes
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
internal class Player
|
internal class Player
|
||||||
{
|
{
|
||||||
[JsonProperty("name")]
|
[JsonProperty("name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
[JsonProperty("score")]
|
[JsonProperty("score")]
|
||||||
public List<int> Score { get; set; } = new List<int>();
|
public List<int> Score { get; set; }
|
||||||
|
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
public Socket socket;
|
public Socket Socket;
|
||||||
|
|
||||||
|
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
return JsonConvert.SerializeObject(this);
|
return JsonConvert.SerializeObject(this);
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace Bowling_Server
|
||||||
string json = Encoding.ASCII.GetString(data, 0, recv);
|
string json = Encoding.ASCII.GetString(data, 0, recv);
|
||||||
Player player = new Player();
|
Player player = new Player();
|
||||||
player.Deserialize(json);
|
player.Deserialize(json);
|
||||||
player.socket = client;
|
player.Socket = client;
|
||||||
players.Add(player);
|
players.Add(player);
|
||||||
});
|
});
|
||||||
thread.Start();
|
thread.Start();
|
||||||
|
@ -64,8 +64,12 @@ namespace Bowling_Server
|
||||||
}
|
}
|
||||||
public static void Send(string message, Socket client)
|
public static void Send(string message, Socket client)
|
||||||
{
|
{
|
||||||
byte[] data = Encoding.ASCII.GetBytes(message);
|
try
|
||||||
client.Send(data);
|
{
|
||||||
|
byte[] data = Encoding.ASCII.GetBytes(message);
|
||||||
|
client.Send(data);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
static void CastOpponents(List<Player> group)
|
static void CastOpponents(List<Player> group)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +79,7 @@ namespace Bowling_Server
|
||||||
{
|
{
|
||||||
if (opponent != player)
|
if (opponent != player)
|
||||||
{
|
{
|
||||||
Send(opponent.Serialize(), player.socket);
|
Send(opponent.Serialize(), player.Socket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,20 +95,20 @@ namespace Bowling_Server
|
||||||
Thread thread = new Thread(() =>
|
Thread thread = new Thread(() =>
|
||||||
{
|
{
|
||||||
byte[] data = new byte[1024];
|
byte[] data = new byte[1024];
|
||||||
player.socket.ReceiveTimeout = 60000;
|
player.Socket.ReceiveTimeout = 60000;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int dataLength = player.socket.Receive(data);
|
int dataLength = player.Socket.Receive(data);
|
||||||
string json = Encoding.ASCII.GetString(data, 0, dataLength);
|
string json = Encoding.ASCII.GetString(data, 0, dataLength);
|
||||||
if (json == "11")
|
if (json == "11")
|
||||||
{
|
{
|
||||||
foreach (var player in group)
|
foreach (var player in group)
|
||||||
{
|
{
|
||||||
player.socket.Send(Encoding.ASCII.GetBytes("11"));
|
player.Socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||||
player.Score = new List<int>();
|
player.Score = new List<int>();
|
||||||
players.Add(player);
|
players.Add(player);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -119,18 +123,20 @@ namespace Bowling_Server
|
||||||
Console.WriteLine("Player disconnected");
|
Console.WriteLine("Player disconnected");
|
||||||
if (group.IndexOf(player) == 1)
|
if (group.IndexOf(player) == 1)
|
||||||
{
|
{
|
||||||
group[0].socket.Send(Encoding.ASCII.GetBytes("11"));
|
group[1].Socket.Send(Encoding.ASCII.GetBytes("12"));
|
||||||
|
group[0].Socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||||
group[0].Score = new List<int>();
|
group[0].Score = new List<int>();
|
||||||
players.Add(group[0]);
|
players.Add(group[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
group[1].socket.Send(Encoding.ASCII.GetBytes("11"));
|
group[0].Socket.Send(Encoding.ASCII.GetBytes("12"));
|
||||||
|
group[1].Socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||||
group[1].Score = new List<int>();
|
group[1].Score = new List<int>();
|
||||||
players.Add(group[1]);
|
players.Add(group[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Players disconnected. Can't process disconnection. Game ended.");
|
Console.WriteLine("Players disconnected. Can't process disconnection. Game ended.");
|
||||||
}
|
}
|
||||||
|
@ -139,9 +145,5 @@ namespace Bowling_Server
|
||||||
thread.Start();
|
thread.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void Die()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Reference in a new issue