.NET programmer's game

xiaoxiao2021-03-06  67

First download the environment to http://www.terrariumgame.net.

Experiment 1: Creating a herbal animal experiment: The purpose of this experiment is to create a function of full organism to land animal feeding. You can start adding some advanced features from creating a simple organism. As long as you think it's the route to meet the requirements, you can introduce it into the land animal ecosystem, and then you can fight against other participants.

Practice 1 - Creating a simple herbivore Animals just a class yourself, this class inherits an Animal class exposed from Terrarium. In this exercise, you can create a simple herbivore with C #, you can Use Microsoft Visual Studio2003 to create, compile and run. --- Start - please use your name instead of any text you see below, , because every one introduced into .NET Terrarium must have a unique name. 1.1 Creating a new Terrarium Animal project in Visual Studio. (Many items will be used in the item options after downloading installations)> First click on Visual Studioi .NET 2003> Click File -> Create a new class and select C # as a development language. > Get a name for this project. OK, start. 1.2 Add a name and email address to your animals. Use your name and mailbox to update the Authorinformation list properties, as follows: [Assembly: Authorinformation ("Your Name", "Someone@microsoft.com")] 1.3 Set the Carnivore property to false. Set the carnivore property to false indicates that your animal is A herbivore. As follows: [Carnivore] 1.4 Select a skin to your animal. Animalskin attributes define your animal type. As shown in: [Animalskinfamily.inchworm] 1.5 Distributes a value of the feature property of your animal, and the sum of the values ​​of all attributes cannot exceed 100. As follows. [MaximUmeNergyPoints (20)]

[Eatingspeedpointsattribute (0)]

[Attackdamagepointsattribute (12)]

[DefendDamagePointsattribute (12)]

[MaximumSpeedPointSattribute (16)]]

[CamouflagePointSattribute (10)]

[EyesightPointSattribute (20)]

1.6 Add a destination place to the Myanimal class. Because your animal is an animal of a herb, it grases, so the destination stores stores your animals to eat, put the following in the Initialize method. As follows: // The Current Plant We're Going After

PlantState Target PLANT = NULL; 1.7 IdleEvent Event Book Idle Event is an event that the last triggered event. This line tells the game engine to call the Myanimal_Idle method each time IdleEvent is triggered, add the following to the initialization method, such as, IDle = new idleeventhandler (Myanimal_Idle); 1.8 Add IdleEvent Handler (handle) This method provides most of your herbivore animals, first, if your animal is ready to resurrection, it provides a replication cycle, Then it is desperate to eat. If it already has a destination place, it starts to start eating at the destination place. If it doesn't have a destination place, it tries to scan it around it, find out a place. Add the following method to the Myanimal class. // Fired After ALL Other Events Are Fired During a Turnvoid Myanimal_Idle (Object Sender, iDleeventargs E)

{

Try

{

// Reproduce As Offen As Possible

canREPRODUCE

BeginReProduction (NULL);

// if we can eat and we have a target, eat

IF (CANEAT)

{

WriteTrace ("Hungry.");

IF (! ity)

{

WriteTrace ("NOT Eating: Have Target Plant?");

IF (targetplant! = null)

{

WriteTrace ("Yes, Have Target Plant Already.");

IF (withineatingrange (targetplant))

{

WriteTrace ("Withnin Range, Start Eating.");

Begineating (TargetPlant);

IF (ismoving)

{

WriteTrace ("Stop While Eating.");

Stopmoving ();

}

}

Else

{

IF (! ismoving)

{

WriteTrace ("Move to Target Plant");

Beginmoving (New Movement.Position, 2));

}

}

}

Else

{

WriteTrace ("Don't Have Target PLANT.");

IF (! scanfortarget ())

{

IF (! ismoving)

{

WriteTrace ("No Plant Found, So Pick A Random Point and Move There");

INT randomx = Organismrandom.next (0, Worldwidth - 1);

INT randomy = Organismrandom.next (0, WorldHeight - 1);

Beginmoving (New MovementVector (New Point (Randomx, Randomy), 2);

}

Else

{

WriteTrace ("Moving and Looking ...");

}

}

}

}

Else

{

WriteTrace ("eating.");

IF (ismoving)

{

WriteTrace ("Stop Moving While Eating.");

Stopmoving ();

}

}

}

Else

{

WriteTrace ("full: do nothing.");

IF (ismoving)

Stopmoving ();

}

}

Catch (Exception EXC)

{

WriteTrace (Exc.toString ());

}

}

// Looks for Target Plants, and Starts Moving Towards

// the first one it find

Bool scanfortargetplant ()

{

Try

{

ArrayList FoundCreatures = scan ();

IF (FoundCreatures.count> 0)

{

// ALWAYS MOVE AFTER Closest Plant

Foreach (OrganismState OrganismState in FoundCreatures)

{

IF (OrganismState Is PlantState)

{

TargetPlant = (PlantState) OrganismState;

Beginmoving (NEW MOVEMENTVECTOR (OrganismState.Position, 2));

Return True;

}

}

}

}

Catch (Exception EXC)

{

WriteTrace (Exc.toString ());

}

Return False;

}

1.9 LoadEvent Event Book LoadEvent is the first event being called every round. This line means that when each LoadEvent event is triggered, the Myanimal_Load method is called (this method has been defined in 1.7). Add the following to the Initialize method. Load = new loadEventhandler (Myanimal_Load); 1.10 Add LoadEvent Handler (handle) In the LoadEvent event, your animal has been checking if the site is existing (it may disappear or eaten) Add below to myaniaml class. // first Event Fired on An ORGANISM EACH TURN

Void Myanimal_Load (Object Sender, LoadEventArgs E)

{

Try

{

IF (targetplant! = null)

{

// See if our target Plant Still Exists (It May Have Died)

// Lookfor Returns Null IT ISN't Found

TargetPlant = (PlantState) Lookfor (TargetPlant);

IF (targetplant == null)

{

// Writetrace is the best way to debug your creatures.

WriteTrace ("Target Plant Disappeared.");

}

}

}

Catch (Exception EXC)

{

WriteTrace (Exc.toString ());

}

}

1.11 Generate Animal DLL Generates this Animal DLL by selecting the generation - generates a solution. 1.12 Introduce your herbivores into terrestrial animal breeding. Terrarium supports two game modes. Land animal model and generating system mode. In the generated system mode, your animals compete with other animals that have been developed. The land animal model is a terrestrial animal test mode. In this mode, you can test your animals in a control environment. Then open the .NET Terrarium 1.2 environment you downloaded and installed, Terrarium 1.2 client opens in ecosystem mode. Terrarium 1.2 has two modes to run, the default mode is an ecosystem mode, which is the place where participants interact. Peers will find each other, you can communicate with each other (here I don't know if there is any translation, huh) (description: Teleport Organisms) and report their status through the server. Two people will be more fun in this mode. Another mode called Terrarium mode, which is a "offline" mode that can test your animals. In this mode, you don't communicate with other Peers, so there is no TelePortation, you will not report your status to the server. In this mode, you can save a state, create a new life, or open existing. You will feel that this model is very helpful for creation and testing your animals. In this exercise, we don't have to introduce animals into the ecosystem because animals may have no ability to survive longer. Instead, we changed to Terrarium mode, which allows you to test your animals before introducing animals into an ecosystem. In the open .NET Terrarium 1.2 environment, you can switch to the Terrarium mode by clicking the New Terrarium button, and enter the lab01 as the name and save it, then restart the client in the Terrarium mode. The next step is to add some plants to the animal breeding office, so you can eat when your grassy animals are introduced. You can click the ADD button, then click the Server list button, then you will see a few animals that have been introduced.

For this experiment, use it as a real world, there are several plant species you can choose, choose any "Plant" and click OK, then you will introduce ten kinds of plants to the breeding where you choose. . To add more plants by selecting plants in the drop-down box, click the INSERT button, there is a large amount of plants in the feeding center. Finally introduce your animals. You can click the Browse button to browse to your created DLL ( .dll), this DLL is placed in the bin directory of your project. You should be able to see the instance of the animals you created in the feeding place. You can also add more animals as using the combo box and the INSERT button as adding plants.

note:. When the code is running, you can't change the basic characteristics of the animal - performance performance: How fast your animal moves, how much is it, how much is it? These features are predefined by specifying properties in the class you created. You can find some valid properties list in Attributes section of Organism's document. Some features require a bit available, you can decide yourself. Every animal can be divided into each of these properties. For example: You can assign more points to maximuspeedpointsattribute properties faster, but if the number of points of the EyesightPointSattribute property is too small, the vision of animals is not very good. Once you define the characteristics of animals, you can write code to control the behavior of animals. Find the Animal class and Organism class in the Organism document (Animal inherited from Organism) to see what you can do in the code. Note that many methods begin with "Begin ...", which are different. When these movements are completed, they will trigger it to tell you that it is ready. ------------ Lab1 OVER ---------- Now Lab2 Begin .........

Experimental Summary: In this experiment, you have created a simple herbivore and tested in the feeding center.

Exercise 2 - Processing Attack In this Hands-ON experiment, an attack event can be processed by using the event model of the feeding office. When you are attacked by another animal, you will trigger an attack event. This is just one of the many events you can handle, you can find all the lists in the Organism document. 2.1 Open the animals (simple herbivores) created in Exercise 1> Open the VS2003, select File - Open the project, browse to the item you created in Exercise 1. turn on. > If the source file is not opened in the main window, you can double-click the MyanImal.cs icon in the Solution window. 2.2 Reservation AttackedEvent (Attacking Event) When your animal is attacked by another animal attack, an attack event will be triggered. Below this line tells the game engine to call the myanimal_attacked method when triggered each attack event. Add the following line to the initialize method Attacked = new attackedEventhandler (myanimal_attacked);

2.3 Add AttackedEvent (Attack Event) Handle

When your animal is attacked, it will try to resist an attacker, then move the following to the Myanimal class by moving into a random location in the gaming board. // Fired if we're being attacked void MyAnimal_Attacked (object sender, AttackedEventArgs e) {if (e.Attacker.IsAlive) {AnimalState theAttacker = e.Attacker; BeginDefending (theAttacker); // defend against the attacker WriteTrace ( "Run Away to Some Random Point "); int x = Organismrandom.next (0, Worldwidth - 1); int y = Organismrandom.next (0, WorldHeight - 1); Beginmoving (New Point (x, y), 10 ));}} 2.4 Rename and generate Animal DLL.> Select Project Properties and open a project properties dialog. > Select "Universal" in the general option, change the assembly name field for _ex2, click OK.> Generate an Animal DLL by selecting a generation-generating solution.

2.5 Introducing your herbivores in Terrarium mode into the feeding center.

------------ Lab2 over ---------- Now Lab3 Begin .........

Experimental Summary: In this experiment, you have turned your herbivores into attacks when attacked and automatically responded.

Practice 3-Communication You will use the antenna property in the next experiment to control communication with other animals. Every animal can be seen in the state of antenna properties. It can be exchanged with other animals in the ecosystem by changing the value of an antenna property. In this experiment, when you find that your plants are occupied by other animals, you can make the animals to signal, after the animal response, the occupation of animals will run away. 3.1 Opens the items you created in Exercise 1. 3.2 MoveCompletedEvent defined event when you stop moving MoveCompletedEvent animals will be triggered, this line tells the game engine when each went to call MyAnimal_MoveCompleted method is triggered when MoveCompletedEvent add the following line to the Initialize method in MoveCompleted = new MoveCompletedEventHandler ( Myanimal_movecompleted);

3.3 Adding a MoveCompletedEvent handle There are two causes of animals to complete its mobile events, one is to reach its destination, one is blocked in the way of moving. If the road of animals is blocked, we have to send a signal to drive the animals that block the block. The signal is used is antenna, the value is 13. Add the following method to the Myanimal class. // Fired When We've Finished Moving.

PRIVATE VOID Myanimal_MoveCompleted (Object Sender, MoveTedEventArgs E)

{

// reset the antenna value

THIS.ANTENNAS.ANTENNAVALUE = 0; // if We've Stopped Because Something is Blocking Us ...

IF (E.reason == ReasonforStop.blocked)

{

WriteTrace ("Something's Blocking My Way.");

IF (E.Blockingorganism IS AnimalState)

{

Animalstate Blockinganimal = (animalstate) E.Blockingorganism;

IF (BlockinganImal.animalspecies.issamespecies))

{

// signal to ou wriend to move out of ur way.

WriteTrace ("One of my friends is blocking my way. I'll ask him to move.");

THIS.ANTENNAS.ANTENNAVALUE = 13;

}

}

}

}

3.4 Join the logic removed when blocking the comrades in each round, we need to find a signal that is issued when the comrades are blocked. ShouldimoveFormyFriend method Looking for animals for signals 13, that is, comrades. If you are found, you will stay away from blocking animals. Add the following method to the Myanimal class. // routine to move out of the way.

Void ShouldimoveFormyFriend ()

{

Try

{

ArrayList Foundanimals = scan ();

IF (FoundAnimals.count> 0)

{

Foreach (OrganismState OrganismState in FoundAnimals)

{

IF (OrganismState Is AnimalState)

{

Animalstate visibleanimal = (animalstate) OrganismState;

// ONLY MOVE IF The Animal IS One of Our Friends (Issamespecies).

VisibleanIMal.Species.issamespecies (this.species))

{

// if The Animal's Antenna Value IS 13, It Means They're Blocked (See the MoveCompleteDevent Method).

IF (visibleanimal.antennas.antennavalue == 13)

{

// We're Blocking Our Friend, So Wehibed Move.

WriteTrace ("I'm Blocking One of My Friends. I shop Move.");

INT newx = this.position.x - (visibleanimal.position.x - this.position.x);

INT newy = this.position.y - (visibleanimal.position.y - this.position.y);

Beginmoving (New MovementVector (New Point (NEWX, NEWY), 2);

Return;

}

}

}

}

}

}

Catch (Exception EXC) {

WriteTrace (Exc.toString ());

}

}

3.5 Call the ShouldimoveFormyFriend () method at the end of each round, we need to call the ShouldimoveForMyFriend () method to remove obstacles for comrades. When each round of IDleEvent event is triggered, add the call to the ShouldimoveForMyFriend method at the end of the Myanimal_Idle method. Add this line to the last line of the Myanimal_Idle method. SHOULDIMOVEFORMYFRIEND (); 3.6 Renaming and Generating Animal DLL> Select Project - Properties, Select - General in Opening Universal Properties, change the Assembly Name field to _ex3.> Select Generate - Generate Solutions to generate animal Dll.3.7 Introduces the herbivore in Terrarium mode into the feeding center. Such as practicing 1 said.

Exercise 3 - Introducing Ecosystem - Finally, you can fight, HOHO in the next experiment, you will introduce your animals into the ecosystem, this ecosystem makes this game more interesting, here you can Find an opponent to make a game. If your machine is connected to the Internet, other animal breeders on the Internet can live safely with you. Double-click to download and install successful->. Net Terrarium 1.2 platform icon Terrarium opens in ecological mode. At this point you can introduce your animals into the ecosystem by clicking the Introduce Animal button. --------- Picture -------- Browse the item you just created ( _ex3.dll), this DLL is placed in the bin directory of your project, click on the animals, click Open is open, then your animals will be introduced into the ecosystem. You should be able to see ten your animals in the screen. You can only insert an animal in the ecosystem, so make sure you have tested it in Terrarium mode before introducing.

Experimental Abstract: Now Your animals have already decided in your technology with other animals in the ecosystem battlefield.

In order to play this game, I spent two hours on the home page for two hours to translate into Chinese, so that I will come back later. Everyone will play.

Hoho, Let's Come and Play It to Together!

Posted on April 30, 2004 1:36 AM

Turn on

Stupid cat .NET Blog: http://blog.9cbs.net/jabby12

转载请注明原文地址:https://www.9cbs.com/read-119755.html

New Post(0)