6 Replies - 6677 Views - Last Post: 28 November 2012 - 02:06 PM Rate Topic: -----

#1 applemad20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 22-November 12

Rock Paper Scissors Task To Make WPF App

Posted 22 November 2012 - 01:09 PM

I need to create a WPf Application in c#. all of the progam will be in its own seperate class. Then the class used in the user interface.

So far my design is an application with 3 rectangles all blue and they have Rockk Paper Scissors images in them, beneath these i have buttons one for each option. when i click my option the rectabgle changes to red and then the computer makes an option randomly. Ive created my random method. But im stuck what to do now.

Is This A Good Question/Topic? 0
  • +

Replies To: Rock Paper Scissors Task To Make WPF App

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Rock Paper Scissors Task To Make WPF App

Posted 22 November 2012 - 01:21 PM

Well... To start with you did this backwards. You started with GUI and dragging out controls because that was not scary - THEN - you started thinking about design and code.

You really should plan first... diagram it all out on a whiteboard or pen and paper... then code when you know where you are going.

There isn't much we can do to help you with "I'm stuck now".

You might consider reading over the "Homework help" article linked in my signature block.
Was This Post Helpful? 0
  • +
  • -

#3 applemad20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 22-November 12

Re: Rock Paper Scissors Task To Make WPF App

Posted 23 November 2012 - 06:46 AM

Ive started to create a Rock Paper Scissors Game, Which Im doing in C# and it will be a WPF Application. So Far i have these classes on my program:

  • Main Window Class
  • RockPaperScissorsGame
  • And The UserInterface Window


The Basics Of The Program:

It has 3 buttons ROCK, PAPER and SCISSORS. And when the user clicks on what ever option a random computer generated choice is made then checks are made to see who wins.

Heres the code i have:

MAIN WINDWO CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
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;

namespace Rock_Paper_Scissors
{
    /// <summary>
    /// Interaction logic for Mainwindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        SolidColorBrush yellow;
        SolidColorBrush green;

        public MainWindow()
        {
            yellow = new SolidColorBrush(Color.FromArgb(255, 255, 255, 0));
            green = new SolidColorBrush(Color.FromArgb(255, 0, 255, 0));
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private void buttonRock_Click(object sender, RoutedEventArgs e)
        {
            rectangleRock.Fill = yellow;
        }

        private void buttonPaper_Click(object sender, RoutedEventArgs e)
        {
            rectanglePaper.Fill = yellow;
        }

        private void buttonScissors_Click(object sender, RoutedEventArgs e)
        {
            rectangleScissors.Fill = yellow;
        }
    }
}




ROCKPAPERSCISSORS CLASS
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rock_Paper_Scissors
{
    class RockPaperScissorsGame
    {

        Random computerRandom = new Random();

        int computerSelection;
        int userChoice;
        string ComputerSelectStrng;
    
        public void ComputerChoice()
        {
            int machineChoice = computerRandom.Next(1, 4);

            if (machineChoice == 1)
            {
                ComputerSelectStrng = "Rock";
            }

            if (machineChoice == 2)
            {
                ComputerSelectStrng = "Paper";
            }

            if (machineChoice == 3)
            {
                ComputerSelectStrng = "Scissors";
            }
        }

        public void WinnerCheck()
        {
            

        }

  
         

        
    }
}



i can get the game to work in a single class, but im struggling on getting the game to work on a different class. Here Is The Code For What I Made Previously:

        double result;
        
        Random randomNum = new Random();
        
         
       



        private void rock_Click(object sender, RoutedEventArgs e)
        {
                
               
                result = 0;
                result = (int)(randomNum.NextDouble() * 12) + 1;             
               
                    if (result <= 4)
                    {
                        MessageBox.Show("Its A Draw!");
                        
                    }

                    else if (result >= 8)
                    {
                        
                        MessageBox.Show("Paper Wins.");
                    }

                    else
                    {
                        
                        MessageBox.Show("Scissors Wins.");
                    }
                
            
        }
        private void paper_Click(object sender, RoutedEventArgs e)
        {
            
                result = 0;
                result = (int)(randomNum.NextDouble() * 12) + 1;

           
                    if (result <= 4)
                    {
                        MessageBox.Show("Its A Draw!");
                    }

                    else if (result >= 8)
                    {
                        
                        MessageBox.Show("Paper Wins!.");
                    }

                    else
                    {
                        
                        MessageBox.Show("Scissors Wins!!.");
                    }
                


            
        }

        private void scissors_Click(object sender, RoutedEventArgs e)
        {
  
           
                result = 0;
                result = (int)(randomNum.NextDouble() * 12) + 1;
                

                
               
                    if (result <= 4)
                    {
                        MessageBox.Show("Its A Draw!");
                    }

                    else if (result >= 8)
                    {
                        
                        MessageBox.Show("Paper Wins.");
                    }

                    else
                    {
                        
                        MessageBox.Show("Scissors Wins!!.");
                    }
                
            

        }
    }
        

        }



Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Rock Paper Scissors Task To Make WPF App

Posted 23 November 2012 - 07:33 AM

Please don't open multiple threads for the same topic.
Your two threads have been merged.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Rock Paper Scissors Task To Make WPF App

Posted 23 November 2012 - 07:38 AM

Quote

i can get the game to work in a single class, but im struggling on getting the game to work on a different class.


Struggling is part of learning in all fields not just coding.
There is virtually nothing in your RockPaperScissors class so we don't really have much to go on.

Did you have a question for us?

There is a tutorial on classes linked in my signature block. It should help you get a better grasp on the concepts.
Was This Post Helpful? 0
  • +
  • -

#6 applemad20   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 22-November 12

Re: Rock Paper Scissors Task To Make WPF App

Posted 28 November 2012 - 01:19 PM

Any Way To Delete This Topic The Work Is Now Done, The Mistake That I was Doing was not creating a new object of the RockPaperScissors Object.

Thanks tlhIn`toq The tutorials were helpful.
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Rock Paper Scissors Task To Make WPF App

Posted 28 November 2012 - 02:06 PM

We don't delete threads when they are resolved. This thread may help the next person who stumbles across it from doing a search.

Glad to have been of help to you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1