コード例 #1
0
        // Loads new level:
        void LoadLevel()
        {
            // Clearing key press adapter:
            this.keyPressAdapters.Clear();

            try
            {
                // Creating a level:
                this.level = new CPlayLevel(++LevelNumber, Players, constructionMap);

                // Setting statistics to show whel level completed:
                this.level.OnLevelExit += OnShowStatistics;

                // Setting key press adapter for player 1:
                for (int i = 0; i < Players.Count; i++)
                {
                    this.keyPressAdapters.Add(new CKeyPressAdapter(ControlKeys[i], Players[i]));
                }

                // Setting scene painter:
                this.gamePainter = level.DrawLevel;

                // Setting current status to Playing:
                this.CurrentGameStatus = GameStatuses.Playing;
            }

            catch (Exception)
            {
                MessageBox.Show("Error loading level!");

                this.gamePainter = null;
            }
        }
コード例 #2
0
        /// <summary>Изменение состояния игры.</summary>
        /// <param name="value">Новое состояние игры.</param>
        /// <param name="args">Дополнительные аргументы, если надо.</param>
        void SetGameStatus(GameStatuses value, object args = null)
        {
            // Сравнение с текущим состоянием.
            if (GameStatus == value)
            {
                return;
            }

            // Присваивание нового значения состояния.
            GameStatus = value;

            // Создание события с разными параметрами в зависимости от переданного значения args.
            // Если args пустое, то в событие передаётся только новое состояние игры.
            // Иначе - передаётся массив из двух элементов: новое состояние игры и параметр args.
            if (args == null)
            {
                ChangedStateEvent?.Invoke(this, new ChangedStateHandlerArgs(NamesState.GameStatus, value));
            }
            else
            {
                // Если новое состояние это победа или ничья, то обновляется статистика.
                if (GameStatus == GameStatuses.Win || GameStatus == GameStatuses.Draw)
                {
                    if (GameStatus == GameStatuses.Win)
                    {
                        RepoStatistic.SaveStatistic(Gamers, CurrentGamerId == Gamers[0].Id, CurrentGamerId == Gamers[1].Id);                        // SaveStatistic();
                    }
                    else
                    {
                        RepoStatistic.SaveStatistic(Gamers, false, false);
                    }
                }
                ChangedStateEvent?.Invoke(this, new ChangedStateHandlerArgs(NamesState.GameStatus, new object[] { value, args }));
            }
        }
コード例 #3
0
        // Shows statistics:
        void OnShowStatistics(object sender, EventArgs e)
        {
            try
            {
                // Setting status to show statistics:
                this.CurrentGameStatus = GameStatuses.ShowStatistics;

                // Getting players:
                CTankPlayer[] players = (sender as CPlayLevel).Players.ToArray();

                // Modify hiscore if any player hits it:
                foreach (CTankPlayer p in players)
                {
                    if (p.Points > hiScore)
                    {
                        hiScore = p.Points;
                    }
                }

                // Creating statistics, taking game status and player from level:
                this.levelStatistics = new CStatisticsViewer((e as LevelEventArgs).GameStatus, this.levelNumber, this.hiScore, players);

                // Setting event that shoud occur when statistics shown
                this.levelStatistics.OnEnd += OnStatisticsEnd;

                // Setting game painter to statistics:
                this.gamePainter = levelStatistics.DrawStatistics;
            }
            catch (Exception)
            {
                MessageBox.Show("Error on statistics show! Going to menu...");

                this.gamePainter = null;
            }
        }
コード例 #4
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public void EndGame()
        {
            GameStatuses gameStatus = GetGameStatus();

            if (gameStatus != GameStatuses.InProgress)
            {
                throw new AvalonHelperException("Attempted to end game when GameStatus != SettingUp.");
            }

            SetGameStatus(GameStatuses.EndScreen);
        }
コード例 #5
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public void ResetGame()
        {
            GameStatuses gameStatus = GetGameStatus();

            if (gameStatus != GameStatuses.EndScreen)
            {
                throw new AvalonHelperException("Attempted to reset game when GameStatus != EndScreen.");
            }

            SetGameStatus(GameStatuses.SettingUp);
            ClearUserRoles();
        }
コード例 #6
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public void SetGameStatus(GameStatuses status)
        {
            gameStateMutex.WaitOne();

            try
            {
                gameStatus = status;
            }
            finally
            {
                gameStateMutex.ReleaseMutex();
            }
        }
コード例 #7
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public bool SelectRole(IUser user, int roleId)
        {
            GameStatuses status = GetGameStatus();

            if (gameStatus != GameStatuses.SettingUp)
            {
                return(false);
            }

            SetRoleIdForUser(user, roleId);

            return(true);
        }
コード例 #8
0
        // Constructor:
        public CPlayLevel(int levelNo, List <CTankPlayer> players, int[] map = null)
        {
            // setting level number:
            this.LevelNumber = levelNo;

            // Setting construction map:
            this.constructionMap = map;

            // Setting players:
            this.Players = players;

            // Setting game status:
            this.GameStatus = GameStatuses.Playing;

            // Dont start level until curtain is completed:
            this.LevelStarted = false;

            // Creating level curtain:
            CreateLevelCurtain();
        }
コード例 #9
0
        public CStatisticsViewer(GameStatuses gs, int levelno, int hiscore, CTankPlayer[] p)
        {
            this.players = p;

            this.Image = images[p.Count() - 1];

            this.X = 0;

            this.Y = 0;

            this.Width = 512;

            this.Height = 448;

            this.gameStatus = gs;

            this.levelNo = levelno;

            this.hiScore = hiscore;

            CreateStaisticsElements();
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: TanaTiX/TciTacToeTestGame
        private static void OnChangeGameStatus(object sender, GameStatuses status)
        {
            Utils.Log("change status", status);
            switch (status)
            {
            case GameStatuses.Zero:
                Utils.Log("Такого быть не должно");
                break;

            case GameStatuses.New:
                Utils.Log("Новая игра создана");
                break;

            case GameStatuses.Game:
                Utils.Log("Можно ходить");
                break;

            case GameStatuses.WinFirst:
                Utils.Log("Победа!", _currentUser);
                break;

            case GameStatuses.WinSecond:
                Utils.Log("Победа!", _currentUser);
                break;

            case GameStatuses.Draw:
                Utils.Log("Ничья");
                break;

            case GameStatuses.Cancel:
                Utils.Log("Игра отменена");
                break;

            default:
                break;
            }
        }
コード例 #11
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        private int GetRoleIdForUser(IUser user)
        {
            if (!user.Roles.Contains("Player"))
            {
                return(-1);
            }

            int roleId;

            userRolesMutex.WaitOne();

            try
            {
                if (userRoles.ContainsKey(user.UserId))
                {
                    roleId = userRoles[user.UserId];
                }
                else
                {
                    GameStatuses gameStatus = GetGameStatus();

                    roleId = gameStatus == GameStatuses.SettingUp ? 0 : -1;
                    {
                        userRoles[user.UserId] = roleId;
                    }
                }

                userRoles[user.UserId] = roleId;
            }
            finally
            {
                userRolesMutex.ReleaseMutex();
            }

            return(roleId);
        }
コード例 #12
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public string CanStartGame()
        {
            GameStatuses gameStatus = GetGameStatus();

            if (gameStatus != GameStatuses.SettingUp)
            {
                return("The game has already been started");
            }

            int playerCount;
            int settingUpCount;

            userRolesMutex.WaitOne();

            try
            {
                playerCount    = userRoles.Keys.Count(k => userRoles[k] > 0);
                settingUpCount = userRoles.Keys.Count(k => userRoles[k] == 0);
            }
            finally
            {
                userRolesMutex.ReleaseMutex();
            }

            if (playerCount < 5)
            {
                return("There are not enough players to start the game");
            }

            if (settingUpCount > 0)
            {
                return("One or more players has not confirmed their role on the role section screen");
            }

            return(string.Empty);
        }
コード例 #13
0
ファイル: AvalonGame.cs プロジェクト: Feefa/GameServer
        public RoleStatusModel[] GetRevealedRoles()
        {
            GameStatuses gameStatus = GetGameStatus();

            if (gameStatus != GameStatuses.EndScreen)
            {
                return(null);
            }

            IList <RoleStatusModel> roles = new List <RoleStatusModel>();

            userRolesMutex.WaitOne();

            try
            {
                foreach (string userId in userRoles.Keys)
                {
                    RoleStatusModel model = new RoleStatusModel {
                        PlayerName = userId
                    };

                    switch (userRoles[userId])
                    {
                    case (1):
                        model.RoleName          = "Merlin";
                        model.RoleImageFileName = "Images/merlin_small.jpg";
                        break;

                    case (2):
                        model.RoleName          = "Percival";
                        model.RoleImageFileName = "Images/percival_small.jpg";
                        break;

                    case (3):
                        model.RoleName          = "Loyal Servant of Arthur";
                        model.RoleImageFileName = "Images/servant1_small.jpg";
                        break;

                    case (4):
                        model.RoleName          = "Loyal Servant of Arthur";
                        model.RoleImageFileName = "Images/servant2_small.jpg";
                        break;

                    case (5):
                        model.RoleName          = "Loyal Servant of Arthur";
                        model.RoleImageFileName = "Images/servant3_small.jpg";
                        break;

                    case (6):
                        model.RoleName          = "Loyal Servant of Arthur";
                        model.RoleImageFileName = "Images/servant4_small.jpg";
                        break;

                    case (7):
                        model.RoleName          = "Loyal Servant of Arthur";
                        model.RoleImageFileName = "Images/servant5_small.jpg";
                        break;

                    case (8):
                        model.RoleName          = "Mordred";
                        model.RoleImageFileName = "Images/mordred_small.jpg";
                        break;

                    case (9):
                        model.RoleName          = "Morgana";
                        model.RoleImageFileName = "Images/morgana_small.jpg";
                        break;

                    case (10):
                        model.RoleName          = "Assassin";
                        model.RoleImageFileName = "Images/assassin_small.jpg";
                        break;

                    case (11):
                        model.RoleName          = "Oberon";
                        model.RoleImageFileName = "Images/oberon_small.jpg";
                        break;

                    case (12):
                        model.RoleName          = "Minion of Mordred";
                        model.RoleImageFileName = "Images/minion1_small.jpg";
                        break;

                    case (13):
                        model.RoleName          = "Minion of Mordred";
                        model.RoleImageFileName = "Images/minion2_small.jpg";
                        break;

                    case (14):
                        model.RoleName          = "Minion of Mordred";
                        model.RoleImageFileName = "Images/minion3_small.jpg";
                        break;
                    }

                    roles.Add(model);
                }
            }
            finally
            {
                userRolesMutex.ReleaseMutex();
            }

            return(roles.ToArray());
        }
コード例 #14
0
 public LevelEventArgs(GameStatuses gs)
 {
     this.GameStatus = gs;
 }
コード例 #15
0
 public void OnStatisticsEnd(object sender, LevelEventArgs e)
 {
     this.CurrentGameStatus = (e as LevelEventArgs).GameStatus;
 }