private void _PlaceP2P(int x, int y) { if (_Player != 0) { if (_Player == _Reversi.GetCurrentPlayer()) { bool result = _Reversi.PlacePiece(y, x); Send(_UpdateBuffer()); _Other.Send(_Other._UpdateBuffer()); if ((_Reversi.GetState() & ReversiState.InProgress) != 0) { if (result) { Send(_EtcBuffer("Placed at (" + (char)(y + '1') + ", " + (char)(x + 'A') + ')')); _Other.Send(_Other._EtcBuffer("Placed at (" + (char)(y + '1') + ", " + (char)(x + 'A') + ')')); } else { Send(_EtcBuffer("Cannot place.")); } } else { Send(_EtcBuffer("")); } } else { Send(_EtcBuffer("Waiting for opponent...")); } } }
static void Main(string[] args) { char i, j; Console.WriteLine(); Reversi reversi = new Reversi(); while (((int)reversi.GetState() & 1) != 0) { Console.Write(reversi); while (Char.IsWhiteSpace(i = (char)Console.Read())) { ; } while (Char.IsWhiteSpace(j = (char)Console.Read())) { ; } Console.Clear(); if (Char.IsLower(i)) { i -= ' '; } if (Char.IsLower(j)) { j -= ' '; } if (i == 'Z' && j == 'Z') { if (!reversi.Undo()) { Console.WriteLine("Cannot undo."); } else { Console.WriteLine("Undid."); } } else if (i == 'Y' && j == 'Y') { if (!reversi.Redo()) { Console.WriteLine("Cannot redo."); } else { Console.WriteLine("Redid."); } } else if (i == 'S' && j == 'S') { if (!reversi.SkipTurn()) { Console.WriteLine("Cannot skip the turn."); } else { Console.WriteLine("Skipped."); } } else if (!Char.IsDigit(i) || !Char.IsLetter(j)) { Console.WriteLine("Invalid command."); } else { if (!reversi.PlacePiece(i - '1', j - 'A')) { Console.WriteLine("Cannot place."); } else { if (reversi.GetState() == ReversiState.NoAvailableSpaces) { Console.WriteLine("No available spaces."); } else { Console.WriteLine(); } } } } }