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;
namespace SnailRaceSimulator
{
public partial class Form1 : Form
{
Snail[] dogs = new Snail[4];
Guy[] guys = new Guy[3];
int m_iWinningSnail;
Random random = new Random();
public Form1()
{
InitializeComponent();
SetupRaceTrack();
}
private void SetupRaceTrack()
{
MinimumBet.Text = string.Format("Minimum bet " + BetAmount.Minimum);
int startingPosition = Snail1.Right - racetrack.Left;
int raceTrackLength = racetrack.Size.Width;
dogs[0] = new Snail() { MyPictureBox = Snail1, m_iRacetrackLength = raceTrackLength, m_iStartingPosition = startingPosition };
dogs[1] = new Snail() { MyPictureBox = Snail2, m_iRacetrackLength = raceTrackLength, m_iStartingPosition = startingPosition };
dogs[2] = new Snail() { MyPictureBox = Snail3, m_iRacetrackLength = raceTrackLength, m_iStartingPosition = startingPosition };
dogs[3] = new Snail() { MyPictureBox = Snail4, m_iRacetrackLength = raceTrackLength, m_iStartingPosition = startingPosition };
guys[0] = new Guy("Joe", null, 50, joeButton, joeBet);
guys[1] = new Guy("Bob", null, 75, bobButton, bobBet);
guys[2] = new Guy("Al", null, 45, alButton, alBet);
for (int i = 0; i < guys.Length; i++)
guys[i].UpdateLabels();
}
private void joeButton_CheckedChanged(object sender, EventArgs e)
{
SetBettorNameTextLabel("Joe");
}
private void bobButton_CheckedChanged(object sender, EventArgs e)
{
SetBettorNameTextLabel("Bob");
}
private void alButton_CheckedChanged(object sender, EventArgs e)
{
SetBettorNameTextLabel("Al");
}
private void SetBettorNameTextLabel(string strName)
{
BettorName.Text = strName;
}
private void Bets_Click(object sender, EventArgs e)
{
int GuyNumber = 0;
if (joeButton.Checked)
{
GuyNumber = 0;
}
else if (bobButton.Checked)
{
GuyNumber = 1;
}
else if (alButton.Checked)
{
GuyNumber = 2;
}
guys[GuyNumber].PlaceBet((int)BetAmount.Value, (int)SnailNumber.Value);
guys[GuyNumber].UpdateLabels();
}
private void race_Click(object sender, EventArgs e)
{
m_iWinningSnail = 0;
race.Enabled = false;
Bets.Enabled = false;
timer1.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
SetBettorNameTextLabel("Joe");
}
private void timer1_Tick_1(object sender, EventArgs e)
{
for (int i = 0; i < dogs.Length; i++)
{
int iTemp = random.Next(-1, 3);
if (iTemp + dogs[i].m_iLocation < 0)
iTemp = random.Next(0, 2);
if (dogs[i].Run(iTemp))
{
timer1.Stop();
m_iWinningSnail = i + 1;
MessageBox.Show("Snail " + m_iWinningSnail + "# won the race!");
for (int j = 0; j < guys.Length; j++)
{
if (guys[j].bet != null)
{
guys[j].Collect(m_iWinningSnail);
guys[j].bet = null;
guys[j].UpdateLabels();
}
}
for (int j = 0; j < dogs.Length; j++)
dogs[j].TakeStartingPosition();
race.Enabled = true;
Bets.Enabled = true;
break;
}
}
}
private void Form1_Load_1(object sender, EventArgs e)
{
SetBettorNameTextLabel("Joe");
}
}
}