Exemplo n.º 1
0
        private async Task <Color> Mark(int i, int j)
        {
            var handler2 = client.Eth.GetContractQueryHandler <GetBoradSquareFunction>();
            var state    = new GetBoradSquareFunction();

            state.Row    = i;
            state.Column = j;
            var cellStatus = await handler2.QueryAsync <string>(state, contractAddress);

            if (cellStatus == "N")
            {
                SetMarkFunction mark = new SetMarkFunction();
                mark.Row    = i;
                mark.Column = j;
                var handler = client.Eth.GetContractTransactionHandler <SetMarkFunction>();
                var rr      = await handler.SendRequestAndWaitForReceiptAsync(mark, contractAddress);

                cellStatus = await handler2.QueryAsync <string>(state, contractAddress);

                if (cellStatus == "X")
                {
                    return(Xcolor);
                }
                else if (cellStatus == "O")
                {
                    return(Ocolor);
                }
            }
            return(Color.Transparent);
        }
Exemplo n.º 2
0
        private async void GetGameBoard()
        {
            try
            {
                if (GameReady == false)
                {
                    var status = new GameStatus();
                    var q      = client.Eth.GetContractQueryHandler <GameStatus>();
                    var ready  = await q.QueryAsync <bool>(status, contractAddress);

                    if (ready == true)
                    {
                        GameReady = true;
                    }
                    else if (BetTurn == false)
                    {
                        var am     = new BetAmount();
                        var bet    = client.Eth.GetContractQueryHandler <BetAmount>();
                        var result = await bet.QueryAsync <Int32>(am, contractAddress);

                        if (result != ProposedBet)
                        {
                            BetTurn = true;
                        }
                        tx_bet.Value = result;
                    }
                }
                if (GameReady == true)
                {
                    pn_bet.Enabled = false;
                    var handler1  = client.Eth.GetContractQueryHandler <GetWinnerFunction>();
                    var win       = new GetWinnerFunction();
                    var winResult = await handler1.QueryAsync <string>(win, contractAddress);

                    if (String.IsNullOrEmpty(winResult.ToString()) == false)
                    {
                        timer1.Stop();
                    }
                    pnl_Board.Enabled = true;
                    var handler2 = client.Eth.GetContractQueryHandler <GetBoradSquareFunction>();
                    var state    = new GetBoradSquareFunction();
                    state.Row    = 0;
                    state.Column = 0;
                    var cellStatus = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_00.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_00.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_00.BackColor = Color.Transparent;
                    }

                    state.Row    = 0;
                    state.Column = 1;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_01.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_01.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_01.BackColor = Color.Transparent;
                    }

                    state.Row    = 0;
                    state.Column = 2;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_02.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_02.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_02.BackColor = Color.Transparent;
                    }

                    state.Row    = 1;
                    state.Column = 0;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_10.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_10.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_10.BackColor = Color.Transparent;
                    }

                    state.Row    = 1;
                    state.Column = 1;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_11.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_11.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_11.BackColor = Color.Transparent;
                    }

                    state.Row    = 1;
                    state.Column = 2;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_12.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_12.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_12.BackColor = Color.Transparent;
                    }


                    state.Row    = 2;
                    state.Column = 0;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_20.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_20.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_20.BackColor = Color.Transparent;
                    }

                    state.Row    = 2;
                    state.Column = 1;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_21.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_21.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_21.BackColor = Color.Transparent;
                    }

                    state.Row    = 2;
                    state.Column = 2;
                    cellStatus   = await handler2.QueryAsync <string>(state, contractAddress);

                    if (cellStatus == "X")
                    {
                        bt_22.BackColor = Xcolor;
                    }
                    else if (cellStatus == "O")
                    {
                        bt_22.BackColor = Ocolor;
                    }
                    else if (cellStatus == "N")
                    {
                        bt_22.BackColor = Color.Transparent;
                    }

                    if (String.IsNullOrEmpty(winResult.ToString()) == false)
                    {
                        pnl_Board.Enabled = false;
                        pn_player.Enabled = true;
                        GameReady         = false;
                        MessageBox.Show(winResult);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }