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
|
||||
{
|
||||
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 SpriteBatch _spriteBatch;
|
||||
private static int gutter_height;
|
||||
|
@ -67,7 +67,7 @@ namespace Bowling
|
|||
gutter_height = 50;
|
||||
ballStartPosition = new Vector2(10, gutter_top_y + (gutter_bottom_y - gutter_top_y) / 2 - 25);
|
||||
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();
|
||||
player2 = new Player();
|
||||
rowWidth = 80;
|
||||
|
@ -138,6 +138,10 @@ namespace Bowling
|
|||
{
|
||||
ResetAll();
|
||||
}
|
||||
else if (msg == "12")
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
player2.Deserialize(msg);
|
||||
|
@ -224,7 +228,7 @@ namespace Bowling
|
|||
{
|
||||
player1.Score.Add(intermediateScore);
|
||||
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);
|
||||
if (player1.Score.Count <= 20 && player1.Score.Count % 2 == 0)
|
||||
{
|
||||
|
@ -357,7 +361,7 @@ namespace Bowling
|
|||
|
||||
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();
|
||||
player1.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.
|
@ -12,10 +12,10 @@ namespace Bowling_Server.Classes
|
|||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("score")]
|
||||
public List<int> Score { get; set; } = new List<int>();
|
||||
public List<int> Score { get; set; }
|
||||
|
||||
[NonSerialized]
|
||||
public Socket socket;
|
||||
public Socket Socket;
|
||||
|
||||
|
||||
public string Serialize()
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace Bowling_Server
|
|||
string json = Encoding.ASCII.GetString(data, 0, recv);
|
||||
Player player = new Player();
|
||||
player.Deserialize(json);
|
||||
player.socket = client;
|
||||
player.Socket = client;
|
||||
players.Add(player);
|
||||
});
|
||||
thread.Start();
|
||||
|
@ -63,10 +63,14 @@ namespace Bowling_Server
|
|||
socket.Listen(100);
|
||||
}
|
||||
public static void Send(string message, Socket client)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = Encoding.ASCII.GetBytes(message);
|
||||
client.Send(data);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
static void CastOpponents(List<Player> group)
|
||||
{
|
||||
foreach (Player player in group)
|
||||
|
@ -75,7 +79,7 @@ namespace Bowling_Server
|
|||
{
|
||||
if (opponent != player)
|
||||
{
|
||||
Send(opponent.Serialize(), player.socket);
|
||||
Send(opponent.Serialize(), player.Socket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -91,18 +95,18 @@ namespace Bowling_Server
|
|||
Thread thread = new Thread(() =>
|
||||
{
|
||||
byte[] data = new byte[1024];
|
||||
player.socket.ReceiveTimeout = 60000;
|
||||
player.Socket.ReceiveTimeout = 60000;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
int dataLength = player.socket.Receive(data);
|
||||
int dataLength = player.Socket.Receive(data);
|
||||
string json = Encoding.ASCII.GetString(data, 0, dataLength);
|
||||
if (json == "11")
|
||||
{
|
||||
foreach (var player in group)
|
||||
{
|
||||
player.socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||
player.Socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||
player.Score = new List<int>();
|
||||
players.Add(player);
|
||||
}
|
||||
|
@ -119,18 +123,20 @@ namespace Bowling_Server
|
|||
Console.WriteLine("Player disconnected");
|
||||
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>();
|
||||
players.Add(group[0]);
|
||||
}
|
||||
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>();
|
||||
players.Add(group[1]);
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Players disconnected. Can't process disconnection. Game ended.");
|
||||
}
|
||||
|
@ -139,9 +145,5 @@ namespace Bowling_Server
|
|||
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