· 6 years ago · Apr 27, 2019, 06:26 PM
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using System.Data;
5using System.Data.SQLite;
6using System.Data.Common;
7using System.IO;
8using System.Collections;
9
10
11public struct Card_door_monster
12{
13 public string Name;
14 public Sprite Logo;
15 public int Level;
16 public int Level_up;
17
18 public Card_door_monster(string name, string logoPath, int level, int level_up)
19 {
20 Name = name;
21 Logo = Resources.Load<Sprite>(logoPath);
22 Level = level;
23 Level_up = level_up;
24 }
25}
26public struct Card_treasure_bonus
27{
28 public string Name;
29 public Sprite Logo;
30 public int Bonus;
31
32 public Card_treasure_bonus(string name, string logoPath, int bonus)
33 {
34 Name = name;
35 Logo = Resources.Load<Sprite>(logoPath);
36 Bonus = bonus;
37 }
38}
39
40public static class CardManager
41{
42 public static List<Card_door_monster> _Cards_door_monster = new List<Card_door_monster>();
43 public static List<Card_treasure_bonus> _Cards_treasure_bonus = new List<Card_treasure_bonus>();
44}
45
46public class CardManagerScr : MonoBehaviour
47{
48 public void Awake()
49 {
50 mysql sq = new mysql();
51 sq.sql();
52 string type;
53 string _name;
54 Sprite _logo;
55
56 int _bonus;
57 for ()
58 {
59 switch (type)
60 {
61 case "bonus":
62 {
63 CardManager._Cards_door_bonus.Add();
64 break;
65 }
66 case "monster":
67 {
68 CardManager._Cards_door_monster.Add(new Card_door_curse(_name, _logo, _level));
69 break;
70 }
71 }
72 }
73 }
74
75}
76
77public class DataBase
78{
79 private const string databaseName = "G:\project\CyberGarden2\proj\Assets\StreamingAssets\Cards.db";
80
81 static void start()
82 {
83 if (!File.Exists(databaseName))
84 {
85 createDB();
86 CreateTable();
87
88 SelectDataDoor();
89 SelectDataTresure();
90 }
91 }
92
93 static void createDB()
94 {
95 SQLiteConnection.CreateFile(databaseName);
96 }
97
98 static void CreateTable()
99 {//bonus curse monster
100 //spell super_bonus
101 SQLiteConnection connection = new SQLiteConnection("Data Source=" + databaseName);
102 SQLiteCommand command1 = new SQLiteCommand("" +
103 "CREATE TABLE IF NOT EXISTS card_door (" +
104 "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
105 "type char(100) NOT NULL," +
106 "name char(100) NOT NULL," +
107 "logo char(100) NOT NULL," +
108 "effect char(100) NOT NULL," +
109 "bonus int NOT NULL," +
110 "level int," +
111 "level_up int" +
112 ");", connection);
113
114 SQLiteCommand command2 = new SQLiteCommand("" +
115 "CREATE TABLE IF NOT EXISTS card_treasure (" +
116 "id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
117 "type char(100) NOT NULL," +
118 "name char(100) NOT NULL," +
119 "logo char(100) NOT NULL," +
120 "effect char(100) NOT NULL," +
121 "bonus int NOT NULL" +
122 ")", connection);
123
124 connection.Open();
125 command1.ExecuteNonQuery();
126 command2.ExecuteNonQuery();
127 connection.Close();
128 }
129
130 static void SelectDataDoor()
131 {
132 addCardDoor("monster", "точка Ñ Ð·Ð°Ð¿Ñтой", "", 5, 2, 0);
133 addCardDoor("aaaaa", " Ñ Ð·Ð°Ð¿Ñтой", "", 5, 2, 0);
134 addCardDoor("monster", "точка Ñ ", "", 5, 2, 0);
135 addCardDoor("monster", "точка запÑтой", "", 5, 2, 0);
136 }
137
138 static void SelectDataTresure()
139 {
140 addCardTresure("spell", "fgfdjgfd", "dfs", 0);
141 }
142
143 static void addCardDoor(string type, string name, string effect, int bonus, int level, int level_up)
144 {
145 SQLiteConnection connection = new SQLiteConnection("Data Source=" + databaseName);
146 SQLiteCommand command = new SQLiteCommand(string.Format("" +
147 "INSERT INTO card_door (type, name, logo, effect, bonus, level, level_up) " +
148 "VALUES ('{0}', '{1}', '{2}', '{3}', {4}, {5}, {6})",
149 type, name, "Sprites/Cards_door/" + name, effect, bonus, level, level_up),
150 connection);
151
152 connection.Open();
153 command.ExecuteNonQuery();
154 connection.Close();
155 }
156
157 static void addCardTresure(string type, string name, string effect, int bonus)
158 {
159 SQLiteConnection connection = new SQLiteConnection("Data Source=" + databaseName);
160 SQLiteCommand command = new SQLiteCommand(string.Format("" +
161 "INSERT INTO card_door (type, name, logo, effect, bonus) " +
162 "VALUES ('{0}', '{1}', '{2}', '{3}', {4})",
163 type, name, "Sprites/Cards_door/" + name, effect, bonus),
164 connection);
165
166 connection.Open();
167 command.ExecuteNonQuery();
168 connection.Close();
169 }
170
171 static List<Card_door_monster> getDoor(string type)
172 {
173 List<Card_door_monster> list = new List<Card_door_monster>();
174
175 SQLiteConnection connection = new SQLiteConnection("Data Source=" + databaseName);
176 SQLiteCommand command = new SQLiteCommand("SELECT * FROM card_door WHERE type='" + type + "'", connection);
177
178 connection.Open();
179 SQLiteDataReader reader = command.ExecuteReader();
180
181 foreach (DbDataRecord record in reader)
182 {
183 list.Add(new Card_door_monster(record["name"].ToString(), record["logo"].ToString(), Convert.ToInt32(record["level"]), Convert.ToInt32(record["level_up"])));
184 }
185
186 connection.Close();
187
188 return list;
189 }
190
191 static List<Card_treasure_bonus> getTreasure(string type)
192 {
193 List<Card_treasure_bonus> list = new List<Card_treasure_bonus>();
194
195 SQLiteConnection connection = new SQLiteConnection("Data Source=" + databaseName);
196 SQLiteCommand command = new SQLiteCommand("SELECT * FROM card_treasure WHERE type='" + type + "'", connection);
197
198 connection.Open();
199 SQLiteDataReader reader = command.ExecuteReader();
200
201 foreach (DbDataRecord record in reader)
202 {
203 list.Add(new Card_treasure_bonus(record["name"].ToString(), record["logo"].ToString(), Convert.ToInt32(record["bonus"])));
204 }
205
206 connection.Close();
207
208 return list;
209 }
210}