let f = function(e){
if(e.target.parentNode && e.target.parentNode.classList && e.target.parentNode.classList.contains("search-icon"))
document.querySelector(".search-input").classList.remove("active");
}
document.addEventListener("click",f,false);
document.addEventListener("touchstart",f,false);
canvas.addEventListener('mousemove', function(event) {
let scaleFactor = 1150/plan.offsetWidth;
event = {
offsetX:event.offsetX*scaleFactor,
offsetY:event.offsetY*scaleFactor
}
for(let i = arr.length - 1; i >= 0; i--) {
...
static void Main(string[] args)
{
CustomPackage cp = new CustomPackage();
cp.offset = 3;
cp.state = true;
cp.latitude = new BitArray(23);
cp.latitude.SetAll(true);
cp.longitude= new BitArray(24);
cp.longitude.SetAll(false);
cp.height= new BitArray(24);
cp.height.SetAll(true);
cp.speedNS= new BitArray(11);
cp.speedNS.SetAll(true);
cp.speedWE = new BitArray(11);
cp.speedWE.SetAll(true);
var bytes = cp.toBytes();//Пакет в байты
var p = CustomPackage.FromBytes(bytes);//Пакет из байтов
}
}
public class CustomPackage{
public int offset;// 4 байта смещения
public bool state;//1 бит - состояние
public BitArray latitude = new BitArray(23);//23 бита - широта,
public BitArray longitude = new BitArray(24);//24 бита - долгота
public BitArray height = new BitArray(12);//12 бит - высота
// 7 бит пропускаем,
public BitArray speedNS = new BitArray(11);// 11 бит - скорость относительно оси север-юг,
public BitArray speedWE = new BitArray(11);//11 бит - скорость относительно оси запад-восток.
public static CustomPackage FromBytes(byte[] arr){
CustomPackage cp = new CustomPackage();
BitArray bt = new BitArray(arr);
int ptr = 0;
cp.offset = BitConverter.ToInt32(arr, ptr);
ptr += 32;
cp.state = bt[ptr++];
cp.latitude = cp.utilCopyBits(bt, ptr, 23);
ptr += 23;
cp.longitude= cp.utilCopyBits(bt, ptr, 24);
ptr += 24;
cp.height= cp.utilCopyBits(bt, ptr, 12);
ptr += 12;
ptr += 7;
cp.speedNS= cp.utilCopyBits(bt, ptr, 11);
ptr += 11;
cp.speedWE= cp.utilCopyBits(bt, ptr, 11);
return cp;
}
public byte[] toBytes(){
byte[] buff = new byte[16];
int ptr = 0;
utilWrite(ref ptr, ref buff, new BitArray(BitConverter.GetBytes(offset)),32);
utilWrite(ref ptr, ref buff, new BitArray(BitConverter.GetBytes(state)), 1);
utilWrite(ref ptr, ref buff, latitude,23);
utilWrite(ref ptr, ref buff, longitude,24);
utilWrite(ref ptr, ref buff, height,12);
ptr += 7;// 7 бит пропускаем
utilWrite(ref ptr, ref buff, speedNS, 11);
utilWrite(ref ptr, ref buff, speedWE, 11);
return buff;
}
private BitArray utilCopyBits(BitArray source, int offset, int length)
{
BitArray b = new BitArray(length);
for (int i = 0; i < length; i++)
b[i] = source[offset + i];
return b;
}
private void utilWrite(ref int ptr, ref byte[] buff, BitArray writeData, int writeBitLength){
BitArray bt = new BitArray(buff);
for (int i = 0; i < writeBitLength; i++)
bt.Set(ptr++, writeData[i]);
bt.CopyTo(buff,0);
}
}
Console.WriteLine(getCount(moves,Figure.Queen));
//....
public int getCount(List<Coords>[][,] arr, Figure figure)
{
int count = 0;
foreach (var c in arr[(int) figure])
count += c.Count;
return count;
}
public class rock_player : MonoBehaviour {
static public int rock;
public const int MAX_ROCKS = 20;
[SerializeField]
public Text TextRock {get { return rock.ToString();}}
void Start(){
rock = 0;
}
}
public class RockTrig : MonoBehaviour {
public int ValueRock;
void OnTriggerEnter(Collider col) {
if(rock_player.rock + ValueRock > rock_player.MAX_ROCKS) {
ValueRock -= rock_player.MAX_ROCKS - rock_player.rock;
rock_player.rock = rock_player.MAX_ROCKS;
}else{
rock_player.rock += ValueRock;
Destroy (gameObject);
}
}
}
void ChangeColors() {
targetCountText.color = (Color)new Color32(Random.Range(0,256), Random.Range(0,256) , Random.Range(0,256),255);
}
public void CellClick(GameObject o){
if(o.GetType() == typeof(Car)){
Car car = (Car)o ;
//todo
}
if(o.GetType() == typeof(Animal)){
Animal animal= (Animal)o ;
//todo
}
}
public static void AddItem(int itemId, int Amount){
int inventoryCellCount = 20;//Количество ячеек инвентаря
int maxCount = GetMaxCountById(itemId);//Получить максимальное кол-во стека для этого айтема по ид
while(Amount > 0){
var item = Items.Find(item => item.id == itemId);
if(item == null || item.Amount == maxCount){
if(Items.Count >= inventoryCellCount)//Если ячейки инвентаря забиты
break;
item = CreateItemById(itemId);//создает итем по ид
Items.Add(item);
}
if(item.Amount + Amount > maxCount){
Amount = Amount - (maxCount - item.Amount);
item.Amount = maxCount;
}
else{
item.Amount += Amount;
Amount = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
const double scale = 0.35;
const int depth = 5;
public MainWindow()
{
InitializeComponent();
btnStart_Click(null, null);
}
private void btnStart_Click(object sender, RoutedEventArgs e)
{
double xmid = image.Width / 2;
double ymid = image.Height / 2;
DrawStar(1, xmid, ymid, 100, -1);
}
private void DrawStar(int level, double x, double y, double r, int skip, bool isRotate = true){
double offset = isRotate? Math.PI / 2:-Math.PI / 2;
const double angle = 4 * Math.PI / 5;
Polyline star = new Polyline();
star.Stroke = Brushes.DarkRed;
image.Children.Add(star);
for (int i = 0; i <= 5; i++){
var angleT = offset + i * angle;
var lx = (int) (x + r*Math.Cos(angleT));
var ly = (int) (y + r*Math.Sin(angleT));
star.Points.Add(new Point(lx,ly));
if (level < depth){
var newrad = r*scale;
var lx2 = (int)(x + (r + newrad) * Math.Cos(angleT));
var ly2 = (int)(y + (r + newrad) * Math.Sin(angleT));
if(i != skip && i !=5)
DrawStar(level + 1, lx2, ly2, newrad, i, !isRotate);
}
}
}
}
}
String str = text.trim();
String digits="";
int sum = 0;
str+=" ";
for (int i = 0; i < str.length(); i++) {
char chrs = str.charAt(i);
if (Character.isDigit(chrs))
digits+=chrs;
else{
if(!digits.equals(""))
sum+= Integer.parseInt(digits);
digits = "";
}
}
System.out.println(sum);