Ejemplo n.º 1
0
        /// <summary>
        /// 启用连接外部设备
        /// </summary>
        /// <param name="_cfg"></param>
        private void SubDeviceInitial()
        {
            try
            {
                AE2DeviceFactory fac = new AE2DeviceFactory();
                //IO模块
                adam = fac.CreateAdamDevice(appConfig.Adam.PortNumber);
                adam.NetChangedAction = (d, n) =>
                {
                    ShowToAllForms(m => m.ADAMNet = n);
                };
                adam.OnSensorTrigger += Adam_OnSensorTrigger;

                //RFID
                rfid = fac.CreateRFIDDevice(appConfig.Rfid);
                //相当于连接变化时的事件
                rfid.NetChangedAction = (d, n) =>
                {
                    ShowToAllForms(m =>
                    {
                        m.RFIDNet = n;
                        m.PrintlnInfo("RFID已连接。");
                    });
                };
                rfid.OnTagDataReaded = TagReaded;//相当于RFID读到标签后的事件

                //串口条码枪
                scan              = fac.CreateScanDevice(appConfig.Scanner);
                scan.OnScanCoded += Scan_OnScanCoded;

                //OPC
                opc = fac.CreateOpcDevice(appConfig.Opc);
                opc.LineStopChangedAction = (s) =>
                {
                    ShowToAllForms(v => v.StopLine = s);
                };
                opc.NetChangedAction = (d, s) =>
                {
                    ShowToAllForms(m =>
                    {
                        m.PLCNet = s;
                    });
                };
                opc.ShieldChangedAction = s =>
                {
                    ShowToAllForms(m =>
                    {
                        m.ShieldStatus = !s;
                        m.PrintlnInfo(s ? "PLC屏蔽PC信号" : "PLC启动接收PC信号");
                    });
                };

                mwCard = fac.CreateCardDevice(appConfig.MwCard);
                Log.Information("设备初始化完成");
            }
            catch (Exception ex)
            {
                Log.Error("外设模块初始化出错," + ex.Message, ex);
            }
        }
Ejemplo n.º 2
0
        public Engine()
        {
            this.cardController = new CardController();
            this.cardFactory    = new CardFactory();

            this.writer = new Writer();
            this.reader = new Reader();
        }
Ejemplo n.º 3
0
 public GameHandler(ICardController cardController, IDatabase database, PokerTable pokerTable)
 {
     this.database        = database;
     this.cardController  = cardController;
     this.dealHandler     = new DealHandler(this.Database);
     this.betHandler      = new BetHandler(this.Database);
     this.pokerTable      = pokerTable;
     this.timerController = new TimerController(this.Database.Players[0]);
 }
Ejemplo n.º 4
0
 public Engine(PokerTable pokerTable, IDatabase database)
 {
     this.pokerTable      = pokerTable;
     this.database        = database;
     this.cardController  = new CardController(this.PokerTable, this.Database);
     this.chipsController = new ChipsController(this.PokerTable, this.Database);
     this.panelController = new PanelController(this.PokerTable, this.Database);
     this.GameHandler     = null;
 }
Ejemplo n.º 5
0
 private void HandleCardClicked(ICardController obj)
 {
     foreach (ICardController cardController in cardControllers)
     {
         if (cardController != obj)
         {
             cardController.Model.Alpha = 0.2f;
         }
     }
 }
Ejemplo n.º 6
0
    //called by the AI when playing a card
    private void AIPlayCard(ICardController card)
    {
        cardPlay.Play();
        GameObject playedCard = card.getPlayedCard(true);

        aiCards.Add(playedCard);
        Instantiate(playedCard, aiPlayArea.transform);
        aiTotal          = GetTotal(aiCards);
        aiTotalText.text = "" + aiTotal;
    }
Ejemplo n.º 7
0
        public MainForm(ScreenConfig config, MainViewModels viewModel, IAdamController iAdam, IOpcController iopc, ICardController iCard)
        {
            try
            {
                _screenConfig = config;
                ViewModel     = viewModel ?? new MainViewModels();
                adam          = iAdam;
                opc           = iopc;
                mwCard        = iCard;
                InitializeComponent();
                Load += FormForm_Load;
                adam.OnSensorTrigger += Adam_OnSensorTrigger;//开关\按钮信息
                mwCard.SwipedEvent   += MwCard_SwipedEvent;
                if (_screenConfig != null)
                {
                    lblAppName.Text = _screenConfig.Title;
                    if (_screenConfig.Part.Available)
                    {
                        panelPart.Visible = true;
                    }
                    if (config.Id != 0)
                    {
                        btClose.Visible = false;
                    }
                    theTitle = config.Title;
                }

                {
                    var dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
                    dataGridViewCellStyle1.Alignment          = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
                    dataGridViewCellStyle1.BackColor          = System.Drawing.SystemColors.Window;
                    dataGridViewCellStyle1.Font               = new System.Drawing.Font("宋体", 36F);
                    dataGridViewCellStyle1.ForeColor          = System.Drawing.SystemColors.ControlText;
                    dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
                    dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
                    dataGridViewCellStyle1.WrapMode           = System.Windows.Forms.DataGridViewTriState.False;
                    this.dataViewTd.DefaultCellStyle          = dataGridViewCellStyle1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Form:" + ex.Message);
            }
        }
Ejemplo n.º 8
0
    //Calculates which card in the AIs hand would be the best play
    private int AICalculateChoices(ICardController[] hand)
    {
        int bestChoice = -1; //value of -1 shows no decent choice was found, otherwise value will be the array index of the best card to play
        int bestTotal;

        if (aiTotal <= 20)
        {
            bestTotal = aiTotal;
        }
        else
        {
            bestTotal = 0;
        }
        int currentTotal;

        for (int i = 0; i < hand.Length; i++)
        {
            ICardController currentChoice = hand[i];
            if (currentChoice.IsSwitch())
            {
                bool switchBack = true;
                //Testing value of original card sign
                currentTotal = aiTotal + currentChoice.getValue();  //the total if this card were played
                if (currentTotal > bestTotal && currentTotal <= 20) //if playing this card would be the best option so far:
                {
                    if (playerHolding)
                    {
                        if (currentTotal > playerTotal)   //if playing this card would win this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                        }
                        else if (currentTotal == playerTotal && currentTotal > aiDrawThreshold)     //if playing this card would draw this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                        }
                    }
                    else if (currentTotal >= aiHoldThreshold && currentTotal >= playerTotal)
                    {
                        bestTotal  = currentTotal;
                        bestChoice = i;
                    }
                }

                currentChoice.OnSwitch();                           //switching card sign and testing value of new sign
                currentTotal = aiTotal + currentChoice.getValue();  //the total if this card were played
                if (currentTotal > bestTotal && currentTotal <= 20) //if playing this card would be the best option so far:
                {
                    if (playerHolding)
                    {
                        if (currentTotal > playerTotal)   //if playing this card would win this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                            switchBack = false;
                        }
                        else if (currentTotal == playerTotal && currentTotal > aiDrawThreshold)     //if playing this card would draw this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                            switchBack = false;
                        }
                    }
                    else if (currentTotal >= aiHoldThreshold && currentTotal >= playerTotal)
                    {
                        bestTotal  = currentTotal;
                        bestChoice = i;
                        switchBack = false;
                    }
                }

                if (switchBack)
                {
                    currentChoice.OnSwitch();             //if the first sign was better, switch the card back
                }
            }
            else
            {
                currentTotal = aiTotal + currentChoice.getValue();  //the total if this card were played
                if (currentTotal > bestTotal && currentTotal <= 20) //if playing this card would be the best option so far:
                {
                    if (playerHolding)
                    {
                        if (currentTotal > playerTotal)   //if playing this card would win this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                        }
                        else if (currentTotal == playerTotal && currentTotal > aiDrawThreshold)     //if playing this card would draw this round:
                        {
                            bestTotal  = currentTotal;
                            bestChoice = i;
                        }
                    }
                    else if (currentTotal >= aiHoldThreshold && currentTotal >= playerTotal)
                    {
                        bestTotal  = currentTotal;
                        bestChoice = i;
                    }
                }
            }
        }
        return(bestChoice);
    }