Example #1
0
        /////////////////////     Game Helpers       ////////////////////////////////
        public bool AddGame(TwodokuGameInfo gameInfo, Boolean useNow)
        {
            string values = "";
            values += "'" + gameInfo.GameId + "',";
            values += "'" + gameInfo.Player1 + "',";
            values += "'" + gameInfo.Player1Score + "',";
            values += "'" + gameInfo.Player2 + "',";
            values += "'" + gameInfo.Player2Score + "',";

            if (useNow)
            {
                gameInfo.StartDate = DateTime.Now;
                gameInfo.PlayDate = DateTime.Now;
            }
            values += "'" + gameInfo.StartDate + "',";
            values += "'" + gameInfo.PlayDate + "',";
            values += "'" + gameInfo.Status + "',";
            values += "'" + gameInfo.Turn + "',";
            values += "'" + gameInfo.HandSystem + "',";
            values += "'" + gameInfo.HandSize + "',";
            values += "'" + gameInfo.ScoringSystem + "',";
            values += "'" + gameInfo.MultiplierSystem + "',";
            values += "'" + gameInfo.BonusSystem + "',";
            values += "'" + gameInfo.LastMove + "',";
            values += "'" + GetHand() + "',";
            values += "'" + gameInfo.InitialBoard + "',";
            values += "'" + gameInfo.PlayerBoard + "',";
            values += "'" + gameInfo.Multipliers + "'";

            LogFile.LogGameMove(gameInfo);

            return Insert(TableGames, values);
        }
        /// <summary>
        /// This is used for retrieving a game from the database
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static TwodokuGameInfo FromSqlReader(SqlDataReader reader)
        {
            TwodokuGameInfo gameInfo = new TwodokuGameInfo();

            gameInfo.GameId = (int)reader[DBHelper.ColumnGameId];
            gameInfo.Player1 = (string)reader[DBHelper.ColumnPlayer1];
            gameInfo.Player1Score = (int)reader[DBHelper.ColumnPlayer1Score];
            gameInfo.Player2 = (string)reader[DBHelper.ColumnPlayer2];
            gameInfo.Player2Score = (int)reader[DBHelper.ColumnPlayer2Score];

            gameInfo.StartDate = (DateTime)reader[DBHelper.ColumnStartDate];
            gameInfo.PlayDate = (DateTime)reader[DBHelper.ColumnPlayDate];

            gameInfo.Status = (int)reader[DBHelper.ColumnStatus];
            gameInfo.Turn = (int)reader[DBHelper.ColumnTurn];

            gameInfo.HandSystem = (string)reader[DBHelper.ColumnHandSystem];
            gameInfo.HandSize = (int)reader[DBHelper.ColumnHandSize];
            gameInfo.ScoringSystem = (string)reader[DBHelper.ColumnScoringSystem];

            gameInfo.MultiplierSystem = (string)reader[DBHelper.ColumnMultiplierSystem];
            gameInfo.BonusSystem = (string)reader[DBHelper.ColumnBonusSystem];

            gameInfo.LastMove = (string)reader[DBHelper.ColumnLastMove];
            gameInfo.Hand = (string)reader[DBHelper.ColumnHand];

            gameInfo.InitialBoard = (string)reader[DBHelper.ColumnStartingBoard];
            gameInfo.PlayerBoard = (string)reader[DBHelper.ColumnPlayerBoard];
            gameInfo.Multipliers = (string)reader[DBHelper.ColumnMultipliers];

            return gameInfo;
        }
        public static TwodokuGameInfo FromHttpPost(int gameId, Hashtable dataEntries)
        {
            TwodokuGameInfo ret = new TwodokuGameInfo();

            ret.GameId = gameId;

            ret.Player1 = (string)dataEntries["Player1"];
            int.TryParse((string)dataEntries["Player1Score"], out ret.Player1Score);
            ret.Player2 = (string)dataEntries["Player2"];
            int.TryParse((string)dataEntries["Player2Score"], out ret.Player2Score);
            int.TryParse((string)dataEntries["Status"], out ret.Status);
            int.TryParse((string)dataEntries["Turn"], out ret.Turn);
            ret.LastMove = (string)dataEntries["LastMove"];
            ret.PlayerBoard = (string)dataEntries["PlayerBoard"];
            ret.HandSystem = (string)dataEntries["HandSystem"];
            int.TryParse((string)dataEntries["HandSize"], out ret.HandSize);
            ret.ScoringSystem = (string)dataEntries["ScoringSystem"];
            ret.MultiplierSystem = (string)dataEntries["MultiplierSystem"];
            ret.BonusSystem = (string)dataEntries["BonusSystem"];
            ret.InitialBoard = (string)dataEntries["StartingBoard"];
            ret.Multipliers = (string)dataEntries["Multipliers"];

            ret.PlayDate = DateTime.Now;

            return ret;
        }
Example #4
0
        public static void LogGameMove(TwodokuGameInfo game)
        {
            string filename = string.Format("{0} - {1} v {2}.txt", game.GameId, game.Player1, game.Player2);

            string entry = string.Format("{0}: {1}, {2}-{3}", DateStrings.ToString(DateTime.Now), game.LastMove, game.Player1Score, game.Player2Score);

            if (!File.Exists(filename))
                CreateGameLog(filename, game);

            TextWriter writer = File.AppendText(filename);
            writer.Write(entry + "\n");
            writer.Close();
        }
Example #5
0
        public static void CreateGameLog(string filename, TwodokuGameInfo game)
        {
            TextWriter writer = File.CreateText(filename);

            writer.WriteLine(string.Format("Initial Board: {0}", game.InitialBoard));
            writer.WriteLine(string.Format("Multipliers: {0}", game.Multipliers));
            writer.WriteLine(string.Format("Hand System: {0} ({1})", game.HandSystem, game.HandSize));
            writer.WriteLine(string.Format("Scoring System: {0}", game.ScoringSystem));
            writer.WriteLine(string.Format("Multiplier System: {0}", game.MultiplierSystem));
            writer.WriteLine(string.Format("Bonus System: {0}", game.BonusSystem));

            writer.Close();
        }
Example #6
0
        public bool UpdateGame(TwodokuGameInfo gameInfo)
        {
            //Retrieve the game and make sure everything matches (players, etc.)
            TwodokuGameInfo existingGame = GetGame(gameInfo.GameId);
            if (existingGame == null || !existingGame.IsSameGame(gameInfo))
                return false;

            LogFile.LogGameMove(gameInfo);

            gameInfo.Player1 = existingGame.Player1;
            gameInfo.Player2 = existingGame.Player2;

            //Update: Scores, PlayDate, Status, Turn, PlayerBoard, LastMove
            string update = "";
            update += string.Format("{0}='{1}',", ColumnPlayer1Score, gameInfo.Player1Score);
            update += string.Format("{0}='{1}',", ColumnPlayer2Score, gameInfo.Player2Score);
            update += string.Format("{0}='{1}',", ColumnPlayDate, gameInfo.PlayDate);
            update += string.Format("{0}='{1}',", ColumnStatus, gameInfo.Status);
            update += string.Format("{0}='{1}',", ColumnTurn, gameInfo.Turn);
            update += string.Format("{0}='{1}',", ColumnPlayerBoard, gameInfo.PlayerBoard);
            update += string.Format("{0}='{1}',", ColumnLastMove, gameInfo.LastMove);

            //Create a new hand for the next turn
            string hand = GetHand();
            //Console.WriteLine("Hand: " + hand);
            update += string.Format("{0}='{1}'", ColumnHand, hand);

            string qualifier = string.Format("{0}='{1}'", ColumnGameId, gameInfo.GameId);
            return Update(TableGames, update, qualifier);
        }
        public bool IsSameGame(TwodokuGameInfo gameInfo)
        {
            if (GameId != gameInfo.GameId)
                return false;
            if (Player1 != gameInfo.Player1)
                return false;
            if (Player2 != gameInfo.Player2)
                return false;
            //if (StartDate != gameInfo.StartDate)
            //    return false;
            //if (HandSystem != gameInfo.HandSystem)
            //    return false;
            //if (HandSize != gameInfo.HandSize)
            //    return false;
            //if (ScoringSystem != gameInfo.ScoringSystem)
            //    return false;

            return true;
        }
        /// <summary>
        /// This is used for importing the database from a text file
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static TwodokuGameInfo FromString(string input)
        {
            string[] parts = input.Split(',');

            TwodokuGameInfo ret = new TwodokuGameInfo();

            int.TryParse(parts[0], out ret.GameId);
            ret.Player1 = parts[1];
            int.TryParse(parts[2], out ret.Player1Score);
            ret.Player2 = parts[3];
            int.TryParse(parts[4], out ret.Player2Score);

            ret.StartDate = DateStrings.FromString(parts[5]);
            ret.PlayDate = DateStrings.FromString(parts[6]);

            int.TryParse(parts[7], out ret.Status);
            int.TryParse(parts[8], out ret.Turn);

            ret.HandSystem = parts[9];
            int.TryParse(parts[10], out ret.HandSize);
            ret.ScoringSystem = parts[11];
            ret.MultiplierSystem = parts[12];
            ret.BonusSystem = parts[13];

            ret.LastMove = parts[14];
            ret.Hand = parts[15];

            ret.InitialBoard = parts[16];
            ret.PlayerBoard = parts[17];
            ret.Multipliers = parts[18];

            return ret;
        }