仅使用 Windows 窗体应用程序的 C# 游戏

本文关键字:游戏 应用程序 窗体 Windows | 更新日期: 2023-09-27 18:32:29

我想开发一个棋盘游戏。我可以仅使用 Windows 窗体应用程序创建它吗?我不想使用 XNA .如果可以使用Windows表单应用程序创建,如何将其转换为可执行文件。我不想将其作为控制台应用程序运行。我想把它创建为一个游戏。

/*
It is a board game.
        15   14    13    12     11    10    9
        16   28    29    30     31    32    8
        17   27    42    43     44    33    7
        18   26    41    48     45    34    6  
        19   25    40    47     46    35    5
        20   24    39    38     37    36    4
        21   22    23     0      1     2    3
 It is my board structure . Player one starts at square 0 . If he puts one , he will   
 get into the game . Then he can move his coin up to 23.He can get into 24 , if he 
 already cut the other player coins . Cut in the sense , player 0 places his coin on a 
 square that contains another player coins.Then he can move his coin from 24 to 48 .    
 when the coin reaches 48 , it will be completed . If player 0 completes his 6 coins 
 first , he will be the winner .   
*/
namespace ConsoleApplication1
{
class Program
{
    public static int playerCount;
    public static int totalSquares = 49;
    public static int totalCoins = 6;
    public static bool errorFlag = false;
    public static bool flagrepeat = false;
    public static bool winner=false;
    static void Main()
    {
        if (ErrorTypes.errors==null)
        {
            ErrorTypes.addMessage();
        }
        getPlayers(); // To get the number of players
        startGame();// It will get the name of the player and 
        // will thorw exception if anything goes wrong and will
        // call the main function again.
    }  
/*
* If a coin reaches center square , then it completes
* A player wins if he completes all the six coins
*/
    public static void setWinner(player[] obj) 
    {
        for (int k = 0; k < Program.playerCount; k++)
        {
            if (obj[k].completedcoins == 6)
            {
                Console.WriteLine("Winner is player " + (k + 1));
                winner = true;
                break;
            }
        }
    }
    public static void play(player[] obj)
    {
        bool rollrepeat; // If a player puts one or five or six , he will get another          chance.
        board boards = new board(); // It contains 49 squares
        List<int> rollstore = new List<int>(10); // To store the rolls of a single  player. 
    // Eg is [6,5,6,2] . Coz no repeat for 2. so his turn ends . Now he has to move the   coin by selecting coin and //rollindex.
        List<int> temprollstore = new List<int>(10);
        int roll;
        bool final = false;
        int i = 0;
        Random rn = new Random(); // To generate roll
        bool flag = false, tempflag = false;
        int[] pos;
        while (true)
        {
            if (!gameover())
            {
                setWinner(obj);
                if (final == false)
                {
                    i = 0;
                    while (i < Program.playerCount)
                    {
    /*
    * to reset the flags so that another player can use it
    */
                        if (flag == true || flagrepeat == true)
                        {
                            flagrepeat = false;
                            flag = false;
                        }
    /*
    * 
    */
                        while (true)
                        {                  
            // This part of the does the job of storing the rolls and call the move   function
    // when the roll ends
          }        
                    }
                    print(obj);
                    Console.WriteLine("'n'nPress a Key To Go Next Round ");
                    Console.ReadKey();
                }
                else
                {
                    break;
                }
            }
        }
    }

请建议我一种创建棋盘并将硬币放在正方形上的方法。

仅使用 Windows 窗体应用程序的 C# 游戏

Windows Form Application您可以通过选择

文件-新建项目-Visual C# 或 Visual Basic - Windows 窗体应用程序

在那里,您可以根据需要开发游戏。

默认情况下,Visual Studio 在[Project's path]'Bin'Debug[Project's path]'Bin'Release中创建项目的输出文件,具体取决于你遵守的生成配置。这可以从项目的属性中更改。

在这些文件夹中,放置了.exe文件以及它需要正确执行的其他文件、资源或 dll。

从那里,您可以通过双击运行.exe,而无需Visual Studio。

你可以从这里了解更多关于Visual Studio输出文件的信息

希望这有帮助

是的,你可以。只需选择"文件-新建项目-Visual C#"或"Visual Basic-Forms Application"。

然后,当您完成编码时,只需编译为发布(在Visual Studio的顶部栏上选择发布,其调试为默认并编译),您的.exe文件将位于(项目文件夹)/bin/release中。

拿起这个文件,你现在不需要Visual Studio来运行。