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) в качестве основы, или для таких целей его использование бессмысленно?
var names = new[] { "n1", "n2", "n3" };
var descriptions = new[] { "d1", "d2", "d3" };
var companies = new[] { "c1", "c2", "c3" };
var products = Enumerable.Range(0, names.Length-1)
.Select(i => new Product { Name = names[i], Description = descriptions[i], Company = companies[i]})
.ToList();
AbstractProcessor
:using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
var list = new List<IProcessor>()
{
new Processor(),
};
IProcessor o = new Processor();
Console.ReadKey();
}
}
interface INode { }
interface IResult { }
interface IProcessor
{
INode Get();
void Print(IResult result);
}
interface IProcessor<out T, in R> : IProcessor where T : class, INode where R : class, IResult
{
new T Get();
void Print(R result);
}
abstract class AbstractProcessor<T, R> : IProcessor<T, R> where T : class, INode where R : class, IResult
{
public abstract T Get();
public abstract void Print(R result);
// Преобразование в не-generic тип
void IProcessor.Print(IResult result)
{
Print(result as R);
}
INode IProcessor.Get()
{
return Get();
}
}
class Node : INode { }
class Result : IResult { }
class Processor : AbstractProcessor<Node, Result>
{
public override Node Get() { return null; }
public override void Print(Result result) {}
}
Dictionary<KeyCode, bool>
вместо нескольких переменных. Это если флаги нужны ещё где-то. А если эти флаги нужны только в Update(), то они и не нужны:int GetKey(KeyCode key) // 1 or 0
{
return Input.GetKeyDown(key) ? 1 : 0;
}
void Update()
{
int hor = GetKey(KeyCode.A) - GetKey(KeyCode.D);
int ver = GetKey(KeyCode.W) - GetKey(KeyCode.S);
transform.position += new Vector3(hor, ver, 0) * CameraSpeed;
}
using System.Collections.Generic;
using System.Linq;
namespace Helpers
{
public static class ArrayHelperExtensions
{
public static IEnumerable<IEnumerable<T>> Split<T>(this T[] array, int size)
{
for (var i = 0; i < (float) array.Length/size; i++)
{
yield return array.Skip(i*size).Take(size);
}
}
}
}
var num = 3;
var parts = listbox1.Items.Split(num);