Subscribe Our Channel

header ads

Search This Blog

Friday, July 28, 2023

HOW TO PRINT STAR IN JAVA LANGUAGE | JAVA PROGRAMMING | STAR DRAWING IN JAVA

 public class star{

public static void main(String[]args){

int s=29, p=1, p2=0, p3=30, p4=0, p5=20,s2=0;

for(int a=1; a<=30; a++){

for(int b=1; b<=s; b++){

if(a>9 & b==p4){

System.out.print("_");

}

else {

if (a==10 & b>=1) {

System.out.print("_");

}

else {

System.out.print(" ");

}

}

}

if (a==1) {

System.out.print("_");

}

for(int c=1; c<=p; c++) {

if(c==1^c==p^c==p2^c==p3) {

System.out.print("_");

}

else {

if(a==10){

System.out.print("_");

}

else {

System.out.print(" ");

}

}

}

if (a>9) {

p4=p4+2;

}

if (a>15) {

p2=p2+4;

p3=p3-2;

}

s=s-1;

p=p+2;

if(a>9 & a<18) {

for(int e=1; e<=p5; e++) {

if(e==p5) {

System.out.print("_");

}

else {

if (a==10) {

System.out.print("_");

}

else {

System.out.print(" ");

}

}

}

p5=p5-3;

s2=s2+1;

}

System.out.println();

}

}

}

Java - Calculate LCM (Least Common Multiple) using Java Program. | JAVA LANGUAGE | JAVA PROGRAMMING

 In this code snippet, we will find the LCM of given numbers using Java program.

LCM can be defined as any common multiple except 1, then it will always be greater than or equal to the maximum number. It cannot be less than it. LCM of two numbers is a number which is a multiple of both the numbers.


import java.util.Scanner;


public class Lcm {


    //  Lowest common Number

    public static int lcm(int First_number, int Second_number) {

        int x, max = 0, min = 0, lcm = 0;

        if (First_number > Second_number) {

            max = First_number;

            min = Second_number;

        } else {

            max = Second_number;

            min = First_number;

        }


        for (int i = 1; i <= min; i++) {

            x = max * i;

            if (x % min == 0) {

                lcm = x;

                break;

            }

        }

        return lcm;

    }


    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);


        System.out.print("First Number  :");

        int num1 = sc.nextInt();

        System.out.print("Second Number :");

        int num2 = sc.nextInt();


        System.out.println("Lowest Common Factor: " + lcm(num1, num2));


    }

}

Java - Greatest Common Factor or Euclidean Algorithm Program or Highest Common Factor. | JAVA PROGRAMMING | JAVA LANGUAGE

In this code snippet we will learn how to get Greatest Common Factor in Java, Implementation of Euclidean Algorithm to get Highest Common Factor.

The Euclidean algorithm is used to find the Greatest Common Factor and Highest Common Factor of two numbers. Highest Common Factor is calculated by divide both numbers with their common factor.


import java.util.Scanner;


public class HCF {


    //  greatest common factor

    public static int hcf(int First_number, int Second_number) {

        int hcf = 0;

        int min = Math.min(First_number, Second_number);


        for (int i = min; i >= 1; i--) {

            if (First_number % i == 0 && Second_number % i == 0) {

                hcf = i;

                break;

            }

        }

        return hcf;

    }


    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);


        System.out.print("First Number  :");

        int num1 = sc.nextInt();

        System.out.print("Second Number :");

        int num2 = sc.nextInt();


        System.out.println("Highest Common Factor: " + hcf(num1, num2));


    }

}

Java - Greatest Common Divisor or Euclidean Algorithm Program or Highest Common Divisor. | JAVA LANGUAGE | JAVA PROGRAMMING

 In this code snippet we will learn how to get Greatest Common Divisor in Java, Implementation of Euclidean Algorithm to get Highest Common Divisor.

The Euclidean algorithm is used to find the Greatest Common Divisor and Highest Common Divisor of two numbers. Greatest Common Divisor is calculated by divide both numbers with their common divisor.


public class Gcd {

    //  greatest common divisor

    public static int gcd(int First_number, int Second_number) {

        int i = First_number % Second_number;

        while (i != 0) {

            First_number = Second_number;

            Second_number = i;

            i = First_number % Second_number;

        }

        return Second_number;

    }


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        System.out.print("First Number  :");

        int num1 = sc.nextInt();

        System.out.print("Second Number :");

        int num2 = sc.nextInt();


        System.out.println("Greatest Common Divisors: " + gcd(num1, num2));


    }

}

Java - Calculate Compound Interest using Java Program. | JAVA PROGRAMMING | JAVA LANGUAGE

 In this code snippet we will learn how to calculate compound interest.

If Mike initially borrows an Amount and in return agrees to make n repayments per year, each of an Amount this amount now acts as a PRINCIPAL AMOUNT. While Mike is repaying the loan, interest is accumulating at an annual percentage rate, and this interest is compounded times a year (along with each payment). Therefore, Mike must continue paying these instalments of Amount until the original amount and any accumulated interest is repaid. This equation gives the Amount that the person still needs to repay after number of years.



CompoundInterest = Principal_Amount * Math.pow((1 + Interest_Rate/100), Time_Period);

import java.util.Scanner;

public class Compound_Interest {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        double Principal_Amount = 0.0;
        double Interest_Rate = 0.0;
        double Time_Period = 0.0;
        double CompoundInterest = 0.0;

        Scanner i = new Scanner(System.in);

        System.out.print("Enter the Principal Amount : ");
        Principal_Amount = i.nextDouble();

        System.out.print("Enter the Time Period : ");
        Time_Period = i.nextDouble();

        System.out.print("Enter the Interest Rate : ");
        Interest_Rate = i.nextDouble();

        CompoundInterest = Principal_Amount * Math.pow((1 + Interest_Rate / 100), Time_Period);

        System.out.println("");
        System.out.println("Compound Interest : " + CompoundInterest);
    }

}

Java example for do while loop demonstration. | JAVA LANGUAGE | JAVA PROGRAMMING

This program will demonstrate example of do while loop in java, the use of do while is similar to c programming language, here we will understand how do while loop works in java programming with examples.


do while Loop Example in Java

//Java program to print name 10 times using do while loop
 
public class PrintNames
{
    public static void main(String args[]){
         
        int loop; //loop counter declaration
        final String name="Mike"; //name as constant
         
        loop=1; //initialization of loop counter
        do{
            System.out.println(name);
            loop++; //increment
        }while(loop<=10);
         
    }
}


Programs 2) Print numbers from 1 to N.

//Java program to print numbers from 1 to N

import java.util.Scanner;

public class PrintNumbers {
    public static void main(String args[]) {
        int loop; //declaration of loop counter
        int N;

        Scanner SC = new Scanner(System.in);

        System.out.print("Enter value of N: ");
        N = SC.nextInt();

        loop = 1;
        do {
            System.out.print(loop + " ");
            loop++;
        } while (loop <= N);

    }
}

Java example for while loop demonstration. | JAVA LANGUAGE | JAVA PROGRAMMING

This program will demonstrate example of while loop in java, the use of while is similar to c programming language, here we will understand how while loop works in java programming with examples.

//Java program to print name 10 times using while loop


public class PrintNames {

    public static void main(String args[]) {


        int loop; //loop counter declaration

        final String name = "Mike"; //name as constant


        loop = 1; //initialization of loop counter

        while (loop <= 10) {

            System.out.println(name);

            loop++; //increment

        }

}

}


Programs 2) Print numbers from 1 to N.


//Java program to print numbers from 1 to N


import java.util.Scanner;


public class PrintNumbers {

    public static void main(String args[]) {

        int loop; //declaration of loop counter

        int N;


        Scanner SC = new Scanner(System.in);


        System.out.print("Enter value of N: ");

        N = SC.nextInt();


        loop = 1;

        while (loop <= N) {

            System.out.print(loop + " ");

            loop++;

        }


    }

}




Java program to demonstrate example of this keyword. | JAVA LANGUAGE | JAVA PROGRAMMING

This program will demonstrate use of this keyword, in this program we will see what will happen if we do not use this keyword even actual and formal arguments of the methods are same and what will happen if we will use this.


//Java program to demonstrate use of this keyword


public class ExThis {

    private String name;

    private int age;

    private float weight;


    //without using this keywords

    public void getDetailsWithoutThis(String name, int age, float weight) {

        name = name;

        age = age;

        weight = weight;

    }


    //using this keywords

    public void getDetailsWithThis(String name, int age, float weight) {

        this.name = name;

        this.age = age;

        this.weight = weight;

    }


    public void putDetails() {

        System.out.println("Name: " + name);

        System.out.println("Age: " + age);

        System.out.println("Weight: " + weight);

    }


    public static void main(String args[]) {

        //Object creation

        ExThis objExThis = new ExThis();


        objExThis.getDetailsWithoutThis("Mr. Neel", 25, 78.5 f);

        System.out.println("Values after get details using getDetailsWithoutThis():");

        objExThis.putDetails();


        objExThis.getDetailsWithThis("Mr. Neel", 25, 78.5 f);

        System.out.println("Values after get details using getDetailsWithThis():");

        objExThis.putDetails();

    }

}

Java program to check whether input number is EVEN or ODD | JAVA LANGUAGE | JAVA PROGRAMMING

To check number is EVEN or ODD: we will divide number by 2 and check remainder is ZERO or not, if remainder is ZERO, number will be EVEN others number will be ODD.


import java.util.*;


/* Java Program to check whether entered number is EVEN or ODD */


public class j6 {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        int num;


        //inpu

        System.out.print("Enter an integer number: ");

        num = sc.nextInt();


        //check EVEN or ODD

        if (num % 2 == 0) {

            System.out.println(num + " is an EVEN number.");

        } else {

            System.out.println(num + " is an ODD number.");

        }

    }

}

Java program to find sqare,cube and square root of a given number | JAVA LANGUAGE | JAVA PROGRAMMING

 Given an integer number and we have to find their Square, Square Root and Cube.

In this program, we are using these two methods of Math class:

1.Math.pow(m,n):It is used to get the power of any base, it will return m to the power of n (m^n).

2.Math.sqrt(m):It is used to get the square root of any number, it will return square root of m.


import java.util.*;

 

/*Java Program to find square, square root and cube of a given number*/

public class j5 

{

public static void main(String args[]){

Scanner sc=new Scanner(System.in);

int num;


System.out.print("Enter an integer number: ");

num=sc.nextInt();


System.out.println("Square of "+ num + " is: "+ Math.pow(num, 2));

System.out.println("Cube of "+ num + " is: "+ Math.pow(num, 3));

System.out.println("Square Root of "+ num + " is: "+ Math.sqrt(num));

}

}



Java program to find sum and average of two integer numbers. | JAVA PROGRAMMING | JAVA LANGUAGE

 Given (input) two integer numbers and we have to calculate their SUM and AVERAGE.

Through this program, we will learn following things:

• Taking integer inputs

• Performing mathematical operations

• Printing the values on output screen



import java.util.*;

class j4
{
    public static void main(String args[])
    {
        int a, b, sum;
        float avg;


        Scanner buf = new Scanner(System.in);

        System.out.print("Enter first number : ");
        a = buf.nextInt();

        System.out.print("Enter second number : ");
        b = buf.nextInt();

        /*Calculate sum and average*/
        sum = a + b;
        avg = (float)((a + b) / 2);

        System.out.print("Sum : " + sum + "\nAverage : " + avg);
    }
}

How to read and print an integer value in Java ? | JAVA PROGRAMMING | JAVA LANGUAGE

 Here, we will learn how to take an integer input from user and print on the screen, to take an integer value's input - we use Scanner class, for this we have to include java.util.* package in our Java program.



import java.util.*;


class j3 {

    public static void main(String args[]) {

        int a;


        //declare object of Scanner Class

        Scanner buf = new Scanner(System.in);


        System.out.print("Enter value of a :");

        /*nextInt() method of Scanner class*/

        a = buf.nextInt();


        System.out.println("Value of a:" + a);

    }

}

How to print different type of values in Java ? | JAVA PROGRAMMING | JAVA LANGUAGE

In this program, we are going to declare and define some of the different type of variables and then will print them using System.out.println() method.


 class j2 {

    public static void main(String args[]) {

        int num;

        float b;

        char c;

        String s;


        //integer

        num = 100;

        //float

        b = 1.234 f;

        //character

        c = 'A';

        //string

        s = "Hello Java";


        System.out.println("Value of num: " + num);

        System.out.println("Value of b: " + b);

        System.out.println("Value of c: " + c);

        System.out.println("Value of s: " + s);

    }

}

PRINT HELLO WORD IN JAVA | JAVA PROGRAMMING | LEARN JAVA LANGUAGE

 public class HelloWorld {

    public static void main(String[] args) {

        //printing the message

        System.out.println("Hello World!");

    }

}

Thursday, July 27, 2023

C++ PROGRAMMING CREATE CALCULATOR | CALCULATOR PROJECT IN C++ LANGUAGE | C++ PROJECT | HOW TO CREATE CALCULATOR IN C PROGRAMMING

 // _________ WELCOME ALL OF YOU ON COMPUTER SOFT SKILLS CHANNEL ___________

//______________ C++ PROGRAMMING CREATE CALCULATOR ____________


#include<stdio.h>

#include<conio.h>

#include<dos.h>

#include<graphics.h>

#include<stdlib.h>

int initmouse();


void showptr();

void hideptr();

void getmousepos(int *,int*,int*);

void restrictptr(int,int,int,int);

int button,x,y,x1,y1,x2,y2,s;

long double num=0,get,num1=0,result=0;

long double addnum(int);

char opr;

int a,b,r,i1,count,c,sq,newnum=1,d=0;

union REGS i,o;

void main()

{

int gd=DETECT,gm;

int q,p[12];

char input;

char *inpu[4][4]={"1","2","3","4","5","6","7","8","9","0","+","-" ,

   "*","/","clr","="};


char inp[4][4]={'1','2','3','4','5','6','7','8','9','0','+','-' ,

  '*','/','l','='};


  initgraph(&gd,&gm,"C:\\TC\\BGI");


  if(initmouse()==0)

  {

    printf("not");

    getch();

    exit(0);

  }


   setbkcolor(7);

  setfillstyle(2,9);

  bar(260,82,450,320);

  bar(430,70,450,320);


  setfillstyle(1,1);

  bar(236,82,432,300);

  setcolor(1);

  rectangle(238,50,430,80);

  rectangle(237,49,431,81);

  rectangle(236,48,432,82);


  c=240;

  d=100;

  s=0;


 for(a=0;a<4;a++)

  {

   c=240;


    for(b=0;b<4;b++)

    {

      setfillstyle(1,14);

      bar(c,d,c+40,d+40);


      setcolor(4);

      outtextxy(c+10,d+14,inpu[a][b]);


      c+=50;

    }


    d+=50;

  }


  showptr();

  num=0;

  gotoxy(36,5);


  printf("%18.1Lf",num);

    count=0;


while(!kbhit())

{

rectangle(20,10,618,468);

rectangle(25,15,615,463);

rectangle(30,20,610,458);


settextstyle(1,0,1);

setcolor(1);

outtextxy(45,390,"COMPUTER SOFT SKILLS");

setcolor(4);

outtextxy(125,410,"(ROHIT)");

setcolor(1);

outtextxy(45,435,"PRESS ANY KEY TO EXIT...");


  i1=0;

  c=240;

  d=100;


  rectangle(0,0,638,478);


  getmousepos(&button,&x,&y);


  for(a=0;a<4;a++)

  {

    c=240;

    for(b=0;b<4;b++)

    {


      if((x>=c&&x<=c+40)&&(y>=d&&y<=d+40))

       {


       if((button&1)==1)

{


     while((button&1)==1)

     {

       setcolor(10);

       rectangle(c,d,c+40,d+40);

       rectangle(c-1,d-1,c+41,d+41);

       rectangle(c-2,d-2,c+42,d+42);

       break;

       }


     delay(100);

     setcolor(1);

     rectangle(c,d,c+40,d+40);

     rectangle(c-1,d-1,c+41,d+41);

     rectangle(c-2,d-2,c+42,d+42);

     input=inp[a][b];

     switch(input)

     {

     case '1':


get=addnum(1);


gotoxy(36,5);

printf("%18.1Lf",get);


break;


     case '2':


get=addnum(2);


gotoxy(36,5);

printf("%18.1Lf",get);

break;


      case '3':


get=addnum(3);

gotoxy(36,5);


printf("%18.1Lf",get);

break;

       case '4':

get=addnum(4);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

     case '5':

get=addnum(5);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

     case '6':

get=addnum(6);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

     case '7':

get=addnum(7);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

   case '8':

get=addnum(8);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

   case '9':

get=addnum(9);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

   case '0':

get=addnum(0);

gotoxy(36,5);

printf("%18.1Lf",get);

break;

    case '+':

num1=num;

num=0;

opr='+';

gotoxy(36,5);

printf("%18.1Lf",num);

break;


  case '-':

num1=num;

num=0;

opr='-';

gotoxy(36,5);

printf("%18.1Lf",num);

break;


  case '*':

num1=num;

num=0;

opr='*';

gotoxy(36,5);

printf("%18.1Lf",num);

break;


  case '/':

num1=num;

num=0;

opr='/';

gotoxy(36,5);

printf("%18.1Lf",num);

break;


     case 'l':

num=0;

num1=0;

result=0;

count=0;

gotoxy(36,5);

printf("%18.1Lf",num);

break;


     case '=':

switch(opr)

{

   case '+':

if(count<1)

{

   result=num+num1;

}

else

{

   result=result+num;

}

gotoxy(36,5);

printf("%18.1Lf",result);

count+=1;

break;


   case '-':


if(count<1)

{

   result=num1-num;

}

else

{

   result=result-num;

}

gotoxy(36,5);

printf("%18.1Lf",result);

count+=1;

break;

   case '*':

if(count<1)

{

  result=num1*num;

}

else

{

  result=result*num;

}

gotoxy(36,5);

printf("%18.1Lf",result);

count+=1;

break;


   case '/':

   if(count<1)

   {

   result=num1/num;

   }

   else

   {

   result=result/num;

   }

     gotoxy(36,5);

     printf("%18.1Lf",result);

     count+=1;

     break;

     }

     }

     }

     }


  c+=50;

    }


  d+=50;

  }

  setcolor(5);

  delay(150);

}

}

long double addnum(int getnum)

{

    num=num*10+getnum;

    return(num);

}

int initmouse()

{

    i.x.ax=0;

    int86(0x33,&i,&o);

    return(o.x.ax);

}


void showptr()

{

   i.x.ax=1;

   int86(0x33,&i,&o);

}

void hideptr()

{

   i.x.ax=2;

   int86(0x33,&i,&o);

}

void restrictptr(int x1,int y1,int x2,int y2)

{

    i.x.ax=7;

    o.x.cx=x1;

    o.x.dx=x2;

    int86(0x33,&i,&o);

    i.x.ax=8;

    o.x.cx=y1;

    o.x.dx=y2;

    int86(0x33,&i,&o);

}

void getmousepos(int *button,int *x,int *y)

{

  i.x.ax=3;

  int86(0x33,&i,&o);

  *button=o.x.bx;

  *x=o.x.cx;

  *y=o.x.dx;

}




//____________ I HOPE YOU LIKE THIS PROGRAMMING VIDEO ___________________


//____________ LIKE __________ SHARE __________ SUBSCRIBE __________________

CALCULATOR PROJECT IN PYTHON TURTLE GRAPHICS | PYTHON TURTLE PROJECT | HOW TO MAKE CALCULATOR IN PYTHON TURTLE

 #___________ WELCOME ALL OF YOU ON COMPUTER SOFT SKILLS CHANEEL __________

#......................... PYTHON PROGRAM TO CREATE CALCULATOR ....................



import turtle


wn = turtle.Screen()

wn.screensize(450,700)                      

wn.setup(450,700,None,None)

wn.title("COMPUTER SOFT SKILLS :- CALCULATOR PROJECT")

wn.bgcolor("aqua")


a = 45

b = 95

wn.register_shape("box", ((a,a), (-a,a), (-a,-a), (a,-a), (a,a), (a,-a), (-a,-a), (-a,a), (a,a)))

wn.register_shape("rect", ((a,b), (-a,b), (-a,-b), (a,-b), (a,b), (a,-b), (-a,-b), (-a,b), (a,b)))


wn.delay(0)

global butn

butn = []


locx = -150

locy = -175

oh = 100


butn.append(turtle.Turtle())

butn[0].penup()


#make turtles update as fast as possible

butn[0].color('blue')

butn[0].speed(0)

butn[0].shape('box')

butn[0].goto(locx+0*oh, locy+0*oh)

for i in range(1,16):

    butn.append(butn[0].clone())

for i in range(0,16):

    butn[i].goto(butn[i].xcor(),locy+i//4*oh)

for i in range(0,4):

    butn[i+0 ].goto(locx+i*oh,butn[i+0 ].ycor())

    butn[i+4 ].goto(locx+i*oh,butn[i+4 ].ycor())

    butn[i+8 ].goto(locx+i*oh,butn[i+8 ].ycor())

    butn[i+12 ].goto(locx+i*oh,butn[i+12 ].ycor())


#zero button

global but0

but0 = turtle.Turtle()

but0.penup()

but0.color('blue')

but0.speed(0)

but0.shape('rect')

but0.goto(locx+.5*oh, locy-1*oh)


#decimal button

global butdot

butdot = turtle.Turtle()

butdot.penup()

butdot.color('blue')

butdot.speed(0)

butdot.shape('box')

butdot.goto(locx+2*oh, locy-1*oh)


#calculate button

global buteq

buteq = turtle.Turtle()

buteq.penup()

buteq.color('red')

buteq.speed(0)

buteq.shape('box')

buteq.goto(locx+3*oh, locy-1*oh)


#labels

for i in range(0,16):

    if i<3:

        butn[i].write(str(i+1), False, "center", ("Monaco",26,"bold"))

    elif 3<i<7:

        butn[i].write(str(i),   False, "center", ("Monaco",26,"bold"))

    elif 7<i<11:

        butn[i].write(str(i-1), False, "center", ("Monaco",26,"bold"))

but0.write    (" 0 ", False, "center", ("Monaco",28,"bold"))

butn[3].write (" + ", False, "center", ("Monaco",28,"bold"))

butn[7].write (" – ", False, "center", ("Monaco",28,"bold"))

butn[11].write(" x ", False, "center", ("Monaco",28,"bold"))

butn[15].write(" ÷ ", False, "center", ("Monaco",28,"bold"))

butn[12].write(" AC ", False, "center", ("Monaco",28,"bold"))

butn[13].write("+/-", False, "center", ("Monaco",28,"bold"))

butn[14].write("exp", False, "center", ("Monaco",28,"bold"))

butdot.write  (" . ", False, "center", ("Monaco",28,"bold"))

buteq.write   (" = ", False, "center", ("Monaco",28,"bold"))


global printer

printer = turtle.Turtle()

printer.penup()

printer.ht()

printer.goto((locx+3.5*oh)-2, locy+4*oh)

printer.pendown()

printer.write("0", False, "right", ("Monaco",32,"normal"))


global cursor

cursor = turtle.Turtle()

cursor.speed(0)

cursor.pu()

cursor.ht()


oldpos = cursor.pos()


#declare variables

var1 = ""

var2 = ""

oper = ""

temp2 = ""

temopr = ""


def calculate(var1,var2,oper):

if var1 == "":

var1 = "0"

if var2 != "":

if   oper[len(oper)-1]=="+":

var1 = str(float(var1)+ float(var2))

if var1[len(var1)-2:len(var1)] == ".0":

var1 = var1[0:len(var1)-2]

elif oper[len(oper)-1]=="–":

var1 = str(float(var1)- float(var2))

if var1[len(var1)-2:len(var1)] == ".0":

var1 = var1[0:len(var1)-2]

elif oper[len(oper)-1]=="x":

var1 = str(float(var1)* float(var2))

if var1[len(var1)-2:len(var1)] == ".0":

var1 = var1[0:len(var1)-2]

elif oper[len(oper)-1]=="÷":

var1 = str(float(var1)/ float(var2))

if var1[len(var1)-2:len(var1)] == ".0":

var1 = var1[0:len(var1)-2]

elif oper        =="\npwr(":

var1 = str(float(var1)**float(var2))

if var1[len(var1)-2:len(var1)] == ".0":

var1 = var1[0:len(var1)-2]

for i in range (10):

    err = var1.find(str(i)+str(i)+str(i)+str(i))

    decpt = var1.find('.')

    if err != -1 and err > decpt:

        if i != 0:

            var1 = var1[0:decpt]

        else:

            var1 = var1[0:decpt+4]

    

return var1


def myMainloop(x,y):

    global oldpos, var1, var2, oper, temp2, temopr

    cursor.goto(x,y)

    #Clear

    if cursor.xcor() in range ((butn[12].xcor()-45),(butn[12].xcor()+45)) and cursor.ycor() in range (butn[12].ycor()-45,butn[12].ycor()+45):

        if var2!="":

            var2=""

            oper=""

        elif var1!="":

            var1=""

            oper=""

            butn[12].clear()

            butn[12].write(" AC ", False, "center", ("Monaco",28,"bold"))

        else:

            var1=""

            var2=""

            oper=""

        printer.clear()

        printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

        print(var1,oper,var2)


    

    elif oper == "" or oper == "=":

        #First Variable

        vary = var1

        if cursor.xcor()   in range ((butn[3].xcor()-45), (butn[3].xcor()+45))  and cursor.ycor() in range (butn[3].ycor()-45,butn[3].ycor()+45):

            printer.clear()

            oper = "\n+"

            printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[7].xcor()-45), (butn[7].xcor()+45))  and cursor.ycor() in range (butn[7].ycor()-45,butn[7].ycor()+45):

            printer.clear()

            oper = "\n–"

            printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[11].xcor()-45),(butn[11].xcor()+45)) and cursor.ycor() in range (butn[11].ycor()-45,butn[11].ycor()+45):

            printer.clear()

            oper = "\nx"

            printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[14].xcor()-45),(butn[14].xcor()+45)) and cursor.ycor() in range (butn[14].ycor()-45,butn[14].ycor()+45):

            printer.clear()

            oper = "\npwr("

            printer.write(var1 + oper + ")", False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[15].xcor()-45),(butn[15].xcor()+45)) and cursor.ycor() in range (butn[15].ycor()-45,butn[15].ycor()+45):

            printer.clear()

            oper = "\n÷"

            printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[13].xcor()-45),(butn[13].xcor()+45)) and cursor.ycor() in range (butn[13].ycor()-45,butn[13].ycor()+45):

            printer.clear()

            if var1[0]!="-":

                var1 = "-" + var1

            else:

                var1 = var1[1:len(var1)]

            printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        

        elif cursor.xcor() in range ((butn[5].xcor()-145),butn[5].xcor()+145) and cursor.ycor() in range (butn[5].ycor()-145,butn[5].ycor()+145):

            if oper == "=":

                var1 = ""

                oper = ""

                temopr = ""

                var2 = ""

            if var1 == "0":

                var1 = ""

            for button in range(0,16):

                if button<3:

                    if cursor.xcor() in range ((butn[button].xcor()-45),(butn[button].xcor()+45)) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var1 += str(button+1)

                        printer.write(var1, False, "right", ("Monaco",32,"normal"))

                        print(var1)

                elif 3<button<7:

                    if cursor.xcor() in range ((butn[button].xcor()-45),butn[button].xcor()+45) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var1 += str(button)

                        printer.write(var1, False, "right", ("Monaco",32,"normal"))

                        print(var1)

                elif 7<button<11:

                    if cursor.xcor() in range (butn[button].xcor()-45,butn[button].xcor()+45) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var1 += str(button-1)

                        printer.write(var1, False, "right", ("Monaco",32,"normal"))

                        print(var1)

        elif ((but0.xcor()-90) < cursor.xcor() < (but0.xcor()+90)) and cursor.ycor() in range (but0.ycor()-45,but0.ycor()+45):

            if oper == "=":

                oper = ""

                var1 = ""

                temopr = ""

                var2 = ""

            if var1 == "0":

                var1 = ""

            printer.clear()

            var1 += "0"

            printer.write(var1, False, "right", ("Monaco",32,"normal")) 

            print(var1)

        elif ((butdot.xcor()-45) < cursor.xcor() < (butdot.xcor()+45)) and cursor.ycor() in range (butdot.ycor()-45,butdot.ycor()+45):

            if oper == "=":

                oper = ""

                var1 = ""

                temopr = ""

                var2 = ""

            printer.clear()

            var1 += "."

            printer.write(var1, False, "right", ("Monaco",32,"normal"))

            print(var1)

        elif ((buteq.xcor()-45) < cursor.xcor() < (buteq.xcor()+45)) and cursor.ycor() in range (buteq.ycor()-45,buteq.ycor()+45):

            printer.clear()

            if temp2 != "" and var1 != "" and len(temopr)>0:

                var1 = calculate(var1,temp2,temopr)

            printer.write(var1, False, "right", ("Monaco",32,"normal"))

            oper = "="

        if vary != var1:

            butn[12].clear()

            butn[12].write(" C ", False, "center", ("Monaco",28,"bold"))

    

        

    elif oper != "" and oper != "=":

        #Second Variable

        if ((but0.xcor()-90) < cursor.xcor() < (but0.xcor()+90)) and cursor.ycor() in range (but0.ycor()-45,but0.ycor()+45):

            printer.clear()

            if oper != "\n÷" or var2 != "":

                if var1 == "0":

                    var1 = ""

                var2 += "0"

                if oper == "\npwr(":

                    printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

                else:

                    printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            else:

                printer.write(var1 + oper + "Can't Divide", False, "right", ("Monaco",32,"normal"))

            print(var2)

        elif ((butdot.xcor()-45) < cursor.xcor() < (butdot.xcor()+45)) and cursor.ycor() in range (butdot.ycor()-45,butdot.ycor()+45):

            printer.clear()

            var2 += "."

            if oper == "\npwr(":

                printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

            else:

                printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            print(var2)

        elif cursor.xcor() in range ((butn[5].xcor()-145),butn[5].xcor()+145) and cursor.ycor() in range (butn[5].ycor()-145,butn[5].ycor()+145):

            for button in range(0,16):

                if button<3:

                    if cursor.xcor() in range ((butn[button].xcor()-45),(butn[button].xcor()+45)) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var2 += str(button+1)

                        if oper == "\npwr(":

                            printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

                        else:

                            printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

                        print(var1 + oper + var2)

                elif 3<button<7:

                    if cursor.xcor() in range ((butn[button].xcor()-45),butn[button].xcor()+45) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var2 += str(button)

                        if oper == "\npwr(":

                            printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

                        else:

                            printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

                            print(var1 + oper + var2)

                elif 7<button<11:

                    if cursor.xcor() in range (butn[button].xcor()-45,butn[button].xcor()+45) and cursor.ycor() in range (butn[button].ycor()-45,butn[button].ycor()+45):

                        printer.clear()

                        var2 += str(button-1)

                        if oper == "\npwr(":

                            printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

                        else:

                            printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

                            print(var1 + oper + var2)

        elif ((buteq.xcor()-45) < cursor.xcor() < (buteq.xcor()+45)) and cursor.ycor() in range (buteq.ycor()-45,buteq.ycor()+45):

            printer.clear()

            var1 = calculate(var1,var2,oper)

            printer.write(var1, False, "right", ("Monaco",32,"normal"))

            temp2 = var2

            temopr = oper

            var2 = ""

            oper = "="

        elif cursor.xcor() in range ((butn[3].xcor()-45),(butn[3].xcor()+45)) and cursor.ycor() in range (butn[3].ycor()-45,butn[3].ycor()+45):

            #add

            printer.clear()

            if var2=="":

                oper = "\n+"

                printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            else:

                var1 = calculate(var1,var2,oper)

                var2 = ""

                oper = "\n+"

                printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[7].xcor()-45),(butn[7].xcor()+45)) and cursor.ycor() in range (butn[7].ycor()-45,butn[7].ycor()+45):

            #subtract

            printer.clear()

            if var2=="":

                oper = "\n-"

                printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            else:

                var1 = calculate(var1,var2,oper)

                var2 = ""

                oper = "\n-"

                printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[11].xcor()-45),(butn[11].xcor()+45)) and cursor.ycor() in range (butn[11].ycor()-45,butn[11].ycor()+45):

            #multiply

            printer.clear()

            if var2=="":

                oper = "\nx"

                printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            else:

                var1 = calculate(var1,var2,oper)

                var2 = ""

                oper = "\nx"

                printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[15].xcor()-45),(butn[15].xcor()+45)) and cursor.ycor() in range (butn[15].ycor()-45,butn[15].ycor()+45):

            #divide

            printer.clear()

            if var2=="":

                oper = "\n÷"

                printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))

            else:

                var1 = calculate(var1,var2,oper)

                var2 = ""

                oper = "\n÷"

                printer.write(var1 + oper, False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[14].xcor()-45),(butn[14].xcor()+45)) and cursor.ycor() in range (butn[14].ycor()-45,butn[14].ycor()+45):

                #exponent

                if var2=="":

                        printer.clear()

                        oper = "\npwr("

                        printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

        elif cursor.xcor() in range ((butn[13].xcor()-45),(butn[13].xcor()+45)) and cursor.ycor() in range (butn[13].ycor()-45,butn[13].ycor()+45):

            printer.clear()

            if var2 == "":

                var2 = "0"

            if var2[0]!="-":

                var2 = "-" + var2

            else:

                var2 = var2[1:len(var2)]

            if oper == "\npwr(":

            printer.write(var1 + oper + var2 + ")", False, "right", ("Monaco",32,"normal"))

            else:

            printer.write(var1 + oper + var2, False, "right", ("Monaco",32,"normal"))    

            

    oldpos = cursor.pos()


wn.onclick(myMainloop)

wn.listen()

wn.mainloop()



#________________________ I HOPE YOU LIKE THIS PROGRAMMING _______________


#________________LIKE _________________SHARE _________________SUBSCRIBE ________________


Tuesday, July 25, 2023

CAR RACING GAME IN C++ PROGRAM, C++ PROJECT

 // WELOCME ALL OF YOU ON ROHIT TECH STUDY CHANNEL //

// CAR RACING GAME IN C++ PROGRAM //

/*****************************************************************************/

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

#include<process.h>

#include<stdlib.h>


void enemycar(int x, int y)

 {

  setcolor(15);

  rectangle(x+1,y,x+49,y+100);

  rectangle(x+1,y+25,x+49,y+75);

  setfillstyle( SOLID_FILL,CYAN);

  floodfill((x+x+50)/2,(y+y+100)/2,15);

  setfillstyle(1,MAGENTA);

  floodfill((x+x+50)/2,(y+y+40)/2,15);

  floodfill((x+x+50)/2,(y+y+160)/2,15);

  }


void mycar(int x, int y)

 {

  setcolor(15);

  rectangle(x+1,y,x+49,y+100);

  rectangle(x+1,y+25,x+49,y+75);

  setfillstyle(5,YELLOW);

  floodfill((x+x+50)/2,(y+y+100)/2,15);

  setfillstyle(2,RED);

  floodfill((x+x+50)/2,(y+y+40)/2,15);

  floodfill((x+x+50)/2,(y+y+160)/2,15);

  }


void myclear(int x,int y)

 {

 setcolor(8);

 rectangle(x+1,y,x+49,y+100);

 rectangle(x+1,y+25,x+49,y+75);

 setfillstyle(SOLID_FILL,8);

 floodfill((x+x+50)/2,(y+y+100)/2,8);

 floodfill((x+x+50)/2,(y+y+40)/2,8);

 floodfill((x+x+50)/2,(y+y+160)/2,8);

 }


 void enemyclear(int x,int y)

 {

 setcolor(8);

 rectangle(x+1,y,x+49,y+100);

 rectangle(x+1,y+25,x+49,y+75);

 }


void main()

 {

 int gdriver = DETECT,gmode;

 initgraph(&gdriver,&gmode,"C:\\TC\\BGI");

 int x=300,y=350,ch,life=3,score=0;

  char choice;

  cout<<"\n\n\n\n\n\t\t\t* THUNDER RACER *";

  cout<<"\n\t\t\t ---------------";

  cout<<"\n\n\tLong long ago the state of Valencia was attacked by the";

  cout<<"\n\n\tenemies and were defeated. Every soldier and citizen was";

  cout<<"\n\n\tkilled except the beautiful princess Cindrella  and you";

  cout<<"\n\n\twho survived. Enemies want to kill her and she is in your";

  cout<<"\n\n\tcar right now. If you have the guts save her from enemies'";

  cout<<"\n\n\tcars and marry her.";

  cout<<"\n\n\tSo all the best...";

  delay(400);

  for(int m=1;m<25;m++)

  for(int n=1;n<80;n++) {

  gotoxy(n,m);

  cout<<" ";

  }

  setcolor(RED);

  rectangle(20,60,200,120);

  rectangle(20,300,200,420);

  gotoxy(5,21);

  cout<<"CAR RACING GAME";

  gotoxy(5,22);

  cout<<"ENJOY GAME";

  gotoxy(5,23);

  cout<<"MODIFY GAME BY";

  gotoxy(5,24);

  cout<<"ROHIT TECH STUDY";

  rectangle(249,0,401,getmaxy());

  setfillstyle(SOLID_FILL,8);

  floodfill(325,getmaxy()/2,RED);

  setcolor(RED);

  rectangle(20,200,200,250);

  gotoxy(5,15);

  cout<<"Press <Esc> to Exit";

  for(int level=1;(level<=5)&&(life>0);level++){

    if(level==1){

      gotoxy(5,5);

      cout<<"Your War Starts Now";

      gotoxy(5,7);

      cout<<"All the best";

      delay(500);

      gotoxy(5,5);

      cout<<"                    ";

      gotoxy(5,7);

      cout<<"            ";

      }

     else {

         gotoxy(5,5);

         cout<<"Next level.";

         delay(500);

         gotoxy(5,5);

         cout<<"           ";

         }

  for(int i=0;(i<15)&&(life>0);i++) {

    if((level==5)&&(i==14)){

       gotoxy(5,5);

       cout<<"You have won";

       gotoxy(5,6);

       cout<<"Wanna continue <y/n>";

       choice = getch();

       if ((choice=='y')||(choice=='Y'))

        main();

       else

        exit(0);

       }

    setcolor(RED);

    rectangle(420,125,600,175);

    gotoxy(55,10);

    cout<<"Level = "<<level;

    rectangle(420,250,600,300);

    gotoxy(55,18);

    cout<<"Lives = "<<life;

    rectangle(420,350,600,400);

    gotoxy(55,24);

    cout<<"Score = "<<score;

    int accident=0;

    int y1=1,x1=250+((rand()%3)*50);

    int y2=1,x2=250+((rand()%3)*50);

    score += 10;

    while(y1<getmaxy()-1)

    {


        enemyclear(x1,y1);

        enemyclear(x2,y2);

        y1++;

        y2++;

        if(accident == 1)

            break;

        enemycar(x1,y1);

        enemycar(x2,y2);

        mycar(x,y);

        delay(5-level);

        if(kbhit())

        {

  mycar(x,y);

  ch=getch();

  switch(ch) {

  case 27: exit(0);

  break;

  case 75:myclear(x,y);

  if(x>250)

  x=x-50;

  if((x==x1)||(x==x2))

  if( ( ((y-y1)<100)&&((y-y1)>0) ) || ( ((y-y2)<100)&&((y-y2)>0) ) )

  {

  accident=1;

  x=x+50;

  mycar(x,y);

  goto Next1;

  }

  mycar(x,y);

  break;

  case 77:myclear(x,y);

  if(x<350)

  x=x+50;

  if((x==x1)||(x==x2))

  if( ( ((y-y1)<100)&&((y-y1)>0) ) || ( ((y-y2)<100)&&((y-y2)>0) ) )

  {

  accident=1;

  x=x-50;

  mycar(x,y);

  goto Next1;

  }

  mycar(x,y);

    break;

    case 72:myclear(x,y);

if(y>0)

      y=y-5;

mycar(x,y);

     break;

     case 80:myclear(x,y);

if(y<getmaxy()-105)

    y=y+5;

mycar(x,y);

     break;

    }

}

  if((x==x1)||(x==x2))

  if( ( ((y-y1)<100)&&((y-y1)>0) ) || ( ((y-y2)<100)&&((y-y2)>0) ) )

  accident=1;

Next1:

      if(accident==1){

life =life-1;

score -= 10;

if(life==0) {

gotoxy(5,5);

cout<<"GAME OVER ";

gotoxy(5,6);

cout<<"You could not save";

gotoxy(5,7);

cout<<"her";

break;

}

gotoxy(5,5);

cout<<"You have lost 1 life";

delay(500);

gotoxy(5,5);

cout<<"                    ";

}

}

  }

  }

 getch();

 }

CREATE A C++ PROJECT TO MAKE BRAINVITA GAME

 //--------WELCOME ALL OF YOU ON ROHIT TECH STUDY CHANNEL------------------//

//----------CREATE A C++ PROJECT TO MAKE BRAINVITA GAME--------------------//


#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <dos.h>

#include <time.h>

#include <bios.h>


#define UP 72

#define DOWN 80

#define LEFT 75

#define RIGHT 77

#define ENTER 13

#define ESC 27

#define YES 1

#define NO 0

int x=320,y=100,marble=32,marble_color=12;

void *p;

size_t area;

// Matrix of board

int board[7][7]=

{

{-1,-1,1,1,1,-1,-1},

{-1,-1,1,1,1,-1,-1},

{ 1, 1,1,1,1, 1, 1},

{ 1, 1,1,1,1, 1, 1},

{ 1, 1,1,1,1, 1, 1},

{-1,-1,1,1,1,-1,-1},

{-1,-1,1,1,1,-1,-1}

};


//------------------------------------------------------------------------

// Function Prototypes

//------------------------------------------------------------------------


void Marble(int x,int y,int c);

void G();

int check();

int GetXY(int X,int Y);

int GetBoard(int X,int Y);

void SetBoard(int X,int Y,int element);

void Blink(int x,int y,int c);

void DrawBoard();

int MakeMove(int X,int Y);

void Init();

int finish();

void win(char *text,int sx,int sy,int ex,int ey,int ck);

void winp(int sx,int sy,int ex,int ey,int state);

void Menu();

void LCD(int left,int top,int NUM);

void Lcd(int x,int y,int n);

void Intro();

void Drawborder(int x,int y);

void Background();

int load_game ();

int save_game();


//------------------------------------------------------------------------

// Main Function

//------------------------------------------------------------------------


void main()

{

   int i;

   G();

   Intro();

   Background();

   DrawBoard();

   Marble(320,220,0);

   board[3][3]=0;

   Init();

   setcolor(0);

   for(i=0;i<=220;i++)

   {

   rectangle(0+i,0+i,640-i,480-i);

   delay(10);

   }

   for(i=0;i<=220;i++)

   {

   rectangle(100+i,100,540-i,380);

   delay(8);

   }

   closegraph();

   getch();

}

void Marble(int x,int y,int c)

{

   setfillstyle(1,c);

   setcolor(c);

   fillellipse(x,y,8,8);

   if(c!=0)

   {

   if(c==15){setcolor(7);setfillstyle(1,7);}

   else {setfillstyle(1,15);setcolor(15);}

   fillellipse(x+3,y-2,1,2);

   }

}

void mydelay(float secs)

{

clock_t start, end;

start = clock();

do

{

end = clock();

if(kbhit()) break;

}while(((end - start)/CLK_TCK)<secs);

}

void Intro()

{

   int i;

   char pattern[8] ={0xfe,0xbc,0xda,0xe4,0xe2,0xc0,0x88,0x00};

   setfillpattern(pattern,1);

   bar(0,0,640,480);

   settextstyle(1,0,5);

   setcolor(10);

   getch();

   setcolor(0);

   for(i=0;i<=320;i++)

   {

   rectangle(0+i,0,640-i,480);

   delay(5);

   }


}

void Drawborder(int x,int y)

{

   setwritemode(COPY_PUT);

   setcolor(0);

   line(x+60,y-20,x+180,y-20);

   line(x+60,y+60,x+60,y-20);

   line(x-40,y+60,x+60,y+60);

   line(x-40,y+60,x-40,y+180);

   setcolor(15);

   line(x-40,y+180,x+60,y+180);

    setcolor(0);

   line(x+60,y+180,x+60,y+280);

   setcolor(15);

   line(x+180,y-20,x+180,y+60);

   setcolor(0);

   line(x+180,y+60,x+290,y+60);

   setcolor(15);

   line(x+290,y+60,x+290,y+180);

   line(x+180,y+180,x+290,y+180);

   line(x+180,y+180,x+180,y+280);

   line(x+180,y+280,x+60,y+280);

   setwritemode(XOR_PUT);

}


void Background()

{

   int i;

   setfillstyle(1,3);

   bar(0,0,640,480);

   for(i=0;i<=15;i++)

   {

   setcolor(i);

   rectangle(0+i,0+i,640-i,480-i);

   }

  win("BRAINVITA modify by ROHIT TECH STUDY",145,45,505,400,1);


  win("Keys",24,45,135,290,1);

  win("Help !",510,45,625,250,1);

  setfillstyle(1,0);

  bar(35,75,125,280);

  bar(520,75,618,240);

  winp(35,75,125,280,1);

  winp(520,75,618,240,1);

  setcolor(14);

  settextstyle(2,0,4);

  outtextxy(42,80,"Keys used");

  setcolor(15);

  outtextxy(42,100,"+ or - : color");

  outtextxy(47,120,"^T  : Up");

  outtextxy(47,140,"_|  : Down");

  outtextxy(42,160,"<- : Left");

  outtextxy(42,180,"-> : Right");

  outtextxy(42,200,"Enter : Pick");

  outtextxy(42,220,"S : save game");

  outtextxy(42,240,"L : load game");

  outtextxy(42,260,"Esc : Exit");

  line(47,120,50,123);

  line(47,120,43,123);

  line(47,140,50,143);

  line(47,140,43,143);

  outtextxy(523,80,"Use Arrow Keys");

  outtextxy(523,100,"to move around");

  outtextxy(523,120,"then press enter");

  outtextxy(523,140,"to select any");

  outtextxy(523,160,"marble,then jump");

  outtextxy(523,180,"over another to");

  outtextxy(523,200,"remove it.");

  win("",190,410,480,460,0);

  setfillstyle(1,0);

  bar(200,420,470,450);

  settextstyle(1,0,3);

  setcolor(10);

  outtextxy(220,420,"Marbles :");

}


//------------------------------------------------------------------------

// Draw The Whole Board on Screen

//------------------------------------------------------------------------


void DrawBoard()

{

   int i,j,x=200,y=100;

   x=200;y=100;

   setfillstyle(1,1);

   bar(x-40,y-20,x+290,y+280);

   setfillstyle(1,7);

   bar(x-41,y-21,x+60,y+60);

   bar(x+180,y-21,x+290,y+60);

   bar(x-41,y+180,x+60,y+290);

   bar(x+180,y+180,x+290,y+290);

   Drawborder(x,y);

   Drawborder(x+1,y+1);

   setfillstyle(1,12);

   setcolor(11);

   for(i=0;i<7;i++)

   {

for(j=0;j<7;j++)

{

    if(board[j][i]!=-1)

    {

     if(board[j][i]==1)

     Marble(x,y,marble_color);

     if(board[j][i]==0)

     Marble(x,y,0);

    }

    x+=40;

}

x=200;

y+=40;

   }

   settextstyle(1,0,3);

}


//------------------------------------------------------------------------

// Switch Into Graphics mode

//------------------------------------------------------------------------


void G()

{

   int gdriver = DETECT, gmode, errorcode;

/*

   // for stand alone

   registerfarbgidriver(EGAVGA_driver_far);

   registerfarbgifont(sansserif_font_far);

   registerfarbgifont(small_font_far);

   registerfarbgifont(gothic_font_far);

   registerfarbgifont(triplex_font_far);

    */

   initgraph(&gdriver, &gmode, "c://tc//bgi");

   errorcode = graphresult();

   if (errorcode != grOk)

   {

      printf("Graphics error: %s", grapherrormsg(errorcode));

      exit(1);

   }

   area=imagesize(150,70,240,180);

   p=malloc(area);

   if(p==NULL)

   {closegraph();exit(1);}

}


//------------------------------------------------------------------------

// Check the board if any move is possible

//------------------------------------------------------------------------


int check() // a know bug is there

{

   int i,j,flag;

   flag=0;

   for(i=0;i<7;i++)

   {

    for(j=0;j<7;j++)

    if(board[j][i]!=-1)

    {

if(board[j][i]==1)

{

if(board[j+1][i]==1)

{

  if(board[j+2][i]==0)

  flag++;


}

if(board[j-1][i]==1)

{

  if(board[j-2][i]==0)

  flag++;


}

if(board[j][i+1]==1)

{

  if(board[j][i+2]==0)

  flag++;


}

if(board[j][i-1]==1)

{

  if(board[j][i-2]==0)

  flag++;


}


}

    }

   }

   //count marble

   marble=0;

   for(i=0;i<7;i++)

   {

    for(j=0;j<7;j++)

    if(board[j][i]==1)

    marble++;

   }

   return flag;

}


//------------------------------------------------------------------------

//      Give the current x,y position on board & find is it valid or not

//------------------------------------------------------------------------


int GetXY(int X,int Y)

{

   int i,j,x=200,y=100,flag=0;

   for(i=0;i<7;i++)

   {

for(j=0;j<7;j++)

{

    if(board[j][i]!=-1)

    {

     if(x==X && y==Y)

     flag=1;

    }

    x+=40;

}

x=200;

y+=40;

   }

   return flag;

}


//------------------------------------------------------------------------

// check current position is filled or not

//------------------------------------------------------------------------


int GetBoard(int X,int Y)

{

   int i,j,x=200,y=100,f=-1;

   for(i=0;i<7;i++)

   {

for(j=0;j<7;j++)

{

    if(board[j][i]!=-1)

    {

     if(x==X && y==Y)

     f=board[j][i];

    }

    x+=40;

}

x=200;

y+=40;

   }

   return f;

}


//------------------------------------------------------------------------

// Sets the board to 1 or 0 ,represents filled & empty respectively

//------------------------------------------------------------------------


void SetBoard(int X,int Y,int element)

{

   int i,j,x=200,y=100;

   for(i=0;i<7;i++)

   {

for(j=0;j<7;j++)

{

    if(board[j][i]!=-1)

    {

     if(x==X && y==Y)

     board[j][i]=element;

    }

    x+=40;

}

x=200;

y+=40;

   }

}


//------------------------------------------------------------------------

// Blinks the cursor or square

//------------------------------------------------------------------------


void Blink(int x,int y,int c)

{

 int i;

 setcolor(c);

 do

 {

rectangle(x-10,y-10,x+10,y+10);

rectangle(x-11,y-11,x+11,y+11);

mydelay(0.5);

rectangle(x-10,y-10,x+10,y+10);

rectangle(x-11,y-11,x+11,y+11);

mydelay(0.5);

 }

 while(!kbhit());

}


//------------------------------------------------------------------------

// When ENTER pressed check for conditions & perform task

//------------------------------------------------------------------------


int MakeMove(int X,int Y)

{

 int flag,key;

 flag=NO;

 if(marble_color==11)

 Marble(X,Y,9);

 else Marble(X,Y,11);

 key = bioskey(0);

 if(key==0x4800)  //up

 {

if(GetBoard(X,Y-80)==0 && GetBoard(X,Y-40)==1)

{

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  Y-=40;

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  Y-=40;

  SetBoard(X,Y,1);

  y=Y;

  flag=YES;

}

 }

 if(key==0x5000)//down

 {

if(GetBoard(X,Y+80)==0 && GetBoard(X,Y+40)==1)

{

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  Y+=40;

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  Y+=40;

  SetBoard(X,Y,1);

  y=Y;

  flag=YES;

}

 }

 if(key==0x4b00)   //left

 {

if(GetBoard(X-80,Y)==0 && GetBoard(X-40,Y)==1)

{

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  X-=40;

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  X-=40;

  SetBoard(X,Y,1);

  x=X;

  flag=YES;

}

 }

 if(key==0x4d00)//right

 {

if(GetBoard(X+80,Y)==0 && GetBoard(X+40,Y)==1)

{

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  X+=40;

  Marble(X,Y,0);

  SetBoard(X,Y,0);

  X+=40;

  SetBoard(X,Y,1);

  x=X;

  flag=YES;

}

  }

  if(kbhit()) getch();

  setcolor(11);

  if(flag==YES)

  {

Marble(X,Y,marble_color);

  }

  else//invalid key

  {

Marble(X,Y,marble_color);

sound(800);

delay(100);

nosound();

  }

  return flag;

}


//------------------------------------------------------------------------

// Handles All the funtions & Perform desired move

//------------------------------------------------------------------------


void Init()

{

   int i,j,e=1;

   char ch;

   setwritemode(XOR_PUT);

   setcolor(15);

   while(e)

   {

    setfillstyle(1,11);

    Lcd(360,425,marble);

    Blink(x,y,11);

    ch=getch();

    Lcd(360,425,marble);

    if(ch==ESC) e=0;

    if(GetXY(x,y)==1)

    {

switch(ch)

{

case    UP :if(GetXY(x,y-40)==1)

if(y>100) y-=40;break;

case  DOWN :if(GetXY(x,y+40)==1)

if(y<340) y+=40;break;

case  LEFT :if(GetXY(x-40,y)==1)

if(x>200) x-=40;break;

case RIGHT :if(GetXY(x+40,y)==1)

if(x<440) x+=40;break;

case ENTER :if(GetBoard(x,y)==1)

    {

     MakeMove(x,y);

    }

    break;

case ESC   :e=0;break;

case '+': marble_color++;

if(marble_color>15) marble_color=2;

DrawBoard();

break;

case '-':marble_color--;

if(marble_color<2) marble_color=15;

DrawBoard();

break;

case 's':case 'S':save_game();break;

case 'l':case 'L':load_game();break;

}//switch

    }//if

   if(check()==0) e=finish();

   }//while

   setwritemode(COPY_PUT);

}


//------------------------------------------------------------------------

// Display Final Screen

//------------------------------------------------------------------------


int finish()

{

    int i,j,f;

    char opt=0;

    setwritemode(COPY_PUT);

    f=0;

    for(i=0;i<7;i++)

    {

    for(j=0;j<7;j++)

    if(board[j][i]==1)

    f++;

    }

    Lcd(360,425,marble);

//    f-=1;

    win("Done !",220,155,425,240,1);

    setcolor(0);

    settextstyle(1,0,1);

    switch(f)

    {

case 1:outtextxy(230,180,"You Are Intelligent !");break;

case 2:outtextxy(255,180,"    Wonderful !");break;

case 3:outtextxy(255,180,"  Good Job !");break;

case 4:outtextxy(255,180,"  Can be better !");break;

case 5:outtextxy(230,180," You Need Practice !");break;

case 6:outtextxy(230,180,"   Very Poor !");break;

case 7:outtextxy(230,180," Very Very Poor !");break;

default:outtextxy(255,180," Try Again !");break;

    }


    getch();

    win("Exit ?",220,155,425,240,1);

    settextstyle(1,0,1);

    setcolor(1);

    outtextxy(240,180,"Play Again [y/n] :");

    opt=getch();

    setfillstyle(1,3);

    bar(17,402,624,464);

    if(opt=='y' || opt=='Y')

    {

     for(i=0;i<7;i++)

     {

for(j=0;j<7;j++)

if(board[j][i]!=-1) board[j][i]=1;

     }

     Marble(320,220,0);

     board[3][3]=0;

     marble=32;

     Background();

     DrawBoard();

     f=1;

    }

    else f=0;

    setwritemode(XOR_PUT);

    return f;

}

void win(char *text,int sx,int sy,int ex,int ey,int ck)

{

   setfillstyle(1,7);

   bar(sx,sy,ex,ey);

   setfillstyle(1,7);

   setcolor(15);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   setcolor(0);

   line(ex,sy,ex,ey);

   line(ex,sy,ex,ey);

   line(sx,ey,ex,ey);

   line(sx,ey,ex,ey);

   if(ck==1)

   {

   settextstyle(0,0,0);

   setfillstyle(1,1);

   bar(sx+2,sy+2,ex-2,sy+17);

   setcolor(15);

   outtextxy(sx+4,sy+4,text);

   //for x

   setfillstyle(1,7);

   bar(ex-15,sy+4,ex-4,sy+15);

   setcolor(15);

   line(ex-15,sy+4,ex-4,sy+4);

   line(ex-15,sy+4,ex-15,sy+15);

   setcolor(0);

   line(ex-15,sy+15,ex-4,sy+15);

   line(ex-4,sy+4,ex-4,sy+15);

   setcolor(1);

   outtextxy(ex-13,sy+5,"x");

   setfillstyle(1,7);

   }

}

void winp(int sx,int sy,int ex,int ey,int state)

{

   if(state==1)

   {

   setcolor(0);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   setcolor(15);

   line(ex,sy,ex,ey);

   line(ex,sy,ex,ey);

   line(sx,ey,ex,ey);

   line(sx,ey,ex,ey);

  }

  else

  {

   setcolor(15);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   line(sx,sy,sx,ey);

   line(sx,sy,ex,sy);

   setcolor(0);

   line(ex,sy,ex,ey);

   line(ex,sy,ex,ey);

   line(sx,ey,ex,ey);

   line(sx,ey,ex,ey);

  }

}

void mybar(int sx,int sy,int ex,int ey)

{

 int i;


 for(i=sy;i<=ey;i++)

 line(sx,i,ex,i);

}

void Menu()

{

 setcolor(0);

 settextstyle(2,0,4);

 getimage(161,80,240,180,p);

 win(" ",161,80,240,180,0);

 outtextxy(170,88,"New Game");

 outtextxy(170,105,"Exit");

 setwritemode(XOR_PUT);

 mybar(170,88,220,100);

 getch();

 mybar(170,88,220,100);

 mybar(170,105,220,117);

 getch();

 mybar(170,105,220,117);

 setwritemode(COPY_PUT);

 getch();

 putimage(161,80,p,COPY_PUT);

}

void Lcd(int x,int y,int n)

{

 int a,b;

 if(n<10)

 {

 LCD(x,y,0);

 LCD(x+15,y,n);

 }

 else if(n<100)

 {

  a=n/10;b=n%10;

  LCD(x,y,a);

  LCD(x+15,y,b);

 }

}

void LCD(int left,int top,int NUM)

{

   int i;

   setcolor(10);


   switch(NUM)

   {

   case 1:

  line(left+11,top+2,left+11,top+9);

  line(left+11,top+11,left+11,top+18);

  break;

   case 2:

   line(left,top,left+10,top);

   line(left+11,top+2,left+11,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left-1,top+11,left-1,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 3:

   line(left,top,left+10,top);

   line(left+11,top+2,left+11,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 4:

   line(left-1,top+2,left-1,top+9);

   line(left+11,top+2,left+11,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left+11,top+11,left+11,top+18);

   break;

   case 5:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 6:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left-1,top+11,left-1,top+18);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 7:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+11,top+2,left+11,top+9);

   line(left+11,top+11,left+11,top+18);

   break;

   case 8:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+11,top+2,left+11,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left-1,top+11,left-1,top+18);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 9:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+11,top+2,left+11,top+9);

   line(left+1,top+10,left+9,top+10);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   case 0:

   line(left,top,left+10,top);

   line(left-1,top+2,left-1,top+9);

   line(left+11,top+2,left+11,top+9);

   line(left-1,top+11,left-1,top+18);

   line(left+11,top+11,left+11,top+18);

   line(left,top+20,left+10,top+20);

   break;

   }

}

int load_game()

{

FILE *fp ;

char *name;

gotoxy(20,2);printf("File name: ");

scanf("%s",name);

if ( ( fp = fopen ( name, "rb" ) ) == NULL )

{

  setfillstyle(1,3);

  bar(20,17,400,40);

  gotoxy(20,2);

  printf("  Unable to Load Game");

  getch();

  setfillstyle(1,3);

  bar(20,17,400,40);

  return 0;

}

fread(board,sizeof(board),1,fp);

fclose ( fp ) ;

setfillstyle(1,3);

bar(20,17,400,40);

DrawBoard();

return 1;

}

int save_game()

{

char *fname;

FILE *fp ;

gotoxy(20,2);printf("File name: ");

scanf("%s",fname);

if ( ( fp = fopen ( fname, "wb" ) ) == NULL ) return 0;

fwrite(board, sizeof ( board ), 1, fp);

fclose(fp) ;

setfillstyle(1,3);

bar(20,17,400,40);

return 1;

}

//______________________THANKS TO WATCH THIS PROJECT_______________________//

//_______________________I HOPE YOU ENJOY THIS GAME________________________//

//______________________PLEASE GIVE LIKE TO THIS WORK______________________//

Featured Post

Happy Republic Day Wish Using HTML and CSS | 26 January wish using HTML/CSS

 Happy Republic Day Wish Using HTML and CSS, 26 January wish using HTML/CSS <!-- WELCOME ALL OF YOU ON COMPUTER SOFT SKILLS CHANNEL -----...

Popular Posts