Skip to main content

Featured

Tic Tac Toe

Tic Tac Toe Tic Tac Toe is a simple, two-player strategy game played on a 3x3 grid. Players take turns marking a square with either an "X" or an "O", with the goal of being the first to align three of their marks in a row, column, or diagonal.  I have made a simple Tic Tac Toe game using html, css, javascript.  The game doesnot have much features. The game is created to be played by two peoples. It is just a simple game. The code of this game you get in my github page   Link of this game code is below: Tic Tac Toe Game Code /

Rock, Paper, Scissor Game in Java

We can make a simple rock, paper, scissor game in java. Heres, the code:


 import java.util.Scanner;

import javax.lang.model.util.ElementScanner14;

import java.util.Random;

public class App {

    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);

        Random rand = new Random();


        int rand_1 = rand.nextInt(3);


        System.out.println("\nRock, Paper, Scissior Game");

        int trial = 1;

        int player_score = 0;

        int computer_score = 0;


        while (trial<=5) {

            System.out.println("\n0) Rock");

            System.out.print("1) Paper");

            System.out.print("\n2) Scissior");


            System.out.print("\nEnter the choice number: ");

            int choice = scan.nextInt();

            

            // System.out.println(rand_1);


            if (choice == rand_1) {

                System.out.println("Player and Computer Selected Same ");

                // System.out.println("Computer Choice: "+ rand_1);

            } else {


                switch (choice) {

                    case 0:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<2){

                            if(0<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 1:

                        System.out.println("Computer choice: "+ rand_1);

                        if(0<rand_1){

                            if(1<rand_1){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        break;

                    case 2:

                        System.out.println("Computer choice: "+ rand_1);

                        if(rand_1<1){

                            if(rand_1<2){

                                System.out.println("Computer wins Match round "+ trial);

                                computer_score = computer_score+1;

                            }

                        }else{

                            System.out.println("Player wins Match round "+ trial);

                            player_score = player_score+1;

                        }

                        

                        break;

                    default:

                        System.out.println("Wrong input");

                        break;

                }   

            }

            trial = trial+1;

        }

        System.out.println("\nPlayer Score: "+ player_score);

        System.out.println("Computer Score: "+computer_score);

    

        if (player_score>computer_score) {

            int sp = player_score-computer_score;

            System.out.println("\nPlayer won the game by " + sp);

        } else if(computer_score>player_score) {

            int cp = computer_score-player_score;

            System.out.println("\nPlayer lose the game by "+cp);

        }else{

            System.out.println("\nNo one wins the game");

        }

    }


}


Comments

Popular Posts