Определить, кто из игроков получил большую сумму очков в игре "Кубики" - C#
Формулировка задачи:
Смоделировать бросание каждым из трех игроков Двух игральных кубиков. определить, кто из игроков получил большую сумму очков
Вот еще програмка))
Решение задачи: «Определить, кто из игроков получил большую сумму очков в игре "Кубики"»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
static Random r;
int temp, temp2, temp3;
int[] mass;
public Form1()
{
InitializeComponent();
r = new Random();
mass = new int[3];
}
private void button1_Click(object sender, EventArgs e)
{
Start();
Leader();
Reset();
}
void Start()
{
temp = r.Next(1, 6);
temp2 = r.Next(1, 6);
MessageBox.Show("Выпавшие числа первого игрока: " + temp + ", " + temp2);
mass[0] = temp + temp2;
textBox1.Text = "Сумма: " + Convert.ToInt32(mass[0]);
//+++++++++++++++++++++++++++++++++++++++
temp = r.Next(1, 6);
temp2 = r.Next(1, 6);
MessageBox.Show("Выпавшие числа второго игрока: " + temp + ", " + temp2);
mass[1] = temp + temp2;
textBox2.Text = "Сумма: " + Convert.ToInt32(mass[1]);
//+++++++++++++++++++++++++++++++++++++++
temp = r.Next(1, 6);
temp2 = r.Next(1, 6);
MessageBox.Show("Выпавшие числа третьего игрока: " + temp + ", " + temp2);
mass[2] = temp + temp2;
textBox3.Text = "Сумма: " + Convert.ToInt32(mass[2]);
}
void Leader()
{
if (mass[0] == mass[1] || mass[0] == mass[2] || mass[1] == mass[2])
MessageBox.Show("Ничья");
else
{
temp3 = mass.Max();
if (temp3 == mass[0])
MessageBox.Show("Победитель Player 1 с суммой в " + mass[0] + " баллов");
if (temp3 == mass[1])
MessageBox.Show("Победитель Player 2 с суммой в " + mass[1] + " баллов");
if (temp3 == mass[2])
MessageBox.Show("Победитель Player 3 суммой в " + mass[2] + " баллов");
}
}
void Reset()
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}
}
}