Ejemplo n.º 1
0
        /// <summary>
        /// start a new party
        /// </summary>
        public void Start()
        {
            //check for requirement before start party
            if (this.m_GameStart)
            {
                return;
            }

            if (this.SelectedPlayer == null)
            {
                this.SelectedPlayer = this.Players[0];
            }
#if JGGAME_CHECK
            //this.Bank.Distribute4Seven (this.SelectedPlayer);
            this.Bank.Distribute21(this.SelectedPlayer);

            foreach (JGPlayer item in this.m_players)
            {
                JGHand hand = this.m_hands.GetHand(item);
                Console.WriteLine("Card For Player =  " + item.Name);
                foreach (JGCard card in hand)
                {
                    Console.WriteLine("->" + card.ToString());
                }
            }
#else
            this.Bank.Distribute();
#endif
            this.m_GameStart = true;
        }
Ejemplo n.º 2
0
        private static int GetCardType(JGHand hand, enuJGCardType t)
        {
            int i = 0;

            foreach (JGCard item in hand)
            {
                if (item.CardType == t)
                {
                    i++;
                }
            }
            return(i);
        }
Ejemplo n.º 3
0
        private static int GetColor(JGHand hand, enuJGCardColor t)
        {
            int i = 0;

            foreach (JGCard item in hand)
            {
                if (item.GetColor() == t)
                {
                    i++;
                }
            }
            return(i);
        }
Ejemplo n.º 4
0
 private void CheckForEnd()
 {
     if (this.m_GameStart)
     {
         JGHand h = this.Hands.GetHand(m_SelectedPlayer);
         if (h.IsEmpty)
         {
             this.Winner      = this.m_gameHand.ControlUser;
             this.m_GameStart = false;
             OnPartyEnded(new JGPartyEndEventArgs(this.Winner, enuJGPartyEndReason.Normal, enuJGExceptionRule.None));
         }
     }
 }
Ejemplo n.º 5
0
        public bool CheckMyRules(JGPlayer player)
        {
            //check for confidition
            if (this.Tour == 0)
            {
                JGHand hand = this.m_hands.GetHand(player);
                if (hand != null)
                {
                    enuJGExceptionRule c = hand.IsSevenRule() | hand.IsTweentyOneRule();
                    if (c != enuJGExceptionRule.None)
                    {
                        this.m_GameStart            = false;
                        this.m_gameHand.ControlUser = player;
                        this.Winner = player;
                        JGPartyEndEventArgs e = new JGPartyEndEventArgs();
                        e.Winner = Winner;
                        foreach (JGCard item in hand)
                        {
                            Console.WriteLine("CARD " + item);
                        }
                        switch (c)
                        {
                        case enuJGExceptionRule.None:
                            break;

                        case enuJGExceptionRule.Threeseven:
                            Console.Write("ThreeSEVEN RULE");

                            break;

                        case enuJGExceptionRule.FourSeven:
                            Console.Write("FourSEVEN RULE");
                            break;

                        case enuJGExceptionRule.TwentyOneRule:

                            Console.Write("TwentyOneRule RULE");
                            break;

                        default:
                            break;
                        }
                        e.Reason = (c != enuJGExceptionRule.None) ?  enuJGPartyEndReason.ExceptionRule : enuJGPartyEndReason.Normal;
                        e.Rule   = c;
                        OnPartyEnded(e);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
        public static enuJGExceptionRule IsTweentyOneRule(this JGHand hand)
        {
            if (hand.Count != 5)
            {
                return(enuJGExceptionRule.None);
            }
            int i = 0;

            foreach (JGCard card in hand)
            {
                i += card.Value;
            }
            return((i <= 21)? enuJGExceptionRule.TwentyOneRule : enuJGExceptionRule.None);
        }
Ejemplo n.º 7
0
        public static enuJGExceptionRule IsSevenRule(this JGHand hand)
        {
            if (hand.Count != 5)
            {
                return(enuJGExceptionRule.None);
            }
            int i = 0;

            foreach (JGCard card in hand)
            {
                if (card.Value == 7)
                {
                    i++;
                }
            }
            switch (i)
            {
            case 3: return(enuJGExceptionRule.Threeseven);

            case 4: return(enuJGExceptionRule.FourSeven);
            }
            return(enuJGExceptionRule.None);
        }
Ejemplo n.º 8
0
        public static void Main(params string[] args)
        {
            try
            {
#if WINDOWS
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                StartForm v_start = new StartForm();
                v_start.Show();
                while (v_start.Created)
                {
                    Application.DoEvents();
                }
#elif ANDROID
#elif LINUX
#elif CONSOLE
                //   JGDB db = null;
                JGDB.StoreDb();

                Console.WriteLine("Demonstration : Welcome to JAMBO GAME");
                JGHumanPlayer player1 = new JGHumanPlayer();
                player1.Name    = "Bertrand";
                player1.Profile = JGDB.GetProfile("*****@*****.**");

                JGGameTablePlayerProfile prof1 = player1.CreateGameProfile(180);
                JGGameTablePlayerProfile prof2 =
                    new JGComputerPlayer()
                {
                    Name    = "Comp2",
                    Profile = JGDB.GetProfile("*****@*****.**")
                }.CreateGameProfile(60);

                JGPartyTable table = JGPartyTable.CreateTable(50, prof1, prof2);
                if (table != null)
                {
                    table.Party.Start();
                    JGParty party = table.Party;
                    JGHand  hand  = null;
                    while (!party.End)
                    {
                        hand = party.Hands.GetHand(party.SelectedPlayer);


                        Console.WriteLine("Tour: " + party.Tour);
                        Console.WriteLine("Jeu: " + party.SelectedPlayer);
                        if (party.Tour == 0)
                        {
                            if ((hand.IsSevenRule() | hand.IsTweentyOneRule()) != enuJGExceptionRule.None)
                            {
                                //Console.WriteLine (" REGLE DES 7 : "+ hand.IsSevenRule ());
                                party.CheckMyRules(party.SelectedPlayer);
                            }
                        }
                        if ((party.ControlCard == null) || (party.ControlUser == party.SelectedPlayer))
                        {
                            party.SelectedPlayer.Play(party, hand[0]);
                        }
                        else if (hand.ContainsCardType(party.ControlCard.CardType))
                        {
                            hand.SortByType();
                            party.SelectedPlayer.Play(party, hand.GetFirstCard(party.ControlCard.CardType));
                        }
                        else
                        {
                            party.SelectedPlayer.Play(party, hand[0]);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("can't create a table .table mis error");
                }
                JGDB.Restore(prof1, prof2);
                Console.WriteLine("Party end");


                /*
                 *
                 * JGComputerPlayer player1 = new JGComputerPlayer();
                 * player1.Name = "Comp1";
                 * JGParty party = JGParty.CreateParty(player1,
                 *  new JGComputerPlayer[]{
                 *  new JGComputerPlayer(){
                 *      Name = "Comp2"
                 *  }
                 *  ,
                 *  new JGComputerPlayer(){
                 *      Name = "Comp3"
                 *  }
                 *  });
                 *
                 * Console.WriteLine("nouvelle party " + party.Players.Count);
                 *
                 * party.MixCard();
                 * party.CutAt(21);
                 *
                 * party.Start();
                 * JGHand hand = null;// party.Hands.GetHand(party.SelectedPlayer);
                 *
                 *
                 *
                 * while (!party.End)
                 * {
                 *  hand = party.Hands.GetHand(party.SelectedPlayer);
                 *
                 *
                 *  Console.WriteLine("Tour: " + party.Tour);
                 *  Console.WriteLine("Jeu: "+party.SelectedPlayer);
                 *  if (party.Tour== 0)
                 *  {
                 *      if ((hand.IsSevenRule() | hand.IsTweentyOneRule ()) != enuJGExceptionRule.None)
                 *      {
                 *          //Console.WriteLine (" REGLE DES 7 : "+ hand.IsSevenRule ());
                 *          party.CheckMyRules(party.SelectedPlayer );
                 *      }
                 *  }
                 *  if ((party.ControlCard == null) || (party.ControlUser == party.SelectedPlayer ))
                 *  {
                 *      party.SelectedPlayer.Play(party, hand[0]);
                 *  }
                 *  else if (hand.ContainsCardType (party.ControlCard.CardType))
                 *  {
                 *      hand.SortByType();
                 *      party.SelectedPlayer.Play(party, hand.GetFirstCard(party.ControlCard.CardType));
                 *  }
                 *  else {
                 *          party.SelectedPlayer.Play(party, hand[0]);
                 *  }
                 *
                 * }
                 * Console.WriteLine("party teminer:  ");
                 * Console.WriteLine ("Winner : "+ party.Winner);
                 * Console.WriteLine ("Card : "+ party.ControlCard );
                 *
                 *
                 *
                 * if ((party.Tour == 5))
                 * {
                 *  party.CheckCoraRule(party.Winner);
                 * }
                 */

                //Console.WriteLine("party teminer " + party.Winner);


                //  JGHand hand = party.Hands.GetHand(player1);

                // Console.WriteLine ("jour 1 jouer");

                //player1.Play(party, hand[0]);



                //Console.WriteLine("Couleur Rouge : " + GetColor(hand, enuJGCardColor.Red ));
                //Console.WriteLine("Couleur Black : " + GetColor(hand, enuJGCardColor.Black));

                //foreach (enuJGCardType item in Enum.GetValues (typeof (enuJGCardType)))
                //{
                //    Console.WriteLine("Carte " + item.ToString() + " " + GetCardType(hand, item));
                //}



                //party.Hands.SortHand(player1, enuJGSortType.Color   );
                //hand.SortByValue();



                Console.ReadLine();
#endif
            }
            catch (Exception ex) {
                MessageBox.Show("L'application s'est malheureusement arrêter : " + ex.Message);
            }
        }
Ejemplo n.º 9
0
        public void Play(JGPlayer player, JGCard card)
        {
            if ((player == this.jGParty.SelectedPlayer) && (card != null))
            {
                JGHand hand = this.jGParty.Hands.GetHand(player);
                if (hand.Contains(card))
                {
                    if (
                        (this.ControlCard == null) ||
                        (this.m_ControlUser == player) ||
                        (card.CardType == this.ControlCard.CardType) ||
                        !hand.ContainsCardType(this.ControlCard.CardType)
                        )
                    {
#if DEBUG
                        Console.WriteLine("card : " + card);
#endif
                        //peux jouer
                        int vtour = m_count / this.jGParty.Players.Count;
                        if (!this.m_dic.ContainsKey(vtour))
                        {
                            this.m_dic.Add(vtour, new List <JGGameHandInfo>());
                        }
                        this.m_dic[vtour].Add(new JGGameHandInfo()
                        {
                            Player  = player,
                            Card    = card,
                            JGParty = jGParty,
                            Tour    = vtour,
                            Index   = m_count
                        });

                        if ((this.ControlUser == null) || (this.ControlUser == player))
                        {
                            this.m_ControlUser = player;
                            this.m_ControlCard = card;
                        }
                        else if
                        ((card.CardType == this.ControlCard.CardType) &&
                         (card.Value > this.ControlCard.Value))
                        {
                            this.m_ControlCard = card;
                            this.m_ControlUser = player;
                        }
                        m_count++;
                        int tt = m_count / this.jGParty.Players.Count;

                        hand.Remove(card);

                        if (tt != vtour)
                        {
                            this.m_tour = tt;
                            Console.WriteLine();
                            this.jGParty.SelectedPlayer = this.m_ControlUser;
                        }
                        else
                        {
                            this.jGParty.SelectedPlayer = this.jGParty.Players[((this.jGParty.Players.IndexOf(player) + 1) % this.jGParty.Players.Count)];
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Ne pas pue jouer la carte " + card.ToString());
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Ne possède pas la carte");
                }
            }
        }