187 lines
5.5 KiB
C#
187 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Diagnostics;
|
|
|
|
namespace WinGreed
|
|
{
|
|
public partial class frmPersonRound : Form
|
|
{
|
|
int y = 79;
|
|
int x = 0;
|
|
int row = 0;
|
|
private List<Button> _dice = new List<Button>();
|
|
private HandleThrow _ht;
|
|
public string Player { get; set; }
|
|
public int TotPoints { get; set; }
|
|
List<int> Points = new List<int>();
|
|
public frmPersonRound(string player)
|
|
{
|
|
InitializeComponent();
|
|
Player = player;
|
|
this.Text = $"Din tur - {Player}";
|
|
_ht = new HandleThrow();
|
|
_ht.Who = Player;
|
|
///ht.Throw();
|
|
}
|
|
|
|
private void btnThrow_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
x = 0;
|
|
y = y + btnDiceTmpl1.Height + 5;
|
|
var no = 0;
|
|
var result = _ht.Throw();
|
|
|
|
|
|
Button btn = null;
|
|
MarkGrayAndDisable(row);
|
|
|
|
|
|
row++;
|
|
|
|
|
|
foreach (var item in result)
|
|
{
|
|
no++;
|
|
switch (item.Number)
|
|
{
|
|
case 1:
|
|
{
|
|
btn = btnDiceTmpl1.Clone<Button>();
|
|
btn.Name = $"btnDice{row}1";
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
btn = btnDiceTmpl2.Clone<Button>();
|
|
btn.Name = $"btnDice{row}2";
|
|
break;
|
|
}
|
|
case 3:
|
|
{
|
|
btn = btnDiceTmpl3.Clone<Button>();
|
|
btn.Name = $"btnDice{row}3";
|
|
break;
|
|
}
|
|
case 4:
|
|
{
|
|
btn = btnDiceTmpl4.Clone<Button>();
|
|
btn.Name = $"btnDice{row}4";
|
|
break;
|
|
}
|
|
case 5:
|
|
{
|
|
btn = btnDiceTmpl5.Clone<Button>();
|
|
btn.Name = $"btnDice{row}5";
|
|
break;
|
|
}
|
|
case 6:
|
|
{
|
|
btn = btnDiceTmpl6.Clone<Button>();
|
|
btn.Name = $"btnDice{row}6";
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
|
|
_dice.Add(btn);
|
|
btn.Location = new Point(x + (btn.Width + 5) * no, y);
|
|
btn.Visible = true;
|
|
btn.Tag = item;
|
|
btn.Click += new System.EventHandler(btnDiceTmpl_Click);
|
|
this.Controls.Add(_dice.Last());
|
|
this.Refresh();
|
|
}
|
|
|
|
CalculateResult(result);
|
|
|
|
}
|
|
|
|
private void CalculateResult(List<Dice> result)
|
|
{
|
|
List<int> Numbers = new List<int>();
|
|
foreach (var item in result)
|
|
{
|
|
Numbers.Add(item.Number);
|
|
}
|
|
|
|
AnalyseNumbers(Numbers);
|
|
}
|
|
|
|
private void MarkGrayAndDisable(int row)
|
|
{
|
|
List<int> Numbers = new List<int>();
|
|
|
|
if (row > 0)
|
|
{
|
|
foreach (var item in _dice)
|
|
{
|
|
if (item.Name.Contains($"btnDice{row}"))
|
|
{
|
|
item.Enabled = false;
|
|
if (item.BackColor == Color.Red)
|
|
{
|
|
item.BackColor = Color.Gray;
|
|
Numbers.Add(((Dice)item.Tag).Number);
|
|
}
|
|
}
|
|
}
|
|
AnalyseNumbers(Numbers, false);
|
|
}
|
|
}
|
|
|
|
private void AnalyseNumbers(List<int> numbers, bool before = true)
|
|
{
|
|
if (before)
|
|
{
|
|
TextBox txt = null;
|
|
TextBox txtRes = null;
|
|
|
|
txt = txtMaxValue.Clone<TextBox>();
|
|
txt.Name = $"txtMaxValue{row}";
|
|
txt.Location = new Point(x + 350, y);
|
|
txt.Visible = true;
|
|
this.Controls.Add(txt);
|
|
this.Refresh();
|
|
|
|
txtRes = txtChosenValue.Clone<TextBox>();
|
|
txtRes.Name = $"txtChosenValue{row}";
|
|
txtRes.Location = new Point(x + 350 + (txtRes.Width + 5), y);
|
|
txtRes.Visible = true;
|
|
this.Controls.Add(txtRes);
|
|
this.Refresh();
|
|
}
|
|
|
|
numbers.ForEach(x => Debug.Write($"{x}, "));
|
|
Debug.WriteLine(" -");
|
|
}
|
|
|
|
private void btnDiceTmpl_Click(object sender, EventArgs e)
|
|
{
|
|
if (((Dice)((Button)sender).Tag).Chosen)
|
|
{
|
|
((Button)sender).BackColor = Color.Green;
|
|
((Dice)((Button)sender).Tag).Chosen = false;
|
|
}
|
|
else
|
|
{
|
|
((Dice)((Button)sender).Tag).Chosen = true;
|
|
((Button)sender).BackColor = Color.Red;
|
|
}
|
|
}
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
}
|
|
}
|