static void Main(string[] args) { Grid grid = new Grid(); WinChecker winChecker = new WinChecker(); Renderer renderer = new Renderer(); Moves player1 = new Moves(); Moves player2 = new Moves(); int rowChecker = 0; // Var that tell the method which row it is supposed to check for an open space Console.WriteLine("Welcome to my wannabe Simplexity Game \n"); Console.WriteLine("Here are the rules:\n"); Console.WriteLine(" - Press from 1 to 7 to choose the column you want to put your piece on. \n"); Console.WriteLine(" - Player 1 goes first, and is the white pieces. \n"); Console.WriteLine(" - First one to score 4 in a line with either Lowercase or Uppercase Wins. \n "); Console.WriteLine("Ready to play? (Y/N)"); string answer = Console.ReadLine(); //String checks if the player wants to start the gameloop if (answer == "Y" || answer == "y") { bool first = true; //Var that checks if it's the first turn while (!winChecker.IsDraw(grid, rowChecker) && winChecker.Check(grid) == State.Undecided) { renderer.Render(grid, rowChecker); //Renders the grid every loop Position nextMove; //Recieves the input from the player and assigns it to this var. if (grid.NextTurn == Player.p1) { if (first != false) { //Console.WriteLine("Player 1, choose your piece. Cilinder or Cube?"); //answer = Console.ReadLine(); Console.WriteLine("Player 1, choose which column to put your piece on"); nextMove = player1.GetPosition(grid, rowChecker); first = false; if (!grid.SetState(nextMove, grid.NextTurn, grid.NextTurn2, rowChecker, first)) { } } else { //Console.WriteLine("Player 1, choose your piece. Cilinder or Cube?"); //answer = Console.ReadLine(); Console.WriteLine("Player 1, choose which column to put your piece on"); nextMove = player1.GetPosition(grid, rowChecker); } } else { //Console.WriteLine("Player 2, choose your piece. Cilinder or Cube?"); //answer = Console.ReadLine(); Console.WriteLine("Player 2, choose which column to put your piece on"); nextMove = player2.GetPosition(grid, rowChecker); } if (!grid.SetState(nextMove, grid.NextTurn, grid.NextTurn2, rowChecker)) { Console.WriteLine("That is not a valid move."); } } renderer.Render(grid, rowChecker); renderer.RenderResults(winChecker.Check(grid)); } Console.WriteLine("I'll see ya next time, goodbye!"); }
static void Main(string[] args) { // Misc string s1 = "Projeto de Linguagens de Programação 2017/2018"; string s2 = "André Pedro, André Santos e Tiago Alves"; string s3 = "Nuno Fachada"; string s4 = "Prima [ENTER] para começar..."; // Board / Layout / Player Board board = new Board(); Layout layout = new Layout(); Player white = new Player(); Player red = new Player(); State estado = new State(); //acrescentei isto, ver se funciona WinChecker winChecker = new WinChecker(); // Start Console.ForegroundColor = ConsoleColor.Gray; Console.Clear(); Console.WriteLine(); Console.WriteLine(s1.PadLeft(s1.Length + 0)); Console.WriteLine(); Console.WriteLine("Contribuidores: " + s2.PadLeft(s2.Length + 3)); Console.WriteLine("Docente: " + s3.PadLeft(s3.Length + 10)); Console.WriteLine(); Console.Write(s4.PadLeft(s4.Length + 0)); Console.ReadKey(); // Turnos while (winChecker.Check(board) == State.Undecided) { for (int turno = 0; turno <= 1000; turno++) { for (int vez = 0; vez <= 1; vez++) { Console.ForegroundColor = ConsoleColor.Gray; Console.Clear(); layout.Render(board); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" 1 2 3 4 5 6 7 "); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); // info jogador 1 Console.Write("Jogador 1 - "); Console.ForegroundColor = ConsoleColor.White; Console.Write("Branco"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); Console.WriteLine("Cubos Brancos: " + cubosBrancos); Console.WriteLine("Cilindros Brancos: " + cilindrosBrancos); Console.WriteLine(); // info jogador 2 Console.Write("Jogador 2 - "); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Vermelho"); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); Console.WriteLine("Cubos Vermelhos: " + cubosVermelhos); Console.WriteLine("Cilindros Vermelhos: " + cilindrosVermelhos); Console.WriteLine(); // info turnos Console.WriteLine("Turno: " + turno); Console.WriteLine(); // info vez do jogador 1 || 2 Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[?] "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Jogador "); if (vez == 0) { jogador = 1; Console.ForegroundColor = ConsoleColor.White; Console.Write("Branco"); Console.ForegroundColor = ConsoleColor.Gray; // play Position next; // pedir colunas next = white.ColumnPosition(board); // info vez do jogador 1 || 2 Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[?] "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Jogador "); Console.ForegroundColor = ConsoleColor.White; Console.Write("Branco"); Console.ForegroundColor = ConsoleColor.Gray; // pedir pecas estado = white.Escolhapecas(board, jogador); board.SetState(next, estado); // WinChecker.Wincheck(board, 1); } if (vez == 1) { jogador = 2; Console.ForegroundColor = ConsoleColor.Red; Console.Write("Vermelho"); Console.ForegroundColor = ConsoleColor.Gray; // play Position next; // pedir colunas next = red.ColumnPosition(board); // info vez do jogador 1 || 2 Console.ForegroundColor = ConsoleColor.Yellow; Console.Write("[?] "); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Jogador "); Console.ForegroundColor = ConsoleColor.Red; Console.Write("Vermelho"); Console.ForegroundColor = ConsoleColor.Gray; // pedir pecas estado = red.Escolhapecas(board, jogador); board.SetState(next, estado); // WinChecker.Wincheck(next, 1); } } if (cubosVermelhos == 0 && cubosBrancos == 0 && cilindrosVermelhos == 0 && cilindrosBrancos == 0) { Console.ForegroundColor = ConsoleColor.Gray; Console.Clear(); Console.WriteLine("Fim de jogo: Empate!"); Console.WriteLine(); Environment.Exit(0); } //introduzir aqui a verificação de vitoria } } Console.WriteLine("WIN"); }
static void Main(string[] args) { //Gera cores //inicialização das instâncias do jogo Board board = new Board(); //criar novo board WinChecker winChecker = new WinChecker(); //checar win or draw Renderer renderer = new Renderer(); // renderizar board Player player1 = new Player(1); // criar player 1 Player player2 = new Player(2); // criar player 2 Position NextMove = new Position(0, 0); //posição para jogada bool move = false; // flag para indicar se a jogada é válida ou não //enquanto NÃO for empate E enquanto NÃO houver vencedor definido, o ciclo continua while (winChecker.Check(board, player1, player2) == 0 && winChecker.IsDraw(board) == 0) { renderer.Render(board); //imprime, na linha de comandos, o tabuleiro atualizado if (board.NextTurn == 1) // caso o turno seja do jogador 1 { Console.WriteLine("Player 1"); //imprime o jogador Console.WriteLine("\nEnter one Column between 1 and 7"); //solicita a coluna a jogar do tabuleiro NextMove = player1.ColumnPlayed(board); // retorna uma posição válida para a jogada Console.WriteLine("\nRow :" + NextMove.Row + "|| Col :" + NextMove.Column + "\n"); // imprime linha e coluna da jogada Console.WriteLine("\nSelect the piece what you want" + " using num pad ( 1-> Square, 2->Circle )"); // solicita a peça a jogar player1.PiecePlayed(); // seleciona a peça do player e decrementa o contador de peças Console.WriteLine("\n"); // pula duas linhas move = board.SetBlockBoard(NextMove, player1.Piece_played); // adiciona a peça no tabuleiro e retorna a flage caso não seja uma jogada possível } else if (board.NextTurn == 2) // caso o turno seja do jogador 2 { Console.WriteLine("Player 2"); //imprime o jogador Console.WriteLine("\nEnter one Column between 1 and 7"); //solicita a coluna a jogar do tabuleiro NextMove = player2.ColumnPlayed(board); // retorna uma posição válida para a jogada Console.WriteLine("\nRow :" + NextMove.Row + "|| Col :" + NextMove.Column + "\n"); // imprime linha e coluna da jogada Console.WriteLine("\nSelect the piece what you want" + " using num pad ( 1-> Square, 2->Circle )"); // solicita a peça a jogar player2.PiecePlayed(); // seleciona a peça do player e decrementa o contador de peças Console.WriteLine("\n"); // pula duas linhas move = board.SetBlockBoard(NextMove, player2.Piece_played); // adiciona a peça no tabuleiro e retorna a flage caso não seja uma jogada possível } Console.Clear(); // limpa tela if (move == false) { Console.WriteLine("\nThat is not a legal move."); } } // após saír do ciclo, imprime o tabuleiro e os resultados do vencedor renderer.Render(board); // mostra o board final renderer.RenderResults(winChecker.Check(board, player1, player2)); // mostra o vencedor // solicita uma tecla para terminar o programa Console.ReadKey(); }
static void Main(string[] args) { Board board = new Board(); WinChecker winChecker = new WinChecker(); Renderer renderer = new Renderer(); Player player1 = new Player(); Player player2 = new Player(); int shape = (int)Shape.empty; bool shapeChoosen, columnChoosen; int turn = 1; // While the game is still going it loop while (!winChecker.IsDraw(board) && winChecker.Check(board) == State.Undecided) { // Reders the board renderer.Render(board, shape); // Creates a position Position nextMove; // If the turn is even if (turn % 2 != 0) { Console.WriteLine("Your turn, player 1"); shapeChoosen = false; // While the shape isnt choosen loop while (shapeChoosen != true) { Console.WriteLine("What shape do you want to play? (Square = 1 / Cylinder = 2)"); // Saves what the player typed ConsoleKeyInfo choice = Console.ReadKey(); // If the user types "1" if (choice.KeyChar == '1') { Console.WriteLine("\nYou choose Square."); shape = (int)Shape.square; shapeChoosen = true; break; } // If the user types "2" else if (choice.KeyChar == '2') { Console.WriteLine("\nYou choose Cylinder."); shape = (int)Shape.cylinder; shapeChoosen = true; break; } // If the user types anything but "1" or "2" else { Console.WriteLine("\nPlease choose a valid answer."); continue; } } columnChoosen = false; // While the player doesnt type anything loop while (columnChoosen != true) { Console.WriteLine("On which column do you want to place your shape? (1 - 7)"); nextMove = player1.GetPosition(board); columnChoosen = true; // If the grid space is occupied already if (!board.SetState(nextMove, board.NextTurn)) { Console.WriteLine("That is not a legal move."); columnChoosen = false; } } turn++; } // If the turn is odd else { Console.WriteLine("Your turn, player 2"); shapeChoosen = false; // While the shape isnt choosen loop while (shapeChoosen != true) { Console.WriteLine("What shape do you want to play? (Square = 1 / Cylinder = 2)"); // Saves what the player typed ConsoleKeyInfo choice = Console.ReadKey(); // If the user types "1" if (choice.KeyChar == '1') { Console.WriteLine("\nYou choose Square."); shape = (int)Shape.square; shapeChoosen = true; break; } // If the user types "2" else if (choice.KeyChar == '2') { Console.WriteLine("\nYou choose Cylinder."); shape = (int)Shape.cylinder; shapeChoosen = true; break; } // If the user types anything but "1" or "2" else { Console.WriteLine("\nPlease choose a valid answer."); continue; } } columnChoosen = false; // While the player doesnt type anything loop while (columnChoosen != true) { Console.WriteLine("On which column do you want to place your shape? (1 - 7)"); nextMove = player2.GetPosition(board); columnChoosen = true; // If the grid space is occupied already if (!board.SetState(nextMove, board.NextTurn)) { Console.WriteLine("That is not a legal move."); columnChoosen = false; } } turn++; } } renderer.Render(board, shape); renderer.RenderResults(winChecker.Check(board)); Console.ReadKey(); }