C# - Create Rock Paper Scissors Game

How To Make a Rock Paper Scissors Game In C#

C# Rock Paper Scissors Game Source Code




in this C# tutorial we will see how to design and code a Rock Paper Scissors game using csharp programming language .

tools:
- c# programming language.
- microsoft visual studio express 2013.
- pixabay.com ( to get the images).

Watch This Full Demo



- The Project Source Code


using System;
using System.Collections;
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 rock_paper_scissors_game
{
    public partial class Game_Form : Form
    {
        public Game_Form()
        {
            InitializeComponent();
        }

        // images
        Bitmap rock = Properties.Resources.rock;
        Bitmap paper = Properties.Resources.paper;
        Bitmap scissors = Properties.Resources.scissors;
        Bitmap random_picture;

        // wins
        int player_wins = 0, computer_wins = 0;
        // a list of images
        ArrayList list = new ArrayList();
        // random to get a random image
        Random random = new Random();

        private void Game_Form_Load(object sender, EventArgs e)
        {
            pictureBoxRock.Image = Properties.Resources.rock;
            pictureBoxPaper.Image = Properties.Resources.paper;
            pictureBoxScissors.Image = Properties.Resources.scissors;

            // add images to the list
            list.Add(rock);
            list.Add(paper);
            list.Add(scissors);
        }

        private void pictureBoxRock_Click(object sender, EventArgs e)
        {
            // display rock image
            pictureBox_player.Image = rock;
            // get random image
            random_picture = (Bitmap)list[random.Next(list.Count)];
            // display the random image
            pictureBox_computer.Image = random_picture;
            // get the winner
            getWinner(rock, random_picture);
        }

        private void pictureBoxPaper_Click(object sender, EventArgs e)
        {
            // display paper image
            pictureBox_player.Image = paper;
            // get random image
            random_picture = (Bitmap)list[random.Next(list.Count)];
            // display the random image
            pictureBox_computer.Image = random_picture;
            // get the winner
            getWinner(paper, random_picture);
        }

        private void pictureBoxScissors_Click(object sender, EventArgs e)
        {
            // display rock image
            pictureBox_player.Image = scissors;
            // get random image
            random_picture = (Bitmap)list[random.Next(list.Count)];
            // display the random image
            pictureBox_computer.Image = random_picture;
            // get the winner
            getWinner(scissors, random_picture);
        }


        // create a function to get the winner
        public void getWinner(Bitmap player, Bitmap computer)
        {
            if(player.Equals(computer))
            {
                // it's a draw - the same image
            }
            else if(player.Equals(rock))
            {
                if(computer.Equals(scissors))
                {
                    player_wins++;
                    label_PlayerWins.Text = player_wins.ToString();
                }
                else
                {
                    computer_wins++;
                    label_ComputerWins.Text = computer_wins.ToString();
                }
            }
            else if(player.Equals(paper))
            {
                if(computer.Equals(rock))
                {
                    player_wins++;
                    label_PlayerWins.Text = player_wins.ToString();
                }
                else
                {
                    computer_wins++;
                    label_ComputerWins.Text = computer_wins.ToString();
                }
            }
            else if(player.Equals(scissors))
            {
                if(computer.Equals(paper))
                {
                    player_wins++;
                    label_PlayerWins.Text = player_wins.ToString();
                }
                else
                {
                    computer_wins++;
                    label_ComputerWins.Text = computer_wins.ToString();
                }
            }

        }

    }
}


OUTPUT:

Rock Paper Scissors Game In C#







Free VB.Net Projects Source Code

Download 9 VB.Net Project Source Code

Download VB.Net Project Source Code



here's a list of free vb.net projects source code + video tutorial / demo.

this list contains vb.net games, mini apps, form designs.

if you want to get premium vb.net projects source code click HERE .


 1 - VB.Net Quiz App Project Source Code 

VB.Net Quiz App Project Source Code

How to Make a Simple Quiz App Using Using WindowsForm, Panel, Button and RadioButtons In Visual Basic.Net Programming Language.


 2 - VB.Net Calculator Project Source Code 

VB.Net Calculator Project Source Code

How To Make A Simple Windows Form Calculator Application With Swith  To Do The Basic Operations (+, -, /, *) Using Visual Basic.Net In Visual Studio Editor.


 3 - VB.Net Login And Register Form Design In One Window Source Code 

VB.Net Login And Register Form Design In One Window Source Code

How to Design a Login and Register Form in One windowForm Using VB.Net Programming Language .


 4 - VB.Net Tic Tac Toe Game Source Code 

VB.Net Tic Tac Toe Game Source Code

How To Build A Tic-Tac-Toe Game With Replay And Get The Winner And Change Winning Boxes Color Using VB.Net Programming Language.


 5 - VB.Net Rock Paper Scissors Game Source Code 

VB.Net Rock Paper Scissors Game Source Code

How To Make a Rock Paper Scissors Game Project Using Visual Basic .Net.


 6 - VB.Net Login & Register Form With MySQL DataBase Source Code 

VB.Net Login & Register Form With MySQL DataBase Source Code

How to Create Login and Register Form in Visual Basic.Net with MySQL Database.


 7 - VB.Net Glass Bridge Game From Squid Game Source Code 

VB.Net Glass Bridge Game From Squid Game Source Code

How To Make The Glass Bridge Game From Squid Game In Visual Basic .Net Using Panels and PictureBoxes.


 8 - VB.Net Mini Project With MySQL Database 

VB.Net Mini Project With MySQL Database

VB.Net Mini Project - How To Insert Update Delete Search Display Images In SQL Database .


 9 - VB.Net Guess The Word Game Source Code 

VB.Net Guess The Word Game Source Code

How to Make a Simple Word Guessing Game App In VB.Net Programming Language..








if you want to download Premium VB.Net Projects source code, click on the download button below




Free Java Projects Source Code

Download 12 Java Project Source Code

Free Java Projects Source Code

here's a list of free java projects source code + video tutorial.

this list contains java games, mini apps, form designs.

if you want to get premium java projects source code click HERE .


 1 - JAVA Quiz App Project Source Code 

JAVA Quiz App Project Source Code

How to Make a Simple Quiz App Using  Jframe JPanels and JRadioButtons In Java NetBeans.


 2 - Java Calculator Project Source Code 

Java Calculator Project Source Code

How To Make A Calculator With Swith  To Do The Basic Operations (+, -, /, *) Using Java And Netbeans Editor.


 3 - Java Login And Register Form Design In One Window Source Code 

Java Login And Register Form Design In One Window Source Code

How To Design A Login Form And A Register Form In One Jframe Using JPanels In Java NetBeans .


 4 - Java Tic Tac Toe Game Source Code 

Java Tic Tac Toe Game Source Code

How To Build A Tic-Tac-Toe Game With Replay And Get The Winner And Change Winning Boxes Color Using Java And Netbeans Editor.


 5 - Java Design Login And Dashboard Form 

Java Design Login And Dashboard Form

How To Design A Login Form And A Dashboard Form In Java NetBeans.


 6 - Java Rock Paper Scissors Game Source Code 

Java Rock Paper Scissors Game Source Code

How to Make a Simple Rock, Paper, Scissors Game Using Jframe JPanels and Jlabels In Java NetBeans.


 7 - Java Login & Register Form With MySQL DataBase Source Code 

Java Login & Register Form With MySQL DataBase Source Code

How To Make a Design a Login Form And a Register Form, plus how to connect those two form with mysql database so the user can signup and signin.


 8 - Java Glass Bridge Game From Squid Game Source Code 

Java Glass Bridge Game From Squid Game Source Code

How to Make The Glass Stepping Stones Game or the glass bridge game From Squid Game Using JPanels and Jlabels In Java NetBeans .


 9 - Java Login & Menu Form Design Source Code 

Java Login & Menu Form Design Source Code

How To Design A Login Form And A Drop-Down Menu Form In Java NetBeans .


 10 - Java Guess The Word Game Source Code 

Java Guess The Word Game Source Code

How to Make a Simple Word Guessing Game App In Java NetBeans..


 11 - Java Login & Register Form Design Source Code (2) 

Java Login & Register Form Design Source Code (2)

how to design a login and register form in java netbeans and connect these two forms with mysql database.


 12 - Java Login & Register Form With Text File Source Code 

Java Login & Register Form With Text File Source Code

How To Design a Login And Register Form + how to use those two form with a text file so the user can signup and signin.






if you want to download Premium Java Projects source code, click on the download button below




C# Transparent Menu

How To Make a Transparent Menu Using C#

Transparent Menu In C#


In a Previous C# Tutorial We Did a Transparent Button and in This One We Will See How To Make a Transparent Horizontal Menu Using Panel and Buttons in C# Windows Form Application Using Visual Studio Editor .



WATCH THIS C# TUTORIAL


Project Source Code:


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 Csharp_Tutorials
{
    public partial class Transparent_Menu : Form
    {
        public Transparent_Menu()
        {
            InitializeComponent();
        }

        private void Transparent_Menu_Load(object sender, EventArgs e)
        {

           // set the panel that contains the buttons to transparent
            panel1.BackColor = Color.FromArgb(70, 0, 0, 0);

            // you can use this code for each buttons
            // or use the foreach loop

            // foreach control in the panel
            foreach (Control control in panel1.Controls)
            {
                // check if the control is a button
                if(control is Button)
                {
                    // convert the control to a button
                    Button btn = (Button) control;

                    // set the button style to flat
                    btn.FlatStyle = FlatStyle.Flat;

                    // set the background color for the button
                    btn.BackColor = Color.FromArgb(120, 0, 0, 0);

                    //button1.FlatAppearance.BorderColor = Color.FromArgb(200,255,255,255);

                    // set the border size
                    btn.FlatAppearance.BorderSize = 0;

                    // set a new background color on mouse over
                    btn.FlatAppearance.MouseOverBackColor = Color.FromArgb(140, 155, 89, 182);

                    // set a new background color on mouse down
                    btn.FlatAppearance.MouseDownBackColor = Color.FromArgb(180, 39, 174, 96);

                    // set button forColor
                    btn.ForeColor = Color.White;

                    // set the font size
                    btn.Font = new Font(btn.Font.FontFamily, 22);

                    // set the cursor to hand
                    btn.Cursor = Cursors.Hand;
                }
            }
        }
    }
}



OUTPUT:


How To Create a Transparent Menu In C#




Java Login And Register Form With Text File

How to Create Login and Register Form in Java NetBeans with Text File

Java Login And Register Form With Text File



In this Java Long Tutorial we will go step by step on How To Design a Login And Register Form, plus how to use those two form with a text file so the user can signup and signin.   

What We Are Gonna Use In This Project:

- Java Programming Language.
- NetBeans Editor.
- Text File.

What We Will Do In This Project:

- Design One Form For The Login and Signup Using JPanels and Borders.
- Add an Icon Using JLabels To Close The Form.
- add Data into the text File When User Register.
- Allow The User to Login.
- Check If The User Leave Some Fields Empty.
- Check If The User Enter Username That Already Exists.
- Check If The User Enter a Wrong Password In The Confirmation Field.  
- Create a Message orm To Display When An Error Occure or To Display Any Information.
- Create a Main Form to Display After The User Login.





Project Source Code:

   
        // create a border for the jpanel
    Border panel_border = BorderFactory.createMatteBorder(2, 2, 2, 2, Color.gray);
    // create a border for the textfields
    Border textfields_border = BorderFactory.createMatteBorder(0, 0, 2, 0, Color.white);
    // optional red border
    Border textfields_red_border = BorderFactory.createMatteBorder(0, 0, 2, 0, Color.red);
    // create a border for the jlabels
    Border lbl_border = BorderFactory.createMatteBorder(0, 0, 2, 0, Color.lightGray);
    // the file path -> C:\Users\1BestCsharp\Desktop\java_app
    String usersFilePath = "C:\\Users\\1BestCsharp\\Desktop\\java_app\\users.txt";
    // array of all usernames
    ArrayList<String> all_usernames = new ArrayList<>();
    // a hashmap of usernames and password
    Map<String, String> usernameANDpassword = new HashMap<>();
    // the message frame
    Message_Frame msgF = new Message_Frame();


    public Login_And_Register() {
        initComponents();
        
        // image link: https://pixabay.com/vectors/cross-no-x-forbidden-closed-42928/
        // display close images in jlabel
        displayImage();
        
        // center the form
        this.setLocationRelativeTo(null);
        
        // set borders
        jPanel_main.setBorder(panel_border);
        jLabel_login_title.setBorder(lbl_border);
        jLabel_register_title.setBorder(lbl_border);
        jTextField_login_username.setBorder(textfields_border);
        jPasswordField_login_pass.setBorder(textfields_border);
        jTextField_register_username.setBorder(textfields_border);
        jTextField_register_fullname.setBorder(textfields_border);
        jTextField_register_email.setBorder(textfields_border);
        jPasswordField_register_pass.setBorder(textfields_border);
        jPasswordField_register_confirmPass.setBorder(textfields_border);
        
        getUsers();
        
        // test
        /*
        for(String uname:all_usernames)
        {
            System.out.println(uname);
        }
        */
        
    }


    // create a function to get all users
    public void getUsers()
    {
       
        // the info structure will be like this
        /*
        Username: aaa
        Fullname: bbb ccc
        Email: abc@mail.com
        Password: pass123
        ---
        */
        
        File file = new File(usersFilePath);
        String username = "";
        String password = "";
        
        try {
            
            FileReader fr = new FileReader(file);
            BufferedReader br = new BufferedReader(fr);
            
            // read line by line from the text file
            Object[] lines = br.lines().toArray();
            for(int i = 0; i < lines.length; i++)
            {  
                // splite the row into two rows
                // one for the name of the field
                // and the other for the value of the field
                String[] row = lines[i].toString().split(": ");
                
                if(row[0].equals("Username"))
                {
                    // if it's the username field we will get the username
                    username = row[1];
                    // add the username to the all username array
                    all_usernames.add(username);
                }
                else if(row[0].equals("Password"))
                {
                    // if it's the password field we will get the password
                    password = row[1];
                }
                if(!username.equals("") && !password.equals(""))
                {
                    // add the username and the password to the hashmap
                    usernameANDpassword.put(username, password);
                }
                
            }

            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Login_And_Register.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }
    
    
    // create a function to check if the username already exist
    public boolean checkIfUsernameExist(String un)
    {
        boolean exist = false;
        
        for(String username: all_usernames)
        {
            if(username.equals(un))
            {
                exist = true;
            }
        }
        
        return exist;
    }
    
    
    // function to display image
    public void displayImage()
    {
        ImageIcon imgico = new ImageIcon(getClass().getResource("\\/images/x.png"));
        Image img = imgico.getImage().getScaledInstance(jLabel_close_.getWidth(), jLabel_close_.getHeight(), Image.SCALE_SMOOTH);
        jLabel_close_.setIcon(new ImageIcon(img));
    }


    private void jLabel_close_MouseClicked(java.awt.event.MouseEvent evt) {                                           
        // close the form
        this.dispose();
    }                                          

    private void jButton_register_ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        // get the textfields data
        String username = jTextField_register_username.getText().trim();
        String fullname = jTextField_register_fullname.getText().trim();
        String email = jTextField_register_email.getText().trim();
        String password = String.valueOf(jPasswordField_register_pass.getPassword()).trim();
        String confirm_password = String.valueOf(jPasswordField_register_confirmPass.getPassword()).trim();
        
        File file = new File(usersFilePath);
        
        try {
            // file = the file we want to write on
            // true = we wan to append the text on it
            FileWriter fw = new FileWriter(file, true);
            
            // we need to check if the textfields are empty
            // we need to check if the confirmation password equal the password
            // we need to check if the username already exist
          
            // check if the textfields are empty
            if( username.equals("") || fullname.equals("") || email.equals("") || password.equals("") )
            {
                System.out.println("One Or More Fields Are Empty");
                msgF.jLabel_Title.setText("Signup Error");
                msgF.jLabel_message.setText("One Or More Fields Are Empty");
            }
            else{
                // confirmation password
                if(password.equals(confirm_password))
                {
                    // check if the username already exist
                    if(!checkIfUsernameExist(username))
                    {
                        fw.write("Username: " + username);
                        fw.write(System.getProperty("line.separator"));
                        fw.write("Fullname: " + fullname);
                        fw.write(System.getProperty("line.separator"));
                        fw.write("Email: " + email);
                        fw.write(System.getProperty("line.separator"));
                        fw.write("Password: " + password);
                        fw.write(System.getProperty("line.separator"));
                        fw.write("---");
                        fw.write(System.getProperty("line.separator"));
                        fw.close(); 
                        // populate the array and hashmap
                        getUsers();
                        
                        msgF.jLabel_Title.setText("Signup");
                        msgF.jLabel_message.setText("You Have Created A New Account Successfully");
                        
                    }
                    else
                    {
                       System.out.println("This Username Already Exist, Try Another One");  
                       msgF.jLabel_Title.setText("Signup Error");
                       msgF.jLabel_message.setText("This Username Already Exist, Try Another One");
                    }

                }
                else
                {
                    System.out.println("Password Confirmation Error");
                    msgF.jLabel_Title.setText("Signup Error");
                    msgF.jLabel_message.setText("The Confirmation Password Does Not Match");
                }
            }
            
            msgF.setVisible(true);
            
        } catch (IOException ex) {
            Logger.getLogger(Login_And_Register.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }                                                 

    private void jButton_login_ActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // get the username and password
        // the hashmap is unorderd
        String username = jTextField_login_username.getText().trim();
        String password = String.valueOf(jPasswordField_login_pass.getPassword()).trim();
        boolean userExist = false;
        
        
        // check if the fields are empty
        if(username.equals("") || password.equals(""))
        {
            msgF.jLabel_Title.setText("Login Error");
            msgF.jLabel_message.setText("You Need To Enter The Username And Password");
            msgF.setVisible(true);
            
            // you can change the jpanel color
            // you can use if to check which one is empty
            // or you can change the border
            /*
            if(username.equals("")){
                //jPanel_username.setBackground(Color.red);
                jTextField_login_username.setBorder(textfields_red_border);
            }
            else if(password.equals("")){
                //jPanel_password.setBackground(Color.red);
                jPasswordField_login_pass.setBorder(textfields_red_border);
            }
            */
            
            
        }
        else
        { 
           for(String uname: usernameANDpassword.keySet())
           {
               // check if the username exist
            if(uname.equals(username))
            {
                // check if the password is correct
                if(usernameANDpassword.get(uname).equals(password))
                {
                    userExist = true;
                   System.out.println("Welcome To The Appliction");
                   /*
                   msgF.jLabel_Title.setText("Login Successfully");
                   msgF.jLabel_message.setText("Welcome To The Appliction");
                   */
                   // show the main app form
                   App_Main_Frame mainF = new App_Main_Frame();
                   mainF.jLabel_welcome_.setText("Welcome Back " + uname);
                   mainF.setVisible(true);
                   // close the login form
                   this.dispose();
                   // break out from the for loop
                   break;
                }
            }
            
           }// outside the for loop
           if(userExist == false)
                {
                   msgF.jLabel_Title.setText("Login Error");
                   msgF.jLabel_message.setText("This User Doesn't Exist");
                   msgF.setVisible(true);
                }
        }

    }                                              

    
    


////// OUTPUT : 

Java Login And Register Form With Text File

Java Login And Register Form With Text File

Java Login And Register Form With Text File



Java Login And Register Form With Text File



download the source code




More Java Projects: