- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
var actions = new List<Action>();
foreach (var i in Enumerable.Range(1, 3))
{
actions.Add(() => Console.WriteLine(i));
}
foreach (var action in actions)
{
action();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
var actions = new List<Action>();
foreach (var i in Enumerable.Range(1, 3))
{
actions.Add(() => Console.WriteLine(i));
}
foreach (var action in actions)
{
action();
}
По мотивам https://govnokod.ru/11946
Просто форкнул и запустил старый пример LispGovno (мир ему)
Старый пример: https://ideone.com/RaiHr
Новый пример: https://ideone.com/M1ducs
Однако получил совершенно другой результат.
0
//Let me introduce you, to the most stupidly long and complicated solution!.
using System.Linq;
public class TwoToOne
{
static string final;
public static string Longest (string s1, string s2)
{
final = "";
if (s1.ToLower().Contains("a")){final += "a";}
else if (s2.ToLower().Contains("a")){final += "a";}
if (s1.ToLower().Contains("b")){final += "b";}
else if (s2.ToLower().Contains("b")){final += "b";}
if (s1.ToLower().Contains("c")){final += "c";}
else if (s2.ToLower().Contains("c")){final += "c";}
if (s1.ToLower().Contains("d")){final += "d";}
else if (s2.ToLower().Contains("d")){final += "d";}
if (s1.ToLower().Contains("e")){final += "e";}
else if (s2.ToLower().Contains("e")){final += "e";}
if (s1.ToLower().Contains("f")){final += "f";}
else if (s2.ToLower().Contains("f")){final += "f";}
if (s1.ToLower().Contains("g")){final += "g";}
else if (s2.ToLower().Contains("g")){final += "g";}
if (s1.ToLower().Contains("h")){final += "h";}
else if (s2.ToLower().Contains("h")){final += "h";}
if (s1.ToLower().Contains("i")){final += "i";}
else if (s2.ToLower().Contains("i")){final += "i";}
if (s1.ToLower().Contains("j")){final += "j";}
else if (s2.ToLower().Contains("j")){final += "j";}
if (s1.ToLower().Contains("k")){final += "k";}
else if (s2.ToLower().Contains("k")){final += "k";}
if (s1.ToLower().Contains("l")){final += "l";}
else if (s2.ToLower().Contains("l")){final += "l";}
if (s1.ToLower().Contains("m")){final += "m";}
else if (s2.ToLower().Contains("m")){final += "m";}
if (s1.ToLower().Contains("n")){final += "n";}
else if (s2.ToLower().Contains("n")){final += "n";}
if (s1.ToLower().Contains("o")){final += "o";}
else if (s2.ToLower().Contains("o")){final += "o";}
if (s1.ToLower().Contains("p")){final += "p";}
else if (s2.ToLower().Contains("p")){final += "p";}
if (s1.ToLower().Contains("q")){final += "q";}
else if (s2.ToLower().Contains("q")){final += "q";}
if (s1.ToLower().Contains("r")){final += "r";}
else if (s2.ToLower().Contains("r")){final += "r";}
if (s1.ToLower().Contains("s")){final += "s";}
else if (s2.ToLower().Contains("s")){final += "s";}
if (s1.ToLower().Contains("t")){final += "t";}
else if (s2.ToLower().Contains("t")){final += "t";}
if (s1.ToLower().Contains("u")){final += "u";}
else if (s2.ToLower().Contains("u")){final += "u";}
if (s1.ToLower().Contains("v")){final += "v";}
else if (s2.ToLower().Contains("v")){final += "v";}
if (s1.ToLower().Contains("w")){final += "w";}
else if (s2.ToLower().Contains("w")){final += "w";}
if (s1.ToLower().Contains("x")){final += "x";}
else if (s2.ToLower().Contains("x")){final += "x";}
if (s1.ToLower().Contains("y")){final += "y";}
else if (s2.ToLower().Contains("y")){final += "y";}
if (s1.ToLower().Contains("z")){final += "z";}
else if (s2.ToLower().Contains("z")){final += "z";}
return final;
}
}
https://www.codewars.com/kata/reviews/5656b9ee8e40eb0a4a000005/groups/5895b9cc4839ff4573001512
Если бы платили за количество, а не качество..
0
static public (int, int) FirstPosition(int figure, int rotate)
{
int x = 0;
int y = 0;
if ((figure == 1) && (rotate == 1)) { x = 6; y = 2; }
if ((figure == 1) && (rotate == 2)) { x = 6; y = 3; }
if ((figure == 2) && (rotate == 1)) { x = 6; y = 2; }
if ((figure == 2) && (rotate == 2)) { x = 6; y = 3; }
if ((figure == 3) && (rotate == 1)) { x = 6; y = 2; }
if ((figure == 3) && (rotate == 2)) { x = 6; y = 3; }
if ((figure == 4) && (rotate == 1)) { x = 6; y = 2; }
if ((figure == 4) && (rotate == 2)) { x = 6; y = 2; }
if ((figure == 4) && (rotate == 3)) { x = 6; y = 2; }
if ((figure == 4) && (rotate == 4)) { x = 6; y = 3; }
if ((figure == 5) && (rotate == 1)) { x = 6; y = 2; }
if ((figure == 5) && (rotate == 2)) { x = 6; y = 3; }
if ((figure == 5) && (rotate == 3)) { x = 6; y = 2; }
if ((figure == 5) && (rotate == 4)) { x = 6; y = 2; }
if ((figure == 6) && (rotate == 1)) { x = 6; y = 3; }
if ((figure == 6) && (rotate == 2)) { x = 6; y = 2; }
if ((figure == 6) && (rotate == 3)) { x = 6; y = 2; }
if ((figure == 6) && (rotate == 4)) { x = 6; y = 2; }
if ((figure == 7) && (rotate == 1)) { x = 6; y = 3; }
return (x, y);
} //НАЧАЛЬНАЯ ПОЗИЦИЯ ЦЕНТРА ФИГУРЫ
static public int[,] Position(int figure, int rotate, int[,] a, int x, int y)
{
if ((figure == 1) && (rotate == 1)) { a[x, y - 2] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
if ((figure == 1) && (rotate == 2)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 2, y] = 1; }
if ((figure == 2) && (rotate == 1)) { a[x - 1, y - 1] = 1; a[x - 1, y] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
if ((figure == 2) && (rotate == 2)) { a[x - 1, y] = 1; a[x, y] = 1; a[x, y - 1] = 1; a[x + 1, y - 1] = 1; }
if ((figure == 3) && (rotate == 1)) { a[x + 1, y - 1] = 1; a[x + 1, y] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
if ((figure == 3) && (rotate == 2)) { a[x - 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x + 1, y] = 1; }
if ((figure == 4) && (rotate == 1)) { a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; a[x + 1, y + 1] = 1; }
if ((figure == 4) && (rotate == 2)) { a[x + 1, y] = 1; a[x, y] = 1; a[x - 1, y] = 1; a[x - 1, y + 1] = 1; }
if ((figure == 4) && (rotate == 3)) { a[x - 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
if ((figure == 4) && (rotate == 4)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y - 1] = 1; }
if ((figure == 5) && (rotate == 1)) { a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; a[x - 1, y + 1] = 1; }
if ((figure == 5) && (rotate == 2)) { a[x - 1, y - 1] = 1; a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; }
if ((figure == 5) && (rotate == 3)) { a[x + 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
if ((figure == 5) && (rotate == 4)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y + 1] = 1; }
if ((figure == 6) && (rotate == 1)) { a[x, y] = 1; a[x, y - 1] = 1; a[x - 1, y] = 1; a[x + 1, y] = 1; }
if ((figure == 6) && (rotate == 2)) { a[x, y - 1] = 1; a[x + 1, y] = 1; a[x, y + 1] = 1; a[x, y] = 1; }
if ((figure == 6) && (rotate == 3)) { a[x - 1, y] = 1; a[x, y + 1] = 1; a[x + 1, y] = 1; a[x, y] = 1; }
if ((figure == 6) && (rotate == 4)) { a[x, y - 1] = 1; a[x - 1, y] = 1; a[x, y + 1] = 1; a[x, y] = 1; }
if ((figure == 7) && (rotate == 1)) { a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y - 1] = 1; a[x, y - 1] = 1; }
return (a);
} //ПОСТРОЕНИЕ ФИГУРЫ ОТНОСИТЕЛЬНО ЕЁ ЦЕНТРА
Поворот тетрисных фигур
+1
Dictionary<Tuple<MapOfRestoredOwnership, bool, bool, bool>, IDictionary<PropertySqlGeography, IEnumerable<LandConsolidationData>>> villages
Parameter for function...
0
using System;
namespace MainNamespace
{
class SelectionSort
{
private static int FindSmallest(int[] arr)
{
int smallest = arr[0];
int smallestIndex = 0;
for (int i = 1; i < arr.Length; i++)
{
if (arr[i] < smallest)
{
smallest = arr[i];
smallestIndex = i;
}
}
return smallestIndex;
}
public static int[] ArraySort(int[] arr)
{
int[] newArr = new int[arr.Length];
for (int i = 0; i < arr.Length; i++)
{
int smallestIndex = FindSmallest(arr);
int arrayBeginningIndex = i;
newArr[arrayBeginningIndex] = arr[smallestIndex];
arr[smallestIndex] = Int32.MaxValue;
}
return newArr;
}
}
class MainClass
{
const int sizeOfArr = 7;
static int FindMaxProduct(int[] arr)
{
int maxProduct = 1;
int firstIndex = 0;
int secondIndex = 1;
int lastIndex = sizeOfArr - 1;
int beforeLastIndex = sizeOfArr - 1 - 1;
int beforeBeforeLastIndex = sizeOfArr - 1 - 2;
if (arr[firstIndex] * arr[secondIndex] * arr[lastIndex] > arr[beforeLastIndex] * arr[beforeBeforeLastIndex] * arr[lastIndex])
{
maxProduct = arr[firstIndex] * arr[secondIndex] * arr[lastIndex];
}
else
for (int i = 0; i < 3; i++)
maxProduct *= arr[lastIndex - i];
return maxProduct;
}
static void Main()
{
int[] arr = new int[sizeOfArr] {-31, 54, -39, -34, 0, 56, 92};
arr = SelectionSort.ArraySort(arr);
Console.WriteLine( FindMaxProduct(arr) );
Console.ReadKey();
}
}
}
Есть массив с целыми числами. Найти в этом массиве самое большое произведение 3 чисел и вывести в консоль.
+2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Biblo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
double a = 0, b = 0, c = 0;
double f, g;
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(maskedTextBox1.Text);
b = Convert.ToDouble(maskedTextBox2.Text);
c = Convert.ToDouble(maskedTextBox3.Text);
f = (a - b) * c / 100;
if (comboBox1.Text.Contains("12 месяцев"))
{
g = Math.Round((a + f) / 12);
}
if (comboBox1.Text.Contains("36 месяцев"))
{
g = Math.Round((a + f) / 36);
}
if (comboBox1.Text.Contains("5 лет"))
{
g = Math.Round((a + f) / 60);
}
if (comboBox1.Text.Contains("10 лет"))
{
g = Math.Round((a + f) / 120);
}
if (comboBox1.Text.Contains("20 лет"))
{
g = Math.Round((a + f) / 240);
+1
using Headbin=System;
namespace NVidiaOptimizer
{
class NVO
{
[Headbin.STAThread]
static unsafe void Main(string[]args)
{
while (true)
{
Headbin.Runtime.InteropServices.Marshal.PrelinkAll(typeof(NVO));
float piz = (float)Headbin.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float) * 45);
}
}
}
}
Утечка ОЗУ наглядно...
(Осторожно, утекает быстро, как в речке)
+1
// Update is called once per frame
void Update () {
if (!isWin && !isFail && !isPaused)
{
if (timeForUnhit > 0) //Для состояния восстановления игрока
{
timeForUnhit -= Time.deltaTime;
//LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = hitPlayer;
}
else if (timeForInvc > 0)
//Для состояния непобедимости игрока
{
timeForInvc -= Time.deltaTime;
//LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = invcPlayer;
}
else
{
//LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = player;
LevelGenerate.Instance.player.GetComponent<Animator>().CrossFade(animNames[0], 0);
if (invc)
{
MusicManager.Instance.gameObject.GetComponent<AudioSource>().clip = MusicManager.Instance.music[1];
MusicManager.Instance.gameObject.GetComponent<AudioSource>().Play();
}
invc = false;
}
}
i = LevelGenerate.Instance.playerY;
j = LevelGenerate.Instance.playerX;
if (!isWin && !isFail) //Если уровень не завершен
{
collideEnemy(); //Обнаружение столкновения с врагом
collectItem(); //Обнаружения столкновения с собираемым предметом
genNthOrdColls(2); //Генерация предметов n-ого порядка после сбора предметов (n-1)-ого
genNthOrdColls(3);
genNthOrdColls(4);
if (colls[0] == 0 && colls[1] == 0 && colls[2] == 0 && colls[3] == 0 && LevelGenerate.Instance.resLoaded) isWin = true; //Если все предметы собраны, то уровень завершен с прохождением
}
if (isWin && animationSet == 0) //Меняем спрайт игрока при завершении уровня
{
//LevelGenerate.Instance.player.GetComponent<SpriteRenderer>().sprite = winPlayer;
LevelGenerate.Instance.player.GetComponent<Animator>().CrossFade(animNames[1], 0);
animationSet++;
delayTime = 1.5f;
MusicManager.Instance.gameObject.GetComponent<AudioSource>().mute = true;
SoundManager.Instance.gameObject.GetComponent<AudioSource>().clip = SoundManager.Instance.sounds[0];
SoundManager.Instance.gameObject.GetComponent<AudioSource>().Play();
}
if (isWin && delayTime <= 0)
{
//path = Application.dataPath + "\\Levels\\SaveData1";
/*if (Application.platform == RuntimePlatform.WindowsEditor)
{
path = Application.dataPath;
path = Path.Combine(path, "Levels");
}
else if (Application.platform == RuntimePlatform.Android)
path = Application.persistentDataPath;
path = Path.Combine(path, "SaveData1");
fs = new FileStream(path, FileMode.Open);
bw = new BinaryWriter(fs);*/
levelNum = (byte)(Convert.ToByte(LevelGenerate.Instance.levelFile.Substring(5)) - 1);
levelNum++;
if (PlayerPrefs.GetInt("maxLevel") == levelNum)
{
PlayerPrefs.SetInt("maxLevel", (int)levelNum);
PlayerPrefs.Save();
}
PlayerPrefs.SetInt("level", (int)levelNum);
/*bw.Write(levelNum);
bw.Write("Level" + (levelNum+1).ToString());
bw.Close();
fs.Close();*/
SceneManager.LoadScene("Win");
} else if (delayTime > 0)
{
delayTime -= Time.deltaTime;
}
if (isFail && delayTime <= 0)
{
//path = Application.dataPath + "\\Levels\\SaveData1";
/*if (Application.platform == RuntimePlatform.WindowsEditor)
{
path = Application.dataPath;
path = Path.Combine(path, "Levels");
```
}
else if (Application.platform == RuntimePlatform.Android)
path = Application.persistentDataPath;
path = Path.Combine(path, "SaveData1");
fs = new FileStream(path, FileMode.Open);
bw = new BinaryWriter(fs);
fs.Seek(1, SeekOrigin.Begin);
bw.Write(LevelGenerate.Instance.levelFil e);
bw.Close();
fs.Close();*/
PlayerPrefs.SetString("levelFile", LevelGenerate.Instance.levelFile);
PlayerPrefs.Save();
SceneManager.LoadScene("Fail");
} else if (delayTime > 0)
{
delayTime -= Time.deltaTime;
}
}
```
Самый страшный метод из EventManager-а (модуль который отвечал за все события в игре - коллизию с врагом, таймаут непобедимости и пр.).
+1
//Генерация уровня из файла
void mapGenerate()
{
float x = 0.72f, y = -0.72f; //Координаты игрового объекта
byte i = 0, j = 0; //Цифровые координаты игрвоого объекта
while (y >= -5.76f)
{
while (x <= 5.76f)
{
if (map[i, j] % 8 == 1) //Если игровой объект - точка спавна игрока
{
player.transform.position = new Vector3(x, y, 0);
playerX = j;
playerY = i;
}
else if (map[i, j] % 8 == 5) //Если игровой объект - точка спавна врага
{
enemy.transform.position = new Vector3(x, y, 0);
enemyX = j;
enemyY = i;
//print("Enemy: " + enemyX + " " + enemyY);
} else if(map[i, j] % 8 == 6) //Если игровой объект - собираемый предмет
{
EventManager.Instance.colls[0]++; //Увеличивается количество собираемых монет на уровне
mapObj[i, j] = Instantiate(entities[map[i, j] % 8], new Vector3(x, y, 0), Quaternion.identity);
}
else if (map[i,j] % 8 != 0) { //Для остальных игровых объектов
mapObj[i,j] = Instantiate(entities[map[i, j] % 8], new Vector3(x, y, 0), Quaternion.identity);
}
x += 0.72f;
j++;
}
y -= 0.72f;
x = 0.72f;
j = 0;
i++;
}
}
//Считывание данных об уровне
void readLevelFile()
{
string path = "";
FileStream fs = null;
BinaryReader br = null;
if (Application.platform == RuntimePlatform.WindowsEditor)
{
path = Application.dataPath;
path = Path.Combine(path, "Levels");
path = Path.Combine(path, levelFile);
fs = new FileStream(path, FileMode.Open);
br = new BinaryReader(fs);
head = br.ReadBytes(8); //Чтение заголовка файла
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
map[i, j] = br.ReadByte(); //Чтение кода игрового объекта
}
}
br.Close();
fs.Close();
} else if (Application.platform == RuntimePlatform.Android)
{
byte[] file = null;
path = "jar:file://"+ Application.dataPath + "!/assets/Levels/"+levelFile;
www = new WWW(path);
while (!www.isDone) { }
if (!string.IsNullOrEmpty(www.error))
{
Debug.LogError("Can't read");
}
file = www.bytes;
for (int i = 0; i < 8; i++)
{
head[i] = file[i];
}
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
map[i, j] = file[j + i * 8 + 8]; //Чтение кода игрового объекта
}
}
www.Dispose();
}
Из кода собственной аркады на Unity 2017-ого года. Неоправданные байто*бские оптимизации, взаимодействие между модулями через десяток глобалов, магические константы не зафиксированные в именах кода, куча хардкода. И ето из модуля для генерации уровня. В модуле для управления событиями код страшнее.
+1
private List<CellControl[]> ComposeLines(List<CellControl[]> vertical, List<CellControl[]> horizontal)
{
List<CellControl[]> result = new List<CellControl[]>();
foreach (var vLine in vertical)
{
var cellsCount = vLine.Length;
List<CellControl[]> linesToCompose = new List<CellControl[]>();
foreach (var vCell in vLine)
{
foreach (var hLine in horizontal)
{
foreach (var hCell in hLine)
{
if (hCell.X == vCell.X && hCell.Y == vCell.Y)
{
linesToCompose.Add(hLine);
cellsCount += hLine.Length;
break;
}
}
if (linesToCompose.Count == 0)
{
result.Add(hLine);
}
}
}
if (linesToCompose.Count == 0)
{
result.Add(vLine);
}
else
{
linesToCompose.Add(vLine);
var newLine = new CellControl[cellsCount];
var i = 0;
foreach (var line in linesToCompose)
{
foreach (var cellControl in line)
{
newLine[i] = cellControl;
cellControl.Selected = true;
i++;
}
}
result.Add(newLine);
}
}
return result;
}