public SlotMachineGump(Mobile from, int[] slotIds, bool secondTurn, SlotMachine machine, string statusText, bool[] holdButtons, int curBet, bool bUseBank)
            : base(0, 0)
        {
            from.CloseGump(typeof(SlotMachineGump));
            m_slotIds = slotIds;
            m_bSecondTurn = secondTurn;
            m_Machine = machine;
            m_HoldButtons = holdButtons;
            m_curBet = curBet;
            m_bUseBank = bUseBank;

            this.Closable = true;
            this.Disposable = true;
            this.Dragable = true;
            this.Resizable = false;

            this.AddPage(0);
            this.AddBackground(50, 68, 566, 483, 9200);
            this.AddBackground(78, 53, 502, 35, 9200);

            this.AddBackground(94, 98, 81, 82, 3000);
            this.AddBackground(184, 98, 81, 82, 3000);
            this.AddBackground(274, 98, 81, 82, 3000);
            this.AddBackground(364, 95, 241, 426, 3000);

            this.AddLabel(534, 525, 0, @"Close");
            this.AddLabel(294, 60, 0, @"Slot Machine");
            this.AddLabel(67, 525, 0, string.Format("Version {0}", SlotMachine.CurrentVersion.ToString()));

            this.AddImage(0, 26, 10440);
            this.AddImage(584, 26, 10441);

            this.AddButton(572, 524, 4017, 4018, (int)Buttons.CLOSE, GumpButtonType.Reply, 0);

            // Options
            this.AddLabel(160, 390, 0, @"Machine Options:");
            this.AddCheck(160, 415, 210, 211, m_bUseBank, (int)Buttons.USEBANK);
            this.AddLabel(190, 415, 0, @"Withdraw money from bank.");
            this.AddLabel(160, 440, 0, string.Format("Bank balance: {0}gp.", Banker.GetBalance( from ).ToString()));

            if (secondTurn)
            {
                this.AddCheck(140, 185, 210, 211, m_HoldButtons[0], (int)Buttons.HOLD1);
                this.AddCheck(230, 185, 210, 211, m_HoldButtons[1], (int)Buttons.HOLD2);
                this.AddCheck(320, 185, 210, 211, m_HoldButtons[2], (int)Buttons.HOLD3);
                this.AddLabel(110, 186, 0, @"Hold");
                this.AddLabel(200, 186, 0, @"Hold");
                this.AddLabel(290, 186, 0, @"Hold");
            }

            this.AddButton(292, 270, 4023, 4024, (int)Buttons.SPIN, GumpButtonType.Reply, 0);
            this.AddLabel(253, 270, 0, @"Spin!");

            int slotLocationX = 109;
            for (int slotLocation = 0; slotLocation < m_slotIds.Length; slotLocation++)
            {
                if (m_slotIds[slotLocation] != 0)
                    this.AddItem(slotLocationX, 123, m_slotIds[slotLocation]);
                slotLocationX += 90;
            }

            int y = 102;
            for (int a = 0; a < m_MainTable.Length; a++)
            {
                SlotMachineEntry entry = (SlotMachineEntry)m_MainTable[a];

                for (int b = 0; b < entry.m_AmountNeeded; b++)
                    this.AddItem(371 + (40 * b), y, entry.m_itemID);

                this.AddLabel(525, y + 3, 0, entry.m_Jackpot ? "Jackpot" : string.Format("{0}gp", entry.m_goldWin * (m_curBet / SlotMachine.m_iBetChange)));
                y += 40;
            }

            if (!secondTurn)
            {
                this.AddButton(177, 283, 4023, 4024, (int)Buttons.CHANGEBET, GumpButtonType.Reply, 0);
                this.AddLabel(101, 283, 0, @"Change Bet");
            }
            this.AddLabel(94, 260, 0, string.Format("Current Bet: {0}", m_curBet));

            this.AddImage(67, 389, 9000);
            this.AddHtml(62, 223, 301, 24, string.Format("<center>{0}</center>", statusText), (bool)true, (bool)false);
        }
Ejemplo n.º 2
0
        public void ReturnsCorrectItem_WhenInvoked()
        {
            //Arrange
            var firstItem = new Item
            {
                Name = "item1",
                CumulativeProbability = 50
            };

            var secondItem = new Item
            {
                Name = "item2",
                CumulativeProbability = 20
            };

            var items = new Dictionary <int, Item>
            {
                { firstItem.CumulativeProbability, firstItem },
                { secondItem.CumulativeProbability, secondItem }
            };

            var randomProviderMock = new Mock <IRandomProvider>();

            randomProviderMock
            .Setup(r => r.Next(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(50);
            var sut = new SlotMachine(randomProviderMock.Object);

            // Act
            var result = sut.GetRandomItem(items);

            // Assert
            Assert.AreEqual(firstItem, result);
        }
Ejemplo n.º 3
0
        public void ReturnsItem_WhenInvoked()
        {
            //Arrange
            var firstItem = new Item
            {
                Name = "item1",
                CumulativeProbability = 50
            };

            var items = new Dictionary <int, Item>
            {
                { firstItem.CumulativeProbability, firstItem }
            };

            var randomProviderMock = new Mock <IRandomProvider>();

            randomProviderMock
            .Setup(r => r.Next(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(50);
            var sut = new SlotMachine(randomProviderMock.Object);

            // Act
            var result = sut.GetRandomItem(items);

            // Assert
            Assert.IsInstanceOfType(result, typeof(Item));
        }
Ejemplo n.º 4
0
        public async Task SlotAsync(CommandContext ctx,
                                    [Description("Bid.")] long bid = 5)
        {
            if (bid <= 0 || bid > _maxBet)
            {
                throw new InvalidCommandUsageException($"Invalid bid amount! Needs to be in range [1, {_maxBet:n0}]");
            }

            using (DatabaseContext db = this.Database.CreateContext()) {
                if (!await db.TryDecreaseBankAccountAsync(ctx.User.Id, ctx.Guild.Id, bid))
                {
                    throw new CommandFailedException($"You do not have enough {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}! Use command {Formatter.InlineCode("bank")} to check your account status.");
                }
                await db.SaveChangesAsync();
            }

            await ctx.RespondAsync(embed : SlotMachine.RollToDiscordEmbed(ctx.User, bid, this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits", out long won));

            if (won > 0)
            {
                using (DatabaseContext db = this.Database.CreateContext()) {
                    await db.ModifyBankAccountAsync(ctx.User.Id, ctx.Guild.Id, v => v + won);

                    await db.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 5
0
        public void CalculeGlobalCoefficientShouldReturnPositiveValue()
        {
            SlotMachine slotMachine = new SlotMachine(2, 3);

            var symbolA        = new Symbol(character: 'A', coefficient: 0.4M, probability: 0.45);
            var symbolB        = new Symbol(character: 'B', coefficient: 0.6M, probability: 0.35);
            var symbolWildcard = new Symbol(character: '*', coefficient: 0.0M, probability: 0.05);
            var table          = new Symbol[][]
            {
                new Symbol[]
                {
                    symbolA,
                    symbolA,
                    symbolA,
                },
                new Symbol[]
                {
                    symbolB,
                    symbolWildcard,
                    symbolB,
                },
            };
            decimal expectedCoefficient = CoefficientsSum(table);
            decimal actualCoefficient   = slotMachine.CalculeGlobalCoefficient(table);

            Assert.AreEqual(expectedCoefficient, actualCoefficient);
        }
 public SlotMachineWindow(string name, EventHandler <Ticket> ticketReady)
 {
     InitializeComponent();
     Title                   = name;
     _slotMachine            = new SlotMachine(name);
     _slotMachine.LogTicket += ticketReady;
 }
Ejemplo n.º 7
0
        public async Task PlayOnSlotMachineAsync([Summary("typ(info - wyświetla informacje)")] string type = "game")
        {
            if (type != "game")
            {
                await ReplyAsync("", false, $"{_fun.GetSlotMachineGameInfo()}".ToEmbedMessage(EMType.Info).Build());

                return;
            }

            using (var db = new Database.UserContext(Config))
            {
                var botuser = await db.GetUserOrCreateAsync(Context.User.Id);

                var machine = new SlotMachine(botuser);

                var toPay = machine.ToPay();
                if (botuser.ScCnt < toPay)
                {
                    await ReplyAsync("", embed : $"{Context.User.Mention} brakuje Ci SC, aby za tyle zagrać.".ToEmbedMessage(EMType.Error).Build());

                    return;
                }
                var win = machine.Play(new SlotEqualRandom());
                botuser.ScCnt += win - toPay;

                await db.SaveChangesAsync();

                QueryCacheManager.ExpireTag(new string[] { $"user-{botuser.Id}", "users" });

                await ReplyAsync("", embed : $"{_fun.GetSlotMachineResult(machine.Draw(), Context.User, botuser, win)}".ToEmbedMessage(EMType.Bot).Build());
            }
        }
Ejemplo n.º 8
0
 public SlotMachineWindow(string name)
 {
     _slotMachine = new SlotMachine(name);
     InitializeComponent();
     Title = name;
     Show();
 }
 public SlotMachineWindow(string title, EventHandler <Ticket> ticketReady)
 {
     InitializeComponent();
     this.Title             = title;
     SlotMachine            = new SlotMachine(Title);
     SlotMachine.LogTicket += ticketReady;
 }
Ejemplo n.º 10
0
            public async Task SlotTest(int tests = 1000)
            {
                if (tests <= 0)
                {
                    return;
                }
                //multi vs how many times it occured
                var dict = new Dictionary <int, int>();

                for (int i = 0; i < tests; i++)
                {
                    var res = SlotMachine.Pull();
                    if (dict.ContainsKey(res.Multiplier))
                    {
                        dict[res.Multiplier] += 1;
                    }
                    else
                    {
                        dict.Add(res.Multiplier, 1);
                    }
                }

                var       sb     = new StringBuilder();
                const int bet    = 1;
                int       payout = 0;

                foreach (var key in dict.Keys.OrderByDescending(x => x))
                {
                    sb.AppendLine($"x{key} occured {dict[key]} times. {dict[key] * 1.0f / tests * 100}%");
                    payout += key * dict[key];
                }
                await Context.Channel.SendConfirmAsync("Slot Test Results", sb.ToString(),
                                                       footer : $"Total Bet: {tests * bet} | Payout: {payout * bet} | {payout * 1.0f / tests * 100}%").ConfigureAwait(false);
            }
Ejemplo n.º 11
0
        public void SpinIsOk()
        {
            bool test        = false;
            var  slotMachine = new SlotMachine(new List <IReel> {
                new Reel(3, new List <ESlotSymbol> {
                    ESlotSymbol.Ace, ESlotSymbol.Jack, ESlotSymbol.King
                })
            },
                                               new SlotEngineStub(new ReportDTO {
                HitTotal        = 1,
                PayoffAmount    = 300,
                PaylineHitTotal = 3,
                SpinTotal       = 1
            }));

            var dto = slotMachine.Spin();

            if (dto.HitTotal == 1 && dto.PayoffAmount == 300 &&
                dto.PaylineHitTotal == 3 && dto.SpinTotal == 1)
            {
                test = true;
            }


            Assert.IsTrue(test);
        }
Ejemplo n.º 12
0
    void OnEnable()
    {
        _machine = target as SlotMachine;
        _script  = MonoScript.FromMonoBehaviour(_machine);

        _state = _machine.State;
    }
Ejemplo n.º 13
0
    private void CreateSlotMachine()
    {
        GameObject prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/GUI/SlotMachine") as GameObject;
        GameObject obj    = CommonFunction.InstantiateObject(prefab, GameSystem.Instance.mClient.mUIManager.m_uiRootBasePanel.transform);

        slotMachine = obj.GetComponent <SlotMachine>();
        NGUITools.SetActive(obj, false);
    }
Ejemplo n.º 14
0
        public Form1()
        {
            InitializeComponent();

            guts = new SlotMachine(100);

            UpdateDisplays();
        }
Ejemplo n.º 15
0
 public void Initialize(SlotMachine parent, int index)
 {
     this._parent   = parent;
     this._index    = index;
     this._image    = GetComponent <Image>();
     this._material = this._image.material;
     SetVisibility(false);
 }
 private void Awake()
 {
     if (Instance != null)
     {
         return;
     }
     Instance = this;
 }
        public SlotMachineWindow(string stationname, EventHandler <Ticket> ticketReady)
        {
            InitializeComponent();
            Title = stationname;

            _slotMachine = new SlotMachine(ticketReady, stationname);
            InitSlotMachine();
        }
Ejemplo n.º 18
0
    void Awake()
    {
        IsBuyingPowerUp = false;

        gameSettings      = GameSettings.Instance;
        moneyMgr          = MoneyManager.Instance;
        pwrUpLifeCycleMgr = PowerUpLifeCycleManager.Instance;
        pwrUpSlotMachine  = SlotMachine.Instance;
    }
Ejemplo n.º 19
0
        public void PopulateTableWithSymbolsProbabilitySumMoreThanHundred()
        {
            SlotMachine slotMachine = new SlotMachine(Configuration.RowCount, Configuration.ColCount);
            var         list        = new List <Symbol>()
            {
                new Symbol(character: '$', coefficient: 1.5M, probability: 1.5)
            };

            Assert.ThrowsException <ProbabilityException>(() => slotMachine.PopulateTableWithSymbols(list));
        }
Ejemplo n.º 20
0
        public void PopulateTableWithSymbolsCheckProbability()
        {
            SlotMachine slotMachine = new SlotMachine(rowsCount: 1, colsCount: 10000);
            var         table       = slotMachine.PopulateTableWithSymbols(Configuration.Symbols);
            var         grouping    = table[0].ToLookup(x => x.Character);

            foreach (var item in Configuration.Symbols)
            {
                Symbol[] firstRow    = table[0];
                double   count       = grouping[item.Character].Count();
                double   probability = count / firstRow.Length;
                Assert.AreEqual(expected: item.Probability, actual: probability, delta: 0.01);
            }
        }
        public async Task AddAsync(string licenseNumber, string model, int numberInHall, string gamingHallId)
        {
            var slotMachine = new SlotMachine
            {
                LicenseNumber = licenseNumber,
                Model         = model,
                NumberInHall  = numberInHall,
                GamingHallId  = gamingHallId,
            };

            await this.repository.AddAsync(slotMachine);

            await this.repository.SaveChangesAsync();
        }
Ejemplo n.º 22
0
        public void Test_Deposit_Win_Should_double_stake()
        {
            var grid = new Mock <IGrid>();

            grid.Setup(g => g.CalculateMultipler()).Returns(2m);
            Func <IGrid> gridFactory = () => grid.Object;

            var slotMachine = new SlotMachine(gridFactory);

            slotMachine.Deposit(1m);
            var outcome = slotMachine.PullHandle(1m);

            Assert.AreEqual(2m, outcome.Balance);
        }
Ejemplo n.º 23
0
        protected virtual void OnCreateNewSlotMachine(SlotMachine slotMachine)
        {
            string title = slotMachine.Title;

            if (title.Length > 0)
            {
                CreateNewSlotMachine?.Invoke(this, slotMachine);
                SlotMachineWindow window = new SlotMachineWindow(title, OnReadyTicket);
                window.Show();
            }
            else
            {
                MessageBox.Show("Keine gültige Adresse.");
            }
        }
Ejemplo n.º 24
0
        public void ReturnSpinDataInstance_WhenInvoked()
        {
            // Arrange
            int     rows               = 4;
            int     cols               = 4;
            decimal amount             = 12.12m;
            var     randomProviderMock = new Mock <IRandomProvider>();
            var     sut = new SlotMachine(randomProviderMock.Object);

            // Act
            var result = sut.Spin(rows, cols, amount);

            // Assert
            Assert.IsInstanceOfType(result, typeof(SpinData));
        }
Ejemplo n.º 25
0
    void Start()
    {
        slotMachine = GameObject.FindGameObjectWithTag("SlotMachine");
        slotScript  = slotMachine.GetComponent <SlotMachine> ();

        if (slotMachine == null)
        {
            Debug.Log("Slot machine object doesn't exist.");
        }

        if (slotScript == null)
        {
            Debug.Log("Slot machine script doesn't exist.");
        }
    }
    public void StartSlotMachine(SlotMachine machine)
    {
        if (machine.SlotStatus == SlotMachine.Status.Running)
        {
            machine.SkipSlotMachine();
            return;
        }

        if (machine.SlotStatus == SlotMachine.Status.Finish || machine.SlotStatus == SlotMachine.Status.Skip)
        {
            return;
        }

        var list = GetTestRandomElement();

        machine.StartSlotMachine(list);
    }
Ejemplo n.º 27
0
    // Use this for initialization
    void Start()
    {
        slotMachine = new SlotMachine();
        slotMachine.Init();

        data          = new GuessData();
        data.boxCount = slotMachine.BoxCount;

        agent = new GuessAgent();
        agent.Init();

        m_rateCounter = new float[slotMachine.BoxCount];

        InitUI();

        m_lastTime = Time.realtimeSinceStartup;
    }
Ejemplo n.º 28
0
            public async Task Slot(int amount = 0)
            {
                if (!_runningUsers.Add(Context.User.Id))
                {
                    return;
                }
                try
                {
                    if (amount < 1)
                    {
                        await ReplyErrorLocalized("min_bet_limit", 1 + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    const int maxAmount = 9999;
                    if (amount > maxAmount)
                    {
                        GetText("slot_maxbet", maxAmount + _bc.BotConfig.CurrencySign);
                        await ReplyErrorLocalized("max_bet_limit", maxAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }

                    if (!await _cs.RemoveAsync(Context.User, "Slot Machine", amount, false))
                    {
                        await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    Interlocked.Add(ref _totalBet, amount);
                    using (var bgFileStream = _images.SlotBackground.ToStream())
                    {
                        var bgImage = ImageSharp.Image.Load(bgFileStream);

                        var   result  = SlotMachine.Pull();
                        int[] numbers = result.Numbers;

                        for (int i = 0; i < 3; i++)
                        {
                            using (var file = _images.SlotEmojis[numbers[i]].ToStream())
                                using (var randomImage = ImageSharp.Image.Load(file))
                                {
                                    bgImage.DrawImage(randomImage, 100, default, new Point(95 + 142 * i, 330));
Ejemplo n.º 29
0
    protected void MainButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (SlotMachine.PullTheLever(out points))
        {
            SuccMessagePanel.Visible = true;
            SuccMessage.Text         = L1.YOUWON + " " + points.ToString() + " " + AppSettings.Payments.CurrencyPointsName + ".";

            if (!Member.IsLogged)
            {
                SuccMessage.Text    += " " + U6006.SLOTMACHINEREGISTER;
                MachinePanel.Visible = false;
            }
        }
        else
        {
            ErrorMessagePanel.Visible = true;
            ErrorMessage.Text         = U6006.SLOTMACHINEERROR;
        }
    }
Ejemplo n.º 30
0
        public void ReturnCorrectCoefficient_WhenInvoked()
        {
            //Arrange
            var firstItem = new Item
            {
                Name                  = "item1",
                Coefficient           = 1,
                CumulativeProbability = 50
            };

            var secondItem = new Item
            {
                Name                  = "item2",
                Coefficient           = 2,
                CumulativeProbability = 20,
                Type                  = ItemType.Wildcard
            };

            var items = new Dictionary <int, Item>
            {
                { firstItem.CumulativeProbability, firstItem },
                { secondItem.CumulativeProbability, secondItem }
            };

            var matrix = new Item[1, 3];

            matrix[0, 0] = firstItem;
            matrix[0, 1] = firstItem;
            matrix[0, 2] = secondItem;

            var randomProviderMock = new Mock <IRandomProvider>();
            var sut = new SlotMachine(randomProviderMock.Object);

            // Act
            var result = sut.CalculateCoefficient(matrix);

            // Assert
            Assert.AreEqual(2, result);
        }
Ejemplo n.º 31
0
 // Use this for initialization
 void Start()
 {
     this.createdMachine = Instantiate <SlotMachine>(this.slotMachinePrefab, this.slotNode);
     this.createdMachine.Init();
     this.AddStartSpinningAction();
 }
Ejemplo n.º 32
-2
        /*
         * Welcome message
         * Directions
         * Choose a machine
         * Place a bet
         * Pull lever
         * Randomly rolls around and gives you
         * Machine tells you if you won or not
         */
        static void Main(string[] args)
        {
            SlotMachine myMachine = new SlotMachine(); // 3 slots, 5 icons per slot

            Console.WriteLine("Welcome to slots!");

            Console.WriteLine("Directions");

            while (true)
            {
                // place a bet
                Console.WriteLine("Type in how many pennies to bet");

                // You could get this using:
                // int userBet = Convert.ToInt32(Console.ReadLine());
                // myMachine.CurrentBet = userBet;
                myMachine.CurrentBet = Convert.ToInt32(Console.ReadLine());

                // pull the lever
                Console.WriteLine("Press enter to pull the lever");
                Console.ReadKey(); // TODO Later: make this actually look for ENTER
                myMachine.PullLever();

                // display the results
                int[] tempResults = myMachine.GetResults();
                for (int i = 0; i < tempResults.Length; i++)
                {
                    Console.Write(tempResults[i] + " ");
                }

                // payout
                Console.WriteLine("You won {0} pennies!", myMachine.GetPayout());
            }
        }