/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
using System;
class HelloWorld {
public static void test()
{
FBGame fBGame1 = new FBGame("Germany", "Italy");
fBGame1.Play();
int r = fBGame1.Winner();
if ( r== 0)
Console.WriteLine(" {0} and {1} are X with {2} Goals",
fBGame1.GetTeam1(),
fBGame1.GetTeam2(),
fBGame1.GetScore1()
);
else if (r == 1)
Console.WriteLine("{0} is the winner! with {1} Goals",
fBGame1.GetTeam1(),
fBGame1.GetScore1()
);
else
Console.WriteLine("{0} is the winner! with {1} Goals",
fBGame1.GetTeam2(),
fBGame1.GetScore2()
);
}
static void Main() {
Console.WriteLine("Hello World");
test();
}
}
using System;
public class FBGame
{
//صفات
private string Team1;
private string Team2;
private int score1;
private int score2;
private Random rd;
//Set/Get
public string GetTeam1() { return this.Team1; }
public string GetTeam2() { return this.Team2; }
public int GetScore1() { return this.score1; }
public int GetScore2() { return this.score2; }
//بناء
public FBGame(string Team1, string Team2)
{
this.Team1 = Team1;
this.Team2 = Team2;
this.score1 = 0;
this.score2 = 0;
this.rd = new Random();
}
//عمليات
public void Play()
{
this.score1 = this.rd.Next(1, 9);
this.score2 = this.rd.Next(1, 9);
Console.WriteLine(this.Team1 + ":" + this.score1 +
", " +
this.Team2 + ":" + this.score2
);
}
public int Winner()
{
if (this.score1 == this.score2)
return 0;
else if (this.score1 > this.score2)
return 1;
else
return 2;
}
}