예제 #1
0
 public String play(Robot r1, Robot r2, int rounds)
 {
     this.r1 = r1;
     this.r2 = r2;
     String output = "";
     int currentRound = 0;
     while (!GameFinished(currentRound, rounds))
     {
         output += Round(currentRound);
         currentRound++;
     }
     output += Winner();
     return output;
 }
예제 #2
0
 //constructor
 public MainMenuGUI()
 {
     InitializeComponent();
     robot = new Robot();
 }
예제 #3
0
 public void setRobot(Robot robotArg)
 {
     robot = robotArg;
 }
예제 #4
0
        /// <summary>
        /// This function saves new robots to the database
        /// </summary>
        /// <param name="r"></param>
        private void saveRobotToDatabase(Robot r)
        {
            String select = "SELECT TOP 1 robotID FROM robot ORDER BY robotID DESC;";
            String insertRobot = "INSERT INTO robot (Name, Life, Win, Draw, Loose) VALUES ('" + r.Name + "', " + r.Liv + ", " + r.Sejre + ", " + r.Uafgjorte + ", " + r.Tab + ");";
            String insertRound = "";
            SqlConnection cnn = new SqlConnection(@"Data Source=WIN-6LM7OUC6HFS\MYSQL;Initial Catalog=Robot;Integrated Security=True");
            cnn.Open();

            SqlCommand myCommand = new SqlCommand(insertRobot, cnn);
            myCommand.ExecuteNonQuery();
            myCommand = new SqlCommand(select, cnn);
            SqlDataReader myReader = myCommand.ExecuteReader();
            myReader.Read();
            int rID = (int)myReader["RobotID"];
            myReader.Close();

            for (int i = 0; i < r.Skjold_Vaaben.Length; i++)
            {
                insertRound += "Insert INTO round (RobotID, RoundID, Shield, Weapon) VALUES (" + rID + ", " + (i + 1) + ", " + r.Skjold_Vaaben[i][0] + ", " + r.Skjold_Vaaben[i][1] + ");";
            }

            SqlTransaction tn = cnn.BeginTransaction();
            myCommand = new SqlCommand(insertRound, cnn);
            myCommand.Transaction = tn;
            myCommand.ExecuteNonQuery();
            tn.Commit();
            cnn.Close();
            r.RID = rID;
        }
예제 #5
0
 private String robotStr(Robot r)
 {
     return "Update Robot Set Win = " + r.Sejre + ", Draw = " + r.Uafgjorte + ", Loose = " + r.Tab + " where RobotID = " + r.RID + ";";
 }
예제 #6
0
 private void readFiles()
 {
     FileUpload1.SaveAs(robot1);
     FileUpload2.SaveAs(robot2);
     //XmlDocument xml1 = new XmlDocument();
     //XmlDocument xml2 = new XmlDocument();
     xml1.Load(robot1);
     xml2.Load(robot2);
     r1 = parseFiles(xml1);
     r2 = parseFiles(xml2);
 }
예제 #7
0
        private Robot parseFiles(XmlDocument xml)
        {
            String navn = xml.GetElementsByTagName("navn").Item(0).InnerText;
            XmlNodeList list = xml.GetElementsByTagName("runde");
            int[][] skjold_vaaben = new int[list.Count][];

            for (int i = 0; i < list.Count; i++)
            {
                XmlAttributeCollection attr = list[i].Attributes;
                int[] x = new int[2];
                //skjold_vaaben[i][0] = Convert.ToInt32(attr[0].Value);
                //skjold_vaaben[i][1] = Convert.ToInt32(attr[1].Value);
                x[0] = Convert.ToInt32(attr[0].Value);
                x[1] = Convert.ToInt32(attr[1].Value);
                skjold_vaaben[i] = x;
            }
            int tab = Convert.ToInt32(xml.GetElementsByTagName("tab").Item(0).InnerText);
            int sejre = Convert.ToInt32(xml.GetElementsByTagName("sejre").Item(0).InnerText);
            int liv = Convert.ToInt32(xml.GetElementsByTagName("liv").Item(0).InnerText);
            int uafgjorte = Convert.ToInt32(xml.GetElementsByTagName("uafgjort").Item(0).InnerText);

            Robot r = new Robot();
            r.Liv = liv;
            r.Tab = tab;
            r.Sejre = sejre;
            r.Uafgjorte = uafgjorte;
            r.Skjold_Vaaben = skjold_vaaben;
            r.Name = navn;
            saveRobotToDatabase(r);
            return r;
        }