Example #1
0
        public static void WithPlayer()
        {
            int possition;
            String Playername1, Playername2;
            Map map = new Map();

            Console.Write("\n\nPodaj imię pierwszego gracza (X): ");
            Playername1 = Console.ReadLine();

            Console.Write("\n\nPodaj imię drugiego gracza (O): ");
            Playername2 = Console.ReadLine();

            Players player1 = new Players('X', Playername1);
            Players player2 = new Players('O', Playername2);

            map.DrawMap();

            do
            {
                possition = player1.getField(player1);
                map.PutSign(possition, player1);
                map.DrawMap();
                if (map.CheckResultGame(player1) == true)
                {
                    break;
                }
                Console.Clear();
                map.DrawMap();
                possition = player2.getField(player2);
                map.PutSign(possition, player2);
                Console.Clear();
                map.DrawMap();
            } while (!(map.CheckResultGame(player2)));
        }
Example #2
0
        public bool CheckResultGame(Players player)
        {
            if((ArrayMap[0] == player.sign && ArrayMap[1] == player.sign && ArrayMap[2] == player.sign) ||
               (ArrayMap[0] == player.sign && ArrayMap[3] == player.sign && ArrayMap[6] == player.sign) ||
               (ArrayMap[0] == player.sign && ArrayMap[4] == player.sign && ArrayMap[8] == player.sign) ||
               (ArrayMap[1] == player.sign && ArrayMap[4] == player.sign && ArrayMap[7] == player.sign) ||
               (ArrayMap[2] == player.sign && ArrayMap[5] == player.sign && ArrayMap[8] == player.sign) ||
               (ArrayMap[2] == player.sign && ArrayMap[4] == player.sign && ArrayMap[6] == player.sign) ||
               (ArrayMap[3] == player.sign && ArrayMap[4] == player.sign && ArrayMap[5] == player.sign) ||
               (ArrayMap[6] == player.sign && ArrayMap[7] == player.sign && ArrayMap[8] == player.sign))
            {
                Console.Write("\n\nWYGRAŁ GRACZ O IMIENIU: {0} (znak {1})\n\n",player.name, player.sign);
                return true;
            }

            int counter = 0;

            for (int i = 0; i < ArrayMap.Length; i++)
            {

                if (ArrayMap[i] != ' ')
                {
                    counter++;
                }

                if(counter == 9)
                {
                    Console.Write("\n\nREMIS!\n\n");
                    return true;
                }
            }

            return false;
        }
Example #3
0
        public static void WithComputer()
        {
            int possition;
            String Playername1;
            Map map = new Map();

            Console.Write("\n\nPodaj imię pierwszego gracza (X): ");
            Playername1 = Console.ReadLine();

            Players player1 = new Players('X', Playername1);
            Players computer = new Players('O', "Komputer");

            map.DrawMap();

            do
            {
                possition = player1.getField(player1);
                map.PutSign(possition, player1);
                map.DrawMap();
                if (map.CheckResultGame(player1) == true)
                {
                    break;
                }
                Console.Clear();
                map.DrawMap();
                possition = computer.getComputersField();
                map.PutSign(possition, computer);
                Console.Clear();
                map.DrawMap();
            } while (!(map.CheckResultGame(computer)));
        }
Example #4
0
        public int getField(Players player)
        {
            do
            {
                Console.Write("\n\n{0} podaj numer pola, w którym chcesz wstawić {1}  : ",name, sign);

                String possitionString = Console.ReadLine();
                possition = int.Parse(possitionString);
                possition--;
            } while (possition < 0 || possition > 8 || Map.ArrayMap[possition] == 'X' || Map.ArrayMap[possition] == 'O');

            return possition;
        }
Example #5
0
 public void PutSign(int possition, Players player)
 {
     ArrayMap[possition] = player.sign;        // wpisuje znak do tablicy
 }