//snake-eyes test
using System;
using System.Threading;
using System.Collections;
public class C_ADice
{
private int m_output = 0;
public void Roll(int value)
{
m_output = value;
}
public int Result()
{
return m_output;
}
}
interface ICounter
{
int Counter();
int Times();
int Total();
}
public class counterbycase : ICounter
{
int m_counter = 0, m_times = 0;
int m_total = 0;
public counterbycase (int a, int b ,int c)
{
m_counter = c;
m_times = a;
m_total = b;
}
int ICounter.Counter()
{
return m_counter;
}
int ICounter.Times()
{
return m_times;
}
int ICounter.Total()
{
return m_total;
}
}
public class Snake_eyes_start
{
//public delegate void SnakeEyeDefected(int d1, int d2);
public string casename(int a)
{
return "c" + a.ToString();
}
public static void Main()
{
int n = Int32.Parse(Console.ReadLine());
Random diceroller = new Random();
C_ADice Dice_1 = new C_ADice();
C_ADice Dice_2 = new C_ADice();
ICounter[] casenumber = new ICounter[n];
for (int i = 0; i < n; i++)
{
int times = 0;
do
{ times ++;
Dice_1.Roll(diceroller.Next(1, 7));
Dice_2.Roll(diceroller.Next(1, 7));
Console.WriteLine("Results are {0} and {1} ", Dice_1.Result(), Dice_2.Result());
} while (Dice_1.Result() * Dice_2.Result() != 1);
Console.WriteLine("Snake eyes defected");
counterbycase casename(times) = new counterbycase();
}
}
}
counterbycase xxxxxx = new counterbycase();
我不知道我是否可以自动生成名称以替换&#34; xxxxxx&#34;, 我想知道xxxxxx是否是字符串?
此致 谢谢, 干杯,(抱歉,我必须添加一些文字来平衡代码)
Hung NGuyen
答案 0 :(得分:1)
我认为您尝试做的是将new counterbycase()
添加到您已为其建立的阵列中:
casenumber[i] = new counterbycase(times, total, counter);