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())); }
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()); }
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); }
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); }
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); } }
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); }
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); } }
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); }
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); }
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()); }
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()); }
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); }
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()); }
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()); }
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()); }
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 }); }
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"); }
public void GIVEN_new_game_THEN_game_is_not_over() { var game = new TTTGame(); Assert.IsFalse(game.isOver()); }
async Task Handle(TTTGame game, SocketGuildUser user, (int x, int y) coords)
public void GIVEN_new_game_THEN_can_place_a_cross() { var game = new TTTGame(); game.placeCross(1, 1); }
public void GIVEN_new_game_THEN_can_place_a_circle() { var game = new TTTGame(); game.placeCircle(1, 1); }