public MainClass() { Application.Init(); Console.WriteLine("Clarion Demo V0.7 - altered by Fabio Tanada"); try { worldServer = new WorldServer("localhost", 4011); String message = worldServer.Connect(); if (worldServer != null && worldServer.IsConnected) { Console.Out.WriteLine("[SUCCESS] " + message + "\n"); worldServer.SendWorldReset(); worldServer.NewCreature(400, 200, 0, out creatureId, out creatureName); worldServer.SendCreateLeaflet(); worldServer.NewBrick(4, 747, 2, 800, 567); worldServer.NewBrick(4, 50, -4, 747, 47); worldServer.NewBrick(4, 49, 562, 796, 599); worldServer.NewBrick(4, -2, 6, 50, 599); // FMT 29/04/2017 - initial population worldServer.GenerateFood(0, 3); worldServer.GenerateFood(1, 3); worldServer.GenerateJewel(0, 3); worldServer.GenerateJewel(1, 3); worldServer.GenerateJewel(2, 3); worldServer.GenerateJewel(3, 3); worldServer.GenerateJewel(4, 3); worldServer.GenerateJewel(5, 3); if (!String.IsNullOrWhiteSpace(creatureId)) { worldServer.SendStartCamera(creatureId); worldServer.SendStartCreature(creatureId); } Console.Out.WriteLine("Creature created with name: " + creatureId + "\n"); agent = new ClarionAgent(worldServer, creatureId, creatureName); Console.Out.WriteLine("Running Simulation ...\n"); agent.Run(); } } catch (WorldServerInvalidArgument invalidArtgument) { Console.Out.WriteLine(String.Format("[ERROR] Invalid Argument: {0}\n", invalidArtgument.Message)); } catch (WorldServerConnectionError serverError) { Console.Out.WriteLine(String.Format("[ERROR] Is is not possible to connect to server: {0}\n", serverError.Message)); } catch (Exception ex) { Console.Out.WriteLine(String.Format("[ERROR] Unknown Error: {0}\n", ex.Message)); } try { Application.Run(); } catch (Exception ex) { Console.Out.WriteLine(String.Format("[ERROR] Unknown Error in GDK: {0}\n", ex.Message)); } }
void processSelectedAction(CreatureActions externalAction) { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); if (worldServer != null && worldServer.IsConnected) { switch (externalAction) { case CreatureActions.DO_NOTHING: // Do nothing as the own value says break; case CreatureActions.ROTATE_CLOCKWISE: worldServer.SendSetAngle(creatureId, 2, -2, 2); break; case CreatureActions.GO_AHEAD: worldServer.SendSetAngle(creatureId, 1, 1, prad); break; // FMT 29/04/2017 case CreatureActions.EAT: Console.WriteLine("Action: EAT"); if (lastSeenFood != null) { worldServer.SendEatIt(creatureId, lastSeenFood); worldServer.GenerateFood(1, 1); if (mind != null) { mind.update(); } } break; case CreatureActions.GET: if (seenThing != null) { Console.WriteLine("Action: GET (thing) " + seenThing.Name); worldServer.SendSackIt(creatureId, seenThing.Name); } else { if (lastSeenJewel != null) { Console.WriteLine("Action: GET (alt) " + lastSeenJewel); worldServer.SendSackIt(creatureId, lastSeenJewel); } } // FMT reseed more jewel worldServer.GenerateJewel(1); if (mind != null) { mind.setBag(worldServer.SendGetSack(creatureId)); mind.update(); } break; case CreatureActions.GO_TO: if (seenThing != null) { Console.Write("Action: GO TO (thing) "); Console.Write(seenThing.comX); Console.WriteLine(seenThing.comY); worldServer.SendSetGoTo(creatureId, 1, 1, seenThing.comX, seenThing.comY); } else { Console.Write("Action: GO TO (alt) "); Console.Write(thingX); Console.WriteLine(thingY); if (thingX > 0) { worldServer.SendSetGoTo(creatureId, thingVr, thingVl, thingX, thingY); Console.WriteLine("Action GoTo sent"); thingX = 0; } } // end else //worldServer.SendSetAngle(creatureId, 1, 1, prad); break; case CreatureActions.HIDE: if (seenThing != null) { Console.WriteLine("Action: HIDE (thing) " + seenThing.Name); worldServer.SendHideIt(creatureId, seenThing.Name); } else { Console.WriteLine("Action: HIDE (alt)"); if (lastSeenJewel != null) { worldServer.SendHideIt(creatureId, lastSeenJewel); if (mind != null) { mind.update(); } // FMT reseed more jewel worldServer.GenerateJewel(1); // FMT redirect creature if (thingX > 0) { Console.WriteLine("Action (HIDE): GO TO"); worldServer.SendSetGoTo(creatureId, thingVr, thingVl, thingX, thingY); thingX = 0; } } } break; case CreatureActions.STOP: worldServer.SendStopCreature(creatureId); break; default: break; } } }