public static Monster createFor( Player player ) { Monster mon = new Monster(); mon.player = player; mon.name = "a monster"; mon.hp = 15; mon.damage = 1; mon.money = 4; for ( int i = 0; i < player.getLevel(); i++ ) { mon.hp += _rand.Next( 0, 6 ); mon.damage += _rand.Next( 0, 2 ); mon.money += _rand.Next( 0, 5 ); } string sql = "REPLACE INTO monsters ( username, name, hp, damage, money ) " + " VALUES ('" + player.getUsername() + "', '" + mon.name + "', " + mon.hp + ", " + mon.damage + ", " + mon.money + ")"; _sqlite.exec( sql ); return mon; }
public static Monster loadFor( Player player ) { Monster mon = new Monster(); mon.player = player; string sql = "SELECT * FROM monsters WHERE username LIKE '" + player.getUsername() + "'"; SQLiteDataReader reader = _sqlite.query( sql ); if ( !reader.Read() ) { return null; } mon.name = reader.GetString( reader.GetOrdinal( "name" ) ); mon.hp = reader.GetInt32( reader.GetOrdinal( "hp" ) ); mon.damage = reader.GetInt32( reader.GetOrdinal( "damage" ) ); mon.money = reader.GetInt32( reader.GetOrdinal( "money" ) ); return mon; }