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;
- using System.Threading;
- namespace ConsoleApp5 {
- class Program {
- static char[] arr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
- static int player = 1;
- static int izbor;
- static int zastavica = 0;
- static void Main(string[] args) {
- Console.WriteLine("Unesite ime prvog igrača: ");
- string igr1 = Console.ReadLine();
- Console.WriteLine("Unesite ime drugog igrača: ");
- string igr2= Console.ReadLine();
- do {
- Console.Clear();
- Console.WriteLine("{0} igra sa:X \n {1} igra sa:O",igr1, igr2);
- Console.WriteLine("\n");
- if (player % 2 == 0)
- {
- Console.WriteLine("{0} Je na redu", igr2);
- } else {
- Console.WriteLine("{0} Je na redu",igr1);
- }
- Console.WriteLine("\n");
- Board();
- izbor = int.Parse(Console.ReadLine());
- if (arr[izbor] != 'X' && arr[izbor] != 'O') {
- if (player % 2 == 0)
- {
- arr[izbor] = 'O';
- player++;
- } else {
- arr[izbor] = 'X';
- player++;
- }
- } else
- {
- Console.WriteLine("Mjesto {0} je već označeno sa {1}",izbor, arr[izbor]);
- Console.WriteLine("\n");
- Console.WriteLine("Pričekajte ploča se učitava.");
- Thread.Sleep(2000);
- }
- zastavica = Provjera();
- } while (zastavica != 1 && zastavica != -1);
- Console.Clear();
- Board();
- if (zastavica == 1 && player%2==1)
- {
- Console.WriteLine("Pobjedio je: {0} ", igr2);
- }
- else if(zastavica==1 && player%2==0) {
- Console.WriteLine("Pobjedio je: {0} ", igr1);
- }
- else
- {
- Console.WriteLine("Izjednačeno");
- }
- Console.ReadLine();
- }
- private static void Board() {
- Console.WriteLine(" | | ");
- Console.WriteLine(" {0} | {1} | {2}", arr[1], arr[2], arr[3]);
- Console.WriteLine("_____|_____|_____ ");
- Console.WriteLine(" | | ");
- Console.WriteLine(" {0} | {1} | {2}", arr[4], arr[5], arr[6]);
- Console.WriteLine("_____|_____|_____ ");
- Console.WriteLine(" | | ");
- Console.WriteLine(" {0} | {1} | {2}", arr[7], arr[8], arr[9]);
- Console.WriteLine(" | | ");
- }
- private static int Provjera() {
- #region Horzontal Winning Condtion
- if (arr[1] == arr[2] && arr[2] == arr[3]) {
- return 1;
- }
- else if (arr[4] == arr[5] && arr[5] == arr[6]) {
- return 1;
- }
- else if (arr[6] == arr[7] && arr[7] == arr[8]) {
- return 1;
- }
- #endregion
- #region vertical Winning Condtion
- else if (arr[1] == arr[4] && arr[4] == arr[7]) {
- return 1;
- }
- else if (arr[2] == arr[5] && arr[5] == arr[8]) {
- return 1;
- }
- else if (arr[3] == arr[6] && arr[6] == arr[9]) {
- return 1;
- }
- #endregion
- #region Diagonal Winning Condition
- else if (arr[1] == arr[5] && arr[5] == arr[9]) {
- return 1;
- } else if (arr[3] == arr[5] && arr[5] == arr[7]) {
- return 1;
- }
- #endregion
- #region Checking For Draw
- else if (arr[1] != '1' && arr[2] != '2' && arr[3] != '3' && arr[4] != '4' && arr[5] != '5' && arr[6] != '6' && arr[7] != '7' && arr[8] != '8' && arr[9] != '9') {
- return -1;
- }
- #endregion
- else {
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement