Neler Yeni

c# sayı bulma oyunu yapımı?

ardaakahs

80+
Katılım
27 Haziran 2023
Mesajlar
475
Dahası  
Reaksiyon skoru
120
İsim
Arda Teksin
(else. if. random) kullanılarak (c# windowsformapp) ile sayı bulma oyunu yapmam gerekiyor yeni nakil geldiğim için hiçbir bilgim yok yardım edebilecek varmı
 

Montofteam

80+ Bronze
Katılım
1 Ocak 2023
Mesajlar
1,568
Dahası  
Reaksiyon skoru
678
İsim
Eren
(else. if. random) kullanılarak (c# windowsformapp) ile sayı bulma oyunu yapmam gerekiyor yeni nakil geldiğim için hiçbir bilgim yok yardım edebilecek varmı
Mesaj otomatik birleştirildi:

Random r = new Random();

int val = r.Next(1, 100);
int guess = 0;
bool correct = false;

Console.WriteLine("I'm thinking of a number between 1 and 100.");

while (!correct)
{
Console.Write("Guess: ");
string input = Console.ReadLine();

if (!int.TryParse(input, out guess))
{
Console.WriteLine("That's not a number.");
continue;
}

if (guess < val)
{
Console.WriteLine("No, the number I'm thinking is higher than that number.");
}
else if (guess > val)
{
Console.WriteLine("No, the number I'm thinking is lower than that number.");
}
else
{
correct = true;
Console.WriteLine("You guessed right!");
}
}

Bu en mantıklısı durdu
 

keremgencer_

80+ Bronze
Katılım
6 Mayıs 2021
Mesajlar
869
Dahası  
Reaksiyon skoru
485
İsim
Kerem Gencer
Mesaj otomatik birleştirildi:


Random r = new Random();

int val = r.Next(1, 100);
int guess = 0;
bool correct = false;

Console.WriteLine("I'm thinking of a number between 1 and 100.");

while (!correct)
{
Console.Write("Guess: ");
string input = Console.ReadLine();

if (!int.TryParse(input, out guess))
{
Console.WriteLine("That's not a number.");
continue;
}

if (guess < val)
{
Console.WriteLine("No, the number I'm thinking is higher than that number.");
}
else if (guess > val)
{
Console.WriteLine("No, the number I'm thinking is lower than that number.");
}
else
{
correct = true;
Console.WriteLine("You guessed right!");
}
}

Bu en mantıklısı durdu
Bunlar konsol uygulaması ama.
 

Montofteam

80+ Bronze
Katılım
1 Ocak 2023
Mesajlar
1,568
Dahası  
Reaksiyon skoru
678
İsim
Eren

Diartios

80+
Katılım
23 Ağustos 2023
Mesajlar
56
Random random = new Random();
int value = r.next(100);
check_button_click()
{
int guessedNum = int.Parse(numbertextbox.Text);
if ( guessedNum < value)
{
//kodun buraya
}
else if (guessedNum > value)
{
//kodun buraya
}
else
{
//kodun buraya
}
}
discorddan ulaşabilirsin her türlü yardımı sağlayabilirim
diartios1881
 

The Semih

80+ Silver
Katılım
10 Mart 2023
Mesajlar
4,932
using System;
using System.Windows.Forms;

namespace SayiBulmaOyunu
{
public partial class Form1 : Form
{
int rastgeleSayi;
int tahminSayisi;

public Form1()
{
InitializeComponent();
YeniOyunBaslat();
}

void YeniOyunBaslat()
{
Random rastgele = new Random();
rastgeleSayi = rastgele.Next(1, 101); // 1 ile 100 arasında rastgele bir sayı seç
tahminSayisi = 0;
}

private void TahminButton_Click(object sender, EventArgs e)
{
int tahmin;
if (int.TryParse(TahminTextBox.Text, out tahmin))
{
tahminSayisi++;
if (tahmin < rastgeleSayi)
{
DurumLabel.Text = "Daha büyük bir sayı deneyin.";
}
else if (tahmin > rastgeleSayi)
{
DurumLabel.Text = "Daha küçük bir sayı deneyin.";
}
else
{
DurumLabel.Text = $"Tebrikler! {tahminSayisi} tahminde bildiniz.";
YeniOyunBaslat();
}
}
else
{
DurumLabel.Text = "Lütfen geçerli bir sayı girin.";
}
TahminTextBox.Clear();
TahminTextBox.Focus();
}
}
}
 
Top Bottom