banner



Number Guesiing Game In Data Logic Design

  • Updated date Dec 11, 2020
  • 31.4k
  • 1

In this game the computer will randomly choose a number and the player must guess the number.

In this game, the computer will randomly choose a number and the player must guess the number. To guess the number, for each guesses the computer will show whether the guess is too high or too low. If the user is able to guess the number then he will be the winner otherwise he loses the game.

In this game there are the following three levels:

1 and 10

1 and 100

1 and 1000

Between 1 and 10: The computer will randomly take a number between 1 and 10 and the user has five chances to guess the number.

Between 1 and 100: The computer will randomly take a number between 1 and 100 and the user has seven chances to guess the number.

Between 1 and 1000: The computer will randomly take a number between 1 and 1000 and the user has ten chances to guess the number.

Main Page

main design.PNG

On this page, there are 7 labels and 3 buttons. The label only contains the description and the button is used for redirecting to another form.

1 and 10 redirect to form2, 1 and 100 redirect to form3 and 1 and 1000 redirect to form4.

Coding

  1. using  System;
  2. using  System.Collections.Generic;
  3. using  System.ComponentModel;
  4. using  System.Data;
  5. using  System.Drawing;
  6. using  System.Linq;
  7. using  System.Text;
  8. using  System.Windows.Forms;
  9. namespace  game
  10. {
  11. public  partial class  Form1 : Form
  12.     {
  13. public  Form1()
  14.         {
  15.             InitializeComponent();
  16.         }
  17. private void  button1_Click( object  sender, EventArgs e)
  18.         {
  19.             Form2 f =new  Form2();
  20.             f.Show();
  21.             Application.OpenForms["form1" ].Hide();
  22.         }
  23. private void  button2_Click( object  sender, EventArgs e)
  24.         {
  25.             Form3 f =new  Form3();
  26.             f.Show();
  27.             Application.OpenForms["form1" ].Hide();
  28.         }
  29. private void  button3_Click( object  sender, EventArgs e)
  30.         {
  31.             Form4 f =new  Form4();
  32.             f.Show();
  33.             Application.OpenForms["form1" ].Hide();
  34.         }
  35.     }
  36. }

Form2

form 2.PNG

It contains the label to show the data and a TextBox for the user to enter the value and a button. It also has rich text boxes to show whether the value is low or high. There are 5 chances to guess the correct number.

Coding:

  1. using  System;
  2. using  System.Collections.Generic;
  3. using  System.ComponentModel;
  4. using  System.Data;
  5. using  System.Drawing;
  6. using  System.Linq;
  7. using  System.Text;
  8. using  System.Windows.Forms;
  9. namespace  game
  10. {
  11. public  partialclass Form2 : Form
  12.     {
  13. static  Random r = newRandom();
  14. int  value=r.Next(10);
  15. int  guessnum;
  16. int  win = 5;
  17. int  guess = 1;
  18. public  Form2()
  19.         {
  20.             InitializeComponent();
  21.         }
  22. private void  button2_Click( object  sender,EventArgs e)
  23.         {
  24.             Form1 f =new  Form1();
  25.             f.Show();
  26.             Application.OpenForms["form2" ].Hide();
  27.         }
  28. private void  button1_Click( object  sender,EventArgs e)
  29.         {
  30.             guessnum = Convert.ToInt32(textBox1.Text);
  31. while  (win >= 0)
  32.             {
  33. if  (guessnum == value)
  34.                 {
  35. if  (guess == 1)
  36.                     {
  37.                         label4.Text ="wow In 1st chance you got the number" ;
  38.                     }
  39. else
  40.                         label4.Text ="you got the number and no of chance you took are "  + guess;
  41. break ;
  42.                 }
  43.                 elseif (guessnum < value)
  44.                 {
  45.                     richTextBox1.Text += guessnum +"\n" ;
  46.                     label4.Text ="wrong Guess and number of guesses left are "  + (5 - guess);
  47.                 }
  48.                 elseif (guessnum > value)
  49.                 {
  50.                     richTextBox2.Text += guessnum +"\n" ;
  51.                     label4.Text ="wrong Guess and number of guesses left are "  + (5 - guess);
  52.                 }
  53.                 guess++;
  54.                 win--;
  55. break ;
  56.             }
  57. if  (guess == 6)
  58.             {
  59.                 label4.Text ="You loose,Correct Guess is "  + value;
  60.             }
  61.         }
  62.     }
  63. }
Form3

form3.PNG

It contains the label to show the data and a TextBox for the user to enter the value and a button. It also has rich text boxes to show whether the value is low or high. There are 7 chances to guess the correct number.

output 1and100.PNG

Output of 1 and 1000

output 1and1000.PNG

Number Guesiing Game In Data Logic Design

Source: https://www.c-sharpcorner.com/uploadfile/ad779a/guessing-game/

Posted by: singletonhimetch.blogspot.com

0 Response to "Number Guesiing Game In Data Logic Design"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel