public Player(int id, string username, Token token, int money, List<Land> landList, bool inGame) { this.id = id; this.username = username; this.token = token; this.money = money; this.landList = landList; this.inGame = inGame; }
public void MoveToken(Token token, int steps) { for (int i = 0; i < steps - 1; i++) { blocks[token.position].TakeToken(token); token.position = (token.position + 1) % blocks.Count; blocks[token.position].PassToken(token); } blocks[token.position].TakeToken(token); token.position = (token.position + 1) % blocks.Count; blocks[token.position].PlaceToken(token); }
private static void BuyLandSelectionEventTask(Block block, Token token) { LandBlock landBlock = block as LandBlock; if (landBlock.land.owner == null) { Console.WriteLine("the money you have: {0}", token.owner.money); Console.WriteLine("you can buy the land: {0} price:{1}", landBlock.land.name, landBlock.land.price); Console.WriteLine("buy the land? y/n"); string instruction; while ((instruction = Console.ReadLine()) != "y" && instruction != "n") ; if(instruction == "y") { landBlock.land.Buy(token.owner); Console.WriteLine(token.owner.username + " buy the land: " + landBlock.land.name); Console.WriteLine("cost money {0}, remain money {1}", landBlock.land.price, token.owner.money); } } }
private static void DrawCardEventTask(Block block, Token token) { CardBlock cardBlock = block as CardBlock; string blockType = ""; if (cardBlock is DestinyBlock) blockType = "Destiny"; else if (cardBlock is ChanceBlock) blockType = "Chance"; Card card = cardBlock.Draw(); List<Player> allPlayers = game.players; switch (card.type) { case CardType.GainMoney: token.owner.money += card.value; Console.WriteLine("[{0}] so lucky! you got {1} dollars! remain money: {2}", blockType, card.value, token.owner.money); break; case CardType.LoseMoney: token.owner.money -= card.value; Console.WriteLine("[{0}] how terrible! you lose {1} dollars! remain money: {2}", blockType, card.value, token.owner.money); break; case CardType.StealMoney: foreach (Player player in allPlayers) { if (player != token.owner) player.money -= card.value; } token.owner.money += card.value * (allPlayers.Count - 1); Console.WriteLine("[{0}] you stole {1} dollars from other players in silence. remain money: {2}", blockType, card.value, token.owner.money); break; case CardType.ReleaseMoney: token.owner.money -= card.value * (allPlayers.Count - 1); foreach (Player player in allPlayers) { if (player != token.owner) player.money += card.value; } Console.WriteLine("[{0}] you give {1} dollars to other players just for fun. remain money: {2}", blockType, card.value, token.owner.money); break; } }
public void TakeToken(Token token) { tokens.Remove(token); if (OnTokenTakeLeave != null) OnTokenTakeLeave(this, token); }
public void PlaceToken(Token token) { tokens.Add(token); if (OnTokenPlaceInto != null) OnTokenPlaceInto(this, token); }
public void PassToken(Token token) { if (OnTokenPass != null) OnTokenPass(this, token); }
public void MoveToken(Token token, int steps) { map.MoveToken(token, steps); }
private void UpgradeLandSelectionEventTask(Block block, Token token) { LandBlock landBlock = block as LandBlock; if (landBlock.land.ownerName == token.ownerName) { Dictionary<byte, object> parameter = new Dictionary<byte, object> { {(byte)UpgradeLandSelectionBroadcastParameterItem.LandDataString, JsonConvert.SerializeObject(landBlock.land, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) } }; List<Peer> peers = new List<Peer>(); peers.Add(userDictionary[token.ownerName].Peer); Broadcast(peers.ToArray(), BroadcastType.UpgradeLandSelection, parameter); } }
private void PayForTollEventTask(Block block, Token token) { LandBlock landBlock = block as LandBlock; if (landBlock.land.ownerName != null && landBlock.land.ownerName != token.ownerName) { Player player = userDictionary[token.ownerName].player; Player owner = userDictionary[landBlock.land.ownerName].player; landBlock.land.PayToll(player, owner); Dictionary<byte, object> parameter1 = new Dictionary<byte, object> { {(byte)PayForTollBroadcastParameterItem.PlayerName, player.username }, {(byte)PayForTollBroadcastParameterItem.LandName, landBlock.land.name }, {(byte)PayForTollBroadcastParameterItem.Toll, landBlock.land.toll }, {(byte)PayForTollBroadcastParameterItem.LandOwnerName, owner.username } }; Dictionary<byte, object> parameter2 = new Dictionary<byte, object> { {(byte)MonopolyGameStatusChangeBroadcastParameterItem.GameDataString, JsonConvert.SerializeObject((player as ServerPlayer).playingGame.Serialize(), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) } }; List<Peer> peers = new List<Peer>(); foreach(ServerUser user in ((player as ServerPlayer).playingGame as ServerGame).users) { peers.Add(user.Peer); } Broadcast(peers.ToArray(), BroadcastType.PayForToll, parameter1); Broadcast(peers.ToArray(), BroadcastType.MonopolyGameStatusChange, parameter2); } }
private void PassStartBlockEventTask(Block block, Token token) { StartBlock startBlock = block as StartBlock; userDictionary[token.ownerName].player.money += startBlock.salary; Player player = userDictionary[token.ownerName].player; Dictionary<byte, object> parameter = new Dictionary<byte, object> { {(byte)MonopolyGameStatusChangeBroadcastParameterItem.GameDataString, JsonConvert.SerializeObject((player as ServerPlayer).playingGame.Serialize(), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) } }; List<Peer> peers1 = new List<Peer>(); foreach (ServerUser user in ((player as ServerPlayer).playingGame as ServerGame).users) { peers1.Add(user.Peer); } List<Peer> peers2 = new List<Peer>(); peers2.Add(userDictionary[token.ownerName].Peer); Broadcast(peers2.ToArray(), BroadcastType.PassStartBlock, new Dictionary<byte, object>()); Broadcast(peers1.ToArray(), BroadcastType.MonopolyGameStatusChange, parameter); }
private void DrawCardEventTask(Block block, Token token) { CardBlock cardBlock = block as CardBlock; Card card = cardBlock.Draw(); string blockType = ""; if (cardBlock is DestinyBlock) blockType = "Destiny"; else if (cardBlock is ChanceBlock) blockType = "Chance"; Player player = userDictionary[token.ownerName].player; List<Player> allPlayers = (player as ServerPlayer).playingGame.players; switch (card.type) { case CardType.GainMoney: player.money += card.value; break; case CardType.LoseMoney: player.money -= card.value; break; case CardType.StealMoney: foreach (Player targetPlayer in allPlayers) { if (targetPlayer != player) targetPlayer.money -= card.value; } player.money += card.value * (allPlayers.Count - 1); break; case CardType.ReleaseMoney: player.money -= card.value * (allPlayers.Count - 1); foreach (Player targetPlayer in allPlayers) { if (targetPlayer != player) targetPlayer.money += card.value; } break; } Dictionary<byte, object> parameter1 = new Dictionary<byte, object> { {(byte)DrawCardBroadcastParameterItem.PlayerName, player.username }, {(byte)DrawCardBroadcastParameterItem.BlockType, blockType }, {(byte)DrawCardBroadcastParameterItem.CardDataString, JsonConvert.SerializeObject(card, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) } }; Dictionary<byte, object> parameter2 = new Dictionary<byte, object> { {(byte)MonopolyGameStatusChangeBroadcastParameterItem.GameDataString, JsonConvert.SerializeObject((player as ServerPlayer).playingGame.Serialize(), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }) } }; List<Peer> peers = new List<Peer>(); foreach (ServerUser user in ((player as ServerPlayer).playingGame as ServerGame).users) { peers.Add(user.Peer); } Broadcast(peers.ToArray(), BroadcastType.DrawCard, parameter1); Broadcast(peers.ToArray(), BroadcastType.MonopolyGameStatusChange, parameter2); }
private static void UpgradeLandSelectionEventTask(Block block, Token token) { LandBlock landBlock = block as LandBlock; if (landBlock.land.owner == token.owner) { Console.WriteLine("the money you have: {0}", token.owner.money); Console.WriteLine("you can upgrade your land: {0} price:{1}", landBlock.land.name, landBlock.land.tollBase); Console.WriteLine("upgrade your land? y/n"); string instruction; while ((instruction = Console.ReadLine()) != "y" && instruction != "n") ; if (instruction == "y") { landBlock.land.Upgrade(token.owner); Console.WriteLine(token.owner.username + " upgrade his land: " + landBlock.land.name + " to level " + landBlock.land.level); Console.WriteLine("cost money {0}, remain money {1}", landBlock.land.tollBase, token.owner.money); } } }
private static void TokenInto(Block block, Token token) { Console.WriteLine(token.owner.username+" go into "+token.position); Console.WriteLine("this block is"+block.GetType()); }
private static void PayForTollEventTask(Block block, Token token) { LandBlock landBlock = block as LandBlock; if (landBlock.land.owner != null && landBlock.land.owner != token.owner) { landBlock.land.PayToll(token.owner); Console.WriteLine("this land is belong to {0}", landBlock.land.owner.username); Console.WriteLine("you paid {0} to him", landBlock.land.toll); Console.WriteLine("remain money: {0}", token.owner.money); } }
private static void PassStartBlockEventTask(Block block, Token token) { StartBlock startBlock = block as StartBlock; token.owner.money += startBlock.salary; Console.WriteLine("when passing the startblock, you get {0} dollars. remain money: {1}", startBlock.salary, token.owner.money); }