Exemplo n.º 1
0
        public static void LoadGame(Save save)
        {
            Console.WriteLine("Loading...");
            if (save.Replay)
            {
                Console.WriteLine("Loading Replay...");
                var ctx         = new AppDbContext();
                var replayquery = ctx.Saves.Where(s => s.SaveId == save.SaveId)
                                  .Include(s => s.Player1).Include(s => s.Player2).Include(s => s.Rules)
                                  .Include(s => s.States).ThenInclude(s => s.Player1GB).ThenInclude(g => g.Squares)
                                  .Include(s => s.States).ThenInclude(s => s.Player2GB).ThenInclude(g => g.Squares)
                                  .Include(s => s.States).ThenInclude(s => s.Player1Map).ThenInclude(g => g.Squares)
                                  .Include(s => s.States).ThenInclude(s => s.Player2Map).ThenInclude(g => g.Squares)
                                  .First();
                foreach (var state in replayquery.States)
                {
                    SaveSystem.GameStates.Add(state.GetDomainState(replayquery.Player1.GetDomainPlayer(state.Player1GB.GetDomainBoard(), state.Player1Map.GetDomainBoard()),
                                                                   replayquery.Player2.GetDomainPlayer(state.Player2GB.GetDomainBoard(), state.Player2Map.GetDomainBoard())
                                                                   , replayquery.Rules.CanTouch));
                }
            }
            Console.WriteLine("Loading Save...");
            Player player1 = new Domain.Player(save.Player1.Name,
                                               save.LastState.Player1GB.GetDomainBoard(),
                                               save.LastState.Player1Map.GetDomainBoard())
            {
                AI = save.Player1.AI
            };

            Player player2 = new Domain.Player(save.Player2.Name,
                                               save.LastState.Player2GB.GetDomainBoard(),
                                               save.LastState.Player2Map.GetDomainBoard())
            {
                AI = save.Player2.AI
            };

            Rules.CanTouch = save.Rules.CanTouch;
            bool p2Turn = save.LastState.P2Turn;

            PlayGame(player1, player2, p2Turn);
        }
Exemplo n.º 2
0
        public static void PlayReplay(Save save)//todo:replays times are wrong
        {
            var replay = new List <State>();

            for (int i = 0; i < save.States.Count; i++)
            {
                var   p1gb    = save.States[i].Player1GB.GetDomainBoard();
                var   p1map   = save.States[i].Player1Map.GetDomainBoard();
                var   player1 = save.Player1.GetDomainPlayer(p1gb, p1map);
                var   player2 = save.Player2.GetDomainPlayer(save.States[i].Player2GB.GetDomainBoard(), save.States[i].Player2Map.GetDomainBoard());
                State state   = save.States[i].GetDomainState(player1, player2, save.Rules.CanTouch);
                state.time = save.States[i].TimeStamp;
                replay.Add(state);
            }

            var rePlayer = new Player("Replay", replay[0].P1.Board, replay[0].P1.Board);
            int index    = 0;

            while (true)
            {
                if (index < 0)
                {
                    index = 0;
                }

                if (index > replay.Count - 1)
                {
                    break;
                }

                var state = replay[index];
                rePlayer.Name = state.time.ToString();
                Draw(rePlayer, state.P1 + new string(' ', state.P1.Board.Board[0].Count * 4 + 3 - state.P1.Name.Length) + "\n" + GetBoardString(state.P1.Board), state.P2 + "\n" + GetBoardString(state.P2.Board));
                Console.WriteLine("---------------------------------------------" +
                                  "\nX - Back, <- Play Backward, Play Forward -> ");
                switch (Console.ReadKey(true).Key)
                {
                case ConsoleKey.X:
                    index = replay.Count;
                    break;

                case ConsoleKey.Enter:
                    continue;

                case ConsoleKey.RightArrow:
                    index++;
                    continue;

                case ConsoleKey.LeftArrow:
                    index--;
                    continue;
                }
            }
//            for (int i = 0; i < replay.Count; i++)
//            {
//                var state = replay[i];
//                rePlayer.Name = state.time.ToString();
//                Draw(rePlayer,state.P1 + new string(' ', state.P1.Board.Board[0].Count * 4 +3 - state.P1.Name.Length) +"\n" + GetBoardString(state.P1.Board),state.P2 + "\n" + GetBoardString(state.P2.Board));
//                switch (Console.ReadKey(true).Key)
//                {
//                    case ConsoleKey.Enter:
//                        break;
//                }
//            }
        }