我想知道如何使我的程序可以添加scoreq [英] I'm wondering how to make it where my program can add a scoreq

查看:84
本文介绍了我想知道如何使我的程序可以添加scoreq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我想把它记录下来,我可以跟踪用户和计算机的胜利数量,我会附上程序看起来像的图像

http://imgur.com/SbxVB5T [ ^ ]



我想跟踪得分具有3D效果的标签,任何帮助都表示赞赏



  const   int  ROCK =  1 ; 
const int PAPER = 2 ;
const int SCISSORS = 3 ;
int userWinsCount;

private void rockButton_Click( object sender,EventArgs e)
{
int userChoice = ROCK;
userPictureBox.Image = Properties.Resources.Rock;

随机randomNumberGenerator = Random();
int computerChoice = randomNumberGenerator.Next( 1 4 );
switch (computerChoice)
{
case ROCK:
computerPictureBox.Image = Properties.Resources.Rock;
break ;

case PAPER:
computerPictureBox.Image = Properties.Resources.Paper;
break ;

case 剪刀:
computerPictureBox.Image = Properties.Resources.Scissors;
break ;
}


if (userChoice == 1 && computerChoice == 2
MessageBox.Show( 你输了!);

else if (userChoice == 1 && computerChoice == 1
{
MessageBox.Show( Tie!);
}
else if (userChoice == 1 && computerChoice == 3
{
MessageBox.Show( 你赢了!);
}
}

私人 void paperButton_Click( object sender,EventArgs e)
{
int userChoice = PAPER;
userPictureBox.Image = Properties.Resources.Paper;

随机randomNumberGenerator = Random();
int computerChoice = randomNumberGenerator.Next( 1 4 );
switch (computerChoice)
{
case ROCK:
computerPictureBox.Image = Properties.Resources.Rock;
break ;

case PAPER:
computerPictureBox.Image = Properties.Resources.Paper;
break ;

case 剪刀:
computerPictureBox.Image = Properties.Resources.Scissors;
break ;

}
if (userChoice == 2 && ; computerChoice == 1
MessageBox.Show( 你赢了!);

else if (userChoice == 2 && computerChoice == 3
{
MessageBox.Show( 你输了!);
}
else if (userChoice == 2 && computerChoice == 2
{
MessageBox.Show( Tie!);
}
}

私人 void scissorsButton_Click( object sender,EventArgs e)
{
int userChoice = SCISSORS;
userPictureBox.Image = Properties.Resources.Scissors;

随机randomNumberGenerator = Random();
int computerChoice = randomNumberGenerator.Next( 1 4 );
switch (computerChoice)
{
case ROCK:
computerPictureBox.Image = Properties.Resources.Rock;
break ;

case PAPER:
computerPictureBox.Image = Properties.Resources.Paper;
break ;

case 剪刀:
computerPictureBox.Image = Properties.Resources.Scissors;
break ;

}
if (userChoice == 3 && ; computerChoice == 1
MessageBox.Show( 你输了!);

else if (userChoice == 3 && computerChoice == 2
{
MessageBox.Show( 你赢了!);
}
else if (userChoice == 3 && computerChoice == 3
{
MessageBox.Show( Tie!);
}

解决方案

只是一个基本想法:

为...创建一个变量得分,并有一个标签,以便跟踪得分。

类似的东西,

  int 得分=  0 ; 
if (userChoice == 3 && computerChoice == 1
{
MessageBox.Show( 你输)!;
得分 - ;
}
else if (userChoice == 3 && computerChoice == 2
{
MessageBox.Show( 你赢了!);
得分++;
}
else if (userChoice == 3 && computerChoice == 3
{
MessageBox.Show( Tie!);
}

scoreLabel.Text =得分+ ;



对于3D效果,你可以谷歌一下。你会得到关于风格动画的建议,你可以使用它:)



-KR


0。建议:将'randomNumberGenerator'的声明移到'rockButton_Click方法之外。如果将其保留在方法中,则每次调用方法时都会生成相同的序列,直到基础默认种子发生更改。在文档中查找随机,并使用基于某些值更改的'种子值,例如:

  private  Random randomNumberGenerator =  new  Random(System.Environment.TickCount); 

1。为UserScore和ComputerScore创建单独的顶级变量:



private int UserScore {set;得到; }



private int ComputerScore {set;得到; }



我在这里使用了属性,因为我希望将来你可能希望保存(序列化)游戏。和...



2.属性的另一个用途是使用属性值的任何更改来更新UI元素;例如:

  //  假设有两个标签 
public 标签lblUserScore;
public 标签lblComputerScore;

private int _userscore;

public int UserScore
{
set
{
if value != _userscore)
{
_userscore = value ;
lblUserScore.Text = _userscore.ToString();
}
}
获取 {返回 _userscore; }
}


private int _computerscore;

public int ComputerScore
{
set
{
if value != _computerscore)
{
_computerscore = value ;
lblComputerScore.Text = _computerscore.ToString();
}
}
获取 {返回 _computerscore; }
}





2.对于3d效果按钮,您可以使用带有BackGround图像的按钮或面板与背景图像。这些CodeProject文章将向您展示实现花哨按钮的各种方法:[ ^


This is my code and I'm wanting to make it where I can keep track of the number of wins for the user and the computer, I will attach an image of what the program looks like
http://imgur.com/SbxVB5T[^]

I want to keep track of the score with the labels that have that 3D effect, any help is appreciated

const int ROCK = 1;
const int PAPER = 2;
const int SCISSORS = 3;
int userWinsCount;

private void rockButton_Click(object sender, EventArgs e)
{
    int userChoice = ROCK;
    userPictureBox.Image = Properties.Resources.Rock;

    Random randomNumberGenerator = new Random();
    int computerChoice = randomNumberGenerator.Next(1, 4);
    switch (computerChoice)
    {
        case ROCK:
            computerPictureBox.Image = Properties.Resources.Rock;
            break;

        case PAPER:
            computerPictureBox.Image = Properties.Resources.Paper;
            break;

        case SCISSORS:
            computerPictureBox.Image = Properties.Resources.Scissors;
            break;
    }


    if (userChoice == 1 && computerChoice == 2)
        MessageBox.Show("You lose!");

    else if (userChoice == 1 && computerChoice == 1)
    {
        MessageBox.Show("Tie!");
    }
    else if (userChoice == 1 && computerChoice == 3)
    {
        MessageBox.Show("You win!");
    }
}

private void paperButton_Click(object sender, EventArgs e)
{
    int userChoice = PAPER;
    userPictureBox.Image = Properties.Resources.Paper;

    Random randomNumberGenerator = new Random();
    int computerChoice = randomNumberGenerator.Next(1, 4);
    switch (computerChoice)
    {
        case ROCK:
            computerPictureBox.Image = Properties.Resources.Rock;
            break;

        case PAPER:
            computerPictureBox.Image = Properties.Resources.Paper;
            break;

        case SCISSORS:
            computerPictureBox.Image = Properties.Resources.Scissors;
            break;

    }
    if (userChoice == 2 && computerChoice == 1)
        MessageBox.Show("You win!");

    else if (userChoice == 2 && computerChoice == 3)
    {
        MessageBox.Show("You lose!");
    }
    else if (userChoice == 2 && computerChoice == 2)
    {
        MessageBox.Show("Tie!");
    }
}

private void scissorsButton_Click(object sender, EventArgs e)
{
    int userChoice = SCISSORS;
    userPictureBox.Image = Properties.Resources.Scissors;

    Random randomNumberGenerator = new Random();
    int computerChoice = randomNumberGenerator.Next(1, 4);
    switch (computerChoice)
    {
        case ROCK:
            computerPictureBox.Image = Properties.Resources.Rock;
            break;

        case PAPER:
            computerPictureBox.Image = Properties.Resources.Paper;
            break;

        case SCISSORS:
            computerPictureBox.Image = Properties.Resources.Scissors;
            break;

    }
    if (userChoice == 3 && computerChoice == 1)
        MessageBox.Show("You lose!");

    else if (userChoice == 3 && computerChoice == 2)
    {
        MessageBox.Show("You win!");
    }
    else if (userChoice == 3 && computerChoice == 3)
    {
        MessageBox.Show("Tie!");
    }

解决方案

Just a basic idea:
Create one variable for score, and have one label for it to keep track of the score.
Something like,

int score = 0;
if (userChoice == 3 && computerChoice == 1)
{
    MessageBox.Show("You lose!");
    score--;
}
else if (userChoice == 3 && computerChoice == 2)
{
    MessageBox.Show("You win!");
    score++;
}
else if (userChoice == 3 && computerChoice == 3)
{
    MessageBox.Show("Tie!");
}

scoreLabel.Text = score + "";


And for the 3d effect, you can google about it. You'll get the suggestion about animations for windforms, you can use it :)

-KR


0. suggestion: move your declaration of 'randomNumberGenerator outside the 'rockButton_Click method. If you leave it in the method, it's going to generate the same seqence every time the method is called until the underlying default "seed" changed. Look up 'Random in the docs, and use a 'seed value that's based on some value that changes, like:

private Random randomNumberGenerator = new Random(System.Environment.TickCount);

1. Create separate top-level variables for UserScore and ComputerScore:

private int UserScore { set; get; }

private int ComputerScore { set; get; }

I used properties here because I expect in the future you may wish to save (serialize) the game. and ...

2. Another use for properties is to use any change in the property value to update UI elements; for example:

// assuming two Labels
public Label lblUserScore;
public Label lblComputerScore;

private int _userscore;

public int UserScore
{
    set 
    {
        if(value != _userscore)
        {
            _userscore = value;
            lblUserScore.Text = _userscore.ToString();
        }
    }
    get { return _userscore; }   
}


private int _computerscore;

public int ComputerScore
{
    set 
    {
        if(value != _computerscore)
        {
            _computerscore= value;
            lblComputerScore.Text = _computerscore.ToString();
        }
    }
    get { return _computerscore; }   
}



2. for your 3d-effect buttons you can use a button with a BackGround Image, or a Panel with a background Image. These CodeProject articles will show you a variety of ways to achieve "fancy" buttons: [^]


这篇关于我想知道如何使我的程序可以添加scoreq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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