TicTacToe.cs

Discussion in 'Spam Forum' started by Noam, Jan 21, 2013.

TicTacToe.cs
  1. Unread #1 - Jan 21, 2013 at 5:43 PM
  2. Noam
    Joined:
    Jul 27, 2011
    Posts:
    2,993
    Referrals:
    1
    Sythe Gold:
    0
    Discord Unique ID:
    688859853535313930
    Discord Username:
    sarbaz#8969
    Two Factor Authentication User Gohan has AIDS

    Noam Apostle of the Setting Sun
    $50 USD Donor New Competition Winner

    TicTacToe.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication8
    {
    class Program
    {
    static void Main (string[] args)
    {
    Console.WriteLine ("--- Tic Tac Toe ---");
    Console.Write ("Enter Board Size: ");
    int boardSize = int.Parse (Console.ReadLine ());
    int[,] board = new int[boardSize + 1, boardSize + 1];
    int rows, header, columns, turns = 0, maxTurns = boardSize * boardSize;
    Console.WriteLine ();
    for (turns = 0; turns < maxTurns; turns++) {
    Console.Clear ();
    if (boardSize > 1 && boardSize < 20) {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Write (" ");
    for (header = 1; header <= boardSize; header++) {

    Console.Write ("{0,-4}", header);
    }
    Console.WriteLine ();
    Console.WriteLine ();
    for (rows = 1; rows <= boardSize; rows++) {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.Write ("{0,-4}", rows);
    Console.ForegroundColor = ConsoleColor.White;
    for (columns = 1; columns <= boardSize; columns++) {
    if (board[rows - 1, columns - 1] == 0) {
    Console.Write ("? ");
    }
    if (board[rows - 1, columns - 1] == 1) {
    Console.ForegroundColor = ConsoleColor.Green;
    Console.Write ("X ");
    Console.ForegroundColor = ConsoleColor.White;
    }
    if (board[rows - 1, columns - 1] == 2) {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.Write ("O ");
    Console.ForegroundColor = ConsoleColor.White;
    }
    Console.ForegroundColor = ConsoleColor.White;
    }
    Console.WriteLine ();
    Console.WriteLine ();
    }
    } else {
    Console.WriteLine ("We Can't Make That Board");
    break;

    }
    int inputRow = -1, inputColumn = -1;
    if (turns % 2 == 0) {
    Console.WriteLine ("X's Turn");
    } else {
    Console.WriteLine ("O's Turn");
    }
    Console.WriteLine ("Type the row and column of the tile you want to select");
    while (1 == 1) {
    inputRow = -1;
    inputColumn = -1;
    while (inputRow < 0 || inputRow >= boardSize) {
    Console.Write ("Enter Row: ");
    inputRow = int.Parse (Console.ReadLine ()) - 1;
    }
    while (inputColumn < 0 || inputColumn >= boardSize) {
    Console.Write ("Enter Column: ");
    inputColumn = int.Parse (Console.ReadLine ()) - 1;
    }
    Console.WriteLine ();
    if (board[inputRow, inputColumn] == 0) {
    board[inputRow, inputColumn] = (turns % 2) + 1;
    break;
    } else {
    Console.WriteLine ("That space is taken");
    }
    }

    for (columns = 1; columns < boardSize; columns++) {
    if (board[inputRow, 0] != board[inputRow, columns]) {
    break;
    }
    }
    if (rows == boardSize) {
    if (turns % 2 == 0) {
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine ("Win for X - Row");
    } else {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine ("Win for O - Row");
    }
    Console.ForegroundColor = ConsoleColor.White;
    break;
    }
    for (rows = 1; rows < boardSize; rows++) {
    if (board[0, inputColumn] != board[rows, inputColumn]) {
    break;
    }
    }
    if (rows == boardSize) {
    if (turns % 2 == 0) {
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine ("Win for X - Column");
    } else {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine ("Win for O - Column");
    }
    Console.ForegroundColor = ConsoleColor.White;
    break;
    }
    if (inputColumn == inputRow) {
    for (rows = 1; rows <= boardSize; rows++) {
    if (board[0, 0] != board[rows, rows]) {
    break;
    }
    }
    if (rows == boardSize) {
    if (turns % 2 == 0) {
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine ("Win for X - Main Diagonal");
    } else {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine ("Win for O - Main Diagonal");
    }
    Console.ForegroundColor = ConsoleColor.White;
    break;
    }
    }
    if (inputColumn + inputRow + 2 == board.GetLength (1)) {
    for (rows = 1; rows < board.GetLength (1); rows++) {
    if (board[0, board.GetLength (1) - 2] != board[rows - 1, board.GetLength (1) - rows - 1]) {
    break;
    }
    }
    if (rows == board.GetLength (1)) {
    if (turns % 2 == 0) {
    Console.ForegroundColor = ConsoleColor.Green;
    Console.WriteLine ("Win for X - Secondary Diagonal");
    } else {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine ("Win for O - Secondary Diagonal");
    }
    Console.ForegroundColor = ConsoleColor.White;
    break;
    }
    }
    }

    if (turns == maxTurns) {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine ("Tie");
    Console.ForegroundColor = ConsoleColor.White;
    }

    }
    }
    }
     
  3. Unread #2 - Jan 21, 2013 at 5:44 PM
  4. Fendle
    Joined:
    Mar 16, 2011
    Posts:
    3,345
    Referrals:
    0
    Sythe Gold:
    0

    Fendle Grand Master
    Banned

    TicTacToe.cs

    This post gave me cancer.
     
< | Public Service Announcement >

Users viewing this thread
1 guest


 
 
Adblock breaks this site