Esempio n. 1
0
        public void SetGamePeriod(string id, Game.PeriodEnum p)
        {
            long lid = Int64.Parse(id);
            Game g   = _db.Games.Where(game => game.Id == lid).ToList()[0];

            g.Period = p;
            _db.SaveChanges();
        }
Esempio n. 2
0
        public void SetGamePeriod(string id, Game.PeriodEnum p)
        {
            long lid = Int64.Parse(id);

            using (WerewolfContext _db = new WerewolfContext())
            {
                Game game = _db.Games.Where(g => g.Id == lid).ToList()[0];
                game.Period = p;
                _db.Games.Update(game);
                _db.SaveChanges();
            }
        }
Esempio n. 3
0
        public void Notify(Model m)
        {
            if (m is WerewolfModel)
            {
                WerewolfModel wm = (WerewolfModel)m;
                switch (wm.Event)
                {
                case EventEnum.JoinGame:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        BtnJoin.Visible = false;
                        AddChatMessage("You're joing the game #" + wm.EventPayloads["Game.Id"] + ", please wait for game start.");
                        _updateTimer.Interval = 1000;
                        _updateTimer.Tick    += new EventHandler(OnTimerEvent);
                        _updateTimer.Enabled  = true;
                    }
                    else
                    {
                        MessageBox.Show("You can't join the game, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;

                case EventEnum.GameStopped:
                    AddChatMessage("Game is finished, outcome is " + wm.EventPayloads["Game.Outcome"]);
                    _updateTimer.Enabled = false;
                    break;

                case EventEnum.GameStarted:
                    players = wm.Players;
                    _myRole = wm.EventPayloads["Player.Role.Name"];
                    AddChatMessage("Your role is " + _myRole + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    EnableButton(BtnAction, true);
                    switch (_myRole)
                    {
                    case WerewolfModel.ROLE_PRIEST:
                        BtnAction.Text = WerewolfModel.ACTION_HOLYWATER;
                        break;

                    case WerewolfModel.ROLE_GUNNER:
                        BtnAction.Text = WerewolfModel.ACTION_SHOOT;
                        break;

                    case WerewolfModel.ROLE_JAILER:
                        BtnAction.Text = WerewolfModel.ACTION_JAIL;
                        break;

                    case WerewolfModel.ROLE_WEREWOLF_SHAMAN:
                        BtnAction.Text = WerewolfModel.ACTION_ENCHANT;
                        break;

                    case WerewolfModel.ROLE_BODYGUARD:
                        BtnAction.Text = WerewolfModel.ACTION_GUARD;
                        break;

                    case WerewolfModel.ROLE_DOCTOR:
                        BtnAction.Text = WerewolfModel.ACTION_HEAL;
                        break;

                    case WerewolfModel.ROLE_SERIAL_KILLER:
                        BtnAction.Text = WerewolfModel.ACTION_KILL;
                        break;

                    case WerewolfModel.ROLE_SEER:
                    case WerewolfModel.ROLE_WEREWOLF_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_REVEAL;
                        break;

                    case WerewolfModel.ROLE_AURA_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_AURA;
                        break;

                    case WerewolfModel.ROLE_MEDIUM:
                        BtnAction.Text = WerewolfModel.ACTION_REVIVE;
                        break;

                    default:
                        EnableButton(BtnAction, false);
                        break;
                    }
                    EnableButton(BtnVote, true);
                    EnableButton(BtnJoin, false);
                    UpdateAvatar(wm);
                    break;

                case EventEnum.SwitchToDayTime:
                    AddChatMessage("Switch to day time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Day;
                    LBPeriod.Text  = "Day time of";
                    break;

                case EventEnum.SwitchToNightTime:
                    AddChatMessage("Switch to night time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    LBPeriod.Text  = "Night time of";
                    break;

                case EventEnum.UpdateDay:
                    // TODO  catch parse exception here
                    string tempDay = wm.EventPayloads["Game.Current.Day"];
                    _currentDay = int.Parse(tempDay);
                    LBDay.Text  = tempDay;
                    break;

                case EventEnum.UpdateTime:
                    string tempTime = wm.EventPayloads["Game.Current.Time"];
                    _currentTime = int.Parse(tempTime);
                    LBTime.Text  = tempTime;
                    UpdateAvatar(wm);
                    break;

                case EventEnum.Vote:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your vote is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't vote now.");
                    }
                    break;

                case EventEnum.Action:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your action is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't perform action now.");
                    }
                    break;

                case EventEnum.YouShotDead:
                    AddChatMessage("You're shot dead by gunner.");
                    _isDead = true;
                    break;

                case EventEnum.OtherShotDead:
                    AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " was shot dead by gunner.");
                    break;

                case EventEnum.Alive:
                    AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " has been revived by medium.");
                    if (wm.EventPayloads["Game.Target.Id"] == null)
                    {
                        _isDead = false;
                    }
                    break;

                case EventEnum.ChatMessage:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage(wm.EventPayloads["Game.Chatter"] + ":" + wm.EventPayloads["Game.ChatMessage"]);
                    }
                    break;

                case EventEnum.Chat:
                    if (wm.EventPayloads["Success"] == WerewolfModel.FALSE)
                    {
                        switch (wm.EventPayloads["Error"])
                        {
                        case "403":
                            AddChatMessage("You're not alive, can't talk now.");
                            break;

                        case "404":
                            AddChatMessage("You're not existed, can't talk now.");
                            break;

                        case "405":
                            AddChatMessage("You're not in a game, can't talk now.");
                            break;

                        case "406":
                            AddChatMessage("You're not allow to talk now, go to sleep.");
                            break;
                        }
                    }
                    break;

                case EventEnum.SignOut:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        this.Visible      = false;
                        formlogin.Visible = true;
                    }
                    break;
                }
                // need to reset event
                wm.Event = EventEnum.NOP;
            }
        }
Esempio n. 4
0
        public void Notify(Model m)
        {
            if (m is WerewolfModel)
            {
                WerewolfModel wm = (WerewolfModel)m;
                switch (wm.Event)
                {
                case EventEnum.SignOut:
                    foreach (int i in Enumerable.Range(0, 16))
                    {
                        this.Controls["panel1"].Controls["BtnPlayer" + i].Click += new System.EventHandler(this.BtnPlayerX_Click);
                        this.Controls["panel1"].Controls["BtnPlayer" + i].Tag    = i;
                    }

                    this.SystemOutBox.Visible = false;
                    this.TbChatBox.Visible    = false;
                    this.TbChatInput.Visible  = false;
                    this.LBDay.Visible        = false;
                    this.LBPeriod.Visible     = false;
                    this.LBTime.Visible       = false;
                    this.label1.Visible       = false;
                    this.label2.Visible       = false;

                    _updateTimer     = new Timer();
                    _voteActivated   = false;
                    _actionActivated = false;
                    _myRole          = null;
                    _isDead          = false;

                    StartSetup();

                    EnableButton(BtnJoin, true);
                    EnableButton(BtnViewRole, true);
                    EnableButton(BtnAction, false);
                    EnableButton(BtnVote, false);
                    EnableButton(BtnLeave, false);
                    EnableButton(BtnSignOut, false);

                    SystemOutBox.Text = "";

                    this.Visible = false;


                    break;

                case EventEnum.LeaveGame:
                    foreach (int i in Enumerable.Range(0, 16))
                    {
                        this.Controls["panel1"].Controls["BtnPlayer" + i].Click += new System.EventHandler(this.BtnPlayerX_Click);
                        this.Controls["panel1"].Controls["BtnPlayer" + i].Tag    = i;
                    }

                    this.SystemOutBox.Visible = false;
                    this.TbChatBox.Visible    = false;
                    this.TbChatInput.Visible  = false;
                    this.LBDay.Visible        = false;
                    this.LBPeriod.Visible     = false;
                    this.LBTime.Visible       = false;
                    this.label1.Visible       = false;
                    this.label2.Visible       = false;

                    _updateTimer     = new Timer();
                    _voteActivated   = false;
                    _actionActivated = false;
                    _myRole          = null;
                    _isDead          = false;
                    StartSetup();
                    EnableButton(BtnJoin, true);
                    EnableButton(BtnViewRole, true);
                    EnableButton(BtnAction, false);
                    EnableButton(BtnVote, false);
                    EnableButton(BtnLeave, false);
                    EnableButton(BtnSignOut, false);
                    SystemOutBox.Text = "";
                    break;

                case EventEnum.JoinGame:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        BtnJoin.Visible = false;
                        //AddChatMessage("You're joining the game #" + wm.EventPayloads["Game.Id"] + ", please wait for game start.");
                        AddSystemMessage("You're joining the game #" + wm.EventPayloads["Game.Id"] + ", please wait for game start.");
                        _updateTimer.Interval = 1000;
                        _updateTimer.Tick    += new EventHandler(OnTimerEvent);
                        _updateTimer.Enabled  = true;

                        foreach (int i in Enumerable.Range(0, 16))
                        {
                            ButtonVisible((Button)Controls["panel1"].Controls["BtnPlayer" + i], true);
                        }

                        this.SystemOutBox.Visible = true;
                        this.TbChatBox.Visible    = true;
                        this.TbChatInput.Visible  = true;
                        this.LBDay.Visible        = true;
                        this.LBPeriod.Visible     = true;
                        this.LBTime.Visible       = true;
                        this.label1.Visible       = true;
                        this.label2.Visible       = true;
                        EnableButton(BtnLeave, true);
                        EnableButton(BtnSignOut, true);
                        EnableButton(BtnViewRole, false);
                    }
                    else
                    {
                        MessageBox.Show("You can't join the game, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;

                case EventEnum.GameStopped:
                    //AddChatMessage("Game is finished, outcome is " + wm.EventPayloads["Game.Outcome"]);
                    AddSystemMessage("Game is finished, outcome is " + wm.EventPayloads["Game.Outcome"]);
                    _updateTimer.Enabled = false;
                    break;

                case EventEnum.GameStarted:
                    players = wm.Players;
                    _myRole = wm.EventPayloads["Player.Role.Name"];
                    //AddChatMessage("Your role is " + _myRole + ".");
                    AddSystemMessage("Your role is " + _myRole + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    EnableButton(BtnAction, true);
                    switch (_myRole)
                    {
                    case WerewolfModel.ROLE_PRIEST:
                        BtnAction.Text = WerewolfModel.ACTION_HOLYWATER;
                        break;

                    case WerewolfModel.ROLE_GUNNER:
                        BtnAction.Text = WerewolfModel.ACTION_SHOOT;
                        break;

                    case WerewolfModel.ROLE_JAILER:
                        BtnAction.Text = WerewolfModel.ACTION_JAIL;
                        break;

                    case WerewolfModel.ROLE_WEREWOLF_SHAMAN:
                        BtnAction.Text = WerewolfModel.ACTION_ENCHANT;
                        break;

                    case WerewolfModel.ROLE_BODYGUARD:
                        BtnAction.Text = WerewolfModel.ACTION_GUARD;
                        break;

                    case WerewolfModel.ROLE_DOCTOR:
                        BtnAction.Text = WerewolfModel.ACTION_HEAL;
                        break;

                    case WerewolfModel.ROLE_SERIAL_KILLER:
                        BtnAction.Text = WerewolfModel.ACTION_KILL;
                        break;

                    case WerewolfModel.ROLE_SEER:
                    case WerewolfModel.ROLE_WEREWOLF_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_REVEAL;
                        break;

                    case WerewolfModel.ROLE_AURA_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_AURA;
                        break;

                    case WerewolfModel.ROLE_MEDIUM:
                        BtnAction.Text = WerewolfModel.ACTION_REVIVE;
                        break;

                    default:
                        EnableButton(BtnAction, false);
                        break;
                    }
                    EnableButton(BtnVote, true);
                    EnableButton(BtnJoin, false);
                    EnableButton(BtnViewRole, false);
                    UpdateAvatar(wm);
                    break;

                case EventEnum.SwitchToDayTime:
                    //AddChatMessage("Switch to day time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    AddSystemMessage("Switch to day time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Day;
                    LBPeriod.Text  = "Day time";
                    break;

                case EventEnum.SwitchToNightTime:
                    //AddChatMessage("Switch to night time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    AddSystemMessage("Switch to night time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    LBPeriod.Text  = "Night time";
                    break;

                case EventEnum.UpdateDay:
                    // TODO  catch parse exception here
                    string tempDay = wm.EventPayloads["Game.Current.Day"];
                    _currentDay = int.Parse(tempDay);
                    LBDay.Text  = tempDay;
                    break;

                case EventEnum.UpdateTime:
                    string tempTime = wm.EventPayloads["Game.Current.Time"];
                    _currentTime = int.Parse(tempTime);
                    LBTime.Text  = tempTime;
                    if (_currentPeriod == Game.PeriodEnum.Night)
                    {
                        this.Sun_moon.Left -= 4;
                        this.BackColor      = ColorTranslator.FromHtml(BG_Arr[BG_count]);
                        if (BG_count < 35)
                        {
                            BG_count++;
                        }
                    }
                    else
                    {
                        this.BackColor = ColorTranslator.FromHtml(BG_Arr[BG_count]);
                        BG_count--;
                        this.Sun_moon.Left += 4;
                        if (BG_count == -1)
                        {
                            BG_count++;
                        }
                    }
                    UpdateAvatar(wm);
                    break;

                case EventEnum.Vote:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        //AddChatMessage("Your vote is registered.");
                        AddSystemMessage("Your vote is registered.");
                    }
                    else
                    {
                        //AddChatMessage("You can't vote now.");
                        AddSystemMessage("You can't vote now.");
                    }
                    break;

                case EventEnum.Action:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        //AddChatMessage("Your action is registered.");
                        AddSystemMessage("Your action is registered.");
                        if (_myRole == WerewolfModel.ROLE_GUNNER)
                        {
                            WerewolfCommand wcmd = new WerewolfCommand();
                            wcmd.Action   = CommandEnum.Chat;
                            wcmd.Payloads = new Dictionary <string, string>()
                            {
                                { "Message", "I am a Gunner" }
                            };
                            controller.ActionPerformed(wcmd);
                            firstshot = true;
                        }
                    }
                    else
                    {
                        //AddChatMessage("You can't perform action now.");
                        AddSystemMessage("You can't perform action now.");
                    }
                    break;

                case EventEnum.YouShotDead:
                    //AddChatMessage("You're shot dead by gunner.");
                    AddSystemMessage("You're shot dead by gunner.");
                    _isDead = true;
                    break;

                case EventEnum.OtherShotDead:
                    //AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " was shot dead by gunner.");
                    AddSystemMessage(wm.EventPayloads["Game.Target.Name"] + " was shot dead by gunner.");
                    break;

                case EventEnum.Alive:
                    //AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " has been revived by medium.");
                    AddSystemMessage(wm.EventPayloads["Game.Target.Name"] + " has been revived by medium.");
                    if (wm.EventPayloads["Game.Target.Id"] == null)
                    {
                        _isDead = false;
                    }
                    break;

                case EventEnum.ChatMessage:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage(wm.EventPayloads["Game.Chatter"] + ":" + wm.EventPayloads["Game.ChatMessage"]);
                    }
                    break;

                case EventEnum.Chat:
                    if (wm.EventPayloads["Success"] == WerewolfModel.FALSE)
                    {
                        switch (wm.EventPayloads["Error"])
                        {
                        case "403":
                            AddSystemMessage("You're not alive, can't talk now.");
                            break;

                        case "404":
                            AddSystemMessage("You're not existed, can't talk now.");
                            break;

                        case "405":
                            AddSystemMessage("You're not in a game, can't talk now.");
                            break;

                        case "406":
                            AddSystemMessage("You're not allow to talk now, go to sleep.");
                            break;
                        }
                    }
                    break;
                }
                // need to reset event
                wm.Event = EventEnum.NOP;
            }
        }
Esempio n. 5
0
        public void Notify(Model m)
        {
            if (m is WerewolfModel)
            {
                WerewolfModel wm = (WerewolfModel)m;
                switch (wm.Event)
                {
                case EventEnum.JoinGame:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        BtnJoin.Visible = false;
                        AddChatMessage("You're joing the game #" + wm.EventPayloads["Game.Id"] + ", please wait for game start.");
                        _updateTimer.Interval = 1000;
                        _updateTimer.Tick    += new EventHandler(OnTimerEvent);
                        _updateTimer.Enabled  = true;
                    }
                    else
                    {
                        MessageBox.Show("You can't join the game, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;

                case EventEnum.GameStopped:
                    AddChatMessage("Game is finished, outcome is " + wm.EventPayloads["Game.Outcome"]);
                    _updateTimer.Enabled = false;
                    BtnJoin.Visible      = true;
                    EnableButton(BtnJoin, true);

                    break;

                case EventEnum.GameStarted:
                    players = wm.Players;
                    _myRole = wm.EventPayloads["Player.Role.Name"];
                    AddChatMessage("Your role is " + _myRole + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    EnableButton(BtnAction, true);
                    switch (_myRole)
                    {
                    case WerewolfModel.ROLE_PRIEST:
                        BtnAction.Text = WerewolfModel.ACTION_HOLYWATER;
                        break;

                    case WerewolfModel.ROLE_GUNNER:
                        BtnAction.Text = WerewolfModel.ACTION_SHOOT;
                        break;

                    case WerewolfModel.ROLE_JAILER:
                        BtnAction.Text = WerewolfModel.ACTION_JAIL;
                        break;

                    case WerewolfModel.ROLE_WEREWOLF_SHAMAN:
                        BtnAction.Text = WerewolfModel.ACTION_ENCHANT;
                        break;

                    case WerewolfModel.ROLE_BODYGUARD:
                        BtnAction.Text = WerewolfModel.ACTION_GUARD;
                        break;

                    case WerewolfModel.ROLE_DOCTOR:
                        BtnAction.Text = WerewolfModel.ACTION_HEAL;
                        break;

                    case WerewolfModel.ROLE_SERIAL_KILLER:
                        BtnAction.Text = WerewolfModel.ACTION_KILL;
                        break;

                    case WerewolfModel.ROLE_SEER:
                    case WerewolfModel.ROLE_WEREWOLF_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_REVEAL;
                        break;

                    case WerewolfModel.ROLE_AURA_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_AURA;
                        break;

                    case WerewolfModel.ROLE_MEDIUM:
                        BtnAction.Text = WerewolfModel.ACTION_REVIVE;
                        break;

                    default:
                        EnableButton(BtnAction, false);
                        break;
                    }
                    EnableButton(BtnVote, true);
                    EnableButton(BtnJoin, false);
                    UpdateAvatar(wm);
                    break;

                case EventEnum.GameWaiting:
                    if (playerCounter != wm.Players.Count)
                    {
                        foreach (Player player in wm.Players)
                        {
                            AddChatMessage(player.Name + " Join Game !!!");
                        }
                        playerCounter = wm.Players.Count;
                    }
                    break;


                case EventEnum.SwitchToDayTime:
                    AddChatMessage("Switch to day time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod       = Game.PeriodEnum.Day;
                    LBPeriod.Text        = "Day time of";
                    this.BackgroundImage = Properties.Resources.Daytime;
                    break;

                case EventEnum.SwitchToNightTime:
                    AddChatMessage("Switch to night time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod       = Game.PeriodEnum.Night;
                    LBPeriod.Text        = "Night time of";
                    this.BackgroundImage = Properties.Resources.Nighttime;
                    break;

                case EventEnum.UpdateDay:
                    // TODO  catch parse exception here
                    string tempDay = wm.EventPayloads["Game.Current.Day"];
                    _currentDay = int.Parse(tempDay);
                    LBDay.Text  = tempDay;
                    break;

                case EventEnum.UpdateTime:
                    string tempTime = wm.EventPayloads["Game.Current.Time"];
                    _currentTime = int.Parse(tempTime);
                    LBTime.Text  = tempTime;
                    UpdateAvatar(wm);
                    break;

                case EventEnum.Vote:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your vote is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't vote now.");
                    }
                    break;

                case EventEnum.Action:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your action is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't perform action now.");
                    }
                    break;

                case EventEnum.YouShotDead:
                    AddChatMessage("You're shot dead by gunner.");
                    _isDead = true;
                    break;

                case EventEnum.OtherShotDead:
                    AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " was shot dead by gunner.");
                    break;

                case EventEnum.Alive:
                    AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " has been revived by medium.");
                    if (wm.EventPayloads["Game.Target.Id"] == null)
                    {
                        _isDead = false;
                    }
                    break;

                case EventEnum.ChatMessage:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        for (int i = 0; i < wm.Players.Count; i++)
                        {
                            if (wm.EventPayloads["Game.Chatter"] == wm.Players[i].Name)
                            {
                                switch (i + 1)
                                {
                                case 1: textBox1.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 2:
                                    textBox2.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 3:
                                    textBox3.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 4:
                                    textBox4.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 5:
                                    textBox5.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 6:
                                    textBox6.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 7:
                                    textBox7.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 8:
                                    textBox8.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 9:
                                    textBox9.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 10:
                                    textBox10.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 11:
                                    textBox11.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 12:
                                    textBox12.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 13:
                                    textBox13.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 14:
                                    textBox14.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 15:
                                    textBox15.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;

                                case 16:
                                    textBox16.Text = wm.EventPayloads["Game.ChatMessage"];
                                    break;
                                }
                            }
                        }


                        AddChatMessage(wm.EventPayloads["Game.Chatter"] + ":" + wm.EventPayloads["Game.ChatMessage"]);
                    }
                    break;

                case EventEnum.Chat:
                    if (wm.EventPayloads["Success"] == WerewolfModel.FALSE)
                    {
                        switch (wm.EventPayloads["Error"])
                        {
                        case "403":
                            AddChatMessage("You're not alive, can't talk now.");
                            break;

                        case "404":
                            AddChatMessage("You're not existed, can't talk now.");
                            break;

                        case "405":
                            AddChatMessage("You're not in a game, can't talk now.");
                            break;

                        case "406":
                            AddChatMessage("You're not allow to talk now, go to sleep.");
                            break;
                        }
                    }
                    break;

                case EventEnum.SignOut:
                    this.Visible    = false;
                    BtnJoin.Visible = true;
                    EnableButton(BtnJoin, true);
                    TbChatBox.Text = "";
                    playerCounter  = 0;
                    break;

                case EventEnum.LeaveGame:
                    BtnJoin.Visible = true;
                    EnableButton(BtnJoin, true);
                    TbChatBox.Text = "";
                    playerCounter  = 0;
                    break;

                case EventEnum.Soundbackground:
                    if (_isSound)
                    {
                        counter = 2;
                        //backGround_sound.settings.volume = 20;
                        //clickSound = !clickSound;
                        _isSound = false;
                        timer_time();
                    }
                    else
                    {
                        counter = 2;
                        //backGround_sound.settings.volume = 0;
                        clickSound = !clickSound;
                        _isSound   = true;
                        timer_time();
                    }
                    EnableButton(BtnJoin, true);
                    TbChatBox.Text = "";
                    break;
                }
                // need to reset event
                wm.Event = EventEnum.NOP;
            }
        }
Esempio n. 6
0
        public void Notify(Model m)
        {
            if (m is WerewolfModel)
            {
                WerewolfModel wm = (WerewolfModel)m;
                switch (wm.Event)
                {
                case EventEnum.JoinGame:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        BtnJoin.Visible = false;
                        AddChatMessage("You're joing the game #" + wm.EventPayloads["Game.Id"] + ", please wait for game start.");
                        _updateTimer.Interval = 1000;
                        _updateTimer.Tick    += new EventHandler(OnTimerEvent);
                        _updateTimer.Enabled  = true;
                    }
                    else
                    {
                        MessageBox.Show("You can't join the game, please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    break;

                case EventEnum.GameStopped:
                    AddChatMessage("Game is finished, outcome is " + wm.EventPayloads["Game.Outcome"]);
                    _updateTimer.Enabled = false;
                    break;

                case EventEnum.GameStarted:
                    players = wm.Players;
                    _myRole = wm.EventPayloads["Player.Role.Name"];
                    AddChatMessage("Your role is " + _myRole + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    EnableButton(BtnAction, true);
                    switch (_myRole)
                    {
                    case WerewolfModel.ROLE_PRIEST:
                        BtnAction.Text = WerewolfModel.ACTION_HOLYWATER;
                        break;

                    case WerewolfModel.ROLE_GUNNER:
                        BtnAction.Text = WerewolfModel.ACTION_SHOOT;
                        break;

                    case WerewolfModel.ROLE_JAILER:
                        BtnAction.Text = WerewolfModel.ACTION_JAIL;
                        break;

                    case WerewolfModel.ROLE_WEREWOLF_SHAMAN:
                        BtnAction.Text = WerewolfModel.ACTION_ENCHANT;
                        break;

                    case WerewolfModel.ROLE_BODYGUARD:
                        BtnAction.Text = WerewolfModel.ACTION_GUARD;
                        break;

                    case WerewolfModel.ROLE_DOCTOR:
                        BtnAction.Text = WerewolfModel.ACTION_HEAL;
                        break;

                    case WerewolfModel.ROLE_SERIAL_KILLER:
                        BtnAction.Text = WerewolfModel.ACTION_KILL;
                        break;

                    case WerewolfModel.ROLE_SEER:
                    case WerewolfModel.ROLE_WEREWOLF_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_REVEAL;
                        break;

                    case WerewolfModel.ROLE_AURA_SEER:
                        BtnAction.Text = WerewolfModel.ACTION_AURA;
                        break;

                    case WerewolfModel.ROLE_MEDIUM:
                        BtnAction.Text = WerewolfModel.ACTION_REVIVE;
                        break;

                    default:
                        EnableButton(BtnAction, false);
                        break;
                    }
                    EnableButton(BtnVote, true);
                    EnableButton(BtnJoin, false);
                    UpdateAvatar(wm);
                    break;

                case EventEnum.SwitchToDayTime:
                    AddChatMessage("Switch to day time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Day;
                    LBPeriod.Text  = "Day time of";
                    DorN           = true;
                    break;

                case EventEnum.SwitchToNightTime:
                    AddChatMessage("Switch to night time of day #" + wm.EventPayloads["Game.Current.Day"] + ".");
                    _currentPeriod = Game.PeriodEnum.Night;
                    LBPeriod.Text  = "Night time of";
                    DorN           = false;
                    break;

                case EventEnum.UpdateDay:
                    // TODO  catch parse exception here
                    string tempDay = wm.EventPayloads["Game.Current.Day"];
                    _currentDay = int.Parse(tempDay);
                    LBDay.Text  = tempDay;
                    break;

                case EventEnum.UpdateTime:
                    string tempTime = wm.EventPayloads["Game.Current.Time"];
                    _currentTime = int.Parse(tempTime);
                    LBTime.Text  = tempTime;
                    UpdateAvatar(wm);
                    if (_isChat)
                    {
                        AddChatMessage(textBox2.ToString());
                        textBox2.Text = "";
                        _isChat       = false;
                    }
                    if (DorN)
                    {
                        TbChatBox.BackColor  = Color.White;
                        TbChatBox.ForeColor  = Color.Black;
                        textBox2.BackColor   = Color.White;
                        textBox2.ForeColor   = Color.Black;
                        this.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject("D" + (_currentTime + 1));
                    }
                    else
                    {
                        TbChatBox.BackColor  = Color.Black;
                        TbChatBox.ForeColor  = Color.White;
                        textBox2.BackColor   = Color.Black;
                        textBox2.ForeColor   = Color.White;
                        this.BackgroundImage = (Image)Properties.Resources.ResourceManager.GetObject("N" + (_currentTime + 1));
                    }
                    break;

                case EventEnum.Vote:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your vote is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't vote now.");
                    }
                    break;

                case EventEnum.Action:
                    if (wm.EventPayloads["Success"] == WerewolfModel.TRUE)
                    {
                        AddChatMessage("Your action is registered.");
                    }
                    else
                    {
                        AddChatMessage("You can't perform action now.");
                    }
                    break;

                case EventEnum.YouShotDead:
                    AddChatMessage("You're shot dead by gunner.");
                    _isDead = true;
                    break;

                case EventEnum.OtherShotDead:
                    AddChatMessage(wm.EventPayloads["Game.Target.Name"] + " was shot dead by gunner.");
                    break;

                case EventEnum.Alive:
                    if (_isDead)
                    {
                        AddChatMessage("You've been revived by medium.");
                        _isDead = false;
                    }
                    break;
                }
                // need to reset event
                wm.Event = EventEnum.NOP;
            }
        }