לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 18-05-2008, 18:36
  משתמש זכר Morishani Morishani אינו מחובר  
 
חבר מתאריך: 04.06.03
הודעות: 340
עשיתי משחק איקס-עיגול בC# ורוצה טיפים לייעול.

אני חדש לשפה הזאת, ואקבל כל טיפּ לגבי התכנון של המשחק, המימוש וכו' בשמחה.
אם כך, זה הקוד :
קוד:
using System; public class ticTacToeClass { private int[,] gameMatrix; public ticTacToeClass() { gameMatrix = new int[3,3]; int i, j; for (i = 0; i < gameMatrix.GetLength(0); i++) for (j = 0; j < gameMatrix.GetLength(1); j++) gameMatrix[i, j] = 0; } public int whoWins() { Boolean rowWin; Boolean columnWin; Boolean primaryDiagonal = (gameMatrix[0,0] != 0); Boolean secondaryDiagonal = (gameMatrix[0,gameMatrix.GetLength(1)-1] != 0); int i, j; for (i = 0; i < gameMatrix.GetLength(0); i++) { rowWin = (gameMatrix[i,0] != 0); columnWin = (gameMatrix[0,i] != 0); if (gameMatrix[0, 0] != gameMatrix[i, i]) primaryDiagonal = false; if (gameMatrix[0, gameMatrix.GetLength(1) - 1] != gameMatrix[i, gameMatrix.GetLength(1) - 1 - i]) secondaryDiagonal = false; for (j = 1; j < gameMatrix.GetLength(1); j++) { if (gameMatrix[i, 0] != gameMatrix[i, j]) rowWin = false; if (gameMatrix[0, i] != gameMatrix[j, i]) columnWin = false; } if (rowWin) return gameMatrix[i, 0]; if (columnWin) return gameMatrix[0, i]; } if (primaryDiagonal) return gameMatrix[0, 0]; else if (secondaryDiagonal) return gameMatrix[0, gameMatrix.GetLength(1) - 1]; if (NumEmptyPlaces() == 0) return 3; return 0; } public Boolean write(int row, int column, int player) { if (row >= gameMatrix.GetLength(0) || column >= gameMatrix.GetLength(1)) return false; if (gameMatrix[row, column] == 0) { gameMatrix[row, column] = player; return true; } return false; } public void randomWrite(int player) { int[,] randomOptions = new int[NumEmptyPlaces(), 2]; int count = 0, i, j; int currentOption; Random randomMachine = new Random(); for (i = 0; i < gameMatrix.GetLength(0); i++) for (j = 0; j < gameMatrix.GetLength(1); j++) if (gameMatrix[i, j] == 0) { randomOptions[count, 0] = i; randomOptions[count, 1] = j; count++; } currentOption = randomMachine.Next(0, count - 1); write(randomOptions[currentOption, 0], randomOptions[currentOption, 1], player); } private int NumEmptyPlaces() { int i, j, count = 0; for (i = 0; i < gameMatrix.GetLength(0); i++) for (j = 0; j < gameMatrix.GetLength(1); j++) if (gameMatrix[i, j] == 0) count++; return count; } public void drawGame() { Console.Clear(); Char[] chars = new Char[3]; int i, j; chars[0] = ' '; chars[1] = 'X'; chars[2] = 'O'; for (i = 0; i < gameMatrix.GetLength(0); i++) { Console.Write("{0}", chars[gameMatrix[i, 0]]); for (j = 1; j < gameMatrix.GetLength(1); j++) Console.Write("|{0}", chars[gameMatrix[i, j]]); Console.WriteLine(); for (j = 0; j < gameMatrix.GetLength(0) * 2 - 1; j++) Console.Write("-"); Console.WriteLine(); } } } public class myProject { private static string szSeperator = "------------"; public static int Main(string[] args) { ConsoleKeyInfo mainCh; Console.Clear(); Console.SetWindowSize(40, 15); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Tic Tac Toe"); Console.WriteLine(myProject.szSeperator); Console.WriteLine("1. Start a new game"); Console.WriteLine("2. Exit"); do { mainCh = Console.ReadKey(); } while (mainCh.KeyChar != '1' && mainCh.KeyChar != '2'); if (mainCh.KeyChar == '1') game(); return 0; } public static void game() { ConsoleKeyInfo myChar; int row,column; Console.Clear(); ticTacToeClass ticTacToe = new ticTacToeClass(); ticTacToe.drawGame(); while (ticTacToe.whoWins() == 0) { do { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine("Enter Row,Column (Char After Char) => "); myChar = Console.ReadKey(); row = int.Parse(myChar.KeyChar.ToString()) - 1; myChar = Console.ReadKey(); column = int.Parse(myChar.KeyChar.ToString()) - 1; } while (!ticTacToe.write(row,column,1)); ticTacToe.drawGame(); if (ticTacToe.whoWins() != 0) break; ticTacToe.randomWrite(2); ticTacToe.drawGame(); } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine("Player {0} Is The Winner!", ticTacToe.whoWins()); Console.WriteLine("Press Any Key To Continue."); Console.ReadKey(); Main(new string[0]); } }


והEXE נמצא כאן :
http://skrap.nar.co.il/TicTacToe.exe


דבר אחד שלא הצלחתי לעשות, הוא שבקבלת מס' השורה והעמודה מהלקוח - זה בדיקת תקינות פלט - האם מדובר בתו שהוא ספרה.

תודה אנשים
_____________________________________
הגלריה שלי בפליקר

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 19:32

הדף נוצר ב 0.04 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר