コード例 #1
0
ファイル: Program.cs プロジェクト: MyLastAngel/TikTakToe
        public static void Main()
        {
            var isUser = false;

            // о первый ходит
            Console.Write("Who start? 1 - user/2 - computer (default - computer): ");
            var key = Console.ReadLine();
            var v   = 0;

            if (int.TryParse(key, out v) && v == 1)
            {
                isUser = true;
            }

            // иницализация поля для игры
            for (var i = 0; i < 9; i++)
            {
                box[i] = new BoxCell(i);
            }

            while (true)
            {
                if (isUser)
                {
                    Console.Write("User move: ");
                    key = Console.ReadLine().ToUpper();

                    var index = GetIndex(key);
                    if (index == -1)
                    {
                        Console.WriteLine("Move out of range..");
                        continue;
                    }

                    if (box[index].State.HasValue)
                    {
                        var who = box[index].State.Value ? "User" : "Computer";
                        Console.WriteLine($"Already set: '{who}'");
                        continue;
                    }

                    box[index].State = true;
                }
                else
                {
                    // Ходим компьютером
                    ComputerMove();
                }

                if (End())
                {
                    break;
                }

                isUser = !isUser;
            }

            Console.WriteLine("Press any key");
            Console.ReadKey();
        }
コード例 #2
0
	bool CanDropHere(BlockGroup group, BoxCell cell){
		foreach (var position in group.positions) {
			BoxCell boxCell = ( grid.GetCell (cell.coord + position) as BoxCell );

			if (boxCell == null || boxCell.HasColor)
				return false;
		}
		return true;
	}