コード例 #1
0
 public void InitData(MainWindowViewModel mainWindowViewModel, GameRole gameRole,
                      EditRoleWindow editRoleWindow)
 {
     MainWindowViewModel = mainWindowViewModel;
     GameRole            = gameRole;
     _editRoleWindow     = editRoleWindow;
 }
コード例 #2
0
 public Player(IUser user, GroupType group, GameRole role)
 {
     User   = user;
     Group  = group;
     Role   = role;
     Active = true;
 }
コード例 #3
0
        private void EndGame()
        {
            gameTimer.Stop();
            end = DateTime.Now;
            getLogThread.Abort();
            TimeSpan duration = end.Subtract(start);

            timeLabel.Text = duration.Minutes.ToString("D2") + ':' + duration.Seconds.ToString("D2");
            int finalScore = 0;

            if (found)
            {
                wonLabel.Text      = "won";
                wonLabel.ForeColor = System.Drawing.Color.LimeGreen;
                finalScore         = Convert.ToInt32(score);
            }
            else
            {
                wonLabel.Text      = "lost";
                wonLabel.ForeColor = System.Drawing.Color.Red;
            }
            scoreLabel.Text    = finalScore.ToString() + " credits";
            statsPanel.Visible = true;
            gamePanel.Visible  = false;
            Program.form.SetGameInProgress(false);
            dal.GetData();
            GameRole role = dal.roles.Find(i => i.Id == 2);

            dal.SaveScore(found, role, finalScore, Program.form.GetUser());
        }
コード例 #4
0
    private void Deal(int numbertiles, GameRole role)
    {
        int n = TILE;

        for (int i = 0; i < numbertiles; i++)
        {
            Domino temp = null;
            for (int j = 0; j < n; j++)
            {
                if (Tile.Dominoes[j].Ownership == GameRole.BoneYard)
                {
                    temp = Tile.Dominoes[j];
                }
            }
            if (role == GameRole.Player1)
            {
                temp.Ownership = GameRole.Player1;
                player1.Dominoes.AddLast(temp);
            }
            if (role == GameRole.Player2)
            {
                temp.Ownership = GameRole.Player2;
                player2.Dominoes.AddLast(temp);
            }
            // Shuffle every time or not ??
            Shuffle();
        }
    }
コード例 #5
0
        protected virtual async Task JoinGame(GameInfo gameInfo, GameRole role, bool host = false)
        {
            IsProgress = true;

            try
            {
                await JoinGameAsync(gameInfo, role, host);
            }
            catch (Exception exc)
            {
                try
                {
                    Error     = exc.Message;
                    FullError = exc.ToString();
                    if (_host != null)
                    {
                        _host.Dispose();
                    }
                }
                catch { }
            }
            finally
            {
                IsProgress = false;
            }
        }
コード例 #6
0
 public void TakeSeat(GameRole role)
 {
     if (role == GameRole.Camera)
     {
         if (_cameraServerSeatTaken)
         {
             _photonView.RPC("BroadcastDebugLog", PhotonTargets.All, "Camera seat is taken but another camera is trying to join");
         }
         else
         {
             _cameraServerSeatTaken = true;
         }
     }
     else if (_redPlayerSeatTaken)
     {
         if (_bluePlayerSeatTaken)
         {
             _photonView.RPC("BroadcastDebugLog", PhotonTargets.All, "Both player seats taken but another player is trying to join");
         }
         else
         {
             _bluePlayerSeatTaken = true;
         }
     }
     else
     {
         _redPlayerSeatTaken = true;
     }
 }
コード例 #7
0
        //备忘录
        public static void testMemento()
        {
            //大战Boss前
            GameRole lixiaoyao = new GameRole();

            lixiaoyao.GetInitState();
            lixiaoyao.StateDisplay();

            //保存进度
            RoleStateCaretaker stateAdmin = new RoleStateCaretaker();

            stateAdmin.Memento = lixiaoyao.SaveState();

            //大战Boss时,损耗严重
            lixiaoyao.Fight();
            lixiaoyao.StateDisplay();

            //恢复之前状态
            lixiaoyao.RecoveryState(stateAdmin.Memento);

            lixiaoyao.StateDisplay();


            Console.Read();
        }
コード例 #8
0
        public string ReturnInfo(Game game, GameRole PlayerRole)
        {
            string RoleInfo = "";

            switch (PlayerRole)
            {
            case GameRole.NotYetChosen:
                RoleInfo += "We are sorry";
                break;

            case GameRole.Servant:
                RoleInfo += "You win if you can complete 3 Missions.";
                break;

            case GameRole.Minion:
                RoleInfo += "The Evil players are: " + whoIsEvil(game);
                break;

            case GameRole.Merlin:
                RoleInfo += "The Evil players are: ";
                game.Players.ForEach(x =>
                {
                    if (x.IsEvil && x.RoleId != GameRole.Mordred)
                    {
                        RoleInfo += x.Name + "   ";
                    }
                });
                break;

            case GameRole.Percival:
                RoleInfo += "Merlin is: ";
                game.Players.ForEach(x =>
                {
                    if (x.RoleId == GameRole.Merlin || x.RoleId == GameRole.Morgana)
                    {
                        RoleInfo += x.Name + " or ";
                    }
                });
                RoleInfo = RoleInfo.Substring(0, RoleInfo.Length - 4);
                break;

            case GameRole.Mordred:
                RoleInfo += "The evil players are: " + whoIsEvil(game);
                break;

            case GameRole.Morgana:
                RoleInfo += "Percival sees you as Merlin.|The evil players are: " + whoIsEvil(game);
                break;

            case GameRole.Oberon:
                RoleInfo += "You are Evil.";
                break;

            case GameRole.Assassin:
                RoleInfo += "If you figure out who Merlin is you win!|The evil players are: " + whoIsEvil(game);
                break;
            }
            return(RoleInfo);
        }
コード例 #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            GameRole gameRole = db.GameRole.Find(id);

            db.GameRole.Remove(gameRole);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #10
0
ファイル: GameRole.cs プロジェクト: RothschildGames/o11
 void Awake()
 {
     if (singletonInstance != null)
     {
         Debug.LogError("Multiple GameRole objects exist");
         return;
     }
     singletonInstance = this;
 }
コード例 #11
0
 public Participant(DiscordMember member, string name, GameRole role = GameRole.Commoner, bool leader = false)
 {
     Member   = member;
     Name     = name;
     Id       = member.Id;
     GameID   = member.Guild.Id;
     Role     = role;
     IsLeader = leader;
 }
コード例 #12
0
 public ActionResult Edit([Bind(Include = "GameRoleID,GameRoleName")] GameRole gameRole)
 {
     if (ModelState.IsValid)
     {
         db.Entry(gameRole).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("~/Views/Admin/GameRoles/Edit.cshtml", gameRole));
 }
コード例 #13
0
ファイル: ReconnectManager.cs プロジェクト: wurunduk/SI
 public ReconnectManager(SlaveServer server, Client client, IViewerClient host, HumanAccount human, GameRole role, string credentials, bool upgrade)
 {
     _server      = server;
     _client      = client;
     _host        = host;
     _human       = human;
     _role        = role;
     _credentials = credentials;
     _upgrade     = upgrade;
 }
コード例 #14
0
        public virtual async Task JoinGameAsync(GameInfo gameInfo, GameRole role, bool isHost = false)
        {
            var name = Human.Name;

            var sex     = Human.IsMale ? 'm' : 'f';
            var command = $"{Messages.Connect}\n{role.ToString().ToLowerInvariant()}\n{name}\n{sex}\n{-1}{GetExtraCredentials()}";

            _ = await _connector.JoinGame(command);

            JoinGameCompleted(role, isHost);
        }
コード例 #15
0
        public ActionResult Create([Bind(Include = "GameRoleID,GameRoleName")] GameRole gameRole)
        {
            if (ModelState.IsValid)
            {
                db.GameRole.Add(gameRole);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View("~/Views/Admin/GameRoles/Create.cshtml", gameRole));
        }
コード例 #16
0
 public Player GetOpponentState(GameRole role)
 {
     if (role == GameRole.Player1)
     {
         return(player2);
     }
     else if (role == GameRole.Player2)
     {
         return(player1);
     }
     return(null);
 }
コード例 #17
0
    public bool DrawCardFromTile(GameRole role, Domino domino)
    {
        if (role != CurrentGameRole || domino.Ownership != GameRole.BoneYard)
        {
            return(false);
        }
        Player currentPlayer = GetCurrentPlayer();

        domino.Ownership = role;
        currentPlayer.Dominoes.AddLast(domino);
        return(true);
    }
コード例 #18
0
ファイル: Domino.cs プロジェクト: alfiesyukur/Dominoes-1
 public Domino(int value1, int value2)
 {
     Value1               = value1;
     Value2               = value2;
     IsObservableByAll    = false;
     Ownership            = GameRole.BoneYard;
     Placement.Direction  = DominoDirection.NotSpecified;
     Placement.LeftValue  = -1;
     Placement.RightValue = -1;
     Placement.UpValue    = -1;
     Placement.DownValue  = -1;
 }
コード例 #19
0
 private bool IsDominoInHand(GameRole role, Domino domino)
 {
     if (role == GameRole.Player1)
     {
         return(player1.Dominoes.Contains(domino));
     }
     else if (role == GameRole.Player2)
     {
         return(player2.Dominoes.Contains(domino));
     }
     return(false);
 }
コード例 #20
0
        public MultiplayerGame(string name, string gameId, GameRole role, GameServerClient gameServerClient, PlayerDto player)
        {
            _gameId           = gameId;
            _role             = role;
            _gameServerClient = gameServerClient;
            _player           = player;
            Name = name;

            Players = new ObservableCollection <PlayerDto>();

            TransitionToState(typeof(WaitingForPlayersState));
            StartListeningToGameState();
        }
コード例 #21
0
        public void InitData(EditRoleWindowViewModel editRoleWindowViewModel)
        {
            _editRoleWindowViewModel = editRoleWindowViewModel;
            _mainWindowViewModel     = editRoleWindowViewModel.MainWindowViewModel;
            _gameRole = editRoleWindowViewModel.GameRole;
            if (MenpaiSelection.Count == 0)
            {
                MenpaiSelection =
                    MenpaiList.Select(
                        menpaiPair
                        =>
                        new ComboBoxNode <int>
                {
                    Title = menpaiPair.Value,
                    Value = menpaiPair.Key
                }
                        ).ToList();
                RaisePropertyChanged(nameof(MenpaiSelection));
            }

            //初始化属性
            Accname     = _gameRole.Accname;
            Charguid    = _gameRole.Charguid;
            Charname    = _gameRole.Charname;
            Title       = _gameRole.Title;
            Menpai      = _gameRole.Menpai;
            Level       = _gameRole.Level;
            Scene       = _gameRole.Scene;
            Xpos        = _gameRole.Xpos;
            Zpos        = _gameRole.Zpos;
            Hp          = _gameRole.Hp;
            Mp          = _gameRole.Mp;
            Str         = _gameRole.Str;
            Spr         = _gameRole.Spr;
            Con         = _gameRole.Con;
            Ipr         = _gameRole.Ipr;
            Dex         = _gameRole.Dex;
            Points      = _gameRole.Points;
            Enegry      = _gameRole.Enegry;
            Energymax   = _gameRole.Energymax;
            Vigor       = _gameRole.Vigor;
            Maxvigor    = _gameRole.Maxvigor;
            Exp         = _gameRole.Exp;
            Pkvalue     = _gameRole.Pkvalue;
            Vmoney      = _gameRole.Vmoney;
            Bankmoney   = _gameRole.Bankmoney;
            Yuanbao     = _gameRole.Yuanbao;
            Menpaipoint = _gameRole.Menpaipoint;
            Zengdian    = _gameRole.Zengdian;
        }
コード例 #22
0
        // GET: GameRoles/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GameRole gameRole = db.GameRole.Find(id);

            if (gameRole == null)
            {
                return(HttpNotFound());
            }
            return(View("~/Views/Admin/GameRoles/Delete.cshtml", gameRole));
        }
コード例 #23
0
ファイル: frmMain.cs プロジェクト: ThornRingleaders/C-
        private void 加入游戏ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //玩家类型
            this._gameType = ChessType.白子;

            //打开连接界面
            this.groupBox1.Visible = true;
            //直接获取本机服务器监听的IP和端口后
            this.txtIP.Text   = NetService.GetLocalIP().ToString();
            this.txtPort.Text = NetService.SERVERPORT.ToString();

            //设置角色
            this._role = GameRole.挑战者;
            this.务开启ToolStripMenuItem.Enabled = false;
        }
コード例 #24
0
        static public CardView CreateFromGameRole(GameRole role)
        {
            CardView view = new CardView();

            if (role.IsHero)
            {
                Hero hero = role.Hero;
                view.CardName.Text    = hero.Name;
                view.CardImage.Source = hero.Image;
                view.LeftNumber.Text  = role.Hp.ToString();
                view.RightNumber.Text = role.Attack.ToString();
                view._gameRole        = role;
            }
            return(view);
        }
コード例 #25
0
ファイル: RoleService.cs プロジェクト: iftree/DotHassServer
        public GameRole CreateRole(GameUser user)
        {
            var role = new GameRole()
            {
                Id         = GeneratorId,
                RoleName   = "",
                HeadId     = "00000",
                Money      = 11111,
                Gold       = 11111,
                Experience = 0,
            };

            this.dataRepos.Add(role);

            return(role);
        }
コード例 #26
0
    public LinkedList <Domino> GetMovableDominoes(GameRole role)
    {
        if (role != CurrentGameRole)
        {
            return(null);
        }
        LinkedList <Domino> dominoes = new LinkedList <Domino>();
        Player currentPlayer         = GetCurrentPlayer();

        foreach (Domino domino in currentPlayer.Dominoes)
        {
            if (History.HorizontalDominoes.Count == 0)
            {
                dominoes.AddLast(domino);
                continue;
            }
            Domino firstHorizontalDomino = History.HorizontalDominoes.First.Value;
            if (firstHorizontalDomino.Placement.LeftValue == domino.Value1 || firstHorizontalDomino.Placement.LeftValue == domino.Value2)
            {
                dominoes.AddLast(domino);
                continue;
            }
            Domino lastHorizontalDomino = History.HorizontalDominoes.Last.Value;
            if (lastHorizontalDomino.Placement.RightValue == domino.Value1 || lastHorizontalDomino.Placement.RightValue == domino.Value2)
            {
                dominoes.AddLast(domino);
                continue;
            }
            if (History.VerticalDominoes.Count == 0)
            {
                continue;
            }
            Domino firstVerticalDomino = History.VerticalDominoes.First.Value;
            if (firstVerticalDomino.Placement.UpValue == domino.Value1 || firstVerticalDomino.Placement.UpValue == domino.Value2)
            {
                dominoes.AddLast(domino);
                continue;
            }
            Domino lastVerticalDomino = History.VerticalDominoes.Last.Value;
            if (lastVerticalDomino.Placement.DownValue == domino.Value1 || lastVerticalDomino.Placement.DownValue == domino.Value2)
            {
                dominoes.AddLast(domino);
                continue;
            }
        }
        return(dominoes);
    }
コード例 #27
0
ファイル: GameElement.cs プロジェクト: Zaokret/Discord.Broker
        public static string Role(GameRole gameRole)
        {
            string name = string.Empty;

            switch (gameRole)
            {
            case GameRole.Killer: name = "Cultist"; break;

            case GameRole.Kicker: name = "Moderate"; break;

            case GameRole.Investigator: name = "Augur"; break;

            default:
                throw new NotImplementedException($"{nameof(gameRole)} : {gameRole}");
            }
            return(name);
        }
コード例 #28
0
ファイル: SIOnlineViewModel.cs プロジェクト: wurunduk/SI
        public override async Task JoinGameAsync(GameInfo gameInfo, GameRole role, bool isHost = false)
        {
            gameInfo = gameInfo ?? _currentGame;

            if (!isHost)
            {
                lock (_serverGamesLock)
                {
                    var passwordRequired = gameInfo != null && gameInfo.PasswordRequired;
                    if (passwordRequired && string.IsNullOrEmpty(_password))
                    {
                        IsProgress = false;
                        return;
                    }
                }
            }

            try
            {
                InitServerAndClient(_gamesHostInfo.Host ?? new Uri(ServerAddress).Host, _gamesHostInfo.Port);
                await ConnectCore(true);

                var result = await _connector.SetGameID(gameInfo.GameID);

                if (!result)
                {
                    Error = Resources.CreatedGameNotFound;
                    return;
                }

                await base.JoinGameAsync(gameInfo, role, isHost);

                _host.Connector.SetGameID(gameInfo.GameID);
            }
            catch (TaskCanceledException exc)
            {
                Error     = Resources.GameConnectionTimeout;
                FullError = exc.ToString();
            }
            catch (Exception exc)
            {
                Error     = exc.Message;
                FullError = exc.ToString();
            }
        }
コード例 #29
0
ファイル: DAL.cs プロジェクト: ParrotLync/Verstoppertje-App
 public int SaveScore(bool _won, GameRole _role, int _score, User _user)
 {
     using (SqlConnection conn = new SqlConnection())
     {
         conn.ConnectionString = connectionString;
         conn.Open();
         string     query = "INSERT INTO user_score (won, role, score, user_id) VALUES (@won, @role, @score, @user_id)";
         SqlCommand cmd   = new SqlCommand(query, conn);
         cmd.Parameters.AddWithValue("@won", _won);
         cmd.Parameters.AddWithValue("@role", _role.Id);
         cmd.Parameters.AddWithValue("@score", _score);
         cmd.Parameters.AddWithValue("@user_id", _user.Id);
         int rows = cmd.ExecuteNonQuery();
         cmd.Dispose();
         this.GetData();
         return(rows);
     }
 }
コード例 #30
0
        public string GetRoleDesc(GameRole role)
        {
            switch (role)
            {
            case GameRole.Village:
                return("村民");

            case GameRole.Werewolf:
                return("狼人");

            case GameRole.Minion:
                return("爪牙");

            case GameRole.Masons:
                return("守夜人");

            case GameRole.Seer:
                return("预言家");

            case GameRole.Robber:
                return("强盗");

            case GameRole.Troublemaker:
                return("捣蛋鬼");

            case GameRole.Drunk:
                return("酒鬼");

            case GameRole.Insomniac:
                return("失眠者");

            case GameRole.Hunter:
                return("猎人");

            case GameRole.Tanner:
                return("皮匠");

            case GameRole.Doppelgänger:
                return("幽灵");
            }
            return(role.ToString());
        }
コード例 #31
0
        public async Task <IActionResult> Handler(PassPortValidationModel model)
        {
            if (this.TryValidateModel(model, out ICollection <ValidationResult> errors) == false)
            {
                return(Error(StatusCodes.Status10000ValidationError));
            }

            //检查用户是否存在
            var user = await identityService.GetUser(model.Pid);

            if (user != null)
            {
                return(Error(StatusCodes.Status10002UserExist));
            }

            //注册用户
            bool result = await identityService.Register(model.Pid, model.Pwd);

            if (result == false)
            {
                return(Error(StatusCodes.Status10001RegisterError));
            }
            user = await identityService.GetUser(model.Pid);

            //认证
            await identityService.SignInAsync(user, this.Sid);

            //注册用户命令
            GameRole role = roleService.CreateRole(user);

            user.GameRoleId = role.Id;

            WriteRoleId(role.Id);
            identityService.Update(user);

            //todo:根据Retail获取Retaildata
            return(Ok(new UserProtocol()
            {
                UserId = user.Id
            }));
        }
コード例 #32
0
ファイル: Program.cs プロジェクト: red201432/Design_pattern
        static void Main(string[] args)
        {
            #region 工厂方法
            double total = 0.0d;
            CashContext cc = new CashContext(new CashNormal());
            total = cc.GetResult(100.04);
            cc = new CashContext(new CashRebate("0.8"));
            total = cc.GetResult(100.04);
            Console.WriteLine(total);
            #endregion

            #region 装饰器方法
            Decorator.Component person = new Decorator.Component("xiaocai");

            Tshirt tshirt = new Tshirt();
            BigTrouser bt = new BigTrouser();

            bt.Decorator(person);
            tshirt.Decorator(bt);
            tshirt.show();

            Console.WriteLine("*****************************");
            #endregion

            #region 代理方法
            SchoolGirl sg = new SchoolGirl();
            sg.Name = "李娇骄";
            Proxy.Proxy daili = new Proxy.Proxy(sg);
            daili.GiveDolls();
            daili.GiveFlowers();
            #endregion

            #region 原型模式
            ConcretePrototype1 p1 = new ConcretePrototype1("123");
            ConcretePrototype1 c1 = (ConcretePrototype1)p1.Clone();
            Console.WriteLine("Cloned :"+c1.Id);

            Resume a = new Resume("Andy");
            a.setInfo("Man", "24");
            a.setWorkExperience("1998-2005","IBM ");
            Resume b = (Resume)a.Clone();
            b.setWorkExperience("2002-2005", "Dell");
            a.display();
            b.display();
            #endregion

            #region 模板模式
            Console.WriteLine("Student A testPaper:");
            TestPaperA testA = new TestPaperA();
            testA.Test1();
            testA.Test2();
            Console.WriteLine("Student B testPaper:");
            TestPaperB testB = new TestPaperB();
            testB.Test1();
            testB.Test2();
            #endregion

            #region 抽象工厂方法
            User user = new User();

            IFactory factory = new SqlServerFactory();
            IUser iu = factory.CreateUser();
            //IUser riu = (IUser)Assembly.Load("AbstractFactory").CreateInstance("SqlserverUser");
            //反射
            //Assembly.Load("程序集名称").CreateInstance("程序集名称.类名称");
            iu.Insert(user);
            iu.GetUser(1);
            #endregion

            #region Facade 外观模式
            Fund jijin = new Fund();
            jijin.BuyFund();
            jijin.sellFund();
            #endregion

            #region 建造者模式
            Director director = new Director();
            abstractBuilder builder1 = new Builder1();
            abstractBuilder builder2 = new BuilderB();
            director.Construct(builder1);
            Builder.Builder b1 = builder1.getBuilder();
            b1.show();

            director.Construct(builder2);
            Builder.Builder b2 = builder2.getBuilder();
            b2.show();
            #endregion
            #region 观察者模式
            Observer.ConcreteSubject s = new Observer.ConcreteSubject();
            s.Attach(new Observer.ConcreteObserver(s, "x"));
            s.Attach(new Observer.ConcreteObserver(s, "y"));
            s.SubjectState = "ABC";
            s.Notify();
            ///下面是使用委托
            ///委托就是一种引用方法的类型。一旦为委托分配了方法,委托将于该方法具有完全相同的行为。
            ///委托方法的使用可以像其他的方法一样具有参数和返回值。委托可以看作是对函数的抽象,是函数的”类“,委托的实例将代表一个具体的函数
            ///一个委托可以搭载多个方法,所有方法被依次唤起,委托搭载的方法不需要属于同一个类,只需要具有相同的原型和形式,也就是拥有相同的参数列表和返回类型。
            ///在使用带参数的委托时,只需要在声明事件的地方将参数传递给事件。在绑定时将调用的方法绑定给事件。
            Bosscs boss = new Bosscs();
            StockObserver tongshi1 = new StockObserver("tongshi1",boss);
            NBAObserver tongshiNBA = new NBAObserver("tongshiNBA", boss);
            boss.Update += new EventHandler1(tongshi1.CloseStockMarket);
            boss.Update += new EventHandler1(tongshiNBA.CloseStockMarket);
            boss.update2 += new EventHandler2(tongshiNBA.print);
            boss.SubjectState = " I am back ";
            boss.Notify();
            #endregion

            #region 状态模式
            State.Context c = new State.Context(new CreateStateA());
            c.Request();
            c.Request();
            c.Request();
            c.Request();

            #endregion

            #region 备忘录模式
            Originator o = new Originator();
            o.State = "On";
            o.Show();
            Caretaker care = new Caretaker();
            care.Memento = o.CreateMemento();
            o.State = "Off";
            o.Show();

            o.SetMemento(care.Memento);
            o.Show();

            GameRole gameRole = new GameRole();
            gameRole.GetInitState();
            gameRole.StateDisplay();

            RoleStateManager stateManager = new RoleStateManager();
            stateManager.Memento = gameRole.SaveState();

            gameRole.Fight();
            gameRole.StateDisplay();

            gameRole.RecoveryState(stateManager.Memento);
            gameRole.StateDisplay();
            #endregion

            #region 组合模式
            Composite.Composite root = new Composite.Component("root");
            root.Add(new Leaf("Leaf A"));
            root.Add(new Leaf("Leaf B"));

            Composite.Composite comp = new Composite.Component("comp X");
            comp.Add(new Leaf("Leaf XA"));
            comp.Add(new Leaf("Leaf XB"));
            root.Add(comp);

            Composite.Composite comp2 = new Composite.Component("Comp X2");
            comp2.Add(new Leaf("Leaf X2A"));
            comp2.Add(new Leaf("Leaf X2B"));
            comp.Add(comp2);

            root.Add(new Leaf("Leaf C"));
            Leaf leaf = new Leaf("Leaf D");

            root.Add(leaf);
            root.Display(1);
            root.Remove(leaf);
            root.Display(1);
            #endregion

            #region 迭代器模式
            ConCreteAggregate aggregate = new ConCreteAggregate();
            aggregate[0] = "大鸟";
            aggregate[1] = "小菜";
            aggregate[2]="行李";
            aggregate[3] = "老外";
            aggregate[4] = "小偷";
            Iterator.Iterator myIterator = new ConCreteIterator(aggregate);
            object item = myIterator.First();
            while (!myIterator.IsDone())
            {
                Console.WriteLine(myIterator.CurrentItem() + "请买车票");
                myIterator.Next();
            }
            #endregion

            #region 单例模式
             //所有类都有构造方法,不编码则默认生成空的构造方法,若有显示定义的构造方法,默认的构造方法就会失效。只要将构造方法改写为私有的,外部的程序就不能通过new 来初始化它。
            //通过一个共有的方法来返回类的实例。
            Singleton.Singleton s1 = Singleton.Singleton.GetInstance();
            Singleton.Singleton s2 = Singleton.Singleton.GetInstance();

            if (s1 == s2)
            {
                Console.WriteLine("两个对象是相同的实例。");
            }

            #endregion

            #region 命令模式
            Receiver r = new Receiver();
            Command.Command command = new Command.ConcreteCommand(r);
            Invoker invoker = new Invoker();
            invoker.SetCommand(command);
            invoker.ExecuteCommand();
            #endregion

            #region 职责链模式
            Handler h1 = new ConcreteHandler1();
            Handler h2 = new ConcreteHandler2();
            h1.SetSuccessor(h2);
            int[] requests = { 2, 3, 4, 5, 6, 12, 34, 11, 15 };
            foreach (int request in requests)
            {
                h1.HandlerRequest(request);
            }
            #endregion

            #region 中介者模式
            ConcreteMediator mediator = new ConcreteMediator();
            ConcreteColleague1 colleague1 = new ConcreteColleague1(mediator);
            ConcreteColleague2 colleague2 = new ConcreteColleague2(mediator);
            mediator.Colleague1 = colleague1;
            mediator.Colleague2 = colleague2;
            colleague1.Send("吃饭了吗?");
            colleague2.Send("还没有呢");
            #endregion

            #region 享元模式
            int extri = 22;
            FlyweightFactory f = new FlyweightFactory();
            Flyweight.Flyweight fx = f.GetFlyweight("X");
            fx.Operation(--extri);

            Flyweight.Flyweight fy = f.GetFlyweight("Y");
            fy.Operation(--extri);

            Flyweight.Flyweight fz = f.GetFlyweight("Z");
            fz.Operation(--extri);

            #endregion

            #region 解释器模式
            <<<<<<< HEAD
            Interpreter.Context context = new Interpreter.Context();
            IList<Interpreter.AbstractExpression> list = new List<Interpreter.AbstractExpression>();
            list.Add(new Interpreter.TerminalExpression());
            list.Add(new Interpreter.NormalExpression());
            foreach (Interpreter.AbstractExpression exp in list)
                exp.Interpret(context);
            =======
            Interpreter.Context context1 = new Interpreter.Context();
            IList<AbstractExpression> list = new List<AbstractExpression>();
            list.Add(new TerminalExpression());
            list.Add(new NonTerminalExpression());
            foreach (AbstractExpression exp in list)
            {
                exp.Interpreter(context1);
            }
            #endregion

            #region 访问者模式
            ObjectStructure os = new ObjectStructure();
            os.Add(new Man());
            os.Add(new Woman());
            Success v1 = new Success();
            os.Display(v1);
            Failing f1 = new Failing();
            os.Display(f1);

            Amativeness a1 = new Amativeness();
            os.Display(a1);
            >>>>>>> 77e342ef6e96917a8dc01e72e41626dcffd4ba13
            #endregion
            Console.Read();
        }
コード例 #33
0
 public void TakeSeat(GameRole role)
 {
     if (role == GameRole.Camera)
     {
         if (_cameraServerSeatTaken)
         {
             _photonView.RPC("BroadcastDebugLog", PhotonTargets.All, "Camera seat is taken but another camera is trying to join");
         }
         else
         {
             _cameraServerSeatTaken = true;
         }
     }
     else if (_redPlayerSeatTaken)
     {
         if (_bluePlayerSeatTaken)
         {
             _photonView.RPC("BroadcastDebugLog", PhotonTargets.All, "Both player seats taken but another player is trying to join");
         }
         else
         {
             _bluePlayerSeatTaken = true;
         }
     }
     else
     {
         _redPlayerSeatTaken = true;
     }
     
 }