Need help understanding C# assignment

Hello all, got a question on coding Homework. The assignment is to finish the missing pieces of a Tic Tac Toe program. Parts of the code are given to us already done, but since I am still new to concepts like classes/properties I am having trouble getting started. There's the Main program, and then 3 classes it refers to, the Player Class, the GameManager class and the Board Class. The areas with comments are where I need to fill in my code, I am thinking what I need to do first is use the create player method in GameManager class.

Here is the code given below;

///code for main////////////

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace TicTacToe

{

class Program { static void Main(string[] args) { GameManager mgr = new GameManager(); mgr.PlayGame(); } } 

}

////Code for Player class////////////////////////////

class Player

{ public string Name; public string Mark; public int Number; } 

/////Code for GameManager

class/////////////////////////////////////////////////////////////////////////////////////////////

public class GameManager

{ private bool _gameOver; private Player _player1; private Player _player2; private Player _currentPlayer; private Board _board; public void PlayGame() { // just keep on setting up boards and playing the game until they indicate // that they'd like to quit the program Console.WriteLine("Welcome to Tic Tac Toe "); Console.ReadLine(); } private void ProcessTurns() { while (!_gameOver) { NextPlayer(); _board.Display(); PromptUser(); _gameOver = _board.IsVictory(_currentPlayer) || _board.IsCatGame(); } } private void PromptUser() { // get user input } private void SetUp() { // set up the game } private void NextPlayer() { if (_currentPlayer == null || _currentPlayer.Number == 2) {// start of game _currentPlayer = _player1; } else { _currentPlayer = _player2; } } private Player CreatePlayer(int number, string mark) { // prompt and create a player return null; } } 

////Code for Board class///////////////////////////////////////////////

class Board

{ private string[] _boardArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; private int _turnsCounter = 0; public bool AddMark(string mark, int position) { if (_boardArray[position-1] == position.ToString()) { _boardArray[position-1] = mark; _turnsCounter += 1; return true; } Console.WriteLine("That position is filled!"); return false; } public void Display() { Console.Clear(); Console.WriteLine(" {0} | {1} | {2}", _boardArray[0], _boardArray[1], _boardArray[2]); Console.WriteLine("---------------"); Console.WriteLine(" {0} | {1} | {2}", _boardArray[3], _boardArray[4], _boardArray[5]); Console.WriteLine("---------------"); Console.WriteLine(" {0} | {1} | {2}\n\n", _boardArray[6], _boardArray[7], _boardArray[8]); } public bool IsVictory(Player currentPlayer) { bool victory = IsHorizontalWin(currentPlayer.Mark) || IsVerticalWin(currentPlayer.Mark) || IsDiagonalWin(currentPlayer.Mark); if (victory == true) { Display(); Console.WriteLine("{0} wins!", currentPlayer.Name); } return victory; } private bool IsHorizontalWin(string mark) { return (_boardArray[0] == mark && _boardArray[1] == mark && _boardArray[2] == mark) || (_boardArray[3] == mark && _boardArray[4] == mark && _boardArray[5] == mark) || (_boardArray[6] == mark && _boardArray[7] == mark && _boardArray[8] == mark); } private bool IsVerticalWin(string mark) { return (_boardArray[0] == mark && _boardArray[3] == mark && _boardArray[6] == mark) || (_boardArray[1] == mark && _boardArray[4] == mark && _boardArray[7] == mark) || (_boardArray[2] == mark && _boardArray[5] == mark && _boardArray[8] == mark); } private bool IsDiagonalWin(string mark) { return (_boardArray[0] == mark && _boardArray[4] == mark && _boardArray[8] == mark) || (_boardArray[2] == mark && _boardArray[4] == mark && _boardArray[6] == mark); } public bool IsCatGame() { Display(); Console.WriteLine("It's a tie!"); return _turnsCounter == 9; } } 

by kickz87 via /r/csharp

Leave a Reply