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 ConsoleApplication1
- {
- class Program
- {
- public static int rozmiar = 3;
- public static int[,] tab = new int[rozmiar, rozmiar];
- public static void CheckWin(int deployment)
- {
- int suma = 0;
- for (int i = 0; i < rozmiar; i++)
- {
- suma = 0;
- for (int j = 0; j < rozmiar; j++)
- suma += tab[i, j];
- }
- if (suma == 3 * deployment)
- {
- Console.WriteLine("Wygrana!"); // 1 opcja
- }
- for (int j = 0; j < rozmiar; j++)
- {
- suma = 0;
- for (int i = 0; i < rozmiar; i++)
- suma += tab[i, j];
- }
- if (suma == 3 * deployment)
- {
- Console.WriteLine("Wygrana!"); // 2 opcja
- }
- suma = 0;
- suma = tab[0, 0] + tab[1, 1] + tab[2, 2];
- if (suma == 3 * deployment)
- {
- Console.WriteLine("Wygrana!"); //3 opcja
- }
- suma = 0;
- suma = tab[2, 0] + tab[1, 1] + tab[0, 2];
- if (suma == 3 * deployment)
- {
- Console.WriteLine("Wygrana!"); //4 opcja
- }
- }
- static void DrawMatrix()
- {
- for (int i = 0; i < 3; i++)
- {
- tab[i, i] = 0;
- for (int j = 0; j < 3; j++)
- {
- tab[j, j] = 0;
- }
- }
- for (int i = 0; i < rozmiar; i++)
- {
- for (int j = 0; j < rozmiar; j++)
- {
- Console.Write(tab[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static void ShowMatrix()
- {
- Console.Clear();
- for (int i = 0; i < rozmiar; i++)
- {
- for (int j = 0; j < rozmiar; j++)
- {
- Console.Write(tab[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- while (true)
- {
- DrawMatrix();
- for (int x = 9; x > 0; x--)
- {
- if (x % 2 == 0)
- {
- try
- {
- Console.WriteLine("Gracz 1 : znak ,,1'' ");
- Console.WriteLine("Wpisz Wiersz ");
- int wiersz = int.Parse(Console.ReadLine());
- Console.WriteLine("Wpisz kolumne: ");
- int kolumna = int.Parse(Console.ReadLine());
- if (wiersz < 0 || wiersz > 2 && kolumna < 0 || kolumna > 2)
- {
- throw new Exception();
- }
- for (int i = 0; i < rozmiar; i++)
- {
- for (int j = 0; j < rozmiar; j++)
- {
- tab[wiersz, kolumna] = 1;
- }
- }
- ShowMatrix();
- CheckWin(1);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- else
- {
- Console.WriteLine("Gracz 2: znak ,, -1 ''");
- Console.WriteLine("Wpisz Wiersz ");
- try
- {
- int wiersz = int.Parse(Console.ReadLine());
- Console.WriteLine("Wpisz kolumne: ");
- int kolumna = int.Parse(Console.ReadLine());
- if (wiersz < 0 || wiersz > 2)
- {
- throw new Exception();
- }
- if (kolumna < 0 || kolumna > 2)
- {
- throw new Exception();
- }
- for (int i = 0; i < rozmiar; i++)
- {
- for (int j = 0; j < rozmiar; j++)
- {
- tab[wiersz, kolumna] = -1;
- }
- }
- ShowMatrix();
- CheckWin(-1);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- }
- Console.ReadKey();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement