AI hat erste Anzeichen von I aus AI (Viel A, ein bisschen I)
This commit is contained in:
38
src/AI.cs
38
src/AI.cs
@@ -1,23 +1,51 @@
|
||||
using System;
|
||||
using System.Timers;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
public class AI
|
||||
{
|
||||
Timer timer;
|
||||
bool challengeSomeone = false;
|
||||
private Timer timer;
|
||||
private Random r;
|
||||
private int decision;
|
||||
private Backend Backend;
|
||||
|
||||
public AI ()
|
||||
public AI (Backend b)
|
||||
{
|
||||
r = new Random ();
|
||||
timer = new Timer (5000.0);
|
||||
timer.Elapsed += new ElapsedEventHandler (OnTimedEvent);
|
||||
timer.Elapsed += new ElapsedEventHandler (this.OnTimedEvent);
|
||||
Backend = b;
|
||||
|
||||
timer.Start ();
|
||||
}
|
||||
|
||||
private static void OnTimedEvent(object source, ElapsedEventArgs e)
|
||||
private void OnTimedEvent(object source, ElapsedEventArgs e)
|
||||
{
|
||||
think ();
|
||||
}
|
||||
|
||||
private void think()
|
||||
{
|
||||
timer.Stop ();
|
||||
if (r.Next (0, 2) == 0) {
|
||||
Console.WriteLine ("Challenging someone");
|
||||
lock (Backend) {
|
||||
Dictionary <int, Player> playerlist;
|
||||
Player player;
|
||||
int x, y;
|
||||
playerlist = Backend.getPlayerList ();
|
||||
player = playerlist[2235];
|
||||
x = player.GetX ();
|
||||
y = player.GetY ();
|
||||
Backend.MoveTo (x, y);
|
||||
}
|
||||
} else {
|
||||
Console.WriteLine ("Waiting for someone");
|
||||
}
|
||||
timer.Start ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user