Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Jogo_de_Damas
- {
- class Program
- {
- static string Cvr(int x) // Função para converssão dos números do vetor em peças e espaços.
- {
- string y = "";
- if (x == 1)
- y = "( )";
- if (x == 3)
- y = "(##)";
- if (x == 0)
- y = " ";
- return y;
- }
- static bool Permitido(string x) // Verifica se o caractere inserido pelo jogador é permitido
- {
- switch (x)
- {
- case "a1":
- case "A1":
- case "a2":
- case "A2":
- case "a3":
- case "A3":
- case "a4":
- case "A4":
- case "a5":
- case "A5":
- case "a6":
- case "A6":
- case "a7":
- case "A7":
- case "A8":
- case "a8":
- case "b1":
- case "B1":
- case "b2":
- case "B2":
- case "b3":
- case "B3":
- case "b4":
- case "B4":
- case "b5":
- case "B5":
- case "b6":
- case "B6":
- case "b7":
- case "B7":
- case "b8":
- case "B8":
- case "c1":
- case "C1":
- case "c2":
- case "C2":
- case "c3":
- case "C3":
- case "c4":
- case "C4":
- case "c5":
- case "C5":
- case "c6":
- case "C6":
- case "c7":
- case "C7":
- case "c8":
- case "C8":
- case "d1":
- case "D1":
- case "d2":
- case "D2":
- case "d3":
- case "D3":
- case "d4":
- case "D4":
- case "d5":
- case "D5":
- case "d6":
- case "D6":
- case "d7":
- case "D7":
- case "D8":
- case "d8":
- case "e1":
- case "E1":
- case "e2":
- case "E2":
- case "e3":
- case "E3":
- case "e4":
- case "E4":
- case "e5":
- case "E5":
- case "e6":
- case "E6":
- case "e7":
- case "E7":
- case "E8":
- case "e8":
- case "f1":
- case "F1":
- case "f2":
- case "F2":
- case "f3":
- case "F3":
- case "f4":
- case "F4":
- case "f5":
- case "F5":
- case "f6":
- case "F6":
- case "f7":
- case "F7":
- case "f8":
- case "F8":
- case "g1":
- case "G1":
- case "g2":
- case "G2":
- case "g3":
- case "G3":
- case "g4":
- case "G4":
- case "g5":
- case "G5":
- case "g6":
- case "G6":
- case "g7":
- case "G7":
- case "g8":
- case "G8":
- case "h1":
- case "H1":
- case "h2":
- case "H2":
- case "h3":
- case "H3":
- case "h4":
- case "H4":
- case "h5":
- case "H5":
- case "h6":
- case "H6":
- case "h7":
- case "H7":
- case "H8":
- case "h8":
- return true;
- default:
- return false;
- }
- }
- static string ConversorCoordenada(string x) // Converte a número, para ser usado no sistema da matriz
- {
- string y = "";
- if (x[0] == 'a' || x[0] == 'A')
- {
- y = "1" + x[1];
- }
- if (x[0] == 'b' || x[0] == 'B')
- {
- y = "2" + x[1];
- }
- if (x[0] == 'c' || x[0] == 'C')
- {
- y = "3" + x[1];
- }
- if (x[0] == 'd' || x[0] == 'D')
- {
- y = "4" + x[1];
- }
- if (x[0] == 'e' || x[0] == 'E')
- {
- y = "5" + x[1];
- }
- if (x[0] == 'f' || x[0] == 'F')
- {
- y = "6" + x[1];
- }
- if (x[0] == 'g' || x[0] == 'G')
- {
- y = "7" + x[1];
- }
- if (x[0] == 'h' || x[0] == 'H')
- {
- y = "8" + x[1];
- }
- return y;
- }
- static void Main(string[] args)
- {
- int fim_de_jogo = 0; // Variável que determina o fim do jogo
- int[,] tab = new int[10, 10]; // Matriz para o tabuleiro e peças
- string escolha_peca = ""; // Variável que armazena a escolha de peça
- string movimentacao_peca = ""; // Variável que armazena o local que o jogador decide movimentá-la
- bool varredura = true; // Variável que dita se há a possibilidade de jogada em cadeia
- bool jogador1 = true;
- bool jogada = false;
- int x1 = 0, x2 = 0;
- int y1 = 0, y2 = 0;
- #region Posicionamento inicial das peças no Tabuleiro
- for (int i = 0; i < 10; i++)
- {
- tab[i, 0] = 99;
- tab[i, 9] = 99;
- tab[0, i] = 99;
- tab[9, i] = 99;
- }
- for (int l = 1; l <= 8; l++)
- {
- if (l <= 3 || l >= 6)
- {
- for (int c = 1; c <= 8; c++)
- {
- if (l % 2 == 0)
- {
- if (c % 2 == 1)
- {
- if (l <= 2)
- tab[l, c] = 1;
- if (l >= 5)
- tab[l, c] = 3;
- }
- }
- else
- {
- if (c % 2 == 0)
- {
- if (l <= 3)
- tab[l, c] = 1;
- if (l >= 6)
- tab[l, c] = 3;
- }
- }
- }
- }
- }
- #endregion
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- Console.Write(tab[i, j] + "\t");
- }
- Console.WriteLine();
- }
- while (fim_de_jogo == 0) // Estrutura de repetição para o jogo
- {
- # region Reperesentação Gráfica do Tabuleiro
- Console.WriteLine("\n A B C D E F G H\n");
- Console.WriteLine(" .------.------.------.------.------.------.------.------.");
- Console.WriteLine(" 1 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[1, 1]), Cvr(tab[1, 2]), Cvr(tab[1, 3]), Cvr(tab[1, 4]), Cvr(tab[1, 5]), Cvr(tab[1, 6]), Cvr(tab[1, 7]), Cvr(tab[1, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 2 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[2, 1]), Cvr(tab[2, 2]), Cvr(tab[2, 3]), Cvr(tab[2, 4]), Cvr(tab[2, 5]), Cvr(tab[2, 6]), Cvr(tab[2, 7]), Cvr(tab[2, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 3 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[3, 1]), Cvr(tab[3, 2]), Cvr(tab[3, 3]), Cvr(tab[3, 4]), Cvr(tab[3, 5]), Cvr(tab[3, 6]), Cvr(tab[3, 7]), Cvr(tab[3, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 4 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[4, 1]), Cvr(tab[4, 2]), Cvr(tab[4, 3]), Cvr(tab[4, 4]), Cvr(tab[4, 5]), Cvr(tab[4, 6]), Cvr(tab[4, 7]), Cvr(tab[4, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 5 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[5, 1]), Cvr(tab[5, 2]), Cvr(tab[5, 3]), Cvr(tab[5, 4]), Cvr(tab[5, 5]), Cvr(tab[5, 6]), Cvr(tab[5, 7]), Cvr(tab[5, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 6 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[6, 1]), Cvr(tab[6, 2]), Cvr(tab[6, 3]), Cvr(tab[6, 4]), Cvr(tab[6, 5]), Cvr(tab[6, 6]), Cvr(tab[6, 7]), Cvr(tab[6, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 7 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[7, 1]), Cvr(tab[7, 2]), Cvr(tab[7, 3]), Cvr(tab[7, 4]), Cvr(tab[7, 5]), Cvr(tab[7, 6]), Cvr(tab[7, 7]), Cvr(tab[7, 8]));
- Console.WriteLine(" |------|------|------|------|------|------|------|------|");
- Console.WriteLine(" 8 | {0} | {1} | {2} | {3} | {4} | {5} | {6} | {7} |", Cvr(tab[8, 1]), Cvr(tab[8, 2]), Cvr(tab[8, 3]), Cvr(tab[8, 4]), Cvr(tab[8, 5]), Cvr(tab[8, 6]), Cvr(tab[8, 7]), Cvr(tab[8, 8]));
- Console.WriteLine(" `------'------'------'------'------'------'------'------'\n\n");
- #endregion
- if (jogador1)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine("Turno do jogador 1.");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- else
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Turno do jogador 2.");
- Console.ForegroundColor = ConsoleColor.Gray;
- }
- Console.Write("Escolha uma peça para mover: ");
- escolha_peca = Console.ReadLine();
- if (Permitido(escolha_peca))
- {
- Console.Write("Decida a nova posição para a peça: ");
- movimentacao_peca = Console.ReadLine();
- if (Permitido(movimentacao_peca))
- {
- // Converssão das letras para numerais para serem usados nos índices da matriz
- escolha_peca = ConversorCoordenada(escolha_peca);
- movimentacao_peca = ConversorCoordenada(movimentacao_peca);
- // Condicional: Movimentação Jogador 1
- if (jogador1)
- {
- // Inverssão de posicionamento para o sistema de coordenada
- y1 = Convert.ToInt16(escolha_peca) / 10;
- x1 = Convert.ToInt16(escolha_peca) % 10;
- // Condicional: A primeira coordenada dita a localização duma peça do jogador 1?
- if (tab[x1, y1] == 1 || tab[x1, y1] == 11)
- {
- // Inverssão de posicionamento para o sistema de coordenada
- y2 = Convert.ToInt16(movimentacao_peca) / 10;
- x2 = Convert.ToInt16(movimentacao_peca) % 10;
- // Condicional: A segunda coordenada dita a localização de um espaço vazio?
- if (tab[x2, y2] == 0)
- {
- // Sequência de Condicionais para Determinar o Tipo de Movimentação
- // Movimentação Normal
- if ((x1 + y1 + 2) == (x2 + y2) && (tab[x1, y1] + tab[x2, y2]) == 1 || ((x1 + y1) == (x2 + y2) && (tab[x1, y1] + tab[x2, y2] == 1)))
- {
- tab[x1, y1] = 0;
- tab[x2, y2] = 1;
- jogador1 = false;
- }
- // Movimentação de ataque simples: Primeiro Quadrante
- if ((x1 + y1) == (x2 + y2) && (tab[x1 + 2, y1 - 2] + tab[x1 + 1, y1 - 1] + tab[x2, y2]) == 4)
- {
- tab[x1 + 1, y1 - 1] = 0;
- tab[x1, y1] = 0;
- tab[x2, y2] = 1;
- jogador1 = false;
- }
- // Movimentação de ataque simples: Segundo Quadrante
- if ((x1 + y1 - 4) == (x2 + y2) && (tab[x1, y1] + tab[x1 - 1, y1 - 1] + tab[x2, y2]) == 4)
- {
- tab[x1 - 1, y1 - 1] = 0;
- tab[x1, y1] = 0;
- tab[x2, y2] = 1;
- jogador1 = false;
- }
- // Movimentação de ataque simples: Terceiro Quadrante
- if ((x1 + y1) == (x2 + y2) && (tab[x1, y1] + tab[x1 + 1, y1 - 1] + tab[x2, y2]) == 4)
- {
- tab[x1 + 1, y1 - 1] = 0;
- tab[x1, y1] = 0;
- tab[x2, y2] = 1;
- jogador1 = false;
- }
- // Movimentação de ataque simples: Quarto Quadrante
- if ((x1 + y1 + 4) == (x2 + y2) && (tab[x1, y1] + tab[x1 + 1, y1 + 1] + tab[x2, y2]) == 4)
- {
- tab[x1 + 1, y1 + 1] = 0;
- tab[x1, y1] = 0;
- tab[x2, y2] = 1;
- jogador1 = false;
- }
- // Caso nenhuma condicional de movimentação seja atendida
- if (jogador1)
- Console.WriteLine("Movimentação inválida.");
- // Caso haja a possibilidade de uma jogada em cadeia
- while (varredura)
- {
- if (((x1 + y1) == (x2 + y2) && (tab[x1 + 2, y1 - 2] + tab[x1 + 1, y1 - 1] + tab[x2, y2]) == 4) || ((x1 + y1 - 4) == (x2 + y2) && (tab[x1, y1] + tab[x1 - 1, y1 - 1] + tab[x2, y2]) == 4)((x1 + y1) == (x2 + y2) && (tab[x1, y1] + tab[x1 + 1, y1 - 1] + tab[x2, y2]) == 4) || ((x1 + y1 + 4) == (x2 + y2) && (tab[x1, y1] + tab[x1 + 1, y1 + 1] + tab[x2, y2]) == 4))
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Movimentação em cadeia detectada. Continue a jogada.");
- Console.ForegroundColor = ConsoleColor.Gray;
- jogador1 = true;
- }
- else
- {
- varredura = false;
- }
- }
- }
- else
- {
- Console.WriteLine("Movimentação inválida.");
- }
- }
- else
- {
- Console.WriteLine("Movimentação inválida.");
- }
- }
- else
- {
- // Movimentaçaõ jogador 2
- y1 = Convert.ToInt16(escolha_peca) / 10;
- x1 = Convert.ToInt16(escolha_peca) % 10;
- if (tab[x1, y1] == 3 || tab[x1, y1] == 33)
- {
- y2 = Convert.ToInt16(movimentacao_peca) / 10;
- x2 = Convert.ToInt16(movimentacao_peca) % 10;
- if (tab[x2, y2] == 0)
- {
- // ---------------- Movimentação Jogador 2
- if ((x1 + y1 - 2) == (x2 + y2) && (tab[x1, y1] + tab[x2, y2]) == 3 || ((x1 + y1) == (x2 + y2) && (tab[x1, y1] + tab[x2, y2] == 3)))
- {
- tab[x1, y1] = 0;
- tab[x2, y2] = 3;
- jogador1 = true;
- }
- }
- else
- {
- Console.WriteLine("Movimentação inválida.");
- }
- }
- else
- {
- Console.WriteLine("Movimentação inválida.");
- }
- }
- }
- else
- {
- Console.WriteLine("Entrada inválida. Tente novamente.");
- jogada = false;
- }
- }
- else
- {
- Console.WriteLine("Entrada inválida. Tente novamente.");
- jogada = false;
- }
- if (jogada)
- {
- }
- Console.ReadKey();
- Console.Clear();
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement