Exemplo n.º 1
0
        private bool EndTurn(GameLogEntry logEntry, int column, bool pause = true, bool drawBoard = true)
        {
            if (column == -1)
            {
                log.Winner = 0;

                return(false);
            }

            if (rules.IsValidMove(column, board))
            {
                board.DropChecker(column, PlayerTurn);

                logEntry.ColumnPlayed = column;
                log.Add(logEntry);

                var winningGroups = rules.PlayerWins(PlayerTurn, board);
                if (winningGroups.Any())
                {
                    log.Winner = PlayerTurn;

                    return(false);
                }
            }
            else
            {
                return(true);
            }


            PlayerTurn = PlayerTurn == 1 ? 2 : 1;
            return(true);
        }
Exemplo n.º 2
0
        public void Update(Match m)
        {
            _gameLog.Add($"Match updated to : {m.Player1.Name}({m.Player1.ID}) v {m.Player2.Name}({m.Player2.ID}) : {m.Player1Wins}-{m.Player2Wins}-{m.Draws}", $"{m.Event}", m);

            _context.ExecuteQuery <dbMatch>($"UPDATE [Matches] SET [Player1Wins]={m.Player1Wins}, [Player2Wins]={m.Player2Wins}, [Draws]={m.Draws} WHERE [Player1ID]='{m.Player1.ID}' AND [Player2ID]='{m.Player2.ID}' AND [Event]='{m.Event}' AND [Round]={m.Round}");
            _context.ExecuteQuery <dbMatch>($"UPDATE [Matches] SET [Player2Wins]={m.Player1Wins}, [Player1Wins]={m.Player2Wins}, [Draws]={m.Draws} WHERE [Player2ID]='{m.Player1.ID}' AND [Player1ID]='{m.Player2.ID}' AND [Event]='{m.Event}' AND [Round]={m.Round}");
        }
Exemplo n.º 3
0
        private bool EndTurn(GameLogEntry logEntry, int column, bool pause = true, bool drawBoard = true)
        {
            if (column == -1)
            {
                if (drawBoard)
                {
                    DrawBoard();
                    Console.WriteLine();
                    Console.WriteLine();
                    Console.BackgroundColor = ConsoleColor.Green;
                    Console.WriteLine($"Draw!");
                }

                log.Winner = 0;
                if (pause)
                {
                    Console.ReadLine();
                }

                return(false);
            }

            if (rules.IsValidMove(column, board))
            {
                board.DropChecker(column, PlayerTurn);

                logEntry.ColumnPlayed = column;
                log.Add(logEntry);

                var winningGroups = rules.PlayerWins(PlayerTurn, board);
                if (winningGroups.Any())
                {
                    if (drawBoard)
                    {
                        DrawBoard();
                        Console.WriteLine();
                        Console.WriteLine();
                        // Console.BackgroundColor = PlayerTurn == 1 ? ConsoleColor.Blue : ConsoleColor.Red;
                        Console.WriteLine($"Player {PlayerTurn} wins!");
                    }
                    log.Winner = PlayerTurn;
                    if (pause)
                    {
                        Console.ReadLine();
                    }

                    return(false);
                }
                else
                {
                    DrawBoard();
                }
            }
            else
            {
                if (drawBoard)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine($"Invalid move. Press any key");
                }

                if (pause)
                {
                    Console.ReadLine();
                }

                return(true);
            }


            PlayerTurn = PlayerTurn == 1 ? 2 : 1;
            return(true);
        }