C# 连接四个控制台

C# 连接四个控制台,c#,console,connect,C#,Console,Connect,C#连接四个控制台应用程序 我目前正在为一个学校作业编写一个连接4游戏作为控制台应用程序 我的老师目前没有做数据库管理,我们的代课老师也帮不了什么忙 由于我对编程非常陌生,我不知道如何编写一个函数,将一张“光盘”从第一行、第二行、第三行等放入阵列,直到它到达底部并停止 我知道零点(光盘)沿阵列向下移动时的延迟“thread.sleep()”,我希望能够将其集成到函数中。 说到电脑,我是个十足的傻瓜,而且我还没有被教够去完成这项任务。这是最后的办法。有人能在27小时内帮我吗?谢谢 我目前在我的主要

C#连接四个控制台应用程序

我目前正在为一个学校作业编写一个连接4游戏作为控制台应用程序

我的老师目前没有做数据库管理,我们的代课老师也帮不了什么忙

由于我对编程非常陌生,我不知道如何编写一个函数,将一张“光盘”从第一行、第二行、第三行等放入阵列,直到它到达底部并停止

我知道零点(光盘)沿阵列向下移动时的延迟“thread.sleep()”,我希望能够将其集成到函数中。

说到电脑,我是个十足的傻瓜,而且我还没有被教够去完成这项任务。这是最后的办法。有人能在27小时内帮我吗?谢谢

我目前在我的主要功能中有以下代码:

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading; // Allows for the delay object

    namespace ConnectFour
    {
        class Program
        {
            static void Main(string[] args)
            {
                introduction();
                int[,] slotBoard = new int[7, 7]; // Initialises array
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("\n\n\t\t\t\t 1 2 3 4 5 6 7\n");
                Console.ForegroundColor = ConsoleColor.White;
                string tabbing = "\t\t\t\t ";
                for (int i = 0; i < 7; i++)
                {
                    Console.Write(tabbing);
                    for (int n = 0; n < 7; n++)
                    {
                        Console.Write(slotBoard[i, n]); // Displays array
                        Console.Write(" ");
                    }
                    Console.WriteLine();
                }
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("\n\n\t\t   Where would you like to place your disc? ");
                Console.ForegroundColor = ConsoleColor.White;
                insertDisc();
                Console.ReadLine();
            }
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading;//允许延迟对象
名称空间连接四
{
班级计划
{
静态void Main(字符串[]参数)
{
导言();
int[,]slotBoard=new int[7,7];//初始化数组
Console.ForegroundColor=ConsoleColor.Yellow;
Console.WriteLine(“\n\n\t\t\t\t 1 2 3 4 5 6 7\n”);
Console.ForegroundColor=ConsoleColor.White;
字符串选项卡=“\t\t\t\t”;
对于(int i=0;i<7;i++)
{
控制台。写入(制表符);
对于(int n=0;n<7;n++)
{
Write(slotBoard[i,n]);//显示数组
控制台。写(“”);
}
Console.WriteLine();
}
Console.ForegroundColor=ConsoleColor.Cyan;
控制台。写入(“\n\n\t\t您想将光盘放在哪里?”);
Console.ForegroundColor=ConsoleColor.White;
插入盘();
Console.ReadLine();
}

事实上,它变得相当复杂。因为它是Connect 4,所以您可以更轻松地添加每行的棋子数量,但您还必须跟踪现场的棋子是哪一队。我能为您做的最好的事情是为您提供如何放置棋子的想法

你必须做的事情

1) 跟踪团队(您可能需要为团队制作另一个阵列)

2) 计算赢家(这将是一件痛苦的事)

3) 使用睡眠制作动画(提供了一个示例)

下面的代码向您演示了如何放下碎片。您应该能够将我的混乱缩短为几行代码,并添加所需的附加功能

        int[,] slotBoard = new int[7,7]; 
        Console.SetCursorPosition(0, 0);
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("\n\n\t\t\t\t 1 2 3 4 5 6 7\n");
        Console.ForegroundColor = ConsoleColor.White;
        string tabbing = "\t\t\t\t ";
        for (int r = 0; r < 7; r++)
        {
            System.Threading.Thread.Sleep(100);
            Console.Write(tabbing);
            for (int c = 0; c < 7; c++)
            {
                Console.Write(0);
                Console.Write(" ");
            }
            Console.WriteLine();
        }
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.Write("\n\n\t\t   Where would you like to place your disc? ");
        Console.ForegroundColor = ConsoleColor.White;
        again:
        switch (Console.ReadKey(true).KeyChar.ToString())
        {
            case "1":
                Console.Write("1");
                if (slotBoard[0, 0] < 7) slotBoard[0, 0]++;
                Console.SetCursorPosition(33, 11 - slotBoard[0, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "2":
                Console.Write("2");
                if (slotBoard[1, 0] < 7) slotBoard[1, 0]++;
                Console.SetCursorPosition(35, 11 - slotBoard[1, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "3":
                Console.Write("3");
                 if (slotBoard[2, 0] < 7) slotBoard[2, 0]++;
                Console.SetCursorPosition(37, 11 - slotBoard[2, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "4":
                Console.Write("4");
                 if (slotBoard[3, 0] < 7) slotBoard[3, 0]++;
                Console.SetCursorPosition(39, 11 - slotBoard[3, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "5":
                Console.Write("5");
                if (slotBoard[4, 0] < 7) slotBoard[4, 0]++;
                Console.SetCursorPosition(41, 11 - slotBoard[4, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "6":
                Console.Write("6");
                if (slotBoard[5, 0] < 7) slotBoard[5, 0]++;
                Console.SetCursorPosition(43, 11 - slotBoard[5, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            case "7":
                Console.Write("7");
                if (slotBoard[6, 0] < 7) slotBoard[6, 0]++;
                Console.SetCursorPosition(45, 11 - slotBoard[6, 0]);
                Console.Write("1");
                Console.SetCursorPosition(60, 13);
                goto again;
            default:
                goto again;
        }
int[,]slotBoard=新的int[7,7];
Console.SetCursorPosition(0,0);
Console.ForegroundColor=ConsoleColor.Yellow;
Console.WriteLine(“\n\n\t\t\t\t 1 2 3 4 5 6 7\n”);
Console.ForegroundColor=ConsoleColor.White;
字符串选项卡=“\t\t\t\t”;
对于(int r=0;r<7;r++)
{
系统线程线程睡眠(100);
控制台。写入(制表符);
对于(int c=0;c<7;c++)
{
控制台写入(0);
控制台。写(“”);
}
Console.WriteLine();
}
Console.ForegroundColor=ConsoleColor.Cyan;
控制台。写入(“\n\n\t\t您想将光盘放在哪里?”);
Console.ForegroundColor=ConsoleColor.White;
再一次:
开关(Console.ReadKey(true.KeyChar.ToString())
{
案例“1”:
控制台。写入(“1”);
如果(槽板[0,0]<7)槽板[0,0]++;
控制台。设置光标位置(33,11-槽板[0,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“2”:
控制台。写入(“2”);
如果(插板[1,0]<7)插板[1,0]++;
控制台。设置光标位置(35,11-槽板[1,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“3”:
控制台。写入(“3”);
如果(插板[2,0]<7)插板[2,0]++;
控制台。设置光标位置(37,11-槽板[2,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“4”:
控制台。写入(“4”);
如果(槽板[3,0]<7)槽板[3,0]++;
控制台。设置光标位置(39,11-槽板[3,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“5”:
控制台。写入(“5”);
如果(槽板[4,0]<7)槽板[4,0]++;
控制台。设置光标位置(41,11-槽板[4,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“6”:
控制台。写入(“6”);
如果(槽板[5,0]<7)槽板[5,0]++;
控制台。设置光标位置(43,11-槽板[5,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
案例“7”:
控制台。写入(“7”);
if(槽板[6,0]<7)槽板[6,0]++;
控制台。设置光标位置(45,11-槽板[6,0]);
控制台。写入(“1”);
控制台。设置光标位置(60,13);
再次转到;
违约:
再次转到;
}

如果我是你,我会将
//显示数组
放入