Make Rock, Paper, Scissors Using C language in hindi

इस आर्टिकल में आप सीखेंगे कि C language का उपयोग करके Rock, Paper, Scissor गेम कैसे बनाया जाता है ।





विजुअल स्टूडियो कोड इंस्टॉल कीजिए। 

IDE(Integrated development environment)
यह एक टूल है जिसका उपयोग हम अपने कोड को अच्छी तरह लिखने के लिए कर सकते हैं ।
यहां से आप विजुअल स्टूडियो कोड IDE को कंप्यूटर में डाउनलोड कर सकते है। नीचे दी हुई लिंक पे जाइए ।



विजुअल स्टूडियो मैं C File बनाए 

यदि आप कोई कोडिंग नहीं जानते हैं तो बस नीचे दिए गए कोड को कॉपी करें और इसे चलाने के लिए बनाम कोड में पेस्ट करें। यदि आप कोड करना जानते हैं तो जारी रखें!

(/* */) इन संकेतों का उपयोग प्रोग्राम में टिप्पणी करने के लिए किया जाता है जो कोड निष्पादित नहीं करता है।

कोड यहाँ से शुरू है:

/*शामिल करने के लिए महत्वपूर्ण Library फ़ाइलें */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/*void result एक फ़ंक्शन है जो कुछ भी रिटर्न नहीं करता है */

void result(char comp, char you)
{
  //Code for draw
  if (comp == 'r' && you == 'r')
  {
    printf("You chose %c and computer chose %c: Draw ! :|\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 'p' && you == 'p')
  {
    printf("You chose %c and computer chose %c: Draw ! :|\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 's' && you == 's')
  {
    printf("You chose %c and computer chose %c: Draw ! :|\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  //Code if not draw
  else if (comp == 'r' && you == 'p')
  {
    printf("You chose %c and computer chose %c: You won ! :)\n", you,comp);
  }
  else if (comp == 'r' && you == 's')
  {
    printf("You chose %c and computer chose %c: You lost ! :(\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 'p' && you == 's')
  {
    printf("You chose %c and computer chose %c: You won ! :)\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 'p' && you == 'r')
  {
    printf("You chose %c and computer chose %c: You lost ! :(\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 's' && you == 'r')
  {
    printf("You chose %c and computer chose %c: You won ! :)\n", you,comp);
    printf("Enter 1 to play again\n");
  }
  else if (comp == 's' && you == 'p')
  {
    printf("You chose %c and computer chose %c: You lost ! :(\n", you,comp);
    printf("Enter 1 to play again\n");
  }
}

/*यहां से हमारा कोड निष्पादित होता है*/

int main()
{
  char comp;
  char you;
  int number, repeat, hard = 1;

/*Random Number उत्पन्न करने के लिए कोड*/

  srand(time(0));
  number = rand() % 100 + 1;

/*Using do-while loop for playing the game again and again*/

  do
  {

/*यहाँ if-else ladder शुरू होती है*/

    if (number < 33)
    {
      comp = 'r';
    }
    if (number > 33 && number < 66)
    {
      comp = 'p';
    }
   else
    {
      comp = 's';
    }
    printf("Enter r for Rock\nEnter p for Paper\nEnter s for Sissor\n");
    fflush(stdin);
    scanf("%c", &you);
    result(comp, you); /*<< यह result ()
फंक्शन है जो ऊपर लिखा था*/

    scanf("%d", &repeat);
    printf("\n");
    if (repeat = 1)
    {
      srand(time(0));
      number = rand() % 100 + 1;
      continue;
    }
  return 0;
}

कोड समाप्त होता है:

इस तरह आप अपना गेम बना सकते हैं।
पढ़ने के लिए धन्यवाद  :)

टिप्पणियाँ

लोकप्रिय पोस्ट