Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Commit

Permalink
feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyl18 committed Feb 19, 2018
1 parent 71c9bcb commit 873a18c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
59 changes: 24 additions & 35 deletions CardSharp/GameComponents/Desk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public GameState State
if (!Desks.ContainsValue(this))
return GameState.Unknown;

switch (_currentParser)
{
switch (_currentParser) {
case WaitingParser _:
return GameState.Wait;
case LandlordDiscuss _:
Expand All @@ -72,7 +71,7 @@ public GameState State

public IRule CurrentRule { get; set; }

public Player CurrentPlayer => GetPlayerFromIndex(((Samsara) _currentParser).CurrentIndex);
public Player CurrentPlayer => GetPlayerFromIndex(((Samsara)_currentParser).CurrentIndex);

public IEnumerable<Card> GeneratePlayCards()
{
Expand All @@ -84,8 +83,7 @@ public IEnumerable<Card> GeneratePlayCards()
[MethodImpl(MethodImplOptions.Synchronized)]
public bool AddPlayer(Player player)
{
if (Players.Count() >= Constants.MaxPlayer || Players.Contains(player))
{
if (Players.Count() >= Constants.MaxPlayer || Players.Contains(player)) {
AddMessage($"已经加入或人数已满: {player.ToAtCode()}");
return false;
}
Expand Down Expand Up @@ -134,16 +132,13 @@ public Player GetPlayerFromIndex(int index)

public void ParseCommand(string playerid, string command)
{
try
{
try {
var player = GetPlayer(playerid);
if (ShutedGroups.All(g => g != DeskId)) {
_currentParser.Parse(this, player, command);
}
_standardParser.Parse(this, player, command);
}
catch (Exception e)
{
} catch (Exception e) {
AddMessage($"抱歉 我们在处理你的命令时发生了错误{e}");
}
}
Expand All @@ -162,11 +157,10 @@ public override int GetHashCode()
public static List<Card> GenerateCards()
{
var list = new List<Card>();
for (var i1 = 0; i1 < 1; i1++)
{
for (var i1 = 0; i1 < 1; i1++) {
for (var i = 0; i < Constants.AmountCardNum; i++)
for (var num = 0; num < Constants.AmountCardMax; num++)
list.Add(new Card(num));
for (var num = 0; num < Constants.AmountCardMax; num++)
list.Add(new Card(num));
list.Add(new Card(Constants.AmountCardMax)); //鬼
list.Add(new Card(Constants.AmountCardMax + 1)); //王
}
Expand Down Expand Up @@ -195,8 +189,7 @@ public override void AddMessage(string msg)
private void SendCards()
{
var cards = GeneratePlayCards();
foreach (var player in Players)
{
foreach (var player in Players) {
var pCards = cards.Take(17 * 1);
player.Cards = pCards.ToListAndSort();
cards = cards.Skip(17 * 1);
Expand All @@ -218,16 +211,12 @@ public void SetLandlord(Player player)
public void BoardcastCards()
{
if (CurrentRule == null)
if (CurrentPlayer.FirstBlood)
{
if (CurrentPlayer.FirstBlood) {
CurrentPlayer.FirstBlood = false;
AddMessage($"{CurrentPlayer.ToAtCodeWithRole()}请开始你的表演");
}
else
{
} else {
AddMessageLine($"{CurrentPlayer.ToAtCodeWithRole()}请出牌");
}
else
} else
AddMessage($"{CurrentRule.ToString()}-{LastCards.ToFormatString()} {CurrentPlayer.ToAtCodeWithRole()}请出牌");
}

Expand All @@ -241,8 +230,7 @@ public void FinishGame(Player player)
var landlords = Players.Where(p => p.Type == PlayerType.Landlord);

if (SuddenDeathEnabled)
switch (player.Type)
{
switch (player.Type) {
case PlayerType.Farmer:
AddMessageLine("农民赢了.");
var n1 = landlords.Sum(p => PlayerConfig.GetConfig(p).Point);
Expand All @@ -255,10 +243,8 @@ public void FinishGame(Player player)
landlordDif = n2;
farmerDif = 0;
break;
}
else
switch (player.Type)
{
} else
switch (player.Type) {
case PlayerType.Farmer:
AddMessageLine("农民赢了.");
landlordDif *= -1;
Expand All @@ -271,20 +257,18 @@ public void FinishGame(Player player)

var sb = new StringBuilder();

foreach (var landlord in landlords)
{
foreach (var landlord in landlords) {
sb.AppendLine($"-{landlord.ToAtCode()} {landlordDif}");
SaveScore(landlord, landlordDif, player);
}

foreach (var farmer in farmers)
{
foreach (var farmer in farmers) {
sb.AppendLine($"-{farmer.ToAtCode()} {farmerDif}");
SaveScore(farmer, farmerDif, player);
}

AddMessage(sb.ToString());
FinishGame();
FinishGame(true);
}

private void SaveScore(Player p, int dif, Player playerWinner)
Expand All @@ -299,8 +283,13 @@ private void SaveScore(Player p, int dif, Player playerWinner)
#endif
}

public void FinishGame()
public void FinishGame(bool force = false)
{
if (force) {
AddMessage("游戏结束.");
Desks.Remove(DeskId);
return;
}
AddMessage(SuddenDeathEnabled ? "你不能结束游戏." : "游戏结束.");
if (!SuddenDeathEnabled)
Desks.Remove(DeskId);
Expand Down
2 changes: 2 additions & 0 deletions CardSharp/GameSteps/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private bool RunHostedCheck(Desk desk)

private static void PlayerWin(Desk desk, Player player)
{
if (desk.State == GameState.Unknown) return;
desk.FinishGame(player);
}

Expand All @@ -233,6 +234,7 @@ private void AnalyzeGiveUpAndMoveNext(Desk desk)

private static bool CheckGameFinished(Desk desk)
{

var farmers = desk.Players.Where(p => p.Type == PlayerType.Farmer);
var landlords = desk.Players.Where(p => p.Type == PlayerType.Landlord);
if (farmers.All(p => p.GiveUp) || landlords.All(p => p.GiveUp))
Expand Down
1 change: 1 addition & 0 deletions CardSharp/GameSteps/StandardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ 带有[R]的命令 是正式功能,'一般'不会做更改
var cfg = PlayerConfig.GetConfig(new Player(target));
cfg.Point = point;
desk.AddMessage("Set done.");
cfg.Save();
}
}
}
Expand Down

0 comments on commit 873a18c

Please sign in to comment.