شاهان کرمی

مهندس شاهان کرمی یکی از فیلسوفان و بزرگترین ستاره شناسان تاریخ هستند

شاهان کرمی

مهندس شاهان کرمی یکی از فیلسوفان و بزرگترین ستاره شناسان تاریخ هستند

۱۳
آذر

using System;

using System.Drawing;

using System.Windows.Forms;

 

namespace ShipOnWater

{

    public partial class Form1 : Form

    {

        // The ship image

        private Image ship = Image.FromFile("ship.png");

        // The water image

        private Image water = Image.FromFile("water.png");

        // The ship position

        private Point shipPos = new Point(200, 200);

        // The ship speed

        private int shipSpeed = 10;

        // The water offset

        private int waterOffset = 0;

        // The water speed

        private int waterSpeed = 2;

 

        public Form1()

        {

            InitializeComponent();

            // Set the form size to match the water image size

            this.ClientSize = new Size(water.Width, water.Height);

            // Set the timer interval to 20 milliseconds

            timer1.Interval = 20;

            // Start the timer

            timer1.Start();

        }

 

        private void timer1_Tick(object sender, EventArgs e)

        {

            // Update the water offset

            waterOffset += waterSpeed;

            // Wrap the water offset around the water image height

            waterOffset %= water.Height;

            // Invalidate the form to trigger the paint event

            this.Invalidate();

        }

 

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

            // Get the graphics object

            Graphics g = e.Graphics;

            // Draw the water image twice to create a scrolling effect

            g.DrawImage(water, 0, waterOffset - water.Height);

            g.DrawImage(water, 0, waterOffset);

            // Draw the ship image at the ship position

            g.DrawImage(ship, shipPos);

        }

 

        private void Form1_KeyDown(object sender, KeyEventArgs e)

        {

            // Move the ship according to the pressed key

            switch (e.KeyCode)

            {

                case Keys.Up:

                    // Move the ship up

                    shipPos.Y -= shipSpeed;

                    break;

                case Keys.Down:

                    // Move the ship down

                    shipPos.Y += shipSpeed;

                    break;

                case Keys.Left:

                    // Move the ship left

                    shipPos.X -= shipSpeed;

                    break;

                case Keys.Right:

                    // Move the ship right

                    shipPos.X += shipSpeed;

                    break;

            }

            // Clamp the ship position to the form boundaries

            shipPos.X = Math.Max(0, Math.Min(shipPos.X, this.ClientSize.Width - ship.Width));

            shipPos.Y = Math.Max(0,

Math.Min(shipPos.Y, this.ClientSize.Height - ship.Height));

        }

    }

}

  • شاهان کرمی
۱۳
آذر

using System;

 

namespace GuessTheNumber

{

    class Program

    {

        static void Main(string[] args)

        {

            // Generate a random number between 1 and 100

            Random random = new Random();

            int secretNumber = random.Next(1, 101);

 

            // Initialize the number of guesses

            int guesses = 10;

 

            // Greet the user and explain the game

            Console.WriteLine("سلام، من بینگ هستم. من یک عدد بین 1 تا 100 در نظر گرفته‌ام. می‌توانید حدس بزنید که چه عددی است؟");

            Console.WriteLine("شما فقط 10 بار می‌توانید حدس بزنید. من به شما می‌گویم که عدد شما بزرگتر یا کوچکتر از عدد من است.");

            Console.WriteLine("آیا آماده‌اید؟ بسیار خب، بیایید شروع کنیم!");

 

            // Start the game loop

            while (guesses > 0)

            {

                // Prompt the user to enter a guess

                Console.Write("حدس شما چیست؟ ");

                string input = Console.ReadLine();

 

                // Try to parse the input as an integer

                int guess;

                bool isValid = int.TryParse(input, out guess);

 

                // If the input is not a valid integer, show an error message and continue the loop

                if (!isValid)

                {

                    Console.WriteLine("لطفا یک عدد صحیح بین 1 تا 100 وارد کنید.");

                    continue;

                }

 

                // If the input is out of range, show an error message and continue the loop

                if (guess < 1 || guess > 100)

                {

                    Console.WriteLine("لطفا یک عدد بین 1 تا 100 وارد کنید.");

                    continue;

                }

 

                // If the guess is correct, congratulate the user and end the game

                if (guess == secretNumber)

                {

                    Console.WriteLine("درست است! شما عدد من را حدس زدید. تبریک می‌گویم!");

                    break;

                }

 

                // If the guess is wrong, show a hint and decrement the number of guesses

                if (guess < secretNumber)

                {

                    Console.WriteLine("نه، عدد من بزرگتر است.");

                }

                else

                {

                    Console.WriteLine("نه، عدد من کوچکتر است.");

                }

 

                guesses--;

                Console.WriteLine("شما {0} بار دیگر می‌توانید حدس بزنید.", guesses);

            }

 

            // If the user ran out of guesses, reveal the secret number and end the game

            if (guesses == 0)

            {

                Console.WriteLine("متاسفم، شما نتوانستید عدد من را حدس بزنید. عدد من {0} بود.", secretNumber);

            }

 

            // Thank the user for playing and say goodbye

            Console.W

riteLine("از اینکه با من بازی کردید ممنونم. خداحافظ!");

        }

    }

}

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی
۱۴
دی

  • شاهان کرمی