2010-05-26 83 views
10

因此,我開始了C#程序員。我知道基本的語法和簡單的東西,如if語句和循環(方法和類也)。我只使用控制檯應用程序,現在還沒有打擾Windows窗體。C# - Noob的控制檯程序構想

所以任何簡單的應用程序的想法,介紹新的重要的C#編程的東西。

另外,沒有教程。我想一個人做。

+0

http://stackoverflow.com/questions/tagged/code-golf – 2010-05-26 23:47:49

+0

如果你不想要教程,閱讀一本書或ECMA。 http://www.ecma-international.org/publications/standards/Ecma-334.htm – Luiscencio 2010-05-26 23:47:52

回答

6

我是Halo的忠實粉絲,我在C#上做的第一件事就是編寫一個應用程序,在播放Halo 2時下載並解析我的在線遊戲狀態。從那裏,我將所有信息加載到一個數據庫並在ASP.NET中重新顯示它。回想起來,代碼是可怕的,但這是一個有趣的練習。

另一項運動是解析XML文件,我的iTunes音樂庫,將其加載到數據庫中,並在ASP.NET中它(當然)顯示位。

總之,想方設法與你喜歡的東西的工作,無論是遊戲,音樂,電視,或什麼的。

4

一個簡單的遊戲可能是一個好的開始,但這些代碼高爾夫球問題可能會更先進一些。

爲什麼不試着寫一個'測試你的反應'遊戲,在哪裏輸出一個字母和時間需要多長時間才能鎖定該字母?然後顯示所需的響應時間和迄今爲止的最佳響應時間。

+0

是的,我可以做一個打字遊戲。這時候你的速度和準確性.. 此外,我想花一點時間上只是C#之前,我移動到C#+ XNA框架 – user377419 2010-05-27 00:01:22

+1

XNA?我建議你先嚐試SlimDX,以獲得3D圖形的一般感受。你不能直接進入視頻遊戲開發[這是XNA真正的優勢= /] – Warty 2010-05-27 04:01:44

0

寫一些遞歸的東西,就像計算階乘值的例程一樣。

+0

大多數應用程序不需要遞歸編程。 – 2015-04-13 08:50:46

+1

@WalterA:這值得讚賞嗎?遞歸是一種公認​​的編程技巧,你的建議是noob不應該學習它?你也應該減少Sudoku求解器的答案,因爲絕大多數應用程序與Sudoku無關。而且,在這裏,你正在壓縮五年前的答案? – Cyberherbalist 2015-04-13 16:11:42

+0

好吧,我解開了downvote – 2015-04-13 17:48:00

3

一旦我不得不通過編寫hangman遊戲來學習針對linux的bash腳本,它應該是c#中控制檯應用的一個很好的例子。

提示:

開始與

while(true) 
{ 
//Game code goes here, use "continue" or "break" according to game logic. 
} 
1

一個有趣的方式來發展你的技能是通過code katas和編程競賽像Top CoderGoogle Code Jam。有很多示例問題會讓你思考,許多解決方案可以在完成後與之比較。

即使你已經有一段時間的開發者,這些簡單的問題也允許你將新的實踐融入你的編程風格中(例如,kata是開始學習TDD原理的好方法)。此外,他們爲樂趣分心。

1

我覺得解決Top-Coder問題將是很好的做法!它特別適合,因爲他們所有的問題都是基於控制檯的,並且它們會讓你不僅增加你對C#的知識,而且增加你的解決問題的能力和你的數據結構/算法知識。這就是說,你可能不會學習太多有關C#的新特性或更多平臺特定的東西,例如linq,事件處理程序,線程,並行任務庫等等。爲此,最好的辦法是找到一個好的C#預訂並通過它。

另一種方式可能是製作小遊戲。我知道它的控制檯,但實際上你可以製作像蛇,吃豆人,hang子手等遊戲,當然還有一點額外的想象力,但它仍然有效,遊戲是很棒的學習練習(對人們來說很有趣)

0

我最近開發了一個數獨解算器和一個8Queens求解。

我做在控制檯中的數獨解算器,其中拼圖本身的項目是硬編碼。您可以嘗試使用文本文件作爲輸入。我實施了一個蠻力算法,與遞歸一起工作。開發這種解算器是很好的,一旦你準備好了,可能會有很多改進。

8Queens求解器瞭解了我兩件事。首先,我必須製作一個棋盤,這是我用表格做的。學習了筆,畫筆和繪畫。此外,它是遞歸一個很好的做法,你必須做很多你瞭解它之前...

0

我建議寫一個命令行工具,做一些事情,也許不能用別的來完成。

一兩件事,彈簧想到的東西,應用XSL樣式表到XML文件,並吐出輸出。到處都有示例代碼,但沒有我見過的簡單Windows工具。這種方法的

潛在的好處是,你最終有一個有用的工具,那麼你必須使它開源,以獲得額外的輸入/支持的選項。

0

那麼,他們都很難做到,所以我建議使用複製粘貼的方法與我的酒杯的應用程序
記得引用添加系統的語音合成器

using System; 
using System.Speech.Synthesis; 

namespace Blackjack 
{ 
    class Blackjack 
    { 
     static string[] playerCards = new string[11]; 
     static string hitOrStay = ""; 
     static int total = 0, count = 1, dealerTotal = 0; 
     static Random cardRandomizer = new Random();  

     static void Main(string[] args) 
     { 
      using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer()) 
      { 
       Console.Title = "Blackjack"; 
       synth.Speak("Please enter your blackjack table's name followed by a comma then the secondary name (AKA table number)"); 
       string bjtn = Console.ReadLine(); 
       Console.Clear(); 
       Console.Title = bjtn; 
      }    
      Start(); 
     }  

     static void Start() 
     { 
      dealerTotal = cardRandomizer.Next(15, 22); 
      playerCards[0] = Deal(); 
      playerCards[1] = Deal(); 

      do 
      { 
       Console.WriteLine("Welcome to Blackjack! You were dealed " + playerCards[0] + " and " + playerCards[1] + ". \nYour total is " + total + ".\nWould you like to hit or stay? h for hit s for stay."); 
       hitOrStay = Console.ReadLine().ToLower(); 
      } 
      while (!hitOrStay.Equals("h") && !hitOrStay.Equals("s")); 

      Game(); 
     } 

     static void Game() 
     { 
      if (hitOrStay.Equals("h")) 
      { 
       Hit(); 
      } 
      else if (hitOrStay.Equals("s")) 
      { 
       if (total > dealerTotal && total <= 21) 
       { 
        Console.WriteLine("\nCongrats! You won the game! The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n"); 
        PlayAgain(); 
       } 
       else if (total < dealerTotal) 
       { 
        Console.WriteLine("\nSorry, you lost! The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n"); 
        PlayAgain(); 
       } 
      } 
      Console.ReadLine(); 
     } 

     static string Deal() 
     { 
      string Card = ""; 
      int cards = cardRandomizer.Next(1, 14); 

      switch (cards) 
      { 
       case 1: Card = "Two"; total += 2; 
        break; 
       case 2: Card = "Three"; total += 3; 
        break; 
       case 3: Card = "Four"; total += 4; 
        break; 
       case 4: Card = "Five"; total += 5; 
        break; 
       case 5: Card = "Six"; total += 6; 
        break; 
       case 6: Card = "Seven"; total += 7; 
        break; 
       case 7: Card = "Eight"; total += 8; 
        break; 
       case 8: Card = "Nine"; total += 9; 
        break; 
       case 9: Card = "Ten"; total += 10; 
        break; 
       case 10: Card = "Jack"; total += 10; 
        break; 
       case 11: Card = "Queen"; total += 10; 
        break; 
       case 12: Card = "King"; total += 10; 
        break; 
       case 13: Card = "Ace"; total += 11; 
        break; 
       default: Card = "2"; total += 2; 
        break; 
      } 
      return Card; 
     } 

     static void Hit() 
     { 
      count += 1; 
      playerCards[count] = Deal(); 
      Console.WriteLine("\nYou were dealed a(n) " + playerCards[count] + ".\nYour new total is " + total + "."); 

      if (total.Equals(21)) 
      { 
       Console.WriteLine("\nYou got Blackjack! The dealer's total was " + dealerTotal + ".\nWould you like to play again?"); 
       PlayAgain(); 
      } 
      else if (total > 21) 
      { 
       Console.WriteLine("\nYou busted, therefore you lost. Sorry. The dealer's total was " + dealerTotal + ".\nWould you like to play again? y/n"); 
       PlayAgain(); 
      } 
      else if (total < 21) 
      { 
       do 
       { 
        Console.WriteLine("\nWould you like to hit or stay? h for hit s for stay"); 
        hitOrStay = Console.ReadLine().ToLower(); 
       } 
       while (!hitOrStay.Equals("h") && !hitOrStay.Equals("s")); 

       Game(); 
      } 
     }  

     static void PlayAgain() 
     { 
      string playAgain = ""; 

      do 
      { 
       playAgain = Console.ReadLine().ToLower(); 
      } 
      while (!playAgain.Equals("y") && !playAgain.Equals("n")); 

      if (playAgain.Equals("y")) 
      { 
       Console.WriteLine("\nPress enter to restart the game!"); 
       Console.ReadLine(); 
       Console.Clear(); 
       dealerTotal = 0; 
       count = 1; 
       total = 0; 

       Start(); 
      } 
      else if (playAgain.Equals("n")) 
      { 
       using (SpeechSynthesizer synth = new System.Speech.Synthesis.SpeechSynthesizer()) 
       { 
        synth.Speak("\nPress enter to close Black jack." + dealerTotal); 
       } 

       ConsoleKeyInfo info = Console.ReadKey(); 
       if (info.Key == ConsoleKey.Enter) 
       { 
        Environment.Exit(0); 
       } 
       else 
       {      
        Console.Read(); 
        Environment.Exit(0); 
       } 
      } 
     } 
    } 
} 
+4

複製 - 編程是程序設計中的最大障礙! – Robik 2011-05-09 16:59:37

+2

似乎OP是專門要求非教程的,因此絕對不是複製/粘貼的想法 - 「我想自己做所有事情。」 – colllin 2012-12-09 05:54:35