电台复活节_复活节彩蛋:它们是什么以及如何创建它们

电台复活节

An Easter egg is a hidden message or feature, completely unrelated to normal functionality, that developers put inside software, website, or game. Unlike viruses, worms, and trojans, Easter eggs are completely harmless. They are often used as a sort of signature of a programmer or as a joke. Sometimes they are written by personal initiative of a programmer and not a company request, and in those cases the company might take legal action against the developer. On the other hand, there are plenty of cases where a company, especially ones that specialize in game development, explicitly request several Easter eggs.

复活节彩蛋是开发人员放入软件,网站或游戏中的与正常功能完全无关的隐藏消息或功能。 与病毒,蠕虫和特洛伊木马不同,复活节彩蛋是完全无害的。 它们通常被用作程序员的一种签名或一个玩笑。 有时,它们是由程序员亲自编写的,而不是公司的要求,在这种情况下,公司可能会对开发人员采取法律行动。 另一方面,在很多情况下,一家公司,尤其是专门从事游戏开发的公司,明确要求几个复活节彩蛋。

复活节彩蛋简史 (A Short History of the Easter Eggs)

The term comes from the Anglo-Saxon tradition where parents, hide some eggs in their garden for Easter and then let their children find them. This type of work is often used in games where, for example, through a combination of keys or performing certain actions in a given order, you can access new levels or new powers.

该术语来自盎格鲁-撒克逊人的传统,父母在父母的花园里藏一些鸡蛋做复活节,然后让孩子们找到它们。 这类工作通常用于游戏中,例如,通过组合键或以给定顺序执行某些操作,您可以使用新的关卡或新功能。

For several years people, myself included, thought that the game Adventure released by Atari in 1979 was the first video game to containing an Easter egg. It wasn’t as amazing as you might think; it just displayed Warren Robinett (the name of the programmer). Although this myth is still alive, it seems that previous Easter eggs existed.

多年来,包括我自己在内的人们一直认为Atari在1979年发行的游戏Adventure是第一个包含复活节彩蛋的视频游戏。 这并不像您想像的那样惊人。 它只是显示Warren Robinett(程序员的名字)。 尽管这个神话仍然存在,但似乎以前的复活节彩蛋已经存在

The number of Easter eggs contained in software and games, even the most famous ones, has increased over the last couple decades. The web offers a plethora of examples; companies like Mozilla, Oracle, and Google are just few who have put Easter eggs in their software.

在过去的几十年中,软件和游戏(甚至是最著名的)中包含的复活节彩蛋数量有所增加。 网络上提供了大量示例。 像Mozilla,Oracle和Google这样的公司很少在软件中添加复活节彩蛋。

  • Mozilla put an Easter egg in all versions of Firefox. To see it in action, type “about:mozilla” in the address bar and then press enter. Firefox displays a quote from the “Book of Mozilla” about the birth of Firefox.

    Mozilla在所有版本的Firefox中都添加了一个复活节彩蛋。 要查看其运行情况,请在地址栏中键入“ about:mozilla”,然后按Enter。 Firefox显示“ Mozilla图书”中关于Firefox诞生的报价。
  • Google created an Easter egg in Picasa. If you open the desktop software and then press Ctrl + Shift + Y, a toy bear image appears. Every time you press the key combination, another bear is displayed.

    Google在Picasa中创建了一个复活节彩蛋。 如果打开桌面软件,然后按Ctrl + Shift + Y,则会出现玩具熊图像。 每次按组合键,都会显示另一只熊。
  • Skype, the famous VoIP software, has a simple but funny example. If you open the chat and then type “(drunk)” a hidden emoticon appears.

    著名的VoIP软件Skype有一个简单但有趣的示例。 如果打开聊天,然后键入“(醉酒)”,则会出现一个隐藏的图释。
  • A Tetris game has been hidden in the uTorrent software. To see it, click the “Help” menu and then go to “About”. Press T key and the game will appear.

    uTorrent软件中隐藏了俄罗斯方块游戏。 要查看它,请单击“帮助”菜单,然后转到“关于”。 按T键,将出现游戏。
  • The OpenOffice suite has a lot of hidden games and other stuff. So many that they have a specific section on their website! If you want to play Tic-Tac-Toe in Calc, write “=GAME(A2:C4;”TicTacToe”)” into the A1 cell and then press enter.

    OpenOffice套件包含许多隐藏的游戏和其他内容。 如此之多,以至于他们在网站上都有特定的部分 ! 如果要在Calc中播放井字游戏,请在A1单元格中写入“ = GAME(A2:C4;“ TicTacToe”)”,然后按Enter。

创建您的第一个复活​​节彩蛋 (Creating Your First Easter Egg)

I’ll guide you in creating a simple Easter egg with PHP. We’ll create a search form, and if a user searches for my name (obviously you can change with your own) the page will show a nice message. This will be the Easter egg.

我将指导您使用PHP创建一个简单的复活节彩蛋。 我们将创建一个搜索表单,如果用户搜索我的名字(显然您可以用自己的名字更改),则该页面将显示一条漂亮的消息。 这将是复活节彩蛋。

Create a PHP file with the following HTML code:

使用以下HTML代码创建一个PHP文件:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>My First Easter Egg!</title>
 </head>
 <body>
  <h1>My First Easter Egg!</h1>
  <h2>Search</h2>
  <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
   <input type="text" name="searched-text" id="searched-text" placeholder="Search..." accesskey="s">
   <input type="submit" value="Search">
  </form>
 </body>
</html>

The form doesn’t have many elements; it only needs an input box where the user can type what she wants to search for and the submit button.

表单没有很多元素; 它只需要一个输入框,用户就可以在其中输入要搜索的内容和提交按钮。

Try to use the form. As you’ll see, it does nothing but redirects the user to the same page, sending what was entered in the search field as a parameter. The business logic has not implemented yet, so don’t worry that nothing special happens.

尝试使用该表格。 正如您将看到的,它什么也不做,只是将用户重定向到同一页面,并将在搜索字段中输入的内容作为参数发送。 业务逻辑尚未实现,所以不用担心没有什么特别的事情发生。

The next step is to write the business logic. We need to analyze the request using the $_GET superglobal array to see its value. If the searched-text parameter isn’t empty, we’ll display what the user searched for, but in case she searched for my name, I’ll add the funny message “I know, I’m so cool!”.

下一步是编写业务逻辑。 我们需要使用$_GET超全局数组分析请求以查看其值。 如果searched-text参数不为空,我们将显示用户搜索的内容,但是如果她搜索了我的名字,我将添加有趣的消息“我知道,我很酷!”。

The resultant code should look as follow.

结果代码应如下所示。

<?php
if (! empty($_GET['searched-text'])) {
    echo "<h3>You searched for: " . htmlentities($_GET["searched-text"]) . "</h3>";
    // The comparison is case-insensitive
    if (strcasecmp($_GET["searched-text"], "Aurelio De Rosa") == 0) {
        echo "<p>I know, I'm so cool!</p>";
}

Now, when the user searches for my name she’ll see the following screen:

现在,当用户搜索我的名字时,她将看到以下屏幕:

alt

一个稍微复杂的例子 (A Slightly More Complicated Example)

As you’ve seen, the previous example is very simple. Now I’ll explain a sightly more complicated example. Imagine you have the form, but it’s not very professional to show the message the first time a user searches for your name. Maybe she’s just searching for some software you’ve written. What you can do is to show the funny message only if the user persists in searching repeatedly your name. Ultimately we need a counter and, for the sake of the example, I’ll display the message if the user searches for my name three consecutively times.

如您所见,前面的示例非常简单。 现在,我将解释一个更为复杂的示例。 想象一下您拥有表单,但是在用户第一次搜索您的名字时显示消息并不是很专业。 也许她只是在搜索您编写的某些软件。 您可以做的是仅在用户继续反复搜索您的姓名时显示有趣的消息。 最终,我们需要一个计数器,并且为示例起见,如果用户连续三次搜索我的名字,我将显示该消息。

The first thing needed is to call session_start(), a function that creates a new session or resumes the current one. Then test if the Easter egg counter is set in the $_SESSION superglobal array; if not, we’ll set its value to zero. Every time the user searches for my name the counter is incremented by 1. In all the other cases, the counter is reset. The last case includes if the message has been displayed too.

需要做的第一件事是调用session_start() ,该函数创建一个新会话或恢复当前会话。 然后测试$_SESSION超全局数组中是否设置了复活节彩蛋计数器; 如果没有,我们将其值设置为零。 每次用户搜索我的名字时,计数器都会增加1。在所有其他情况下,计数器都会重置。 最后一种情况包括该消息是否也已显示。

The resulting source code is the following:

产生的源代码如下:

<?php
session_start();
if (!isset($_SESSION["easter-egg"])) {
    $_SESSION["easter-egg"] = 0;
}
?>
<html>
 <head>
  <meta charset="UTF-8">
  <title>My First Easter Egg!</title>
 </head>
 <body>
  <h1>My First Easter Egg!</h1>
  <h2>Search</h2>
  <form method="get" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
   <input type="text" name="searched-text" id="searched-text" placeholder="Search..." accesskey="s">
   <input type="submit" value="Search">
  </form>
<?php
if (!empty($_GET["searched-text"])) {
    echo "<h3>You searched for: " . htmlentities($_GET["searched-text"]) . "</h3>";
    // The comparison is case-insensitive
    if (strcasecmp($_GET["searched-text"], "Aurelio De Rosa") == 0) {
        $_SESSION["easter-egg"]++;
        if ($_SESSION["easter-egg"] == 3) {
            echo "<p>I know, I'm so cool!</p>";
            $_SESSION["easter-egg"] = 0;
        }
    }
    else {
        $_SESSION["easter-egg"] = 0;
    }
}
else {
    $_SESSION["easter-egg"] = 0;
}
?>
 </body>
</html>

结论 (Conclusions)

I’ve shown you in this article how you can create a simple Easter egg. Easter eggs are a fun way to sign your software and to prove your paternity, Be careful though not to add one in your company software because the consequences could be undesirable. Now, every time you run a new program you’ll probably want search the Internet to see if it contains an Easter egg.

我在本文中向您展示了如何创建一个简单的复活节彩蛋。 复活节彩蛋是一种用于签名软件和证明亲子关系的有趣方式。请注意,尽管不要在公司软件中添加复活节彩蛋,否则可能会带来不良后果。 现在,每次运行新程序时,您可能都希望在Internet上搜索以查看其是否包含复活节彩蛋。

Image via Fotolia

图片来自Fotolia

翻译自: https://www.sitepoint.com/easter-eggs-what-they-are-and-how-to-create-them/

电台复活节

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值