Exemplo n.º 1
0
 void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
 {
     Vector2 newrun = run;
     if (e.KeyCode == Program.Instance.Keybindings[-10]) newrun.Y = -1;
     if (e.KeyCode == Program.Instance.Keybindings[-9]) newrun.X = -1;
     if (e.KeyCode == Program.Instance.Keybindings[-8]) newrun.Y = 1;
     if (e.KeyCode == Program.Instance.Keybindings[-7]) newrun.X = 1;
     if (newrun.X != run.X || newrun.Y != run.Y)
     {
         run = newrun;
         Program.Instance.NetworkOut.StartRun(Program.Instance.ServerEndpoint, newrun.X, newrun.Y);
     }
     if (e.KeyCode == System.Windows.Forms.Keys.Space) Program.Instance.NetworkOut.Jump(Program.Instance.ServerEndpoint);
     if (e.KeyCode == System.Windows.Forms.Keys.Tab) Program.Instance.NetworkOut.NextTarget(Program.Instance.ServerEndpoint);
     if (e.KeyCode == System.Windows.Forms.Keys.P)
     {
         Common.GameStats stats = new Common.GameStats();
         stats.AddPlayer("Albe0", "Albert", 2);
         stats.AddPlayer("Herb0", "Herbert", 1);
         Program.Instance.ChangeState(new EndOfGameState()
             {
                 VictoryText = "Test successful",
                 GameStats = stats
             });
     }
     if (e.KeyCode == System.Windows.Forms.Keys.Escape)
     {
         GameScene.StopTargetGround();
     }
 }
Exemplo n.º 2
0
        public Server_(String map, int clientport, bool storeCombatLog)
        {
            Log.Init();
            MapName = map;
            this.clientport = clientport;
            Socket = new Common.Network.UdpServer(clientport);
            Socket.OnSocketError += new Common.Network.UdpServer.SocketErrorDelegate((e, ep) => { throw new Exception(e.ToString()); });
            Socket.OnReceive += new Common.Network.UdpServer.ReceiveDelegate((d, e) => Invoke(() => Socket_OnReceive(d, e)));
            InitNetworkOut();
            Socket.Start();
            Log.WriteLine("Client comm inited at port " + clientport);

            if (storeCombatLog)
            {
                combatLog = new StreamWriter("Logs/CombatLog-" + DateTime.Now.ToString("yyyyMMdd-HH.mm") + ".log");
                combatLog.AutoFlush = true;
            }

            //BinaryFormatter f = new BinaryFormatter();
            Common.XmlFormatter f = new Common.XmlFormatter();
            FileStream r = new FileStream("Maps/" + MapName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            Map = (Common.Map.Map)f.Deserialize(r);
            r.Close();
            if (File.Exists("Maps/" + MapName + ".terrain"))
            {
                BinaryFormatter bf = new BinaryFormatter();
                r = new FileStream("Maps/" + MapName + ".terrain", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                Map.Heightmap = (float[,])bf.Deserialize(r);
                r.Close();
            }

            int nplayers = 0;
            List<Common.Map.Team> slotToTeam = new List<Common.Map.Team>();
            for (int i = 0; i < Map.Teams.Length; i++)
            {
                nplayers += Map.Teams[i].NumberOfPlayers;
                for (int x = 0; x < Map.Teams[i].NumberOfPlayers; x++)
                    slotToTeam.Add(Map.Teams[i]);
            }
            Players = new Player[nplayers];
            SlotToTeam = slotToTeam.ToArray();

            Log.WriteLine();
            state = new States.Lobby(this);
            state.Enter();

            updateTimer = new Timer(new TimerCallback(Update));
            updateTimer.Change(updatePeriod, 0);
            lastUpdate = DateTime.Now;

            Log.WriteLine("Server started!");
            GameStats = new Common.GameStats();
        }