127 lines
4.1 KiB
C#
127 lines
4.1 KiB
C#
using System.Media;
|
|
|
|
namespace WinGreed
|
|
{
|
|
public partial class frmStart : Form
|
|
{
|
|
private bool GameOver = false;
|
|
private GameOverCheck gocFirst = new GameOverCheck();
|
|
private GameOverCheck gocSecond = new GameOverCheck();
|
|
private frmPersonRound fPR = null;
|
|
private int actPlayerNo = -1;
|
|
public frmStart()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btnSpela_Click(object sender, EventArgs e)
|
|
{
|
|
if (lvMemberList.Items.Count > 0)
|
|
{
|
|
var nextLvInstance = lvMemberList.Items[NextLvItem()];
|
|
var nextPlayerName = nextLvInstance.Text;
|
|
|
|
if (!GameOver || (GameOver && nextLvInstance != gocFirst.lvsave))
|
|
{
|
|
fPR = new frmPersonRound(nextPlayerName);
|
|
fPR.TotPoints = int.Parse(nextLvInstance.SubItems[2].Text);
|
|
fPR.ShowDialog();
|
|
nextLvInstance.SubItems[2].Text = fPR.TotPoints.ToString();
|
|
lstLogBox.Items.Add($"{nextPlayerName} -> {fPR.AddedPoints} poäng.");
|
|
}
|
|
|
|
if (GameOver)
|
|
{
|
|
if (nextLvInstance == gocFirst.lvsave)
|
|
{
|
|
PlaySomething();
|
|
if (gocSecond.lvsave != null)
|
|
{
|
|
gocSecond.lvsave.SubItems[1].Text = (int.Parse(gocSecond.lvsave.SubItems[1].Text) + 1).ToString();
|
|
}
|
|
else
|
|
{
|
|
nextLvInstance.SubItems[1].Text = (int.Parse(nextLvInstance.SubItems[1].Text) + 1).ToString();
|
|
}
|
|
btnSpela.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
if(fPR.TotPoints > gocFirst.points && nextLvInstance != gocFirst.lvsave)
|
|
{
|
|
if(nextLvInstance != gocSecond.lvsave && fPR.TotPoints > gocSecond.points)
|
|
{
|
|
gocSecond.points = fPR.TotPoints;
|
|
gocSecond.lvsave = nextLvInstance;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (fPR.TotPoints > 10000)
|
|
{
|
|
GameOver = true;
|
|
gocFirst.points = fPR.TotPoints;
|
|
gocFirst.lvsave = nextLvInstance;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private int NextLvItem()
|
|
{
|
|
var retValue = 0;
|
|
if (lvMemberList.Items.Count > 1)
|
|
{
|
|
actPlayerNo++;
|
|
if (actPlayerNo > lvMemberList.Items.Count - 1)
|
|
{
|
|
actPlayerNo = 0;
|
|
}
|
|
retValue = actPlayerNo;
|
|
}
|
|
return retValue;
|
|
}
|
|
|
|
private void btnAddPlayer_Click(object sender, EventArgs e)
|
|
{
|
|
txtNewName.Visible = true;
|
|
|
|
}
|
|
|
|
private void btnAddOk_Click(object sender, EventArgs e)
|
|
{
|
|
var item = lvMemberList.Items.Add(txtNewName.Text.Trim());
|
|
item.SubItems.Add("0");
|
|
item.SubItems.Add("0");
|
|
txtNewName.Text = "";
|
|
txtNewName.Visible = false;
|
|
btnAddOk.Visible = false;
|
|
}
|
|
|
|
private void txtNewName_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txtNewName.Text.Trim().Length > 0)
|
|
{
|
|
btnAddOk.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
btnAddOk.Visible = false;
|
|
}
|
|
}
|
|
|
|
private void PlaySomething()
|
|
{
|
|
var soundPlayer = new SoundPlayer();
|
|
soundPlayer.SoundLocation = @"C:\Users\tommy\Downloads\smartsound_HUMAN_CROWD_Applause_Short.wav";
|
|
soundPlayer.Play();
|
|
}
|
|
|
|
private void btnSound_Click(object sender, EventArgs e)
|
|
{
|
|
PlaySomething();
|
|
}
|
|
}
|
|
} |