v.0.8
This commit is contained in:
parent
e607085e72
commit
d995c5f2b7
27 changed files with 110 additions and 27 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.
|
@ -9,8 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bowling_Server", "Bowling_S
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetLib", "BowlingNetLib\NetLib.csproj", "{8F4FCE29-064E-45E4-AF43-87F31420EF2F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{A3F442D5-C149-401F-BC5C-9BADED32E621}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -29,10 +27,6 @@ Global
|
|||
{8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8F4FCE29-064E-45E4-AF43-87F31420EF2F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A3F442D5-C149-401F-BC5C-9BADED32E621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A3F442D5-C149-401F-BC5C-9BADED32E621}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A3F442D5-C149-401F-BC5C-9BADED32E621}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A3F442D5-C149-401F-BC5C-9BADED32E621}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Bowling.Classes
|
|||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("score")]
|
||||
public List<int> Score { get; set; }
|
||||
public List<int> Score { get; set; } = new List<int>();
|
||||
|
||||
|
||||
public string Serialize()
|
||||
|
|
1
Bowling/Connect.Designer.cs
generated
1
Bowling/Connect.Designer.cs
generated
|
@ -121,6 +121,7 @@
|
|||
this.Controls.Add(this.NameTB);
|
||||
this.Name = "Connect";
|
||||
this.Text = "Launcher";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Connect_FormClosing);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
|
|
@ -39,5 +39,9 @@ namespace Bowling
|
|||
private void ExitBtn_Click(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void Connect_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,13 @@ using System.Collections.Generic;
|
|||
using System.Windows.Forms;
|
||||
using NetLib;
|
||||
using System.Threading;
|
||||
using System.Text;
|
||||
|
||||
namespace Bowling
|
||||
{
|
||||
public enum GameState
|
||||
{
|
||||
Menu, Game, Exit, Connect_to_server, EndGame
|
||||
Menu, Game, Exit, Connect_to_server, PauseGame, EndGame
|
||||
}
|
||||
public class Game1 : Game
|
||||
{
|
||||
|
@ -33,8 +34,7 @@ namespace Bowling
|
|||
private Vector2 ballStartPosition;
|
||||
private List<Classes.UI.Label> tableLabels;
|
||||
private int intermediateScore;
|
||||
private Classes.UI.Label lblCountP1;
|
||||
private Classes.UI.Label lblCountP2;
|
||||
private int counter;
|
||||
|
||||
|
||||
private List<Pin> pins = new List<Pin>();
|
||||
|
@ -52,6 +52,7 @@ namespace Bowling
|
|||
_graphics.PreferredBackBufferHeight = 1000;
|
||||
Content.RootDirectory = "Content";
|
||||
IsMouseVisible = true;
|
||||
Window.Title = "Bowling";
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
|
@ -70,6 +71,7 @@ namespace Bowling
|
|||
tableMarginLeft = 20;
|
||||
tableLabels = new List<Classes.UI.Label>();
|
||||
intermediateScore = 0;
|
||||
counter = 0;
|
||||
|
||||
base.Initialize();
|
||||
}
|
||||
|
@ -125,12 +127,34 @@ namespace Bowling
|
|||
{
|
||||
while (true)
|
||||
{
|
||||
player2.Deserialize(NetLib.NetLib.Receive());
|
||||
string msg = NetLib.NetLib.Receive();
|
||||
if (msg == "11")
|
||||
{
|
||||
ResetAll();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
player2.Deserialize(msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
else { gameState = GameState.Menu; }
|
||||
else { gameState = GameState.Exit; }
|
||||
break;
|
||||
case GameState.EndGame:
|
||||
counter++;
|
||||
if (counter >= 300)
|
||||
{
|
||||
gameState = GameState.Menu;
|
||||
NetLib.NetLib.Send("11");
|
||||
counter = 0;
|
||||
}
|
||||
break;
|
||||
case GameState.PauseGame:
|
||||
if (player2.Score.Count == 21 || (player2.Score.Count == 20 && player2.Score[18] + player2.Score[19] != 10)) gameState = GameState.EndGame;
|
||||
if (tableLabels.Count >= 77) gameState = GameState.EndGame;
|
||||
break;
|
||||
}
|
||||
base.Update(gameTime);
|
||||
|
@ -161,6 +185,20 @@ namespace Bowling
|
|||
case GameState.Menu:
|
||||
menu.Draw(_spriteBatch);
|
||||
break;
|
||||
case GameState.EndGame:
|
||||
DrawGrid();
|
||||
foreach (Classes.UI.Label lbl in tableLabels)
|
||||
{
|
||||
lbl.Draw(_spriteBatch);
|
||||
}
|
||||
break;
|
||||
case GameState.PauseGame:
|
||||
DrawGrid();
|
||||
foreach (Classes.UI.Label lbl in tableLabels)
|
||||
{
|
||||
lbl.Draw(_spriteBatch);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
base.Draw(gameTime);
|
||||
|
@ -190,9 +228,10 @@ namespace Bowling
|
|||
{
|
||||
if (player1.Score[18] + player1.Score[19] == 10) NewMove();
|
||||
}
|
||||
if (player1.Score.Count == 20 && player1.Score[18] + player1.Score[19] != 10)
|
||||
if (player1.Score.Count == 21 || (player1.Score.Count == 20 && player1.Score[18] + player1.Score[19] != 10))
|
||||
{
|
||||
gameState = GameState.EndGame;
|
||||
gameState = GameState.PauseGame;
|
||||
if (player2.Score.Count == 21 || (player2.Score.Count == 20 && player2.Score[18] + player2.Score[19] != 10)) gameState = GameState.EndGame;
|
||||
}
|
||||
SendPlayerData(player1);
|
||||
}
|
||||
|
@ -250,8 +289,9 @@ namespace Bowling
|
|||
if (i % 2 == 0) score = 0;
|
||||
else if (i == 1) score = Sum(player1.Score);
|
||||
else score = Sum(player2.Score);
|
||||
Classes.UI.Label lbl = new Classes.UI.Label(score.ToString(), new Vector2(tableMarginLeft + rowWidth * 12 + rowWidth / 2, tableMarginTop + countRows + rowHeight + 5),
|
||||
Classes.UI.Label lbl = new Classes.UI.Label(score.ToString(), new Vector2(tableMarginLeft + rowWidth * 12 + rowWidth / 2 - 15, tableMarginTop + countRows + rowHeight + ((i % 2 == 1) ? 15 : 5)),
|
||||
Color.Fuchsia);
|
||||
if (i % 2 == 1) lbl.FontName = "gameFont2";
|
||||
lbl.LoadContent(Content);
|
||||
tableLabels.Add(lbl);
|
||||
countRows += (i != 0 && i % 2 == 1) ? 2 * rowHeight : rowHeight;
|
||||
|
@ -274,6 +314,14 @@ namespace Bowling
|
|||
lbl.LoadContent(Content);
|
||||
tableLabels.Add(lbl);
|
||||
}
|
||||
Classes.UI.Label label_p1_name = new Classes.UI.Label(player1.Name[0].ToString(), new Vector2(tableMarginLeft + 2, tableMarginTop + rowHeight),
|
||||
Color.Red);
|
||||
label_p1_name.LoadContent(Content);
|
||||
tableLabels.Add(label_p1_name);
|
||||
|
||||
Classes.UI.Label label_p2_name = new Classes.UI.Label(player2.Name[0].ToString(), new Vector2(tableMarginLeft + 2, tableMarginTop + 4 * rowHeight), Color.Red);
|
||||
label_p2_name.LoadContent(Content);
|
||||
tableLabels.Add(label_p2_name);
|
||||
}
|
||||
|
||||
private void NewMove()
|
||||
|
@ -296,5 +344,23 @@ namespace Bowling
|
|||
{
|
||||
NetLib.NetLib.Send(player.Serialize());
|
||||
}
|
||||
|
||||
private void ResetAll()
|
||||
{
|
||||
ball = new Ball(ballStartPosition, Vector2.Zero, Color.Blue, Gutter_top_y, gutter_bottom_y, gutter_height, _graphics.PreferredBackBufferWidth);
|
||||
menu = new Menu();
|
||||
player2 = new Player();
|
||||
player1 = new Player();
|
||||
rowWidth = 80;
|
||||
rowHeight = 50;
|
||||
tableMarginTop = 20;
|
||||
tableMarginLeft = 20;
|
||||
tableLabels = new List<Classes.UI.Label>();
|
||||
intermediateScore = 0;
|
||||
counter = 0;
|
||||
gameState = GameState.Menu;
|
||||
pins.Clear();
|
||||
LoadContent();
|
||||
}
|
||||
}
|
||||
}
|
BIN
Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo
Normal file
BIN
Bowling/bin/Debug/netcoreapp3.1/.vs/Bowling/v17/.suo
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -12,7 +12,7 @@ namespace Bowling_Server.Classes
|
|||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("score")]
|
||||
public List<int> Score { get; set; }
|
||||
public List<int> Score { get; set; } = new List<int>();
|
||||
|
||||
[NonSerialized]
|
||||
public Socket socket;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using Bowling_Server.Classes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Bowling_Server.Classes;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using NetLib;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Bowling_Server
|
||||
{
|
||||
|
@ -99,22 +98,41 @@ namespace Bowling_Server
|
|||
{
|
||||
int dataLength = player.socket.Receive(data);
|
||||
string json = Encoding.ASCII.GetString(data, 0, dataLength);
|
||||
if (json.Contains("11"))
|
||||
{
|
||||
foreach (var player in group)
|
||||
{
|
||||
player.socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||
player.Score = new List<int>();
|
||||
players.Add(player);
|
||||
}
|
||||
break;
|
||||
}
|
||||
player.Deserialize(json);
|
||||
CastOpponents(group);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine("Player disconnected");
|
||||
if (group.IndexOf(player) == 1)
|
||||
{
|
||||
group[0].socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||
players.Add(group[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
group[1].socket.Send(Encoding.ASCII.GetBytes("11"));
|
||||
players.Add(group[1]);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Players disconnected. Can't process disconnection. Game ended.");
|
||||
}
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
|
|
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