예제 #1
0
    // Saves the replay with the specified file path
    public static void SaveReplayAs(string filepath, GameReplay replay)
    {
        IFormatter formatter = new BinaryFormatter();
        Stream     stream    = new FileStream(filepath, FileMode.Create, FileAccess.Write, FileShare.None);

        formatter.Serialize(stream, replay);
    }
    private void LoadReplay(GameReplay replay)
    {
        this._replay = replay;
        var info = replay.Info;

        Application.targetFrameRate = info.TargetFrameRate;
        _frameCount = 0;
    }
예제 #3
0
        public void IsExistTest()
        {
            GameReplay gr1 = new GameReplay(1, 1);

            Assert.IsTrue(_testRM.IsExist(gr1._gameRoomID, gr1._gameNumber));
            gr1._gameNumber = 2;
            Assert.IsFalse(_testRM.IsExist(gr1._gameRoomID, gr1._gameNumber));
            gr1._gameNumber = 1;
            gr1._gameRoomID = 2;
            Assert.IsFalse(_testRM.IsExist(gr1._gameRoomID, gr1._gameNumber));
        }
예제 #4
0
        public void DeleteGameReplayTest()
        {
            Assert.IsNotNull(_testRM.GetGameReplayForUser(1, 1, 1));
            _testRM.DeleteGameReplay(1, 1);
            Assert.IsNull(_testRM.GetGameReplayForUser(1, 1, 1));
            _testGR = new GameReplay(1, 1);
            _testGR.AddAction(_testAction);
            List <int> ids = new List <int>();

            ids.Add(1);
            Assert.IsTrue(_testRM.AddGameReplay(_testGR, ids));
        }
예제 #5
0
    // Saves the replay with current time as the file name in the default folder
    public static void SaveReplayWithTimeAsFilename(GameReplay replay)
    {
        DateTime now      = DateTime.Now;
        string   filename = string.Format("{0:HH_mm_dd_MM_yyyy}.rep", now);

        if (!Directory.Exists(FolderPath))
        {
            Directory.CreateDirectory(FolderPath);
        }
        SaveReplayAs(FolderPath + filename, replay);
        Debug.Log("Saved in " + FolderPath);
    }
예제 #6
0
        public GameRoomXML(GameRoom g)
        {
            Id      = g.Id;
            Players = new List <PlayerXML>();
            foreach (Player p in g.GetPlayersInRoom())
            {
                Players.Add(new PlayerXML(p));
            }

            Spectatores = new List <SpecXML>();
            foreach (Spectetor p in g.GetSpectetorInRoom())
            {
                Spectatores.Add(new SpecXML(p));
            }

            DealerPos     = g.GetDealerPos();
            maxBetInRound = g.GetMaxBetInRound();
            PotCount      = g.GetPotSize();
            Bb            = g.getBBnum();
            Sb            = g.getSBNUM();
            Deck          = g.GetDeck();
            Hand_Step     = g.GetHandStep();
            PublicCards   = g.GetPublicCards();
            IsActiveGame  = g.IsGameActive();
            if (g.GetSidePots() != null)
            {
                sidePotsXML = new List <SidePotTuple>();
                SidePots    = new List <Tuple <int, PlayerXML> >();
                foreach (var p in g.GetSidePots())
                {
                    PlayerXML pp = new PlayerXML(p.Item2);
                    SidePots.Add(new Tuple <int, PlayerXML>(p.Item1, pp));
                    sidePotsXML.Add(new SidePotTuple(p.Item1, pp));
                }
            }

            GameReplay    = g.GetGameRepObj();
            league        = g.GetLeagueName();
            ReplayManager = g.GetRepManager();

            CurrentPlayer = new PlayerXML(g.GetCurrPlayer());
            DealerPlayer  = new PlayerXML(g.GetDealer());
            BbPlayer      = new PlayerXML(g.GetBb());
            SbPlayer      = new PlayerXML(g.GetSb());
            //  MyDecorator = g.GetDecorator();

            GameNumber                 = g.GetGameNum();
            FirstPlayerInRound         = new PlayerXML(g.GetFirstPlayerInRound());
            currentPlayerPos           = g.GetCurrPosition();
            firstPlayerInRoundPoistion = g.GetFirstPlayerInRoundPos();
            lastRaiseInRound           = g.GetlastRaiseInRound();
            useCommunication           = g.GetUseComm();
        }
        public void SetRecorder(GameRecorder recorder)
        {
            replay = new GameReplay(recorder);

            DisplayGame(replay.Game);

            //Set the color of all buttons to neutral
            foreach (var button in allPoints)
            {
                button.Background = colorBrushMap[Game.HostId];
            }
        }
    // Use this for initialization
    private void Start()
    {
        GameReplay p = GlobalState.Instance.ReplayToLoad;

        if (p == null)
        {
            Debug.LogError("ReplayToLoad is empty");
        }

        LoadReplay(p);
        StartReplay();
    }
예제 #9
0
        public void Initialize()
        {
            testGR = new GameReplay(1, 1);
            User user1 = new User(1, "test1", "mo", "1234", 0, 5000, "*****@*****.**");
            User user2 = new User(1, "test2", "no", "1234", 0, 5000, "*****@*****.**");

            testAction1 = new CallAction(new Player(user1, 1000, 1),
                                         new Card(Suits.Hearts, 1), new Card(Suits.Hearts, 2), 10);
            testAction2 = new CallAction(new Player(user2, 1000, 1),
                                         new Card(Suits.Hearts, 3), new Card(Suits.Hearts, 4), 20);
            testGR.AddAction(testAction1);
            testGR.AddAction(testAction2);
        }
예제 #10
0
        public void Initialize()
        {
            User       user1 = new User(1, "test1", "mo", "1234", 0, 5000, "*****@*****.**");
            List <int> ids   = new List <int>();

            ids.Add(1);
            _testRM     = new ReplayManager();
            _testGR     = new GameReplay(1, 1);
            _testAction = new CallAction(new Player(user1, 1000, 1),
                                         new Card(Suits.Hearts, 1), new Card(Suits.Hearts, 2), 10);
            _testGR.AddAction(_testAction);
            _testRM.AddGameReplay(_testGR, ids);
        }
예제 #11
0
        public void Next()
        {
            GameReplay gReplay = ((GameReplay)game);

            if (gReplay.Action[gReplay.NbAction].GetType() == typeof(FightAction))
            {
                FightAction actionf = (FightAction)gReplay.Action[gReplay.NbAction];
                FightingBox = "Dégâts reçus : " + actionf.Damage;
                OnPropertyChanged("FightingBox");
            }
            gReplay.NextAction();
            ReloadMap();
        }
    // Start recording of the game
    public void StartRecording()
    {
        _started = true;
        _replay  = new GameReplay {
            Info = new ReplayInfo(
                GetGameVersion(),
                TARGET_FRAMERATE
                ),
            Entries = new Queue <GameReplay.Entry>()
        };

        _frameCount = 0;
        _state      = ReplayState.Started;
    }
예제 #13
0
        public List <string> GetGameReplay(int roomId, int gameNum, int userId)
        {
            GameReplay    replay  = _replayManager.GetGameReplayForUser(roomId, gameNum, userId);
            List <string> replays = new List <string>();

            if (replay == null)
            {
                return(replays);
            }
            TexasHoldem.Logic.Actions.Action action = replay.GetNextAction();
            while (action != null)
            {
                replays.Add(action.ToString());
                action = replay.GetNextAction();
            }
            return(replays);
        }
예제 #14
0
        public void AddGameReplayTest()
        {
            List <int> ids = new List <int>();

            ids.Add(1);
            List <int> ids2 = new List <int>();

            ids.Add(2);
            GameReplay gr1 = new GameReplay(1, 1);

            Assert.IsFalse(_testRM.AddGameReplay(gr1, ids));  //same room&game
            Assert.IsFalse(_testRM.AddGameReplay(gr1, ids2)); //same room&game
            GameReplay gr2 = new GameReplay(1, 2);

            Assert.IsTrue(_testRM.AddGameReplay(gr2, ids)); //diffrent game same room
            GameReplay gr3 = new GameReplay(2, 1);

            Assert.IsTrue(_testRM.AddGameReplay(gr3, ids)); //diffrent room same game number
        }
예제 #15
0
        // ReSharper disable once UnusedMember.Global
        public async Task <IActionResult> OnGet(Guid gameId, int moveId = 0)
        {
            if (gameId == Guid.Empty)
            {
                return(NotFound());
            }

            GameId = gameId;
            MoveId = moveId;

            var replay = await context.Replay.AsQueryable()
                         .Include(r => r.Moves)
                         .Include(r => r.Players)
                         .Include(r => r.Snapshots)
                         .FirstOrDefaultAsync(r => r.ReplayId == gameId);

            if (replay == null)
            {
                return(NotFound());
            }

            GameReplay = new GameReplay(replay.Players.Select(p => p.PlayerName).ToArray(),
                                        replay.Moves
                                        .Select(m => new GameLogEvent(
                                                    m.EventType,
                                                    m.SourcePlayer,
                                                    m.TargetPlayer,
                                                    m.Cards)).ToArray(),
                                        replay.Snapshots
                                        .Select(s => new GameSnapshot(
                                                    s.CurrentPlayerId,
                                                    s.PlayerHands,
                                                    s.CenterRow)).ToArray(),
                                        replay.GameStartDate
                                        );

            var startDateUtc = new DateTime(replay.GameStartDate.Ticks, DateTimeKind.Utc);

            Title =
                $"{replay.GuildTitle}#{replay.ChannelTitle} - {startDateUtc.ToString("g", CultureInfo.InvariantCulture)}";

            return(Page());
        }
예제 #16
0
        public GameReplay GetGameReplay(long gameId)
        {
            GameReplay ret = new GameReplay();

            using (BattleshipsDbEntities bdc = new BattleshipsDbEntities())
            {
                BattleshipsDatabase.Game game = bdc.Games.Include("WinnerRef").Include("LoserRef").Include("Turns").FirstOrDefault(g => g.GameId == gameId);
                if (game == null)
                {
                    return(null);
                }
                ret.Player1 = new PlayerContract(game.WinnerRef.PlayerId, game.WinnerRef.Name);
                ret.Player2 = new PlayerContract(game.LoserRef.PlayerId, game.LoserRef.Name);
                foreach (Turn t in game.Turns)
                {
                    ret.Moves.Add(new Move(t.Player, t.X, t.Y, t.Hit == true ? BlockState.HIT : BlockState.MISS));
                }
            }
            return(ret);
        }
예제 #17
0
 public void Run(long gameId)
 {
     Player1Board.Clear();
     Player2Board.Clear();
     moves.Clear();
     player1 = null;
     player2 = null;
     using (var channelFactory = new ChannelFactory <IBattleshipsService>("MyNetNamedPipeEndpoint"))
     {
         IBattleshipsService client = channelFactory.CreateChannel();
         GameReplay          gr     = client.GetGameReplay(gameId);
         if (gr == null)
         {
             return;
         }
         player1 = gr.Player1;
         player2 = gr.Player2;
         moves   = gr.Moves.OrderBy(m => m.Time).ToList();
     }
     updateButtons();
     Player1Button.MainText = $"Player {player1.Name} turn...";
     Player2Button.MainText = $"Player {player2.Name} turn...";
     Visibility             = Visibility.Visible;
 }