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