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
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
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace game
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click( object sender, EventArgs e)
- {
- Form2 f =new Form2();
- f.Show();
- Application.OpenForms["form1" ].Hide();
- }
- private void button2_Click( object sender, EventArgs e)
- {
- Form3 f =new Form3();
- f.Show();
- Application.OpenForms["form1" ].Hide();
- }
- private void button3_Click( object sender, EventArgs e)
- {
- Form4 f =new Form4();
- f.Show();
- Application.OpenForms["form1" ].Hide();
- }
- }
- }
Form2
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:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace game
- {
- public partialclass Form2 : Form
- {
- static Random r = newRandom();
- int value=r.Next(10);
- int guessnum;
- int win = 5;
- int guess = 1;
- public Form2()
- {
- InitializeComponent();
- }
- private void button2_Click( object sender,EventArgs e)
- {
- Form1 f =new Form1();
- f.Show();
- Application.OpenForms["form2" ].Hide();
- }
- private void button1_Click( object sender,EventArgs e)
- {
- guessnum = Convert.ToInt32(textBox1.Text);
- while (win >= 0)
- {
- if (guessnum == value)
- {
- if (guess == 1)
- {
- label4.Text ="wow In 1st chance you got the number" ;
- }
- else
- label4.Text ="you got the number and no of chance you took are " + guess;
- break ;
- }
- elseif (guessnum < value)
- {
- richTextBox1.Text += guessnum +"\n" ;
- label4.Text ="wrong Guess and number of guesses left are " + (5 - guess);
- }
- elseif (guessnum > value)
- {
- richTextBox2.Text += guessnum +"\n" ;
- label4.Text ="wrong Guess and number of guesses left are " + (5 - guess);
- }
- guess++;
- win--;
- break ;
- }
- if (guess == 6)
- {
- label4.Text ="You loose,Correct Guess is " + value;
- }
- }
- }
- }
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 of 1 and 1000
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