- [DEVEXPRESS] Chia sẻ source code cách tạo biểu đồ sơ đồ tổ chức công ty Org Chart trên Winform C#
- [C#] Hướng dẫn tạo Auto Number trên Datagridview winform
- [DATABASE] Hướng dẫn tạo Procedure String Split in Mysql
- [C#] Thiết lập dấu (,) hay dấu (.) ở định dạng số đúng với định dạng số Việt Nam
- [C#] Chia sẻ source code Game Spin Lucky Wheel
- [C#] Hướng dẫn Encode and Decode HTML
- Danh sách tài khoản ChatGPT miễn phí - Hướng dẫn tạo tài khoản Chat Open AI GPT tại Việt Nam
- [C#] Hướng dẫn thay đổi giao diện ứng dụng Winform theo giao diện của Windows
- [VB.NET] Hiệu ứng Acrylic, Mica, Tabbed Blur Effect trên Winform
- [DEVEXPRESS] Hướng dẫn sử dụng HTML Template trên Combobox Edit
- [C#] Chia sẻ source code Orange Rain in Winform
- [DEVEXPRESS] Hướng dẫn sử dụng HTML Template trên XtraMessageBox Winform Devexpress 22.2.3
- [DEVEXPRESS] Hướng dẫn sử dụng HTML and CSS Code Viewer trên Winform
- [C#] Number Effect Counter up and down in winform
- [C#] Hướng dẫn Supend and Resume Process ID in Winform
- [C#] Hiển thị line number trên Richtextbox Winform
- [C#] Fake Blue Screen BSOD in winform
- [C#] Chia sẽ code demo sử dụng Async Parallel Foreach and For in Winform
- [C#] Sử dụng ActionBlock run X task at time winform
- [C#] Hướng dẫn sử dụng Property Grid để lưu và tải lại thông tin cấu hình user trên winform
[C#] Chia sẻ source code Game Spin Lucky Wheel
Xin chào các bạn, hôm nay mình tiếp tục chia sẻ đến các bạn source code Game Spin Lucky Wheel trên C#, Winform.
[C#] Source code Game Spin Lucky Wheel Winform
Đây là một giới thiệu ngắn về trò chơi Lucky Wheel:
Lucky Wheel là một trò chơi may mắn truyền thống mà bao gồm việc xoay một bánh xe với nhiều lựa chọn giải thưởng.
Người chơi có thể đặt cược vào nơi họ nghĩ rằng bánh sẽ dừng lại, và nếu dự đoán của họ đúng, họ có thể nhận được giải thưởng.
Trò chơi thường được chơi tại các hội chợ, hội chợ và trong các sòng bạc, và nó có thể được chuyển tải cho việc sử dụng trong nhiều môi trường khác nhau.
Lucky Wheel là một trò chơi đơn giản và vui nhộn mà được người ta trên mọi độ tuổi yêu thích.
Giao diện demo ứng dụng:
Video demo ứng dụng:
Source code C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DrawLuckyWheel
{
public partial class Form1 : Form
{
bool wheelIsMoved;
float wheelTimes;
Timer wheelTimer;
LuckyCirlce koloFortuny;
public Form1()
{
InitializeComponent();
wheelTimer = new Timer();
wheelTimer.Interval = 30; // speed
wheelTimer.Tick += wheelTimer_Tick;
koloFortuny = new LuckyCirlce();
}
public class LuckyCirlce
{
public Bitmap obrazek;
public Bitmap tempObrazek;
public float kat;
public int[] wartosciStanu;
public int stan;
public LuckyCirlce()
{
tempObrazek = new Bitmap(Properties.Resources.lucky_wheel);
obrazek = new Bitmap(Properties.Resources.lucky_wheel);
wartosciStanu = new int[] { 12, 11, 10 ,09, 08, 07, 06, 05, 04, 03, 02, 01};
kat = 0.0f;
}
}
public static Bitmap RotateImage(Image image, float angle)
{
return RotateImage(image, new PointF((float)image.Width / 2, (float)image.Height / 2), angle);
}
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
if (image == null)
throw new ArgumentNullException("image");
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
Graphics g = Graphics.FromImage(rotatedBmp);
g.TranslateTransform(offset.X, offset.Y);
g.RotateTransform(angle);
g.TranslateTransform(-offset.X, -offset.Y);
g.DrawImage(image, new PointF(0, 0));
return rotatedBmp;
}
private void RotateImage(PictureBox pb, Image img, float angle)
{
if (img == null || pb.Image == null)
return;
Image oldImage = pb.Image;
pb.Image = RotateImage(img, angle);
if (oldImage != null)
{
oldImage.Dispose();
}
}
private void wheelTimer_Tick(object sender, EventArgs e)
{
if (wheelIsMoved && wheelTimes > 0)
{
koloFortuny.kat += wheelTimes / 10;
koloFortuny.kat = koloFortuny.kat % 360;
RotateImage(pictureBox1, koloFortuny.obrazek, koloFortuny.kat);
wheelTimes--;
}
koloFortuny.stan = Convert.ToInt32(Math.Ceiling(koloFortuny.kat / 30));
if (koloFortuny.stan == 0)
{
koloFortuny.stan = 0;
}
else
{
koloFortuny.stan -= 1;
}
label1.Text = Convert.ToString(koloFortuny.wartosciStanu[koloFortuny.stan]);
}
private void btnPlay_Click(object sender, EventArgs e)
{
wheelIsMoved = true;
Random rand = new Random();
wheelTimes = rand.Next(150, 200); //random số vòng quay
wheelTimer.Start();
}
}
}
Thanks for watching!