SELECT id, title, 'article' as `type` FROM Article WHERE ...
UNION SELECT id, title, 'news' as `type` FROM News WHERE ...
UNION SELECT id, title, 'post' as `type` FROM Post WHERE ...
ob_start()
перед выводом echo). double a = 10.123, b = 20.234, c = 30.345;
Console.WriteLine(Math.Round(a, 2) + " " + Math.Round(b, 2) + " " + Math.Round(c, 2));
Console.WriteLine(string.Join(" ", new []{a, b, c}.Select(x => x.ToString("F2"))));
public enum DamageType { Melee, Range, Magic }
public class Monster
{
public double Health { get; private set; }
public double MeleeDamage { get; private set; }
public double RangeDamage { get; private set; }
public double MagicDamage { get; private set; }
public DamageType FavoriteDamageType { get; private set; }
public Monster(double health, double meleeDamage, double rangeDamage, double magicDamage, DamageType favoriteDamageType)
{
Health = health;
MeleeDamage = meleeDamage;
RangeDamage = rangeDamage;
MagicDamage = magicDamage;
FavoriteDamageType = favoriteDamageType;
}
public void AttackTo(Monster monster, DamageType damageType)
{
switch (damageType) // используется switch
{
case MonsterType.Melee: monster.Health -= MeleeDamage; break;
case MonsterType.Range: monster.Health -= RangeDamage; break;
case MonsterType.Magic: monster.Health -= MagicDamage; break;
}
}
public void AttackTo(Monster monster)
{
AttackTo(monster, FavoriteDamageType);
}
}
public class Monster
{
public double Health { get; set; }
public double MeleeDamage { get; private set; }
public double RangeDamage { get; private set; }
public double MagicDamage { get; private set; }
public IDamageStrategy FavoriteDamageStrategy { get; private set; }
public Monster(double health, double meleeDamage, double rangeDamage, double magicDamage, IDamageStrategy favoriteDamageStrategy)
{
Health = health;
MeleeDamage = meleeDamage;
RangeDamage = rangeDamage;
MagicDamage = magicDamage;
FavoriteDamageStrategy = favoriteDamageStrategy;
}
public void AttackTo(Monster monster, IDamageStrategy damageStrategy)
{
damageStrategy.Attack(this, monster); // не используется switch
}
public void AttackTo(Monster monster)
{
AttackTo(monster, FavoriteDamageStrategy);
}
}
public interface IDamageStrategy
{
void Attack(Monster attacker, Monster defender);
}
public class MeleeDamageStrategy : IDamageStrategy
{
public void Attack(Monster attacker, Monster defender)
{
defender.Health -= attacker.MeleeDamage;
}
}
public class RangeDamageStrategy : IDamageStrategy
{
public void Attack(Monster attacker, Monster defender)
{
defender.Health -= attacker.RangeDamage;
}
}
public class MagicDamageStrategy : IDamageStrategy
{
public void Attack(Monster attacker, Monster defender)
{
defender.Health -= attacker.MagicDamage;
}
}
private string _name;
public string Name
{
get
{
return _name;
}
set
{
if (_name != value)
{
_name= value;
RaisePropertyChanged(nameof(Name));
}
}
}
// можно сделать в базовом классе, в котором и реализовать интерфейс INotifyPropertyChanged
protected virtual void RaisePropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
private const byte VK_LMENU = 0xA4;
private const byte KEYEVENTF_EXTENDEDKEY = 0x01;
private const byte KEYEVENTF_KEYUP = 0x02;
private const byte KEYSCAN_LALT = 0xB8;
[DllImport("user32.dll")]
internal static extern bool SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);
public static void BringWindowToFront(IntPtr hwnd)
{
// симуляция нажатия клавиши ALT https://stackoverflow.com/a/13881647/1343405
keybd_event(VK_LMENU, KEYSCAN_LALT, 0, 0);
keybd_event(VK_LMENU, KEYSCAN_LALT, KEYEVENTF_KEYUP, 0);
SetForegroundWindow(hwnd);
}
GameScript GridObject;
void Start()
{
GridObject = FindObjectOfType<GameScript>();
}
void Update ()
{
CheckUserInput();
}
void CheckUserInput()
{
if (Input.touchCount > 0) ProcessTouch(Input.GetTouch(0));
if (Input.GetKeyDown(KeyCode.RightArrow)) MoveFigureBy(1);
if (Input.GetKeyDown(KeyCode.LeftArrow)) MoveFigureBy(-1);
if (Input.GetKeyDown(KeyCode.UpArrow)) RotateFigure();
if (Input.GetKeyDown(KeyCode.DownArrow) || Time.time - fall >= fallSpeed) FallFigure();
}
void ProcessTouch(Touch touch)
{
if (touch.phase == TouchPhase.Began)
{
previousUnitPosition = new Vector2 (touch.position.x, touch.position.y);
} else if (touch.phase == TouchPhase.Moved)
{
Vector2 touchDeltaPosition = touch.deltaPosition;
direction = touchDeltaPosition.normalized;
if (Mathf.Abs(touch.position.x - previousUnitPosition.x) >= touchSensitivityHorizontal && direction.x < 0 &&toucht.deltaPosition.y > -10 && touch.deltaPosition.y < 10) // на этой строке ошибка direction < 0
{
// что делать???
}
} else if (touch.phase == TouchPhase.Ended)
{
}
}
void MoveFigureBy(int value)
{
transform.position += new Vector3(value, 0, 0);
if (CheckIsValidPosition())
{
GridObject.UpdateGrid(this);
} else
{
transform.position += new Vector3(-1 * value, 0, 0);
}
}
void RotateFigure()
{
if (allowRotation)
{
if (limitRotation)
{
if (transform.rotation.eulerAngles.z >= 90) {
transform.Rotate(0,0,-90);
} else
{
transform.Rotate(0,0,90);
}
} else
{
transform.Rotate (0,0,90);
}
if(CheckIsValidPosition())
{
GridObject.UpdateGrid(this);
} else
{
if (limitRotation)
{
if (transform.rotation.eulerAngles.z >= 90)
{
transform.Rotate(0,0,-90);
} else
{
transform.Rotate (0,0,90);
}
} else
{
transform.Rotate (0,0,-90);
}
}
}
}
void FallFigure()
{
transform.position += new Vector3(0, -1, 0);
fall = Time.time;
if (CheckIsValidPosition())
{
GridObject.UpdateGrid(this);
} else
{
transform.position += new Vector3(0, 1, 0);
GridObject.DeleteRow();
if (GridObject.CheckIsAboveGrid (this))
{
GridObject.GameOver ();
}
enabled = false;
GridObject.SpawnNextFigure();
}
}
SomeClass obj = new SomeClass();
главный вопрос, как нужно комментировать эту строку: "my.age = 5"?
так и не осознал, что хранится в БД, а что - в RAM ... автоматические системы кеширования/сброса в БД?
Как, собственно, производить синхронизацию клиента и сервера?
создавать на клиенте экземпляр той же симуляции мира, что и на сервере
может ли что-нибудь дать использование ASP.NET (возможно core) в качестве основы, или для таких целей его использование бессмысленно?