• 计设大赛作品分享


     参加计算机设计大赛团队做了两个月的游戏,拿到了国三的好成绩,下面是项目分享。

    目录

    一、游戏流程图

    场景编号:​

    二、分块剖析

    1、封面设计-场景①

    (1)思路:

    (2)技术:

    (3)代码:

    跳转到下一场景和角色移动脚本:

    2、登录与注册-②③场景

    (1)思路:

    (2)技术:

     (3)代码

    Login脚本: 

    Exit脚本:

    GameUI脚本:

     Gradualchage脚本:

     LoginJudge脚本:

    Register脚本:

     RJudge脚本:

    Confirm 脚本: 

    Return 脚本: 

     3、主菜单-场景④

    (1)思路

    (2)技术

    (3)代码

    ReturnLogin脚本:

    zhucaidan_kaishi 脚本:

    zhucaidan_openguanyu 脚本:

    zhucaidan_tuichu 脚本:

    4、剧情漫画-场景⑤

    (1)思路

    (2)技术

    (3)代码

            donghua_jindu 脚本:

    5、游戏地图-场景⑥⑦

    (1)思路

    (2)技术

    (3)代码

    play_zhuliguan 脚本:

    积分排行脚本:

    6、游戏玩法1-(场景⑧~⑫)

    (1)思路

    (2)技术

    (3)代码

    玩法设计脚本:

    7、游戏玩法2-(场景⑬~⑲)

    (1)思路

    (2)技术

    (3)代码

             玩法脚本设计:


    一、游戏流程图

    游戏的是由一个个游戏场景组成的,各个场景之间有都接口相连。

    场景编号:

    二、分块剖析

    1、封面设计-场景①

    (1)思路:

    游戏角色从右下角向左边乘船驶出,到达最左侧直到身影消失后,显示游戏封面《诗梦游记》。

     

    (2)技术:

    ①背景由美工制作。

    ②字体采用制作的字体图片完成。

    ③动画由unity动画器制作完成。

    ④跳转到下一场景和角色移动由代码完成。

    (3)代码:

    跳转到下一场景和角色移动脚本:

    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. public class fengmian_jindutiao : MonoBehaviour
    4. {
    5. public float speed;
    6. public GameObject gameobject;
    7. void Update()
    8. {
    9. transform.Translate(speed * Time.deltaTime, 0, 0);
    10. if (Input.GetKeyDown(KeyCode.Escape) /*|| Input.GetKeyDown(KeyCode.Home)*/)
    11. {
    12. SceneManager.LoadScene("Login");//build index
    13. }
    14. }
    15. void OnTriggerEnter2D(Collider2D other)
    16. {
    17. Debug.Log("下一个场景:登录界面");
    18. //切换下一个场景
    19. SceneManager.LoadScene("Login");//build index
    20. }
    21. }

    2、登录与注册-②③场景

    (1)思路:

    玩家通过注册功能注册游戏账号,返回登录界面进行登录。玩家的账号信息及密码都由服务器数据库保存,如果注册完成,直接登录即可,如果没有注册则无法登录。

    (2)技术:

    ①UI设计

    ②数据库连接

    ③登录功能(代码)

    ④注册功能(代码)

     (3)代码

    登录代码:

    Login脚本: 

    1. using MySql.Data.MySqlClient;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Data;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. using UnityEngine.SceneManagement;
    9. public class Login : MonoBehaviour
    10. {
    11. public InputField i1, i2;
    12. private bool show = true;
    13. public Text RUname;//获取用户名
    14. public string reName;
    15. public void toLogin(string s1,string s2)
    16. {
    17. //建立连接语句
    18. //charset=utf8这句要写,不然可能会报错
    19. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    20. //建立连接
    21. MySqlConnection mycon = new MySqlConnection(constr);
    22. //打开连接
    23. mycon.Open();
    24. //插入数据
    25. /*MySqlCommand mycmd = new MySqlCommand("insert into user(username,pw) values ('" + s1 + "','" + s2 + "')", mycon);
    26. if (mycmd.ExecuteNonQuery() > 0)
    27. {
    28. print("Insert success!");
    29. }*/
    30. //查询数据
    31. string selstr = "select * from peotry";
    32. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    33. MySqlDataReader reader = cmd.ExecuteReader();
    34. /*try
    35. {*/
    36. while (reader.Read())
    37. {
    38. if(reader[0].ToString() == s1 && reader[1].ToString() == s2)
    39. {
    40. Debug.Log("登陆成功进入:主菜单");
    41. i1.text = "";
    42. i2.text = "";
    43. show = false;
    44. //获取当前用户名
    45. RUname.text = s1;
    46. reName = s1;
    47. // 保存用户名数据
    48. PlayerPrefs.SetString("reName", reName);
    49. //登录成功切换场景
    50. SceneManager.LoadScene("主菜单");//build index
    51. break;
    52. }
    53. }
    54. if (show)
    55. {
    56. GameObject.Find("游戏主控").GetComponent().error();
    57. i1.text = "";
    58. i2.text = "";
    59. }
    60. //}
    61. //关闭连接
    62. mycon.Close();
    63. }
    64. }

    Exit脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. public class Exit : MonoBehaviour
    6. {
    7. // Start is called before the first frame update
    8. public void OnStartGame()
    9. {
    10. SceneManager.LoadScene(1);
    11. }
    12. public void OnExitGame()
    13. {
    14. #if UNITY_EDITOR
    15. UnityEditor.EditorApplication.isPlaying = false;
    16. #else
    17. Application.Quit();
    18. #endif
    19. }
    20. }

    GameUI脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. public class GameUI : MonoBehaviour
    6. {
    7. public Image image1;
    8. public Image image2;
    9. // Start is called before the first frame update
    10. void Start()
    11. {
    12. image1.transform.position = new Vector3(1000, 1000, 0);
    13. image2.transform.position = new Vector3(1000, 1000, 0);
    14. }
    15. // Update is called once per frame
    16. void Update()
    17. {
    18. }
    19. public void onExit()
    20. {
    21. image1.transform.position = new Vector3(0, 0, 0);
    22. GameObject.Find("退出按钮").GetComponent
    23. GameObject.Find("关于按钮").GetComponent
    24. }
    25. public void cancel1()
    26. {
    27. image1.transform.position = new Vector3(1000,1000,0);
    28. GameObject.Find("退出按钮").GetComponent
    29. GameObject.Find("关于按钮").GetComponent
    30. }
    31. public void cancel2()
    32. {
    33. image2.transform.position = new Vector3(1000, 1000, 0);
    34. GameObject.Find("退出按钮").GetComponent
    35. GameObject.Find("关于按钮").GetComponent
    36. }
    37. public void error()
    38. {
    39. image2.transform.position = new Vector3(0, 0, 0);
    40. GameObject.Find("退出按钮").GetComponent
    41. GameObject.Find("关于按钮").GetComponent
    42. }
    43. }

     Gradualchage脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. public class Gradualchange : MonoBehaviour
    7. {
    8. public Image image;
    9. public float showTime = 2.50f;//规定的显示时间
    10. public float ShowTimeTrigger = 0;//显示的实时时间
    11. public float fadeTime = 2;//规定的消失时间
    12. public float fadeTimeTrigger = 0;//消失的实时时间
    13. private bool show = true;
    14. private bool turn = true;
    15. // Update is called once per frame
    16. void Update()
    17. {
    18. if (turn)
    19. {
    20. ShowTimeTrigger += Time.deltaTime;
    21. if (ShowTimeTrigger > showTime)
    22. {
    23. if (fadeTimeTrigger >= 0 && fadeTimeTrigger < fadeTime)
    24. {
    25. fadeTimeTrigger += Time.deltaTime;
    26. if (show)
    27. {
    28. image.color = new Color(1, 1, 1, 1 - (fadeTimeTrigger / fadeTime));
    29. }
    30. else
    31. {
    32. image.color = new Color(1, 1, 1, (fadeTimeTrigger / fadeTime));
    33. }
    34. }
    35. else
    36. {
    37. SceneManager.LoadScene("Login");
    38. turn = false;
    39. }
    40. }
    41. }
    42. }
    43. }

     LoginJudge脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. public class LoginJudge : MonoBehaviour
    6. {
    7. public InputField i1,i2;
    8. private string s1, s2;
    9. private int count = 0;
    10. private bool show = true;
    11. // Start is called before the first frame update
    12. public void Jugde()
    13. {
    14. show = true;
    15. s1 = i1.text;
    16. s2 = i2.text;
    17. for(int i = 0;i < s2.Length; i++)
    18. {
    19. count++;
    20. }
    21. if(count < 6)
    22. {
    23. GameObject.Find("游戏主控").GetComponent().error();
    24. i1.text = "";
    25. i2.text = "";
    26. show = false;
    27. }
    28. count = 0;
    29. if (show)
    30. {
    31. GameObject.Find("游戏主控").GetComponent().toLogin(s1, s2);
    32. }
    33. }
    34. }

    Register脚本:

    1. using MySql.Data.MySqlClient;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Data;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. using UnityEngine.SceneManagement;
    9. public class Register : MonoBehaviour
    10. {
    11. public void change()
    12. {
    13. SceneManager.LoadScene("Register");
    14. }
    15. }

    注册代码:

     RJudge脚本:

    1. using MySql.Data.MySqlClient;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Data;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. public class RJudge : MonoBehaviour
    9. {
    10. public InputField i1, i2, i3;
    11. public Image m1, m2, m3, m4;
    12. private string s1, s2, s3,sco;
    13. private bool show = true;
    14. private int score = 0;
    15. // Start is called before the first frame update
    16. void Start()
    17. {
    18. m1.transform.position = new Vector3(1000, 1000, 0);
    19. m2.transform.position = new Vector3(1000, 1000, 0);
    20. m3.transform.position = new Vector3(1000, 1000, 0);
    21. m4.transform.position = new Vector3(1000, 1000, 0);
    22. }
    23. public void registerjudge()
    24. {
    25. show = true;
    26. s1 = i1.text;
    27. s2 = i2.text;
    28. s3 = i3.text;
    29. sco = score.ToString();
    30. if(s1 == "")
    31. {
    32. GameObject.Find("注册按钮").GetComponent
    33. m4.transform.position = new Vector3(0, 0, 0);
    34. show = false;
    35. }
    36. if (show)
    37. {
    38. if (s2 != s3 || s2.Length < 6 || s3.Length < 6)
    39. {
    40. GameObject.Find("注册按钮").GetComponent
    41. m1.transform.position = new Vector3(0, 0, 0);
    42. show = false;
    43. }
    44. }
    45. if (show)
    46. {
    47. //建立连接语句
    48. //charset=utf8这句要写,不然可能会报错
    49. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    50. //建立连接
    51. MySqlConnection mycon = new MySqlConnection(constr);
    52. //打开连接
    53. mycon.Open();
    54. GameObject.Find("注册按钮").GetComponent
    55. /*try
    56. {
    57. MySqlCommand mycmd = new MySqlCommand("insert into 表(username,pw) values ('" + s1 + "','" + s2 + "')", mycon);
    58. if (mycmd.ExecuteNonQuery() > 0)
    59. {
    60. print("Insert success!");
    61. }
    62. m2.transform.position = new Vector3(0, 0, 0);
    63. }
    64. catch (Exception e)
    65. {
    66. m3.transform.position = new Vector3(0, 0, 0);
    67. }*/
    68. string selstr = "select * from 表";
    69. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    70. MySqlDataReader reader = cmd.ExecuteReader();
    71. bool judge = true;
    72. while (reader.Read())
    73. {
    74. if (reader[0].ToString() == s1)
    75. {
    76. m3.transform.position = new Vector3(0, 0, 0);
    77. judge = false;
    78. }
    79. }
    80. reader.Close();
    81. cmd.Clone();
    82. if (judge)
    83. {
    84. MySqlCommand mycmd = new MySqlCommand("insert into 表(username,pw,score) values ('" + s1 + "','" + s2 + "','" + score + "')", mycon);
    85. if (mycmd.ExecuteNonQuery() > 0)
    86. {
    87. print("Insert success!");
    88. }
    89. m2.transform.position = new Vector3(0, 0, 0);
    90. }
    91. mycon.Close();
    92. }
    93. }
    94. }

    Confirm 脚本: 

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. public class Confirm : MonoBehaviour
    7. {
    8. public InputField i1, i2, i3;
    9. public Image m1, m2, m3, m4;
    10. public void confirm1()
    11. {
    12. GameObject.Find("注册按钮").GetComponent
    13. m1.transform.position = new Vector3(1000, 1000, 0);
    14. i1.text = "";
    15. i2.text = "";
    16. i3.text = "";
    17. }
    18. public void confirm2()
    19. {
    20. GameObject.Find("注册按钮").GetComponent
    21. m2.transform.position = new Vector3(1000, 1000, 0);
    22. SceneManager.LoadScene("Login");
    23. }
    24. public void confirm3()
    25. {
    26. GameObject.Find("注册按钮").GetComponent
    27. m3.transform.position = new Vector3(1000, 1000, 0);
    28. i2.text = "";
    29. i3.text = "";
    30. }
    31. public void confirm4()
    32. {
    33. i2.text = "";
    34. i3.text = "";
    35. GameObject.Find("注册按钮").GetComponent
    36. m4.transform.position = new Vector3(1000, 1000, 0);
    37. }
    38. }

    Return 脚本: 

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. public class Return : MonoBehaviour
    6. {
    7. public void returnLogin()
    8. {
    9. SceneManager.LoadScene("Login");
    10. }
    11. }

     3、主菜单-场景④

    (1)思路

            实现四个按钮:一是左上角的返回登录按钮,二是游戏开始按钮,三是游戏关于按钮,四是游戏退出按钮。

    (2)技术

           ① UI设计

           ②按钮功能代码

    (3)代码

    返回登录界面:

    ReturnLogin脚本:

    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. public class zhucaidan_fanhuidenglu : MonoBehaviour
    4. {
    5. public void ReturnLogin()
    6. {
    7. SceneManager.LoadScene("Login");//build index
    8. }
    9. }

     开始按钮:

    zhucaidan_kaishi 脚本:

    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.SceneManagement;
    4. public class zhucaidan_kaishi : MonoBehaviour
    5. {
    6. public void Kaishi()
    7. {
    8. Debug.Log("进入场景:漫画");
    9. SceneManager.LoadScene("manhua");//build index
    10. }
    11. }

     关于按钮:

    zhucaidan_openguanyu 脚本:

    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. public class zhucaidan_openguanyu : MonoBehaviour
    4. {
    5. public GameObject guyuPanel;
    6. public void OpenGuanYu()
    7. {
    8. guyuPanel.SetActive(true);
    9. }
    10. }

     退出按钮:

    zhucaidan_tuichu 脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5. public class zhucaidan_tuichu : MonoBehaviour
    6. {
    7. public void OnExitGame()
    8. {
    9. #if UNITY_EDITOR
    10. UnityEditor.EditorApplication.isPlaying = false;
    11. #else
    12. Application.Quit();
    13. #endif
    14. }
    15. }

    4、剧情漫画-场景⑤

    (1)思路

            加载场景动画,一共三页,每页的内容由动画器制作,页面间的跳转由代码控制。

    (2)技术

            ①漫画制作

            ②控制脚本

    (3)代码

            控制漫画进度代码:

            donghua_jindu 脚本:

    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.SceneManagement;
    4. public class donghua_jindu : MonoBehaviour
    5. {
    6. public GameObject panel_1;
    7. public GameObject panel_2;
    8. public GameObject panel_3;
    9. public GameObject page1;
    10. public GameObject page2;
    11. public GameObject page3;
    12. public float speed;
    13. void Update()
    14. {
    15. transform.position += new Vector3(speed * Time.deltaTime, 0, 0);
    16. if (Input.GetKeyDown(KeyCode.Escape) /*|| Input.GetKeyDown(KeyCode.Home)*/)
    17. {
    18. //加载场景
    19. SceneManager.LoadScene("诗梦秘境");//build index
    20. }
    21. }
    22. private void OnTriggerEnter2D(Collider2D other)
    23. {
    24. if (other.tag == "page_1")
    25. {
    26. panel_1.SetActive(false);
    27. panel_2.SetActive(true);
    28. }
    29. else if (other.tag == "page_2")
    30. {
    31. panel_2.SetActive(false);
    32. panel_3.SetActive(true);
    33. }
    34. else if (other.tag == "page_3")
    35. {
    36. panel_3.SetActive(true);
    37. //加载场景
    38. SceneManager.LoadScene("诗梦秘境");//build index
    39. transform.position = new Vector3(-10, -8, 0);
    40. }
    41. }
    42. }

    5、游戏地图-场景⑥⑦

    (1)思路

            实现关卡的进入与地图的转换还有积分排行功能。

    (2)技术

            ①美工设计

            ②功能实现

     

    (3)代码

    进入游戏代码:

    play_zhuliguan 脚本:

    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.SceneManagement;
    4. public class play_zhuliguan : MonoBehaviour
    5. {
    6. public void Play_ZLG()
    7. {
    8. Debug.Log("进入游戏:竹里馆");
    9. SceneManager.LoadScene("竹里馆");//build index
    10. }
    11. }

    积分排行脚本:

    1. using MySql.Data.MySqlClient;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Data;
    6. using UnityEngine;
    7. using UnityEngine.UI;
    8. public class paihangbang_duquAndxianshi : MonoBehaviour
    9. {
    10. public GameObject PaiMing;
    11. //private List s = new List();
    12. public Text userName_And_userScore;
    13. private string texts;
    14. public void OpenPaiHangbang()
    15. {
    16. PaiMing.SetActive(true);
    17. }
    18. public void ReadScore()
    19. {
    20. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    21. //建立连接
    22. MySqlConnection mycon = new MySqlConnection(constr);
    23. //打开连接
    24. mycon.Open();
    25. //读取数据
    26. string selstr = "select * from 表";
    27. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    28. MySqlDataReader reader = cmd.ExecuteReader();
    29. string temp1;
    30. string temp2;
    31. List s = new List();
    32. while (reader.Read())
    33. {
    34. temp1 = reader[0].ToString();//用户名
    35. temp2 = reader[2].ToString();//得分
    36. s.Add(new user(temp1, int.Parse(temp2)));
    37. }
    38. s.Sort((x, y) => { return -x.score.CompareTo(y.score); });//升序排序
    39. texts = " ";
    40. for (int i = 0; i < s.Count; i++)
    41. {
    42. //Debug.Log(s[i].score + " " + s[i].username);//打印用户名及分数
    43. //userName_And_userScore.text = (s[i].score + " " + s[i].username).ToString();
    44. //userName_And_userScore.Add((s[i].score + " " + s[i].username).ToString());
    45. texts += ((i + 1).ToString() + "\t用户名: " + s[i].username + "\t" + " 总得分: " + s[i].score + " 分").ToString();
    46. texts += '\n';
    47. texts += '\n';
    48. }
    49. userName_And_userScore.text = texts;
    50. mycon.Close();
    51. }
    52. public class user
    53. {
    54. public string username;
    55. public int score;
    56. public user(string username, int score)
    57. {
    58. this.username = username;
    59. this.score = score;
    60. }
    61. }
    62. }

    6、游戏玩法1-(场景⑧~⑫)

    (1)思路

            第一个关卡地图里都是五言诗,所以玩法是一轮点击五次,若五次能连成一句诗则消除此句,直到将整首诗消除即可通关。

    (2)技术

            ①玩法设计

            ②美工设计

    (3)代码

    玩法设计脚本:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. //数据库连接
    7. using MySql.Data.MySqlClient;
    8. using System.Data;
    9. //using System;
    10. public class jinagxue_play : MonoBehaviour
    11. {
    12. //小关排名
    13. public Text Name_And_Score;
    14. private string texts;
    15. //获取当前用户名
    16. private string recentUsername;//当前用户名
    17. public GameObject TongguanUI;
    18. public Sprite[] gameWords;//汉字图片数组
    19. public List
    20. public List hudie = new List();//将所有蝴蝶存入列表
    21. public List words = new List();//将古诗汉字存入列表
    22. //新玩法:一次点五下!!!
    23. private bool firstGuess, secondGuess, thirdGuess, forthGuess, fifthGuess;
    24. private int firstGuess_Index, secondGuess_Index, thirdGuess_Index, forthGuess_Index, fifthGuess_Index;//按钮索引
    25. private int firstGuess_Word, secondGuess_Word, thirdGuess_Word, forthGuess_Word, fifthGuess_Word;//汉字索引
    26. private int countGuess;//点击次数
    27. private int countCorrectGuess;//点击正确次数
    28. private int gameGuess;
    29. //游戏计时
    30. //已经花费的时间
    31. float timeSpeed = 0.0f;
    32. public Text timeText;
    33. //随机显示答案
    34. public Image AnswerImage;
    35. public Text anserText;
    36. void Awake()
    37. {
    38. gameWords = Resources.LoadAll("江雪/诗句");
    39. }
    40. void Start()
    41. {
    42. TongguanUI.SetActive(false);
    43. GetButtons();//获取按钮组件
    44. AddSprite();//将资源文件下的图片填入图片列表
    45. Shuffle(words);//图片随机排列函数
    46. AddListeners();//为按钮组件添加事件监听器
    47. gameGuess = 4;//5句诗
    48. //showAnser();
    49. }
    50. void Update()//更新游戏时间
    51. {
    52. timeSpeed += Time.deltaTime;
    53. if (Input.GetKeyDown(KeyCode.Escape) /*|| Input.GetKeyDown(KeyCode.Home)*/)
    54. {
    55. SceneManager.LoadScene("诗梦秘境");//build index
    56. }
    57. }
    58. void GetButtons()//添加按钮组件
    59. {
    60. GameObject[] objects = GameObject.FindGameObjectsWithTag("GameButton");
    61. GameObject[] hudies = GameObject.FindGameObjectsWithTag("HuDie");
    62. for (int i = 0; i < objects.Length; i++)
    63. {
    64. btns.Add(objects[i].GetComponent
    65. hudie.Add(hudies[i].GetComponent());
    66. }
    67. }
    68. void AddListeners()//添加按钮监听器
    69. {
    70. foreach (Button btn in btns)
    71. {
    72. btn.onClick.AddListener(() => PickUpButtons());//lambda表达式
    73. }
    74. }
    75. void PickUpButtons()//按钮响应事件
    76. {
    77. if (!firstGuess)
    78. {
    79. firstGuess = true;
    80. firstGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    81. firstGuess_Word = int.Parse(words[firstGuess_Index].name);//获取按钮组件的image序号
    82. //关闭此处的蝴蝶图层,显示汉字
    83. hudie[firstGuess_Index].color = new Color(255, 255, 255, 0);
    84. btns[firstGuess_Index].image.sprite = words[firstGuess_Index];
    85. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 255);
    86. //Debug.Log(firstGuess_Word);
    87. }
    88. else if (!secondGuess)
    89. {
    90. secondGuess = true;
    91. secondGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    92. secondGuess_Word = int.Parse(words[secondGuess_Index].name);//此处的汉字序号
    93. //关闭此处的蝴蝶图层,显示汉字
    94. hudie[secondGuess_Index].color = new Color(255, 255, 255, 0);
    95. btns[secondGuess_Index].image.sprite = words[secondGuess_Index];
    96. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 255);
    97. //Debug.Log(secondGuess_Word);
    98. }
    99. else if (!thirdGuess)
    100. {
    101. thirdGuess = true;
    102. thirdGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    103. thirdGuess_Word = int.Parse(words[thirdGuess_Index].name);//此处的汉字序号
    104. //关闭此处的蝴蝶图层,显示汉字
    105. hudie[thirdGuess_Index].color = new Color(255, 255, 255, 0);
    106. btns[thirdGuess_Index].image.sprite = words[thirdGuess_Index];
    107. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 255);
    108. //Debug.Log(thirdGuess_Word);
    109. }
    110. else if (!forthGuess)
    111. {
    112. forthGuess = true;
    113. forthGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    114. forthGuess_Word = int.Parse(words[forthGuess_Index].name);//此处的汉字序号
    115. //关闭此处的蝴蝶图层,显示汉字
    116. hudie[forthGuess_Index].color = new Color(255, 255, 255, 0);
    117. btns[forthGuess_Index].image.sprite = words[forthGuess_Index];
    118. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 255);
    119. //Debug.Log(forthGuess_Word);
    120. }
    121. else if (!fifthGuess)
    122. {
    123. fifthGuess = true;
    124. fifthGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    125. fifthGuess_Word = int.Parse(words[fifthGuess_Index].name);//此处的汉字序号
    126. //关闭此处的蝴蝶图层,显示汉字
    127. hudie[fifthGuess_Index].color = new Color(255, 255, 255, 0);
    128. btns[fifthGuess_Index].image.sprite = words[fifthGuess_Index];
    129. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 255);
    130. //Debug.Log(fifthGuess_Word);
    131. StartCoroutine(CheckIfThePuzzleMatch());
    132. }
    133. }
    134. IEnumerator CheckIfThePuzzleMatch()
    135. {
    136. yield return new WaitForSeconds(1f);
    137. if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word == 10)
    138. &&(firstGuess_Word>=0&&firstGuess_Word<=4) && (secondGuess_Word >= 0 && secondGuess_Word <= 4)
    139. && (thirdGuess_Word >= 0 && thirdGuess_Word <= 4) && (forthGuess_Word >= 0 && forthGuess_Word <= 4)
    140. && (fifthGuess_Word >= 0 && fifthGuess_Word <= 4))
    141. {
    142. yield return new WaitForSeconds(.5f);
    143. Debug.Log("第一行结束");//0~4
    144. btns[firstGuess_Index].interactable = false;
    145. btns[secondGuess_Index].interactable = false;
    146. btns[thirdGuess_Index].interactable = false;
    147. btns[forthGuess_Index].interactable = false;
    148. btns[fifthGuess_Index].interactable = false;
    149. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    150. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    151. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    152. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    153. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    154. CheckIfTheGameIsFinished();
    155. }
    156. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word == 35)
    157. && (firstGuess_Word >= 5 && firstGuess_Word <= 9) && (secondGuess_Word >= 5 && secondGuess_Word <= 9)
    158. && (thirdGuess_Word >= 5 && thirdGuess_Word <= 9) && (forthGuess_Word >= 5 && forthGuess_Word <= 9)
    159. && (fifthGuess_Word >= 5 && fifthGuess_Word <= 9))
    160. {
    161. yield return new WaitForSeconds(.5f);
    162. Debug.Log("第二行结束");//5~9
    163. btns[firstGuess_Index].interactable = false;
    164. btns[secondGuess_Index].interactable = false;
    165. btns[thirdGuess_Index].interactable = false;
    166. btns[forthGuess_Index].interactable = false;
    167. btns[fifthGuess_Index].interactable = false;
    168. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    169. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    170. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    171. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    172. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    173. CheckIfTheGameIsFinished();
    174. }
    175. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word == 60)
    176. && (firstGuess_Word >= 10 && firstGuess_Word <= 14) && (secondGuess_Word >= 10 && secondGuess_Word <= 14)
    177. && (thirdGuess_Word >= 10 && thirdGuess_Word <= 14) && (forthGuess_Word >= 10 && forthGuess_Word <= 14)
    178. && (fifthGuess_Word >= 10 && fifthGuess_Word <= 14))
    179. {
    180. yield return new WaitForSeconds(.5f);
    181. Debug.Log("第三行结束");//10~14:10\11\12\13\14
    182. btns[firstGuess_Index].interactable = false;
    183. btns[secondGuess_Index].interactable = false;
    184. btns[thirdGuess_Index].interactable = false;
    185. btns[forthGuess_Index].interactable = false;
    186. btns[fifthGuess_Index].interactable = false;
    187. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    188. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    189. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    190. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    191. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    192. CheckIfTheGameIsFinished();
    193. }
    194. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word == 85)
    195. && (firstGuess_Word >= 15 && firstGuess_Word <= 19) && (secondGuess_Word >= 15 && secondGuess_Word <= 19)
    196. && (thirdGuess_Word >= 15 && thirdGuess_Word <= 19) && (forthGuess_Word >= 15 && forthGuess_Word <= 19)
    197. && (fifthGuess_Word >= 15 && fifthGuess_Word <= 19))
    198. {
    199. yield return new WaitForSeconds(.5f);
    200. Debug.Log("第四行结束");//15~19; 15\16\17\18\19
    201. btns[firstGuess_Index].interactable = false;
    202. btns[secondGuess_Index].interactable = false;
    203. btns[thirdGuess_Index].interactable = false;
    204. btns[forthGuess_Index].interactable = false;
    205. btns[fifthGuess_Index].interactable = false;
    206. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    207. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    208. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    209. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    210. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    211. CheckIfTheGameIsFinished();
    212. }
    213. else
    214. {
    215. yield return new WaitForSeconds(.5f);
    216. //开启蝴蝶图层
    217. hudie[firstGuess_Index].color = new Color(255, 255, 255, 200);
    218. hudie[secondGuess_Index].color = new Color(255, 255, 255, 200);
    219. hudie[thirdGuess_Index].color = new Color(255, 255, 255, 200);
    220. hudie[forthGuess_Index].color = new Color(255, 255, 255, 200);
    221. hudie[fifthGuess_Index].color = new Color(255, 255, 255, 200);
    222. btns[firstGuess_Index].image.sprite = words[firstGuess_Index];
    223. btns[secondGuess_Index].image.sprite = words[secondGuess_Index];
    224. btns[thirdGuess_Index].image.sprite = words[thirdGuess_Index];
    225. btns[forthGuess_Index].image.sprite = words[forthGuess_Index];
    226. btns[fifthGuess_Index].image.sprite = words[fifthGuess_Index];
    227. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    228. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    229. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    230. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    231. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    232. Debug.Log("还原");
    233. }
    234. yield return new WaitForSeconds(.5f);
    235. firstGuess = secondGuess = thirdGuess = forthGuess = fifthGuess = false;
    236. }
    237. //返回时间函数
    238. public float returnTime()
    239. {
    240. return timeSpeed;
    241. }
    242. void CheckIfTheGameIsFinished()
    243. {
    244. countCorrectGuess++;
    245. if (countCorrectGuess == gameGuess)
    246. {
    247. TongguanUI.SetActive(true);
    248. Debug.Log("game finished");
    249. Time.timeScale = 0;
    250. //更改玩家得分
    251. UpDateScore();
    252. //进行小关排名
    253. GamePaiMing();
    254. Debug.Log(timeSpeed.ToString("0"));
    255. timeText.text = timeSpeed.ToString("0");
    256. Time.timeScale = 1;
    257. }
    258. }
    259. public void UpDateScore()
    260. {
    261. recentUsername = PlayerPrefs.GetString("reName");
    262. Debug.Log(recentUsername);
    263. //建立连接语句
    264. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    265. //建立连接
    266. MySqlConnection mycon = new MySqlConnection(constr);
    267. //打开连接
    268. mycon.Open();
    269. //获取最后一个用户的用户名
    270. //float timeScore = timeSpeed;
    271. //得到score变化后的值用代码表示为t1.text 该用户的用户名为u1
    272. string selstr = "update 表set score=score+1 where username='"+recentUsername+"'";// + t1.text + "where username = u1";
    273. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    274. if (cmd.ExecuteNonQuery() > 0)
    275. {
    276. print("Insert success!");
    277. }
    278. //小关得分
    279. int flag = 1;
    280. if(timeSpeed >= 250)
    281. {
    282. flag = 0;//如果分数大于250秒则不计入小关排行榜
    283. }
    284. if(flag == 1)
    285. {
    286. string selstr_p1 = "update 表set p1='" + timeSpeed + "'where username='" + recentUsername + "' and p1 = 0 or username='" + recentUsername + "' and p1 > '" + timeSpeed + "'";//取最好成绩
    287. MySqlCommand cmd_p1 = new MySqlCommand(selstr_p1, mycon);
    288. if(cmd_p1.ExecuteNonQuery() > 0)
    289. {
    290. print("Insert success!");
    291. }
    292. }
    293. mycon.Close();
    294. }
    295. void GamePaiMing()
    296. {
    297. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    298. //建立连接
    299. MySqlConnection mycon = new MySqlConnection(constr);
    300. //打开连接
    301. mycon.Open();
    302. //读取数据
    303. string selstr = "select * from peotry where p1<>0";//注意零分不计入排名
    304. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    305. MySqlDataReader reader = cmd.ExecuteReader();
    306. string temp1;
    307. string temp2;
    308. List s = new List();
    309. while (reader.Read())
    310. {
    311. temp1 = reader[0].ToString();//用户名
    312. temp2 = reader[3].ToString();//p1得分
    313. s.Add(new user(temp1, int.Parse(temp2)));
    314. }
    315. s.Sort((x, y) => { return x.score.CompareTo(y.score); });//升序排序
    316. texts = " ";
    317. for (int i = 0; i < s.Count; i++)
    318. {
    319. texts += ((i + 1).ToString() + "\t用户名: " + s[i].username + "\t" + " 通关用时: " + s[i].score + " 秒").ToString();
    320. texts += '\n';
    321. texts += '\n';
    322. }
    323. Name_And_Score.text = texts;
    324. mycon.Close();
    325. }
    326. public class user
    327. {
    328. public string username;
    329. public int score;
    330. public user(string username, int score)
    331. {
    332. this.username = username;
    333. this.score = score;
    334. }
    335. }
    336. void AddSprite()//将汉字图片加入汉字图片列表
    337. {
    338. int n = btns.Count;//按钮数
    339. for (int i = 0; i < n; i++)
    340. {
    341. words.Add(gameWords[i]);
    342. }
    343. }
    344. void Shuffle(List list)//图片随机排序
    345. {
    346. for (int i = 0; i < list.Count; i++)
    347. {
    348. Sprite temp = list[i];
    349. int randomIndex = Random.Range(i, list.Count);
    350. list[i] = list[randomIndex];
    351. list[randomIndex] = temp;
    352. }
    353. }
    354. public void showAnser()
    355. {
    356. int temp = Random.Range(0, words.Count);
    357. AnswerImage.sprite = words[temp];
    358. anserText.text = (temp+1).ToString();
    359. }
    360. }

    7、游戏玩法2-(场景⑬~⑲)

    (1)思路

              第二个关卡地图里都是七言诗,所以玩法是一轮点击七次,若七次能连成一句诗则消除此句,直到将整首诗消除即可通关。

    (2)技术

                ①玩法设计

                ②美工设计

    (3)代码

             玩法脚本设计:

    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. //数据库连接
    7. using MySql.Data.MySqlClient;
    8. using System.Data;
    9. //using System;
    10. public class chunxue_play : MonoBehaviour
    11. {
    12. //小关排名
    13. public Text Name_And_Score;
    14. private string texts;
    15. //获取当前用户名
    16. private string recentUsername;//当前用户名
    17. public GameObject TongguanUI;
    18. public Sprite[] gameWords;//汉字图片数组
    19. public List
    20. public List hudie = new List();//将所有蝴蝶存入列表
    21. public List words = new List();//将古诗汉字存入列表
    22. //新玩法:一次点七下!!!
    23. private bool firstGuess, secondGuess, thirdGuess, forthGuess, fifthGuess, sixthGuess, seventhGuess;
    24. private int firstGuess_Index, secondGuess_Index, thirdGuess_Index, forthGuess_Index, fifthGuess_Index, sixthGuess_Index, seventhGuess_Index;//按钮索引
    25. private int firstGuess_Word, secondGuess_Word, thirdGuess_Word, forthGuess_Word, fifthGuess_Word, sixthGuess_Word, seventhGuess_Word;//汉字索引
    26. private int countGuess;//点击次数
    27. private int countCorrectGuess;//点击正确次数
    28. private int gameGuess;
    29. //游戏计时
    30. //已经花费的时间
    31. float timeSpeed = 0.0f;
    32. public Text timeText;
    33. //随机显示答案
    34. public Image AnswerImage1;
    35. public Image AnswerImage2;
    36. public Image AnswerImage3;
    37. public Text anserText1;
    38. public Text anserText2;
    39. public Text anserText3;
    40. void Awake()
    41. {
    42. gameWords = Resources.LoadAll("春雪/诗句");
    43. }
    44. void Start()
    45. {
    46. TongguanUI.SetActive(false);
    47. GetButtons();//获取按钮组件
    48. AddSprite();//将资源文件下的图片填入图片列表
    49. Shuffle(words);//图片随机排列函数
    50. AddListeners();//为按钮组件添加事件监听器
    51. gameGuess = 4;//4句诗
    52. //showAnser();
    53. }
    54. void Update()//更新游戏时间
    55. {
    56. timeSpeed += Time.deltaTime;
    57. if (Input.GetKeyDown(KeyCode.Escape) /*|| Input.GetKeyDown(KeyCode.Home)*/)
    58. {
    59. Debug.Log("强制退出!");
    60. SceneManager.LoadScene("诗梦秘境续");//build index
    61. }
    62. }
    63. void GetButtons()//添加按钮组件
    64. {
    65. GameObject[] objects = GameObject.FindGameObjectsWithTag("GameButton");
    66. GameObject[] hudies = GameObject.FindGameObjectsWithTag("HuDie");
    67. for (int i = 0; i < objects.Length; i++)
    68. {
    69. btns.Add(objects[i].GetComponent
    70. hudie.Add(hudies[i].GetComponent());
    71. }
    72. }
    73. void AddListeners()//添加按钮监听器
    74. {
    75. foreach (Button btn in btns)
    76. {
    77. btn.onClick.AddListener(() => PickUpButtons());//lambda表达式
    78. }
    79. }
    80. void PickUpButtons()//按钮响应事件
    81. {
    82. if (!firstGuess)
    83. {
    84. firstGuess = true;
    85. firstGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    86. firstGuess_Word = int.Parse(words[firstGuess_Index].name);//获取按钮组件的image序号
    87. //关闭此处的蝴蝶图层,显示汉字
    88. hudie[firstGuess_Index].color = new Color(255, 255, 255, 0);
    89. btns[firstGuess_Index].image.sprite = words[firstGuess_Index];
    90. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 255);
    91. //Debug.Log(firstGuess_Word);
    92. }
    93. else if (!secondGuess)
    94. {
    95. secondGuess = true;
    96. secondGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    97. secondGuess_Word = int.Parse(words[secondGuess_Index].name);//此处的汉字序号
    98. //关闭此处的蝴蝶图层,显示汉字
    99. hudie[secondGuess_Index].color = new Color(255, 255, 255, 0);
    100. btns[secondGuess_Index].image.sprite = words[secondGuess_Index];
    101. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 255);
    102. //Debug.Log(secondGuess_Word);
    103. }
    104. else if (!thirdGuess)
    105. {
    106. thirdGuess = true;
    107. thirdGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    108. thirdGuess_Word = int.Parse(words[thirdGuess_Index].name);//此处的汉字序号
    109. //关闭此处的蝴蝶图层,显示汉字
    110. hudie[thirdGuess_Index].color = new Color(255, 255, 255, 0);
    111. btns[thirdGuess_Index].image.sprite = words[thirdGuess_Index];
    112. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 255);
    113. //Debug.Log(thirdGuess_Word);
    114. }
    115. else if (!forthGuess)
    116. {
    117. forthGuess = true;
    118. forthGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    119. forthGuess_Word = int.Parse(words[forthGuess_Index].name);//此处的汉字序号
    120. //关闭此处的蝴蝶图层,显示汉字
    121. hudie[forthGuess_Index].color = new Color(255, 255, 255, 0);
    122. btns[forthGuess_Index].image.sprite = words[forthGuess_Index];
    123. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 255);
    124. //Debug.Log(forthGuess_Word);
    125. }
    126. else if (!fifthGuess)
    127. {
    128. fifthGuess = true;
    129. fifthGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    130. fifthGuess_Word = int.Parse(words[fifthGuess_Index].name);//此处的汉字序号
    131. //关闭此处的蝴蝶图层,显示汉字
    132. hudie[fifthGuess_Index].color = new Color(255, 255, 255, 0);
    133. btns[fifthGuess_Index].image.sprite = words[fifthGuess_Index];
    134. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 255);
    135. //Debug.Log(fifthGuess_Word);
    136. }
    137. else if (!sixthGuess)
    138. {
    139. sixthGuess = true;
    140. sixthGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    141. sixthGuess_Word = int.Parse(words[sixthGuess_Index].name);//此处的汉字序号
    142. //关闭此处的蝴蝶图层,显示汉字
    143. hudie[sixthGuess_Index].color = new Color(255, 255, 255, 0);
    144. btns[sixthGuess_Index].image.sprite = words[sixthGuess_Index];
    145. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 255);
    146. //Debug.Log(forthGuess_Word);
    147. }
    148. else if (!seventhGuess)
    149. {
    150. seventhGuess = true;
    151. seventhGuess_Index = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);//获取按钮序号
    152. seventhGuess_Word = int.Parse(words[seventhGuess_Index].name);//此处的汉字序号
    153. //关闭此处的蝴蝶图层,显示汉字
    154. hudie[seventhGuess_Index].color = new Color(255, 255, 255, 0);
    155. btns[seventhGuess_Index].image.sprite = words[seventhGuess_Index];
    156. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 255);
    157. //Debug.Log(fifthGuess_Word);
    158. StartCoroutine(CheckIfThePuzzleMatch());
    159. }
    160. }
    161. IEnumerator CheckIfThePuzzleMatch()
    162. {
    163. yield return new WaitForSeconds(1f);
    164. if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word+ sixthGuess_Word+ seventhGuess_Word == 21)
    165. &&(firstGuess_Word>=0&&firstGuess_Word<=6) && (secondGuess_Word >= 0 && secondGuess_Word <= 6)
    166. && (thirdGuess_Word >= 0 && thirdGuess_Word <= 6) && (forthGuess_Word >= 0 && forthGuess_Word <= 6)
    167. && (fifthGuess_Word >= 0 && fifthGuess_Word <= 6) && (sixthGuess_Word >= 0 && sixthGuess_Word <= 6)
    168. && (seventhGuess_Word >= 0 && seventhGuess_Word <= 6))
    169. {
    170. yield return new WaitForSeconds(.5f);
    171. Debug.Log("第一行结束");//0~4
    172. btns[firstGuess_Index].interactable = false;
    173. btns[secondGuess_Index].interactable = false;
    174. btns[thirdGuess_Index].interactable = false;
    175. btns[forthGuess_Index].interactable = false;
    176. btns[fifthGuess_Index].interactable = false;
    177. btns[sixthGuess_Index].interactable = false;
    178. btns[seventhGuess_Index].interactable = false;
    179. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    180. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    181. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    182. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    183. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    184. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 0);
    185. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 0);
    186. CheckIfTheGameIsFinished();
    187. }
    188. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word + sixthGuess_Word + seventhGuess_Word == 70)
    189. && (firstGuess_Word >= 7 && firstGuess_Word <= 13) && (secondGuess_Word >= 7 && secondGuess_Word <= 13)
    190. && (thirdGuess_Word >= 7 && thirdGuess_Word <= 13) && (forthGuess_Word >= 7 && forthGuess_Word <= 13)
    191. && (fifthGuess_Word >= 7 && fifthGuess_Word <= 13) && (sixthGuess_Word >= 7 && sixthGuess_Word <= 13)
    192. && (seventhGuess_Word >= 7 && seventhGuess_Word <= 13))
    193. {
    194. yield return new WaitForSeconds(.5f);
    195. Debug.Log("第二行结束");//5~9
    196. btns[firstGuess_Index].interactable = false;
    197. btns[secondGuess_Index].interactable = false;
    198. btns[thirdGuess_Index].interactable = false;
    199. btns[forthGuess_Index].interactable = false;
    200. btns[fifthGuess_Index].interactable = false;
    201. btns[sixthGuess_Index].interactable = false;
    202. btns[seventhGuess_Index].interactable = false;
    203. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    204. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    205. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    206. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    207. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    208. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 0);
    209. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 0);
    210. CheckIfTheGameIsFinished();
    211. }
    212. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word + sixthGuess_Word + seventhGuess_Word == 119)
    213. && (firstGuess_Word >= 14 && firstGuess_Word <= 20) && (secondGuess_Word >= 14 && secondGuess_Word <= 20)
    214. && (thirdGuess_Word >= 14 && thirdGuess_Word <= 20) && (forthGuess_Word >= 14 && forthGuess_Word <= 20)
    215. && (fifthGuess_Word >= 14 && fifthGuess_Word <= 20) && (sixthGuess_Word >= 14 && sixthGuess_Word <= 20)
    216. && (seventhGuess_Word >= 14 && seventhGuess_Word <= 20))
    217. {
    218. yield return new WaitForSeconds(.5f);
    219. Debug.Log("第三行结束");//10~14:10\11\12\13\14
    220. btns[firstGuess_Index].interactable = false;
    221. btns[secondGuess_Index].interactable = false;
    222. btns[thirdGuess_Index].interactable = false;
    223. btns[forthGuess_Index].interactable = false;
    224. btns[fifthGuess_Index].interactable = false;
    225. btns[sixthGuess_Index].interactable = false;
    226. btns[seventhGuess_Index].interactable = false;
    227. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    228. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    229. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    230. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    231. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    232. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 0);
    233. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 0);
    234. CheckIfTheGameIsFinished();
    235. }
    236. else if ((firstGuess_Word + secondGuess_Word + thirdGuess_Word + forthGuess_Word + fifthGuess_Word + sixthGuess_Word + seventhGuess_Word == 168)
    237. && (firstGuess_Word >= 21 && firstGuess_Word <= 27) && (secondGuess_Word >= 21 && secondGuess_Word <= 27)
    238. && (thirdGuess_Word >= 21 && thirdGuess_Word <= 27) && (forthGuess_Word >= 21 && forthGuess_Word <= 27)
    239. && (fifthGuess_Word >= 21 && fifthGuess_Word <= 27) && (sixthGuess_Word >= 21 && sixthGuess_Word <= 27)
    240. && (seventhGuess_Word >= 21 && seventhGuess_Word <= 27))
    241. {
    242. yield return new WaitForSeconds(.5f);
    243. Debug.Log("第四行结束");//15~19; 15\16\17\18\19
    244. btns[firstGuess_Index].interactable = false;
    245. btns[secondGuess_Index].interactable = false;
    246. btns[thirdGuess_Index].interactable = false;
    247. btns[forthGuess_Index].interactable = false;
    248. btns[fifthGuess_Index].interactable = false;
    249. btns[sixthGuess_Index].interactable = false;
    250. btns[seventhGuess_Index].interactable = false;
    251. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    252. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    253. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    254. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    255. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    256. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 0);
    257. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 0);
    258. CheckIfTheGameIsFinished();
    259. }
    260. else
    261. {
    262. yield return new WaitForSeconds(.5f);
    263. //开启蝴蝶图层
    264. hudie[firstGuess_Index].color = new Color(255, 255, 255, 200);
    265. hudie[secondGuess_Index].color = new Color(255, 255, 255, 200);
    266. hudie[thirdGuess_Index].color = new Color(255, 255, 255, 200);
    267. hudie[forthGuess_Index].color = new Color(255, 255, 255, 200);
    268. hudie[fifthGuess_Index].color = new Color(255, 255, 255, 200);
    269. hudie[sixthGuess_Index].color = new Color(255, 255, 255, 200);
    270. hudie[seventhGuess_Index].color = new Color(255, 255, 255, 200);
    271. btns[firstGuess_Index].image.sprite = words[firstGuess_Index];
    272. btns[secondGuess_Index].image.sprite = words[secondGuess_Index];
    273. btns[thirdGuess_Index].image.sprite = words[thirdGuess_Index];
    274. btns[forthGuess_Index].image.sprite = words[forthGuess_Index];
    275. btns[fifthGuess_Index].image.sprite = words[fifthGuess_Index];
    276. btns[sixthGuess_Index].image.sprite = words[sixthGuess_Index];
    277. btns[seventhGuess_Index].image.sprite = words[seventhGuess_Index];
    278. btns[firstGuess_Index].image.color = new Color(0, 0, 0, 0);
    279. btns[secondGuess_Index].image.color = new Color(0, 0, 0, 0);
    280. btns[thirdGuess_Index].image.color = new Color(0, 0, 0, 0);
    281. btns[forthGuess_Index].image.color = new Color(0, 0, 0, 0);
    282. btns[fifthGuess_Index].image.color = new Color(0, 0, 0, 0);
    283. btns[sixthGuess_Index].image.color = new Color(0, 0, 0, 0);
    284. btns[seventhGuess_Index].image.color = new Color(0, 0, 0, 0);
    285. Debug.Log("还原");
    286. }
    287. yield return new WaitForSeconds(.5f);
    288. firstGuess = secondGuess = thirdGuess = forthGuess = fifthGuess = sixthGuess = seventhGuess = false;
    289. }
    290. //返回时间函数
    291. public float returnTime()
    292. {
    293. return timeSpeed;
    294. }
    295. void CheckIfTheGameIsFinished()
    296. {
    297. countCorrectGuess++;
    298. if (countCorrectGuess == gameGuess)
    299. {
    300. // UpDateScore();
    301. TongguanUI.SetActive(true);
    302. Debug.Log("game finished");
    303. Time.timeScale = 0;
    304. //更改玩家得分
    305. UpDateScore();
    306. //进行小关排名
    307. GamePaiMing();
    308. Debug.Log(timeSpeed.ToString("0"));
    309. timeText.text = timeSpeed.ToString("0");
    310. Time.timeScale = 1;
    311. }
    312. }
    313. public void UpDateScore()
    314. {
    315. recentUsername = PlayerPrefs.GetString("reName");
    316. Debug.Log(recentUsername);
    317. //建立连接语句
    318. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    319. //建立连接
    320. MySqlConnection mycon = new MySqlConnection(constr);
    321. //打开连接
    322. mycon.Open();
    323. //获取最后一个用户的用户名
    324. //得到score变化后的值用代码表示为t1.text 该用户的用户名为u1
    325. string selstr = "update 表set score=score+5 where username='" + recentUsername + "'";// + t1.text + "where username = u1";
    326. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    327. if (cmd.ExecuteNonQuery() > 0)
    328. {
    329. print("Insert success!");
    330. }
    331. //小关得分
    332. int flag = 1;
    333. if (timeSpeed >= 250)
    334. {
    335. flag = 0;//如果分数大于250秒则不计入小关排行榜
    336. }
    337. if (flag == 1)
    338. {
    339. string selstr_p7 = "update 表set p7='" + timeSpeed + "'where username='" + recentUsername + "'and p7 > '" + timeSpeed + "'or username='" + recentUsername + "' and p7 = 0";//取最好成绩
    340. MySqlCommand cmd_p7 = new MySqlCommand(selstr_p7, mycon);
    341. if (cmd_p7.ExecuteNonQuery() > 0)
    342. {
    343. print("Insert success!");
    344. }
    345. }
    346. mycon.Close();
    347. }
    348. void GamePaiMing()
    349. {
    350. string constr = "server=服务器公网网址;port=端口;User Id=用户名;password=密码;Database=数据库;charset=utf8";
    351. //建立连接
    352. MySqlConnection mycon = new MySqlConnection(constr);
    353. //打开连接
    354. mycon.Open();
    355. //读取数据
    356. string selstr = "select * from peotry where p7<>0";//注意零分不计入排名
    357. MySqlCommand cmd = new MySqlCommand(selstr, mycon);
    358. MySqlDataReader reader = cmd.ExecuteReader();
    359. string temp1;
    360. string temp2;
    361. List s = new List();
    362. while (reader.Read())
    363. {
    364. temp1 = reader[0].ToString();//用户名
    365. temp2 = reader[9].ToString();//p7得分
    366. s.Add(new user(temp1, int.Parse(temp2)));
    367. }
    368. s.Sort((x, y) => { return x.score.CompareTo(y.score); });//升序排序
    369. texts = " ";
    370. for (int i = 0; i < s.Count; i++)
    371. {
    372. texts += ((i + 1).ToString() + "\t用户名: " + s[i].username + "\t" + " 通关用时: " + s[i].score + " 秒").ToString();
    373. texts += '\n';
    374. texts += '\n';
    375. }
    376. Name_And_Score.text = texts;
    377. mycon.Close();
    378. }
    379. public class user
    380. {
    381. public string username;
    382. public int score;
    383. public user(string username, int score)
    384. {
    385. this.username = username;
    386. this.score = score;
    387. }
    388. }
    389. void AddSprite()//将汉字图片加入汉字图片列表
    390. {
    391. int n = btns.Count;//按钮数
    392. for (int i = 0; i < n; i++)
    393. {
    394. words.Add(gameWords[i]);
    395. }
    396. }
    397. void Shuffle(List list)//图片随机排序
    398. {
    399. for (int i = 0; i < list.Count; i++)
    400. {
    401. Sprite temp = list[i];
    402. int randomIndex = Random.Range(i, list.Count);
    403. list[i] = list[randomIndex];
    404. list[randomIndex] = temp;
    405. }
    406. }
    407. public void showAnser()
    408. {
    409. /*
    410. for(int i = 0; i
    411. {
    412. Debug.Log(words[i]);
    413. //words[i]--Sprite类型
    414. // i 是汉字序号
    415. //第 i 个汉字图片为 words[i]
    416. }
    417. */
    418. int temp1 = Random.Range(0, words.Count);
    419. int temp2 = Random.Range(0, words.Count);
    420. int temp3 = Random.Range(0, words.Count);
    421. AnswerImage1.sprite = words[temp1];
    422. AnswerImage2.sprite = words[temp2];
    423. AnswerImage3.sprite = words[temp3];
    424. anserText1.text = (temp1 + 1).ToString();
    425. anserText2.text = (temp2 + 1).ToString();
    426. anserText3.text = (temp3 + 1).ToString();
    427. }
    428. }

    总结完毕。

    游戏链接:

            链接:https://pan.baidu.com/s/1oT_GgFRgD5em4tY1SfG00A 
            提取码:jc7r 

  • 相关阅读:
    jquery加载初始化的三种方法
    在哪里考华为认证更容易?
    神经网络激活函数有哪些,人工神经网络激活函数
    java本地开发上传图片可见两种处理办法
    C++精通之路:红黑树的应用(模拟实现map/set)
    报错解决——AttributeError: ‘OpenpyxlWriter‘ object has no attribute ‘save‘
    【docker专栏8】使用IDEA远程管理docker镜像及容器服务
    【精讲】vue2框架 路由的使用及案例精讲
    opencv将32位深图片合成视频跳帧解决办法
    Leetcode: 63. 不同路径 II(动态规划)
  • 原文地址:https://blog.csdn.net/qq_51701007/article/details/126314992