Exemplo n.º 1
0
        public static void Main2(string[] args)
        {
            // Setting up the game.
            TTTGame curGame = new TTTGame();

            Console.WriteLine("This is a new TTT game");

            while (!curGame.IsGameFinished())
            {
                // Ask for index to place player sign.
                Console.WriteLine("its " + curGame.GetCurrentPlayer() + " turn, please type position: ");
                int.TryParse(Console.ReadLine(), out int x);
                int.TryParse(Console.ReadLine(), out int y);

                // try to place the sign and respond if not available.
                if (!curGame.TryToPlacePiece(x, y))
                {
                    Console.WriteLine("that position is marked / unavailable, please try again.");
                }

                // Print the current game table.
                Console.WriteLine(curGame.GetCurrentTable());
            }

            // Output according to result
            Console.WriteLine(GetWinnerString(curGame.GetWinner()));
        }
Exemplo n.º 2
0
        public async Task <RuntimeResult> Game(int rows = 3, SocketGuildUser other = null)
        {
            if (Service.Games.Any(x => x.Contains(Context.User)))
            {
                return(Error("You are already playing a game."));
            }
            if (Context.Guild.VoiceChannels.Count(x => x.Name.StartsWith("ttt-")) != (rows * rows))
            {
                var existing = Service.Games.Any(x => x.Message.Channel.Id == Context.Channel.Id);
                if (existing)
                {
                    return(Error($"There is already a game occuring in this channel."));
                }
                await ReplyAsync("As VCs have not been setup, you must use text messages to indicate where you wish to go. Eg, `A1` as top left");
            }
            var game = new TTTGame(Context.Guild, rows);
            var msg  = await ReplyAsync(embed : game.ToEmbed());

            game.Message = msg;
            var _    = Task.Run(game.AddReactions);
            var role = Context.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName);
            var self = Context.User as SocketGuildUser;
            await self.AddRoleAsync(role);

            if (other != null)
            {
                await other.AddRoleAsync(role);
            }
            Service.Games.Add(game);
            return(Success());
        }
Exemplo n.º 3
0
        public void GIVEN_new_game_WHEN_last_move_placed_cross_THEN_can_not_place_a_cross()
        {
            var game = new TTTGame();

            game.placeCross(1, 1);
            game.placeCross(1, 2);
        }
Exemplo n.º 4
0
        public void GIVEN_new_game_WHEN_cell_occupied_THEN_can_not_make_move_in_that_cell()
        {
            var game = new TTTGame();

            game.placeCross(1, 1);
            game.placeCircle(1, 1);
        }
Exemplo n.º 5
0
 private async Task Client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3)
 {
     if (!(arg1 is SocketGuildUser user))
     {
         return;
     }
     if (TTTGame.IsTTTVoice(arg2.VoiceChannel) || TTTGame.IsTTTVoice(arg3.VoiceChannel))
     {
         return;
     }
     if (user.IsBot)
     {
         return;
     }
     if (arg3.VoiceChannel == null)
     {
         await UserLeftVc(user, arg2);
     }
     else if (arg2.VoiceChannel == null)
     {
         await UserJoinedVc(user, arg3);
     }
     else if (arg2.VoiceChannel.Id != arg3.VoiceChannel.Id)
     {
         await UserMovedVc(user, arg2, arg3);
     }
 }
Exemplo n.º 6
0
        async Task Handle(TTTGame game, SocketGuildUser user, SocketVoiceChannel before, SocketVoiceChannel gameVc)
        {
            var position = int.Parse(gameVc.Name.Split('-')[1]);
            var coords   = game.GetCoords(position);

            await Handle(game, user, coords);
        }
Exemplo n.º 7
0
        private async Task Client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3)
        {
            if (arg1.IsBot || !(arg1 is SocketGuildUser user))
            {
                return;
            }
            if (!(TTTGame.IsTTTVoice(arg2.VoiceChannel) || TTTGame.IsTTTVoice(arg3.VoiceChannel)))
            {
                return;
            }
            if (!TTTGame.IsTTTVoice(arg3.VoiceChannel))
            {
                return; // left the channel.
            }
            var game = Games.FirstOrDefault(x => x.Contains(arg1));

            if (game == null)
            {
                game = Games.FirstOrDefault(x => x.In(arg3.VoiceChannel.Guild));
            }
            try
            {
                await Handle(game, user, arg2.VoiceChannel, arg3.VoiceChannel);
            } catch (Exception ex)
            {
                Program.LogMsg("VCTTT", ex);
            } finally
            {
                await user.ModifyAsync(x => x.Channel = arg2.VoiceChannel);
            }
        }
Exemplo n.º 8
0
        public void GIVEN_new_game_WHEN_place_a_cross_THEN_can_place_a_circle_in_a_different_cell()
        {
            var game = new TTTGame();

            game.placeCross(1, 1);
            game.placeCircle(1, 2);
        }
        private void RunTTTGame()
        {
            tttModel     = new TTTGameModel(mainMenuModel);
            tttView      = new TTTGame();
            tttPresenter = new TTTGamePresenter(tttModel, tttView);

            Application.Run(tttView);
        }
Exemplo n.º 10
0
        async Task resendMessage(TTTGame game)
        {
            var channel = game.Message.Channel;
            var newMsg  = await channel.SendMessageAsync(embed : game.ToEmbed());

            await game.Message.DeleteAndTrackAsync("resending game message");

            game.Message = newMsg;
            var _ = Task.Run(game.AddReactions);
        }
Exemplo n.º 11
0
        public void GIVEN_new_game_WHEN_three_crosses_in_left_column_THEN_cross_wins()
        {
            var game = new TTTGame();

            game.placeCross(0, 0);
            game.placeCircle(2, 1);
            game.placeCross(1, 0);
            game.placeCircle(2, 2);
            game.placeCross(2, 0);
            Assert.AreEqual(2, game.winner());
        }
Exemplo n.º 12
0
        public void GIVEN_new_game_WHEN_three_crosses_in_diagonal_from_top_right_THEN_cross_wins()
        {
            var game = new TTTGame();

            game.placeCross(0, 2);
            game.placeCircle(1, 0);
            game.placeCross(1, 1);
            game.placeCircle(2, 1);
            game.placeCross(2, 0);
            Assert.AreEqual(2, game.winner());
        }
Exemplo n.º 13
0
        public void GIVEN_game_is_over_WHEN_place_a_move_THEN_exception_is_thrown()
        {
            var game = new TTTGame();

            game.placeCross(0, 0);
            game.placeCircle(1, 0);
            game.placeCross(0, 1);
            game.placeCircle(1, 1);
            game.placeCross(0, 2);
            game.placeCircle(1, 2);
        }
Exemplo n.º 14
0
        public void GIVEN_new_game_WHEN_three_circles_in_top_row_THEN_circle_wins()
        {
            var game = new TTTGame();

            game.placeCircle(0, 0);
            game.placeCross(1, 0);
            game.placeCircle(0, 1);
            game.placeCross(1, 1);
            game.placeCircle(0, 2);

            Assert.AreEqual(1, game.winner());
        }
Exemplo n.º 15
0
        public void GIVEN_game_has_a_winner_circle_THEN_game_is_over()
        {
            var game = new TTTGame();

            game.placeCircle(0, 0);
            game.placeCross(1, 0);
            game.placeCircle(0, 1);
            game.placeCross(1, 1);
            game.placeCircle(0, 2);

            Assert.IsTrue(game.isOver());
        }
Exemplo n.º 16
0
        public void GIVEN_game_with_all_cells_occupied_WHEN_no_three_in_a_line_THEN_game_is_a_draw()
        {
            var game = new TTTGame();

            game.placeCircle(2, 2);
            game.placeCross(0, 0);
            game.placeCircle(0, 1);
            game.placeCross(0, 2);
            game.placeCircle(1, 0);
            game.placeCross(1, 1);
            game.placeCircle(1, 2);
            game.placeCross(2, 1);
            game.placeCircle(2, 0);

            Assert.AreEqual(3, game.winner());
        }
Exemplo n.º 17
0
        async Task Client_UserVoiceStateUpdated(Discord.WebSocket.SocketUser arg1, Discord.WebSocket.SocketVoiceState arg2, Discord.WebSocket.SocketVoiceState arg3)
        {
            if (arg1.IsBot)
            {
                return;
            }
            if (TTTGame.IsTTTVoice(arg2.VoiceChannel) || TTTGame.IsTTTVoice(arg3.VoiceChannel))
            {
                return;
            }
            var thread = new Thread(handle);

            thread.Start(new passing()
            {
                arg1 = arg1,
                arg2 = arg2,
                arg3 = arg3
            });
        }
Exemplo n.º 18
0
        async Task newPlayerTryJoin(SocketGuildUser user, TTTGame game)
        {
            if (game.GetPlayer(user) != Position.Empty)
            {
                return;
            }
            if (game.Crosses == null)
            {
                game.Crosses = user;
            }
            else
            {
                game.Naughts = user;
            }
            await game.Message.ModifyAsync(x => x.Embed = game.ToEmbed());

            var role = game.Guild.Roles.FirstOrDefault(x => x.Name == TTTService.RoleName);
            await user.AddRoleAsync(role);

            await game.Message.Channel.SendMessageAsync($"{user.Mention} has joined as {game.GetPlayer(user)}s");
        }
Exemplo n.º 19
0
        public void GIVEN_new_game_THEN_game_is_not_over()
        {
            var game = new TTTGame();

            Assert.IsFalse(game.isOver());
        }
Exemplo n.º 20
0
 async Task Handle(TTTGame game, SocketGuildUser user, (int x, int y) coords)
Exemplo n.º 21
0
        public void GIVEN_new_game_THEN_can_place_a_cross()
        {
            var game = new TTTGame();

            game.placeCross(1, 1);
        }
Exemplo n.º 22
0
        public void GIVEN_new_game_THEN_can_place_a_circle()
        {
            var game = new TTTGame();

            game.placeCircle(1, 1);
        }