Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Exemplu OOP inventar
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Newtonsoft.Json; namespace Rextester{ public class Inventar{ //Presupunem inventar de 10x5 //Numerotat de la 1 la 50 private static int[,] items = new int[51,2]; // [posx, 0] = itmID; // [posx, 1] = itmCount; public Inventar(){ //De aici citești un fișier în care ai puse toate datele despre //iteme, cum ar fi: imagine, nume, etc, etc :)) //Poate chiar și proprietăți, depinde de ce stochezi Console.WriteLine("Obiect initializat"); } public static void setItm(int pos, int itmID, int itmCount){ items[pos,0] = itmID; items[pos,1] = itmCount; } public static void saveToFile(){ string json = JsonConvert.SerializeObject(items); //Scrii în „inventar.data” stringul json Console.WriteLine("Salvat in fisier" + json); } public static void getFromFile(){ //Iei din fișier textul //Presupunem ca apoi il salvezi in stringul json string json = "[[0,0],[5,4],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]"; Console.WriteLine("Extras din fișier"); //Îl parsezi, apoi îl salvezi string[,] deserialized = JsonConvert.DeserializeObject<string[,]>(json); for(int i=1;i<=50;i++){ setItm(i, Int32.Parse(deserialized[i,0]), Int32.Parse(deserialized[i,1])); i++; } } } public class Program{ public static void Main(string[] args){ //Your code goes here Inventar inv = new Inventar(); Inventar.setItm(1, 1, 4); Inventar.setItm(1, 3, 4); Inventar.setItm(1, 5, 4); Inventar.getFromFile(); //Inventar.saveToFile(); //Console.WriteLine(Inventar.test(1, 2)); } } }
run
|
edit
|
history
|
help
0
operatoru
Intuit // C# // listing_4.3 (StreamWriter // @"c:\Temp\output.txt")
walle
Working with Dictionaries (csharp)
SevenSevenSeven
SIN_in_Pow
Strings: Padding Integers and Handling Decimal Float Numbers
07-05-20
double to hex to double lose precision
Linked Lists