Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Beginning form problems

$
0
0

Hello all,

I am currently in my first semester of C# programming and just starting the form portion. Our assignment was to turn a rock, paper scissors console game developed earlier in the semester and turn it into a forms app. I have most of it operational, however, no matter the outcome, the draw label appears instead of the win or lose label. Not sure if it is an if, else if problem or what. Also I have been researching, but can not find anything to help me reset the game to play again. If you could look at my code and offer suggestions where to start or where i am going wrong it would be appreciated.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RockPaperScissors
       
{
    public partial class rockPaperScissors : Form
    {
        public rockPaperScissors()
         
        {
            InitializeComponent();
            int compChoice;
            Random randomNumber=new Random();

            compChoice = randomNumber.Next(0, 3);

            switch (compChoice)
            {
                case 0:
                    
                    pbCompChoice.Image = Properties.Resources.rock;
                    
                    break;

                case 1:
                   
                    pbCompChoice.Image = Properties.Resources.sillouttepaper;
                    
                    break;
                case 2:
                    
                    pbCompChoice.Image = Properties.Resources.scirrorssilloutte;
                    
                    break;

            }
        }//End Rock Paper Scissors
       
          
       

     
        
       
        private void pbRock_Click(object sender, EventArgs e)
        {
            pbYourChoice.Image = Properties.Resources.rock;
           PlayGame();
           pbCompChoice.Visible = true;
        }

        private void pbPaper_Click(object sender, EventArgs e)
        {
            pbYourChoice.Image = Properties.Resources.sillouttepaper;
            PlayGame();
            pbCompChoice.Visible = true;
        }

        private void pbScissors_Click(object sender, EventArgs e)
        {
            pbYourChoice.Image = Properties.Resources.scirrorssilloutte;
            PlayGame();
            pbCompChoice.Visible = true;
        }//End pbRock Click

        public void PlayGame()
        {
            if ((pbYourChoice == pbPaper && pbCompChoice == pbRock) || (pbYourChoice == pbRock && pbCompChoice == pbScissors) || (pbYourChoice == pbScissors && pbCompChoice == pbPaper))
            {
                lblWin.Visible=true;
            }

            else if ((pbYourChoice == pbScissors && pbCompChoice == pbPaper) || (pbYourChoice == pbPaper && pbCompChoice == pbScissors) || (pbYourChoice == pbRock && pbCompChoice == pbPaper))
            {
                lblLose.Visible = true;
            }

            else
            {
                lblPush.Visible = true;
            }

            bttnPlayAgain.Visible = true;
        }

        private void bttnPlayAgain_Click(object sender, EventArgs e)
        {
            //pbYourChoice.Visible = false;
            //pbCompChoice.Visible = false;
            //new Random();
                      
            bttnPlayAgain.Visible=false;
        }



Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>