如何在课堂上定义卡片和总值? [英] How to define cards andtotal values in class?

查看:82
本文介绍了如何在课堂上定义卡片和总值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Non-invocable member cannot be used like a method

错误uri

名称ImageSource在当前上下文中不存在

卡不包含卡和总数的定义。

error for uri
The name ImageSource does not exist in the current context
card does not contain a definition for cards and total.

How to define cards andtotal values in class?



任何人都可以帮我解决这些错误吗?



我尝试过的事情:




Can anyone please help me with these Errors?

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Threading;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Data;
using System.ComponentModel;
using static System.Net.Mime.MediaTypeNames;
using System.IO;

namespace solitair
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        BackgroundWorker backgroundWorker1 = new BackgroundWorker();
        public MainWindow()
        {
            InitializeComponent();
            pbStatus.Visibility = Visibility.Hidden;
            Reset();

        }
        public void Reset()

        {

            Uri("image\\Cards\\back.png");

            ImgCard.Source = imageSource;

            OfCardstext.Content = "";

            Cardtext.Content = "";

            Totaltext.Content = "";

            ListHeader.Items.Clear();

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void hscroll_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Shuffle.Visibility = Visibility.Visible;

            pbStatus.Visibility = Visibility.Visible;
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            backgroundWorker1 = new BackgroundWorker();

            backgroundWorker1.DoWork += backgroundWorker1_DoWork;

            backgroundWorker1.ProgressChanged +=

            backgroundWorker1_ProgressChanged;

            backgroundWorker1.RunWorkerCompleted +=

            backgroundWorker1_RunWorkerCompleted;

            backgroundWorker1.WorkerReportsProgress = true;

            backgroundWorker1.WorkerSupportsCancellation = true;

            backgroundWorker1.RunWorkerAsync(100);
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

        {

            int result = 0;

            for (int i = 1; i <= 100; i++)

            {

                if (backgroundWorker1.CancellationPending)

                {

                    e.Cancel = true;

                    break;

                }

                Thread.Sleep(100);

                // Report progress.

                backgroundWorker1.ReportProgress(i);

                //TODO: your result code here

            }

            e.Result = result;

        }

        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)

        {

            int item = e.ProgressPercentage;

            // Change the value of the ProgressBar to the BackgroundWorker progress.

            pbStatus.Value = item;

            // Set the text.

        }

        void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

        {

            if (e.Cancelled)

            {

            }

            else

            {

                Random RMNumber = new Random();

                int Card = RMNumber.Next(1, 12);

                var CardCodes = new List<string> { " c", " d ", "s", " h" };

                Random RMChar = new Random();

                int index = RMChar.Next(CardCodes.Count);

                var Codes = CardCodes[index];

                String CardName = "image\\Cards\\" + Codes;


                if (Card > 10)

                {

                    CardName = CardName + Convert.ToString(Card) + ".png";

                }

                else

                {

                    CardName = CardName + "0" + Convert.ToString(Card) + ".png";

                }

                ImageSource imageSource = new BitmapImage(new Uri(CardName));

                ImgCard.Source = imageSource;

                string CardNm = "";

                if (Codes == "c")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Clubs";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Clubs";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Clubs";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Clubs";

                    }

                }

                else if (Codes == "d")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Diamonds";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Diamonds";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Diamonds";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Diamonds";

                    }

                }

                else if (Codes == "s")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Spades";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Spades";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Spades";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Spades";

                    }

                }

                else if (Codes == "h")

                {

                    if (Card == 11)

                    {

                        CardNm = "Jack of Hearts ";

                    }

                    else if (Card == 12)

                    {

                        CardNm = "Queen of Hearts";

                    }

                    else if (Card == 13)

                    {

                        CardNm = "King of Hearts";

                    }

                    else

                    {

                        CardNm = Convert.ToString(Card) + "of Hearts";

                    }

                }

                int total = 0;

                if (ListHeader.Items.Count> 0)

                {
                    total = Card + Convert.ToInt32(Totaltext.Content);

                    OfCardstext.Content = Convert.ToInt32(OfCardstext.Content) + 1;

                    Totaltext.Content = total;
                }



                else

                {

                    total = Card;

                    OfCardstext.Content = 1;

                    Cardtext.Content = Card;

                    Totaltext.Content = total;

                }

                Cardtext.Content = Card.ToString();

                ListHeader.Items.Add(new card { Cards = CardNm, Total = total });


            }

        }

    }
}

推荐答案

根据代码,我们无法确定确切的问题,但您的错误表明您的解决方案步骤明确



1 )当前上下文中不存在ImageSource名称



ImageSource 未在当前范围,你需要在你所在的位置声明

使用它或确保它在需要的地方可以访问。



2)卡片不包含卡片定义和tota l。



卡片中没有定义,总计



3)不可调用的成员不能像方法一样使用

评论Uri来自重置

By the bit of code, we can not identify exact issue but your error says your resolution steps clearly

1) The name ImageSource does not exist in the current context

ImageSource is not declared in the current scope, You need to declare at where you are
using same or make sure it should be accessible where it needed.

2) card does not contain a definition for cards and total.

There is no defination for cards and total in card

3) Non-invocable member cannot be used like a method
Comment Uri from reset
public void Reset()

{

// Uri("image\\Cards\\back.png");

ImgCard.Source = imageSource;

OfCardstext.Content = "";

Cardtext.Content = "";

Totaltext.Content = "";

ListHeader.Items.Clear();

}



并设置只更新你的bitmapimage代码这样


and set just update your bitmapimage code like this

BitmapImage myBitmapImage = new BitmapImage();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"your image path");


ImageSource imageSource = myBitmapImage


这篇关于如何在课堂上定义卡片和总值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆