Advertisement
cuniszkiewicz

Game_if_else

May 15th, 2024
556
0
16 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Game
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int userNumber;
  15.             char decision;
  16.             Random rand = new Random(DateTime.Now.Millisecond);
  17.         newGame:
  18.             Console.Clear();
  19.             int winNumber = Convert.ToInt32(rand.Next(1, 11));//randomized number from rande 1-10
  20.             int chances = 3;
  21.            
  22.             Console.WriteLine($"Win number: {winNumber}");
  23.            
  24.         userNum:
  25.            
  26.             Console.Write("Put a number from range 1-10: ");
  27.             userNumber = int.Parse(Console.ReadLine());
  28.  
  29.             if (userNumber == winNumber)
  30.             {
  31.                 Console.Clear();
  32.                 Console.WriteLine("\n\n\n\n\n\n\n\t\t\t\t\t\t\tYou won!");
  33.             }
  34.             else
  35.             {
  36.                 chances--; // chances = chances - 1;
  37.                 if (chances != 0)
  38.                 {
  39.                     Console.WriteLine("Try again!");
  40.                     goto userNum;
  41.                 }
  42.                 else
  43.                 {
  44.                     Console.Clear();
  45.                     Console.WriteLine("\n\n\n\n\n\n\n\t\t\t\t\t\t\tGame over!");  
  46.                 }
  47.             }
  48.            
  49.             Console.Write("Do you want to play again? y - yes: ");
  50.             decision = char.Parse(Console.ReadLine());
  51.             if (decision == 'y')
  52.                 goto newGame;
  53.             else
  54.             {
  55.                 Console.Clear();
  56.                 Console.WriteLine("\n\n\n\n\n\n\n\t\t\t\t\t\t\tThank you!");
  57.                 System.Threading.Thread.Sleep(1000);
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement