看到一个暴强的翻译,闲的蛋疼,写个c#版的
在豆瓣上看到一篇关于拿破仑的翻译,文科生的翻译有几段相当传神,不得不佩服汉语的强大。有好事者还用程序语言实现了一下,现已有java、python和html的版本,我也来写个渺小的C#版本,运行结果和java版是一致的,但是本文的这个稍作抽象(java版的我不觉得有多好,甚至应该说写得真烂),更符合C#程序员的阅读习惯。贴代码先:
【渺小滴C#版(知道运行结果又如何)】
using System;
using System.Collections.Generic;
public abstract class Person
{
/// <summary>
/// name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Chrysanthemum Damage Per Second
/// </summary>
public int CDPM { get; set; }
}
public class Enemy : Person
{
public Enemy(string name, int cdpm)
{
this.Name = name;
this.CDPM = cdpm;
}
public void Shout()
{
if (this.CDPM > 0)
{
Console.WriteLine(string.Format("{0} says: we are invincible!!!", this.Name));
}
else
{
Console.WriteLine(string.Format("{0} says: ......", this.Name));
}
}
public bool IsCanBeatNapoleon(Napoleon n)
{
if (n == null)
{
throw new ArgumentNullException("Napoleon was not initialized...");
}
return this.CDPM > n.CDPM;
}
}
public class Napoleon : Person
{
private IList<Enemy> enemies = new List<Enemy>();
private Napoleon()
{
this.Name = "Napoleon";
this.CDPM = 100000;
enemies.Add(new Enemy("Italy", 100));
enemies.Add(new Enemy("Egypt", 100));
enemies.Add(new Enemy("Russia ", 100));
}
private void Speak()
{
Console.WriteLine("My enemy number: " + enemies.Count);
IList<Enemy> trueEnemies = new List<Enemy>();
foreach (Enemy item in enemies)
{
if (item.CDPM > CDPM)
{
trueEnemies.Add(item);
}
}
Console.WriteLine("The number of enemies who can beat me: " + trueEnemies.Count);
foreach (Enemy item in enemies)
{
do
{
item.Shout();
}
while (item.IsCanBeatNapoleon(this));
}
Console.WriteLine("I am {0},my cdpm is {1}", this.Name, this.CDPM);
Console.WriteLine("Dispose enemy list...");
enemies.Clear();
Console.WriteLine("Enemy list disposed!");
}
static void Main(string[] args)
{
(new Napoleon()).Speak();
Console.Read();
}
}
using System.Collections.Generic;
public abstract class Person
{
/// <summary>
/// name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Chrysanthemum Damage Per Second
/// </summary>
public int CDPM { get; set; }
}
public class Enemy : Person
{
public Enemy(string name, int cdpm)
{
this.Name = name;
this.CDPM = cdpm;
}
public void Shout()
{
if (this.CDPM > 0)
{
Console.WriteLine(string.Format("{0} says: we are invincible!!!", this.Name));
}
else
{
Console.WriteLine(string.Format("{0} says: ......", this.Name));
}
}
public bool IsCanBeatNapoleon(Napoleon n)
{
if (n == null)
{
throw new ArgumentNullException("Napoleon was not initialized...");
}
return this.CDPM > n.CDPM;
}
}
public class Napoleon : Person
{
private IList<Enemy> enemies = new List<Enemy>();
private Napoleon()
{
this.Name = "Napoleon";
this.CDPM = 100000;
enemies.Add(new Enemy("Italy", 100));
enemies.Add(new Enemy("Egypt", 100));
enemies.Add(new Enemy("Russia ", 100));
}
private void Speak()
{
Console.WriteLine("My enemy number: " + enemies.Count);
IList<Enemy> trueEnemies = new List<Enemy>();
foreach (Enemy item in enemies)
{
if (item.CDPM > CDPM)
{
trueEnemies.Add(item);
}
}
Console.WriteLine("The number of enemies who can beat me: " + trueEnemies.Count);
foreach (Enemy item in enemies)
{
do
{
item.Shout();
}
while (item.IsCanBeatNapoleon(this));
}
Console.WriteLine("I am {0},my cdpm is {1}", this.Name, this.CDPM);
Console.WriteLine("Dispose enemy list...");
enemies.Clear();
Console.WriteLine("Enemy list disposed!");
}
static void Main(string[] args)
{
(new Napoleon()).Speak();
Console.Read();
}
}
最后,弱弱问一下,我怎么觉得程序实现的都和翻译无关呢? 比文科的翻译逊色不是一点点。
作者:Jeff Wong
出处:http://jeffwongishandsome.cnblogs.com/
本文版权归作者和博客园共有,欢迎围观转载。转载时请您务必在文章明显位置给出原文链接,谢谢您的合作。