Exemplo n.º 1
0
 public override void Trigger(Player player)
 {
     PlayerArrivedEvent(this, new PlayerArrivedEventArgs(player));
     string[] choices = { "Welcom to the bank! How can I help you?", "1.Deposit", "2.Withdraw", "3.Leave" };
     int choice = player.Choose(choices);
     while (choice != 3)
     {
         switch (choice)
         {
             case 1:
                 if (player.Deposit(player.InputInt("How much?")))
                 {
                     player.Inform("Done!");
                 }
                 else
                 {
                     player.Inform("Failed!");
                 }
                 break;
             case 2:
                 if (player.Withdraw(player.InputInt("How much?")))
                 {
                     player.Inform("Done!");
                 }
                 else
                 {
                     player.Inform("Failed!");
                 }
                 break;
             default:
                 throw new Exception();
         }
         choice = player.Choose(choices);
     }
 }
Exemplo n.º 2
0
 public int Choose(string[] choices, Player target)
 {
     foreach (string item in choices)
     {
         Console.WriteLine(item);
     }
     int ret;
     while (true)
     {
         try
         {
             ret = int.Parse(Console.ReadLine());
             if (ret <= 0 || ret >= choices.Length)
             {
                 Console.WriteLine("Illegal input. Please enter again.");
                 continue;
             }
             break;
         }
         catch (Exception e)
         {
             Console.WriteLine("Please retry...");
         }
     }
     return ret;
 }
Exemplo n.º 3
0
 public bool Confirm(string cue, Player target)
 {
     Console.WriteLine(cue + "\nY for Yes or Any Other for No:");
     string ans = Console.ReadLine();
     switch (ans[0])
     {
         case 'Y':
         case 'y':
             return true;
         case 'N':
         case 'n':
             return false;
         default:
             return false;
     }
 }
Exemplo n.º 4
0
 public void AllPlayerMoneyEventHandler(Player player, Player.MoneyEventArgs e)
 {
     Console.WriteLine(e.Info + "\nAmount: " + e.Amount+"\nPlayer: "+player.Name);
 }
Exemplo n.º 5
0
 public void AllPlayerEstateEventHandler(Player p, Player.EstateEventArgs e)
 {
     Console.WriteLine(e.Info+" Estate: "+e.Target.Name);
 }
Exemplo n.º 6
0
 public void Write(object item, Player target)
 {
     Console.WriteLine(item);
 }
Exemplo n.º 7
0
 public int ReadInt(string cue, Player target)
 {
     Console.WriteLine(cue);
     string s = Console.ReadLine();
     Console.WriteLine(s);
     return int.Parse(s);
 }
Exemplo n.º 8
0
 public string Read(string cue, Player target)
 {
     return Console.ReadLine();
 }
Exemplo n.º 9
0
 public void OtherPlayerEventHandler(Player p,Player.PlayerEventArgs e)
 {
     Console.WriteLine(e.Info);
 }
Exemplo n.º 10
0
 public override void Trigger(Player player)
 {
     PlayerArrivedEvent(this, new PlayerArrivedEventArgs(player));
     if (player.Confirm("I want to play a game..."))
     {
         int invest = player.InputInt("How much do you want to bet?");
         player.SpendCash(invest);
         int revenue = Calculate(invest);
         player.AddCash(revenue);
         if (invest >= revenue)
         {
             player.Inform("Poor guy...");
             ResultEvent(player,new CasinoEventArgs(false));
         }
         else
         {
             player.Inform("Lucky you...");
             ResultEvent(player,new CasinoEventArgs(true));
         }
     }
 }
Exemplo n.º 11
0
 protected virtual void Upgrade(Player player)
 {
     if (player != Owner)
     {
         return;
     }
     if (Level < 6)
     {
         if (player.SpendCash(Price))
         {
             UpgradeEvent(this);
             ++Level;
             player.Inform("Congratulations! You have upgraded this estate!");
         }
     }
 }
Exemplo n.º 12
0
 //methods
 public override void Trigger(Player player)
 {
     PlayerArrivedEvent(this, new PlayerArrivedEventArgs(player));
     if (Owner == null)
     {
         if (player.Cash >= Price)
         {
             if (player.Confirm("Would you like to buy the estate? Price: " + Price))
             {
                 player.BuyEstate(this);
             }
         }
         else
         {
             player.Inform("Sorry, but you cannot afford this estate. Price: " + Price);
         }
     }
     else if (Owner == player)
     {
         if (player.Cash >= Price && Level != 6)
         {
             if (player.Confirm("Would you like to upgrade the estate? Price: " + Price))
             {
                 Upgrade(player);
             }
         }
         else if (Level == 6)
         {
             player.Inform("The estate is fully upgraded!");
         }
         else
         {
             player.Inform("Sorry, but you cannot afford upgrading this estate. Price: " + Price);
         }
     }
     else
     {
         player.PayRent();
     }
 }
Exemplo n.º 13
0
        public static void Initialize(IIo io, int playerCount, XmlElement map)
        {
            VerifyStage(GameStage.NotInitialized);

            _Io = io;

            Map = new Map(map);

            Players = new Player[playerCount];
            for (int i = 0; i < playerCount; i++)
            {
                Players[i] = new Player(i);
            }
            _CurrentPlayerId = 0;

            Day = 1;

            Stage = GameStage.Start;
        }
Exemplo n.º 14
0
 internal PlayerArrivedEventArgs(Player player)
 {
     Player = player;
 }