Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to write a program that creates a wild tic tac toe game from an extensible framework. I made a base of the
I am trying to write a program that creates a wild tic tac toe game from an extensible framework. I made a base of the program with some glitches for what I can not get the expected output.
I need to
i cater the game for another modehuman vs human as my current code is only about human vs computer mode.
ii Games can be played from start to finish, and should be able to be saved and restored from any state of play ie save file A game should be replayable from any position after being loaded from a save file.
iii. During a game, all moves made by both players should be undoable and redoable ie the full history of moves are tracked But the history of the moves does not have to be saved into a save file. That is immediately after loading the saved state from a file, undo and redo operations are not available until new moves have been made.
iv I tried to include a primitive help system which id accessible within the running game, rather than a separate offline help document to assist users with the available commands. I do not know to actually use it
Please suggest how to apply the above specific criteria in my following code including some help to erase my bug which is sometimes the console takes the random number very well, other time it becomes an indefinite loop. Please suggest.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace TwoPlayerBoardGames
public class TicTacToe : IBoardGame
private int board new int;
private Random rand new Random;
public void Initialize
for int i ; i ; i
boardi;
public void DisplayBoard
for int i ; i ; i
if boardi
Console.Write;
else if boardi
Console.WriteX;
else if boardi
Console.WriteO;
if i i i
Console.WriteLine;
public void Play
int userTurn ;
int computerTurn ;
Human player's turn
while userTurn boarduserTurn
Console.WriteLinePlease enter a number from to ;
userTurn int.ParseConsoleReadLine;
Console.WriteLineYou typed: userTurn;
boarduserTurn;
Computer player's turn
while computerTurn boardcomputerTurn
computerTurn rand.Next;
Console.WriteLineComputer chooses: computerTurn;
boardcomputerTurn;
public bool IsGameOver
Implement game over logic
Return true if the game is over, false otherwise
Example: check for a winner or if the board is full
return false;
public void SaveGamestring filename
using FileStream fileStream new FileStreamfilename FileMode.Create
BinaryFormatter formatter new BinaryFormatter;
formatter.SerializefileStream board;
Console.WriteLineGame saved successfully";
public void LoadGamestring filename
try
using FileStream fileStream new FileStreamfilename FileMode.Open
BinaryFormatter formatter new BinaryFormatter;
int loadedBoard intformatterDeserializefileStream;
Array.CopyloadedBoard board, ;
Console.WriteLineGame loaded successfully";
catch Exception ex
Console.WriteLine$"Error loading game: exMessage;
public void DisplayHelp
Console.WriteLineAvailable commands:";
Console.WriteLineundo: Undo the last move";
Console.WriteLinesavefilename: Save the current game state to a file";
Console.WriteLineloadfilename: Load a saved game state from a file";
Console.WriteLinehelp: Display this help message";
Console.WriteLineexit: Quit the game.";
public void DisplayResult
Implement displaying result
public void SwitchPlayer
Implement switching player logic if needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started