void client1_GetStateCompleted(object sender, ServiceReference1.GetStateCompletedEventArgs e)
        {
            try
            {
                // lst2.Items.Clear();
                Dices.Clear();
                Dat.Clear();
                foreach (var item in e.Result.lastDieRoll)
                {
                    Dat.Add(new Dicies()
                    {
                        Dieces = item
                    });
                }
                Dices.Add(new Dice()
                {
                    TileName = e.Result.ActiveTileName
                });
            }

            catch (Exception ex)
            {
                //  MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        public TurnContext Reroll(BoardContext board, IList <int> dicesToReroll)
        {
            var newDices = Dices.ToList(); //copy

            foreach (int diceToReroll in dicesToReroll)
            {
                if (newDices.Contains(diceToReroll))
                {
                    newDices.RemoveAt(newDices.LastIndexOf(diceToReroll));
                }
                else
                {
                    throw new System.FormatException();
                }
            }
            newDices.AddRange(Enumerable.Range(0, 4 - newDices.Count).Select(_ => RollDice));
            var newDicesArray = newDices.ToArray();

            return(new TurnContext(
                       currentPlayer: CurrentPlayer,
                       dices: newDicesArray,
                       remainReroll: dicesToReroll.Count - 1,
                       remainMove: dicesToReroll.Count,
                       isStuckInThisTurn: board.IsStuck(CurrentPlayer, newDicesArray)
                       ));
        }
예제 #3
0
        /// <summary>
        /// Roll the dices
        /// </summary>
        /// <returns></returns>
        public int Roll()
        {
            var rcr = new RngCryptoRandom(true);

            ResultRoll = Dices.Aggregate(0, (current, c) => current += c.Roll(rcr));

            return(ResultRoll);
        }
예제 #4
0
        /// <summary>
        /// Roll the dices
        /// </summary>
        /// <returns></returns>
        public string[] Roll()
        {
            var rcr = new RngCryptoRandom(true);

            Result = Dices.Select(c => c.Roll(rcr)).ToArray();

            return(Result);
        }
예제 #5
0
 public new object ToClient()
 {
     return(new {
         playerName = Player.Name,
         dices = Dices.Select(d => d.ToClient()),
         lockStatus = LockStatus.ToString()
     });
 }
예제 #6
0
        public App()
        {
            Properties["Dices"] = new Dices();
            Properties["Rand"]  = new Random(); //new Random(Environment.TickCount)

            new MainWindow {
                DataContext = new MainWindowViewModel(new LcrGame())
            }.Show();
        }
예제 #7
0
        public RollResult ComputeTurnResult()
        {
            RollResult rollResult = RollResult.Lose;

            if (Dices.All(dice => dice.Face == Dices[0].Face))
            {
                rollResult = Dices[0].Face == Dices[0].Max ? RollResult.Jackpot : RollResult.Win;
            }
            return(rollResult);
        }
예제 #8
0
        /// <summary>
        /// Complete random roll of random count of random dice type
        /// </summary>
        /// <returns></returns>
        /// <remarks>There will be 1 to 9 rolled dices</remarks>
        public int Roll(IRandomizer rnd)
        {
            int dicesCount = rnd.GetNext(1, 10);

            string[] numDiceTypes      = Enum.GetNames(typeof(Dices));
            int      selectedDiceIndex = rnd.GetNext(numDiceTypes.Length);
            Dices    selectedDice      = (Dices)Enum.Parse(typeof(Dices), numDiceTypes[selectedDiceIndex]);

            return(this.Roll(dicesCount, selectedDice, rnd));
        }
예제 #9
0
        private static void Main(string[] args)
        {
            IDashCell dashCell = new DashCellOca();
            IDices    dices    = new Dices(6, 2);
            Board     board    = new Board(dashCell, dices);

            Console.WriteLine(dashCell.GetInfoGame());
            List <IPlayer> playersList = GetListPlayers(CountPlayers());

            while (!PlayerWin(playersList))
            {
                TurnPlayer(playersList, board);
            }
        }
예제 #10
0
            public InternalSellInfo()
            {
                Add(typeof(BarkeepContract), BarkeepContract.GetSBSellValue());

                Add(typeof(Jug), Jug.GetSBSellValue());
                Add(typeof(BeverageBottle), BeverageBottle.GetSBSellValue());
                Add(typeof(Pitcher), Pitcher.GetSBSellValue());
                Add(typeof(GlassMug), GlassMug.GetSBSellValue());

                Add(typeof(Chessboard), Chessboard.GetSBSellValue());
                Add(typeof(CheckerBoard), CheckerBoard.GetSBSellValue());
                Add(typeof(Backgammon), Backgammon.GetSBSellValue());
                Add(typeof(Dices), Dices.GetSBSellValue());
            }
예제 #11
0
        static void Main(string[] args)
        {
            Dices dice = new Dices();
            Console.WriteLine("How many throws do you want to throw?: ");
            string times = Console.ReadLine();
            int number;
            bool result = int.TryParse(times, out number);
            // luodaan olio Noppa-Luokasta
            for (int i=1;i<= number; i++)
            {
                int luku = dice.Throw(); //1-6
                Console.WriteLine("Luku on {0}", luku);
            }

        }
예제 #12
0
        public override void ActionEffect()
        {
            if (Actions.HasTargetLockOn(Combat.Attacker, Combat.Defender))
            {
                char letter = ' ';
                letter = Actions.GetTargetLocksLetterPair(Combat.Attacker, Combat.Defender);

                Selection.ActiveShip.SpendToken(typeof(Tokens.BlueTargetLockToken), letter);
                Combat.Defender.RemoveToken(typeof(Tokens.RedTargetLockToken), letter);

                //TODO: 2 Kinds of reroll
                //TODO: Block buttons
                Dices.RerollDices(Combat.CurentDiceRoll, "failures", Unblock);
            }
        }
예제 #13
0
            public InternalSellInfo()
            {
                Add(typeof(VendorRentalContract), VendorRentalContract.GetSBSellValue());

                Add(typeof(Torch), Torch.GetSBSellValue());
                Add(typeof(Candle), Candle.GetSBSellValue());
                Add(typeof(Backpack), Backpack.GetSBSellValue());
                Add(typeof(Bag), Bag.GetSBSellValue());
                Add(typeof(Pouch), Pouch.GetSBSellValue());

                Add(typeof(Chessboard), Chessboard.GetSBSellValue());
                Add(typeof(CheckerBoard), CheckerBoard.GetSBSellValue());
                Add(typeof(Backgammon), Backgammon.GetSBSellValue());
                Add(typeof(Dices), Dices.GetSBSellValue());
            }
예제 #14
0
        internal void MoveAndRemoveDice(Dices a_diceNumber)
        {
            int index = m_savedDiceList.FindIndex(d => d.Dicenumber == a_diceNumber);

            if (index == -1)
            {
                throw new DiceNotFoundException();
            }
            else
            {
                model.Dice dice = m_savedDiceList[index];
                m_diceList.Add(dice);
                m_savedDiceList.RemoveAt(index);
            }
        }
예제 #15
0
        static void Main(string[] args)
        {
            Dices dice = new Dices();

            Console.WriteLine("How many throws do you want to throw?: ");
            string times = Console.ReadLine();
            int    number;
            bool   result = int.TryParse(times, out number);

            // luodaan olio Noppa-Luokasta
            for (int i = 1; i <= number; i++)
            {
                int luku = dice.Throw(); //1-6
                Console.WriteLine("Luku on {0}", luku);
            }
        }
예제 #16
0
            public InternalBuyInfo()
            {
                Add(new GenericBuyInfo("Vendor Rental Contract", typeof(VendorRentalContract), VendorRentalContract.GetSBPurchaseValue(), 25, 0x14F0, 0));

                Add(new GenericBuyInfo("Lantern", typeof(Lantern), Lantern.GetSBPurchaseValue(), 25, 0xA25, 0));
                Add(new GenericBuyInfo("Torch", typeof(Torch), Torch.GetSBPurchaseValue(), 25, 0xF6B, 0));
                Add(new GenericBuyInfo("Candle", typeof(Candle), Candle.GetSBPurchaseValue(), 25, 0xA28, 0));
                Add(new GenericBuyInfo("Backpack", typeof(Backpack), Backpack.GetSBPurchaseValue(), 25, 0x9B2, 0));
                Add(new GenericBuyInfo("Bag", typeof(Bag), Bag.GetSBPurchaseValue(), 25, 0xE76, 0));
                Add(new GenericBuyInfo("Pouch", typeof(Pouch), Pouch.GetSBPurchaseValue(), 25, 0xE79, 0));

                Add(new GenericBuyInfo("Chess Board", typeof(Chessboard), Chessboard.GetSBPurchaseValue(), 25, 0xFA6, 0));
                Add(new GenericBuyInfo("Checker Board", typeof(CheckerBoard), CheckerBoard.GetSBPurchaseValue(), 25, 0xFA6, 0));
                Add(new GenericBuyInfo("Backgammon", typeof(Backgammon), Backgammon.GetSBPurchaseValue(), 25, 0xE1C, 0));
                Add(new GenericBuyInfo("Dice", typeof(Dices), Dices.GetSBPurchaseValue(), 25, 0xFA7, 0));
            }
예제 #17
0
        public void FindJunk(Mobile from)
        {
            if (from == null)
            {
                return;
            }

            Item item = null;

            switch (Utility.RandomMinMax(1, 10))
            {
            case 1: item = new Torch(); break;

            case 2: item = new Lantern(); break;

            case 3: item = new Skillet(); break;

            case 4: item = new Beeswax(); break;

            case 5: item = new Bedroll(); break;

            case 6: item = new Dices(); break;

            case 7: item = new Kindling(); break;

            case 8: item = new Bottle(); break;

            case 9: item = new BeverageBottle(BeverageType.Ale); break;

            case 10: item = new Jug(BeverageType.Cider); break;
            }

            if (item != null)
            {
                if (from.AddToBackpack(item))
                {
                    from.SendMessage("You retrieve some junk from the shipwreck and place it in your backpack.");
                }

                else
                {
                    from.SendMessage("You retrieve some junk from the shipwreck, and place it at your feet.");
                    item.MoveToWorld(from.Location, from.Map);
                }
            }
        }
예제 #18
0
        public void SetCategoryType()
        {
            Dictionary <int, int> secondPlayerGroup =
                Dices.GroupBy(m => m).ToDictionary(s => s.Key, s => s.Count());

            if (secondPlayerGroup.Count() == 4)
            {
                CategoryType = CategoryType.NoPoints;
            }
            else if (secondPlayerGroup.Count() == 1)
            {
                CategoryType = CategoryType.AllTheSameKind;
            }
            else if (secondPlayerGroup.Count() == 3)
            {
                CategoryType = CategoryType.NormalPoints;
            }
        }
예제 #19
0
            public InternalBuyInfo()
            {
                Add(new GenericBuyInfo("Barkeep Contract", typeof(BarkeepContract), 6250, 20, 0x14F0, 0));

                Add(new BeverageBuyInfo("Jug of Cider", typeof(Jug), BeverageType.Cider, Jug.GetSBPurchaseValue(), 25, 0x9C8, 0));
                Add(new BeverageBuyInfo("Bottle of Ale", typeof(BeverageBottle), BeverageType.Ale, BeverageBottle.GetSBPurchaseValue(), 25, 0x99F, 0));
                Add(new BeverageBuyInfo("Bottle of Wine", typeof(BeverageBottle), BeverageType.Wine, BeverageBottle.GetSBPurchaseValue(), 25, 0x9C7, 0));
                Add(new BeverageBuyInfo("Bottle of Liquor", typeof(BeverageBottle), BeverageType.Liquor, BeverageBottle.GetSBPurchaseValue(), 25, 0x99B, 0));
                Add(new BeverageBuyInfo("Pitcher of Milk", typeof(Pitcher), BeverageType.Milk, Pitcher.GetSBPurchaseValue(), 25, 0x9F0, 0));
                Add(new BeverageBuyInfo("Pitcher of Ale", typeof(Pitcher), BeverageType.Ale, Pitcher.GetSBPurchaseValue(), 25, 0x1F95, 0));
                Add(new BeverageBuyInfo("Pitcher of Cider", typeof(Pitcher), BeverageType.Cider, Pitcher.GetSBPurchaseValue(), 25, 0x1F97, 0));
                Add(new BeverageBuyInfo("Pitcher of Liquor", typeof(Pitcher), BeverageType.Liquor, Pitcher.GetSBPurchaseValue(), 25, 0x1F99, 0));
                Add(new BeverageBuyInfo("Pitcher of Wine", typeof(Pitcher), BeverageType.Wine, Pitcher.GetSBPurchaseValue(), 25, 0x1F9B, 0));
                Add(new BeverageBuyInfo("Pitcher of Water", typeof(Pitcher), BeverageType.Water, Pitcher.GetSBPurchaseValue(), 25, 0x1F9D, 0));

                Add(new GenericBuyInfo("Chess Board", typeof(Chessboard), Chessboard.GetSBPurchaseValue(), 25, 0xFA6, 0));
                Add(new GenericBuyInfo("Checker Board", typeof(CheckerBoard), CheckerBoard.GetSBPurchaseValue(), 25, 0xFA6, 0));
                Add(new GenericBuyInfo("Backgammon", typeof(Backgammon), Backgammon.GetSBPurchaseValue(), 25, 0xE1C, 0));
                Add(new GenericBuyInfo("Dice", typeof(Dices), Dices.GetSBPurchaseValue(), 25, 0xFA7, 0));
            }
예제 #20
0
        private void PresentDices(PresentationViewController presentationViewController)
        {
            var count  = 200;
            var spread = 6;

            // drop rigid bodies cubes
            var intervalTime   = 5.0 / count;
            var remainingCount = count;

            Timer = NSTimer.CreateRepeatingTimer(intervalTime, delegate(NSTimer obj) {
                if (Step > 4)
                {
                    Timer.Invalidate();
                    return;
                }

                SCNTransaction.Begin();

                var worldPos = GroundNode.ConvertPositionToNode(new SCNVector3(0, 30, 0), null);

                var dice = CreateBlock(worldPos, new SCNVector3(1.5f, 1.5f, 1.5f));

                //add to scene
                ((SCNView)presentationViewController.View).Scene.RootNode.AddChildNode(dice);

                dice.PhysicsBody.Velocity        = new SCNVector3(RandFloat(-spread, spread), -10, RandFloat(-spread, spread));
                dice.PhysicsBody.AngularVelocity = new SCNVector4(RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-1, 1), RandFloat(-3, 3));

                SCNTransaction.Commit();

                Dices.Add(dice);

                // ensure we stop firing
                if (--remainingCount < 0)
                {
                    Timer.Invalidate();
                }
            });

            NSRunLoop.Current.AddTimer(Timer, NSRunLoopMode.Default);
        }
예제 #21
0
 public RollResult ComputeTurnResult()
 {
     if (Dices.Distinct().Skip(1).Any())
     {
         if (Dices[0].Face == 6)
         {
             Console.WriteLine("Jackpot!!");
             Console.ReadLine();
             return(RollResult.Jackpot);
         }
         else
         {
             Console.WriteLine("Win!");
             Console.ReadLine();
             return(RollResult.Win);
         }
     }
     Console.WriteLine("Lose");
     Console.ReadLine();
     return(RollResult.Lose);
 }
예제 #22
0
 static void ComputerTurn(Dices dices)
 {
     do
     {
         for (int i = 23; i >= 0; i--)
         {
             if (checkers[i] >= 0) continue;
             if (dices.diceA > 0 && checkers[i - dices.diceA] < 2)
             {
                 MoveDice(-1, i, i - dices.diceA);
                 dices.diceA = 0;
                 break;
             }
             if (dices.diceB > 0 && checkers[i - dices.diceB] < 2)
             {
                 MoveDice(-1, i, i - dices.diceB);
                 dices.diceB = 0;
                 break;
             }
         }
     } while (dices.diceA > 0 || dices.diceB > 0);
 }
예제 #23
0
        public TurnContext Reroll(IList <int> dicesToReroll)
        {
            var newDices = Dices.ToList(); //copy

            foreach (int diceToReroll in dicesToReroll)
            {
                if (newDices.Contains(diceToReroll))
                {
                    newDices.RemoveAt(newDices.LastIndexOf(diceToReroll));
                }
                else
                {
                    throw new System.FormatException();
                }
            }
            newDices.AddRange(Enumerable.Range(0, 2 - newDices.Count).Select(_ => RollDice));

            return(new TurnContext(
                       currentPlayer: CurrentPlayer,
                       dices: newDices.ToArray(),
                       remainReroll: newDices[0] == newDices[1] ? dicesToReroll.Count : dicesToReroll.Count - 1
                       ));
        }
예제 #24
0
 public override void ActionEffect()
 {
     Dices.ApplyFocus(Combat.CurentDiceRoll);
     Selection.ActiveShip.SpendToken(typeof(Tokens.FocusToken));
 }
예제 #25
0
 /// <summary>
 /// Removes all elements from the <see cref="DicesCup"/>.
 /// </summary>
 public void Clear()
 {
     Dices.Clear();
 }
예제 #26
0
 static void Main()
 {
     Console.Title = "Backgammon game";
     Console.SetWindowSize(boardWidth, boardHeight);
     Console.OutputEncoding = Encoding.Unicode;
     DrawEmptyTable();
     for (int i = 0; i < checkers.Length; i++)
         if (checkers[i] != 0)
             DrawCheckerPile(i);
     Dices dices = new Dices();
     do
     {
         dices.Roll();
         UserTurn(dices);
         dices.Roll();
         ComputerTurn(dices);
     } while (true);
     Console.ReadLine();
 }
예제 #27
0
    static void UserTurn(Dices dices)
    {
        bool validMove;
        bool equalDices = dices.diceA == dices.diceB;
        int equalDicesCounter = 4;
        do
        {
            int step = 0;
            int userFrom = 0;
            int userTo = 0;
            bool CanMoveDiceA;
            bool CanMoveDiceB;
            do
            {
                CanMoveDiceA = CheckForAvailableMove(1, dices.diceA);
                CanMoveDiceB = CheckForAvailableMove(1, dices.diceB);
                if (dices.diceA == 0 && !CanMoveDiceB || // first dice is moved, but second cannot
                    dices.diceB == 0 && !CanMoveDiceA || // second dice is moved, but first cannot
                    !(CanMoveDiceA || CanMoveDiceB)) // no dice can be moved
                {
                    Console.SetCursorPosition(15 * cellWidth + barWidth, 13);
                    Console.WriteLine("User cannot move");
                    return;
                }
                Console.ForegroundColor = ConsoleColor.Red;
                userFrom = GetUserInput(10); // get number and check that is in range 1-24
                Console.SetCursorPosition(15 * cellWidth + barWidth, 13);
                Console.Write("                "); // erase "Wrong move" message
                userTo = GetUserInput(11); // get number and check that is in range 1-24
                validMove = CheckMove(userFrom, userTo);
                step = userTo - userFrom;
                validMove = validMove && (step == dices.diceA || step == dices.diceB); // any dice number is equal to move
                if (!validMove)
                {
                    Console.SetCursorPosition(15 * cellWidth + barWidth, 13);
                    Console.Write("Wrong move");
                    Console.Beep(1200, 500);
                }
                ClearUserInput(10);
                ClearUserInput(11);
                RestorePileSign(userFrom);
                RestorePileSign(userTo);
            } while (!validMove);

            MoveDice(1, userFrom, userTo);
            if (step == dices.diceA)
                if (equalDices)
                    equalDicesCounter--;
                else
                    dices.diceA = 0;
            else
                dices.diceB = 0;
        } while ((dices.diceA != 0 || dices.diceB != 0) && equalDicesCounter != 0);
    }
예제 #28
0
 /// <summary>
 /// Adds an object to the end of the <see cref="DicesCup"/>.
 /// </summary>
 /// <param name="item">The Dice to be added to the end of the <see cref="DicesCup"/>.</param>
 public void Add(Dice item)
 {
     Dices.Add(item);
 }
예제 #29
0
 /// <summary>
 /// Returns an enumerator that iterates through the <see cref="DicesCup"/>.
 /// </summary>
 /// <returns> A <see cref="DicesCup"/>.Enumerator for the <see cref="DicesCup"/>.</returns>
 public IEnumerator <Dice> GetEnumerator()
 {
     return(Dices.GetEnumerator());
 }
예제 #30
0
 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 {
     return(Dices.GetEnumerator());
 }
예제 #31
0
 /// <summary>
 /// Removes the first occurrence of a specific object from the <see cref="DicesCup"/>.
 /// </summary>
 /// <param name="item">The object to remove from the <see cref="DicesCup"/>.</param>
 /// <returns>True if item is successfully removed; otherwise, false. This method also returns false if item was not found in the <see cref="DicesCup"/>.</returns>
 public bool Remove(Dice item)
 {
     return(Dices.Remove(item));
 }
예제 #32
0
 /// <summary>
 /// Copies the entire <see cref="DicesCup"/> to a compatible one-dimensional array, starting at the specified index of the target array.
 /// </summary>
 /// <param name="array">The one-dimensional System.Array that is the destination of the elements copied from <see cref="DicesCup"/>. The System.Array must have zero-based indexing.</param>
 /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param>
 /// <exception cref="System.ArgumentNullException">Array is null.</exception>
 /// <exception cref="System.ArgumentOutOfRangeException">ArrayIndex is less than 0.</exception>
 /// <exception cref="System.ArgumentException">The number of elements in the source <see cref="DicesCup"/> is greater than the available space from arrayIndex to the end of the destination array.</exception>
 public void CopyTo(Dice[] array, int arrayIndex)
 {
     Dices.CopyTo(array, arrayIndex);
 }
예제 #33
0
 /// <summary>
 /// Determines whether an element is in the <see cref="DicesCup"/>.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="DicesCup"/>.</param>
 /// <returns>True if item is found in the <see cref="DicesCup"/>; otherwise, false.</returns>
 public bool Contains(Dice item)
 {
     return(Dices.Contains(item));
 }
예제 #34
0
 public override void ActionEffect()
 {
     Dices.RerollOne(Combat.CurentDiceRoll, Unblock);
 }
예제 #35
0
 public int Roll(int count, Dices dice, IRandomizer rnd)
 {
     return Roll(count, (int)dice, rnd);
 }