swf flash örnek c# mpmatch

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

dede454531

ReportSpammer
Banlı Üye
Katılım
15 Ara 2017
Mesajlar
300
Beğeni Puanı
22
Kod:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using PlayerIO.GameLibrary;
using System.Drawing;

namespace Mpmatch
{
    //Player class. each player that join the game will have these attributes.
    //public class Player : BasePlayer {
    //}

    public class Player : BasePlayer
    {

        public bool wannaplay = false;
        public string Name;
        public string skin;
        public string fbuid;
        public string outfit;
        public int bg;
        public int highscore;
        public int rounds;
        public int mp_won;
        public int mp_lost;
        public int level;
        public int xp;
        public int mpper;
        public int a_num;
        public int prestige;
        public int wannaplay2 = 0;
        public bool ingame = false;
        public bool joined;
        public int points = 0;
        public int allpoints = 0;
        public int score = 0;


        //character
        public string hat;
        public string glasses;
        public string mouth;
        public string hands;
        public string shoes;
        public string back;
        public List<string> listplayers = new List<string>();

        //settings
        public int cID;
        public bool loaded = false;
        public bool canchat = true;
        public int status = 0;
        public int exx = 0;
        public bool ready = false;
        public bool alive = false;
    }




    [RoomType("mpmatch")]
    public class GameCode : Game<Player>
    {
        public int players = 0;
        public int joinedplayers = 0;
        public int round = 0;
        public bool rds1 = false;
        public bool rds2 = false;
        public bool rds3 = false;
        public int alive;
        public bool started = false;
        // This method is called when an instance of your the game is created
        public override void GameStarted()
        {

            // anything you write to the Console will show up in the
            PreloadPlayerObjects = true;
            Console.WriteLine("Game is started");
        }

        // This method is called when the last player leaves the room, and it's closed down.
        public override void GameClosed()
        {
            Console.WriteLine("RoomId: " + RoomId);
        }

        // This method is called whenever a player joins the game
        public override void UserJoined(Player player)
        {
            PlayerIO.BigDB.LoadOrCreate("PlayerObjects", player.ConnectUserId, delegate (DatabaseObject playerobj)
            {
                //Send info about all already connected users to the newly joined users chat
                Message m = Message.Create("*", player.Id);
                if (players == 0)
                {
                    string[] ides = RoomData["playersUids"].Split(';');
                    foreach (string id in ides)
                    {
                        players++;
                    }
                }
                player.Name = playerobj.GetString("fbname");
                player.bg = 1;
                updatePlayersOnline(player);
            });
        }

        public void CheckuserExist(Player player)
        {
            foreach (Player p in Players)
            {
                if (player.ConnectUserId != p.ConnectUserId)
                {
                    if (player.listplayers.Contains("" + p.ConnectUserId))
                    {

                    }
                    else
                    {
                        player.listplayers.Add("" + p.ConnectUserId);
                        player.status = 1;
                        player.Send("pubmsg", p.Id, "PlayerJoined", p.ConnectUserId.Replace("fb", ""));
                    }
                }
            }
        }

        public void updatePlayersOnline(Player player)
        {
            String playerstatus = "";
            Message psOnline = Message.Create("privmsg", player.Id, "joinSuccess", RoomData["playersUids"], RoomData["playersNames"]);
            foreach (Player p in Players)
            {
                playerstatus += p.status + ";";
            }
            for (int i = PlayerCount; i <= 3; i++)
            {
                playerstatus += 0 + ";";
            }
            playerstatus = playerstatus.Substring(0, playerstatus.Length - 1);
            psOnline.Add(playerstatus);
            player.Send(psOnline);
            player.status = 0;
            foreach (Player p in Players)
            {
                CheckuserExist(p);
            }
            if (PlayerCount == players)
            {
                if (checkall())
                {
                    Broadcast("srvrmsg", "preGameStatus", 0);
                    ScheduleCallback(delegate
                    {
                        gameReady();
                    }, 3000);
                }
            }
        }

        public void gameReady()
        {
            started = true;
            alive = PlayerCount;
            if (round == 1)
            {
                rds1 = true;
            }
            if (round == 2)
            {
                rds2 = true;
            }
            foreach(Player p in Players)
            {
                p.alive = true;
            }
            String ids = "";
            String spawns = "";
            String outfits = "";
            String bg = "";
            int num = 0;
            Message psOnline = Message.Create("srvrmsg", "spawnAll");
            alive = PlayerCount;
            string[] positions = { "174", "136", "98", "59" };
            foreach (Player p in Players)
            {
                ids += p.Id + ";";
                spawns += positions[num] + ";";
                outfits += p.outfit + ";";
                num++;
            }
            bg += 15 + ";" + 9 + ";" + 15 + ";" + 13 + ";" + 6 + ";" + 1 + ";" + 10 + ";" + 15 + ";" + 5 + ";" + 2 + ";" + 0 + ";" + 14 + ";" + 8 + ";" + 2 + ";" + 10 + ";" + 0 + ";" + 15 + ";" + 14 + ";" + 6 + ";" + 1 + ";";
            ids = ids.Substring(0, ids.Length - 1);
            spawns = spawns.Substring(0, spawns.Length - 1);
            outfits = outfits.Substring(0, outfits.Length - 1);
            bg = bg.Substring(0, bg.Length - 1);
            psOnline.Add(ids);
            psOnline.Add(spawns);
            psOnline.Add(outfits);
            psOnline.Add(bg);
            if (round == 0)
            {
                Broadcast(psOnline);
            }
            Broadcast("srvrmsg", "roundCountdown");
            ScheduleCallback(delegate
            {
                Broadcast("srvrmsg", "roundCountdown");
            }, 1000);
            ScheduleCallback(delegate
            {
                Broadcast("srvrmsg", "roundCountdown");
            }, 2000);
            ScheduleCallback(delegate
            {
                Broadcast("srvrmsg", "startRoundRun");
            }, 3000);
        }

        // This method is called when a player leaves the game
        public override void UserLeft(Player player)
        {
            Broadcast("pubmsg", player.Id, "PlayerLeft", player.ConnectUserId.Replace("fb", ""));
            if (player.alive == true)
            {
                alive--;
            }
            players--;
            joinedplayers--;
        }

        public bool checkall()
        {
            foreach (Player p in Players)
            {
                if (p.status == 0)
                {
                    return false;
                }
            }
            return true;
        }

        public int getpoints(Player player)
        {
            int points = 0;
            if (PlayerCount == 4) {
                if (alive == 3)
                {
                    points = 0;
                }
                else if (alive == 2)
                {
                    points = 1;
                }
                else if (alive == 1)
                {
                    points = 2;
                }
                else if (alive == 0)
                {
                    points = 3;
                }
            }
            else if (PlayerCount == 3)
            {
                if (alive == 2)
                {
                    points = 0;
                }
                else if (alive == 1)
                {
                    points = 1;
                }
                else if (alive == 0)
                {
                    points = 2;
                }
            }
            else if (PlayerCount == 2)
            {
                if (alive == 1)
                {
                    points = 0;
                }
                else if (alive == 0)
                {
                    points = 1;
                }
            }
            return points;
        }



        public void RoundEnd()
        {
            if (alive == 0)
            {
                round++;
                started = false;
                String ids = "";
                Message psOnline = Message.Create("srvrmsg", "roundEnd", round);
                foreach (Player p in Players)
                {
                    ids += p.Id + ":" + p.points + ";";
                }
                ids = ids.Substring(0, ids.Length - 1);
                psOnline.Add(ids);
                Broadcast(psOnline);
                if (round == 1)
                {
                    ScheduleCallback(delegate
                    {
                        if (rds1 == false)
                        {
                            gameReady();
                            rds1 = true;
                            foreach (Player p in Players)
                            {
                                p.ready = false;
                            }
                        }
                    }, 10000);
                }
                else if (round == 2)
                {
                    ScheduleCallback(delegate
                    {
                        if (rds2 == false)
                        {
                            gameReady();
                            rds2 = true;
                            foreach (Player p in Players)
                            {
                                p.ready = false;
                            }
                        }
                    }, 10000);
                }
                else if (round == 3)
                {
                    ScheduleCallback(delegate
                    {
                        if (rds3 == false)
                        {
                            rds3 = true;
                            EndGame();
                        }
                    }, 10000);
                }
            }
        }

        public void EndGame()
        {
            if (round == 3)
            {
                String ids = "";
                Message psOnline = Message.Create("srvrmsg", "endGame");
                foreach (Player p in Players)
                {
                    ids += p.Id + ":" + p.allpoints + ":" + p.highscore + ";";
                }
                ids = ids.Substring(0, ids.Length - 1);
                psOnline.Add(ids);
                Broadcast(psOnline);

            }
        }

        public bool checkallready()
        {
            foreach(Player p in Players)
            {
                if (!p.ready)
                {
                    return false;
                }
            }
            return true;
        }

        public void readyForNextRound()
        {
            if (checkallready())
            {
                if (started == false)
                {
                    gameReady();
                    foreach (Player p in Players)
                    {
                        p.ready = false;
                    }
                }
            }
        }

        //Broadcast a message to all connected players


        // This method is called when a player sends a message into the server code
        public override void GotMessage(Player player, Message message)
        {
            switch (message.Type)
            {
                case "pubmsg":
                    {
                        switch (message.GetString(0))
                        {
                            case "chatMsg":
                                Broadcast("pubmsg", player.Id, "chatMsg", player.Name, message.GetString(2));
                                break;
                            case "readyForNextRound":
                                player.ready = true;
                                Broadcast("pubmsg", player.Id, "readyForNextRound");
                                readyForNextRound();
                                break;
                            case "move":
                                Broadcast("pubmsg", player.Id, "move", message.GetInt(1));
                                break;
                            case "die":
                                alive--;
                                player.alive = false;
                                player.points = getpoints(player);
                                player.allpoints = player.allpoints + getpoints(player);
                                player.highscore = player.highscore + message.GetInt(1);
                                Broadcast("pubmsg", player.Id, "die", message.GetInt(1), message.GetInt(2), message.GetInt(3), message.GetInt(4), message.GetInt(5));
                                RoundEnd();
                                break;
                            case "posC":
                                Broadcast("pubmsg", player.Id, "posC", message.GetInt(1), message.GetInt(2), message.GetInt(3), message.GetInt(4));
                                break;
                            case "jump":
                                Broadcast("pubmsg", player.Id, "jump", message.GetInt(1), message.GetInt(2));
                                break;
                            case "jump_stop":
                                Broadcast("pubmsg", player.Id, "jump_stop");
                                break;
                            case "land":
                                Broadcast("pubmsg", player.Id, "land", message.GetInt(1), message.GetInt(2));
                                break;
                            case "crouch":
                                Broadcast("pubmsg", player.Id, "crouch", message.GetBoolean(1));
                                break;
                        }
                    }
                    break;

                case "sysmsg":
                    {
                        switch (message.GetString(0))
                        {
                            case "myAccount":
                                player.outfit = message.GetString(1);
                                player.exx = message.GetInt(2);
                                break;
                        }
                    }
                    break;

                    case "privmsg":
                    {
                        switch (message.GetString(1))
                        {
                            case "heythere":
                                foreach (Player p in Players)
                                {
                                    if (message.GetInt(0) == p.Id)
                                    {
                                        //player.Send("privmsg", p.Id, "heythere", p.ConnectUserId.Replace("fb", ""), p.Name);
                                    }
                                }
                                break;
                        }
                    }
                    break;
            }
        }
    }
}
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...

Üst Alt