public Game(GameType gT, GardenGraph g, int c) { player2 = new Computer(true); colorBoxes = new List<ColorBox>(); gameType = gT; graph = g; colors = ColorsCreator.GetColors(c); usedColors = new List<Color>(); this.whoseTurn = 0; this.gardenerStartedMove = false; }
public Game(GameType gT, GameMode gM, GardenGraph g, int c, ContentManager content, Player p1, Player p2, GameOrder go) { player2 = new Computer(true); colorBoxes = new List<ColorBox>(); gameType = gT; gameMode = gM; graph = g; gameOrder = go; colors = ColorsCreator.GetColors(c); usedColors = new List<Color>(); this.whoseTurn = 0; this.gardenerStartedMove = false; int distx = 55; int disty = 30; int offset = 10; colorsText = new TextBox(content, "", new Vector2(0, 0), new Vector2(0, 0), "KoloryText"); for(int i =0;i<colors.Length;i++) { Vector2 vect = new Vector2(10+offset + (distx) * (i % 3), 30 +offset + (disty) * ((int)i / 3)); colorBoxes.Add(new ColorBox(colors[i], content, vect)); } player1 = p1; player2 = p2; panels = new List<TextBox>() { new TextBox(content, "",new Vector2(0,0),new Vector2(0,0),"Panel") }; string ps1 = p1.isGardener ? "O: " : "S: "; string ps2 = p2.isGardener ? "O: " : "S: "; WhoseTurnText = new TextBox(content, "Tura: " + (p1.isGardener ? "Ogrodnika" : "Sasiada"), new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(250, 0)), Color.White, null, 0, "CzcionkaUI"); Escape = new Button(Game1.GetRatioDimensions(new Vector2(1010, 740)), content, "wyjscie"); if(p2 is Computer) { PlayersTexts = new TextBox[] { new TextBox(content, ps1 + p1.login, new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(10, 400)), Color.White, null, 0, "CzcionkaUI") }; PlayerPoints = new TextBox[] { new TextBox(content, p1.points.ToString(), new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(30, 440)), Color.White, null, 0, "CzcionkaUI") }; } else { PlayersTexts = new TextBox[] { new TextBox(content, ps1 + p1.login, new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(10, 400)), Color.White, null, 0, "CzcionkaUI"), new TextBox(content, ps2 + p2.login, new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(10, 600)), Color.White, null, 0, "CzcionkaUI"),}; PlayerPoints = new TextBox[] { new TextBox(content, p1.points.ToString(), new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(30, 440)), Color.White, null, 0, "CzcionkaUI"), new TextBox(content, p2.points.ToString(), new Vector2(0, 0), Game1.GetRatioDimensions(new Vector2(30, 640)), Color.White, null, 0, "CzcionkaUI"), }; } }
public void EndGameTest1() { List<Flower> flowers = new List<Flower>() { new Flower(new Vector2(0, 0), 0), new Flower(new Vector2(500, 300), 1), new Flower(new Vector2(300, 150), 2), }; List<Fence> fences = new List<Fence>() { new Fence(flowers[0],flowers[1]), new Fence(flowers[1],flowers[2]), new Fence(flowers[2],flowers[0]), }; GardenGraph gg = new GardenGraph(flowers, fences); GraphColoring.Game game = new GraphColoring.Game(GameType.EdgesColoring, gg, 0); bool result; game.CheckIfEnd(out result); Assert.AreEqual(false, result); }
public void EndGameTest3() { List<Flower> flowers = new List<Flower>() { new Flower(new Vector2(0, 0), 0), new Flower(new Vector2(500, 300), 1), new Flower(new Vector2(300, 150), 2), }; List<Fence> fences = new List<Fence>() { new Fence(flowers[0],flowers[1]), new Fence(flowers[1],flowers[2]), new Fence(flowers[2],flowers[0]), }; GardenGraph gg = new GardenGraph(flowers, fences); GraphColoring.Game game = new GraphColoring.Game(GameType.VerticesColoring, gg, 1); gg.MakeMove(flowers[0], game.colors[0], game); bool result; bool res; result = game.CheckIfEnd(out res); Assert.AreEqual(true, result); }
/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element okna zapytania o ilosc kwiatkow w grafie /// </summary> /// <param name="mousePos"></param> /// <param name="pi"></param> /// <param name="content"></param> public void CheckVerticesAsking(Point mousePos, PlayerInterface pi, ContentManager content) { int i = GetIndex(VerticesButtons, mousePos); if(i>-1) { switch(VerticesButtons[i].name) { case "start": VerticesNr = int.Parse(VerticesNrBuilder.ToString()); if (VerticesNr > 2) { graph = PredefinedGraphs.CreateEmptyGraph(VerticesNr, content); pi.state = InterfaceState.GraphCreation; } break; case "anuluj": pi.state = InterfaceState.MainMenu; break; } } }
public PlayerInterface(ContentManager content) { PlayerSb = new StringBuilder[] { new StringBuilder("Gracz1"), new StringBuilder("Gracz2") }; state = InterfaceState.MainMenu; MainMenuButtons = new List<Button>() { new Button(Game1.GetRatioDimensions(new Vector2(470, 300)), content, "nowa-gra"), new Button(Game1.GetRatioDimensions(new Vector2(440, 400)), content, "stworz-graf"), new Button(Game1.GetRatioDimensions(new Vector2(485, 500)), content, "wyjscie"), }; NewGameTextBoxes = new List<TextBox>() { new TextBox(content,colorsNr.ToString(),Game1.GetRatioDimensions(new Vector2(650,390)),Game1.GetRatioDimensions(new Vector2(845,475)),"liczba-kolorow",0,"CzcionkaUI"), new TextBox(content,"",Game1.GetRatioDimensions(new Vector2(650,50)),new Vector2(0,0),"trybBox"), new TextBox(content,"",Game1.GetRatioDimensions(new Vector2(650,220)),new Vector2(0,0),"kolorowanie"), new TextBox(content,"",Game1.GetRatioDimensions(new Vector2(650,560)),new Vector2(0,0),"gra"), new TextBox(content,"",Game1.GetRatioDimensions(new Vector2(50,560)),new Vector2(0,0),"poziom"), }; p1 = new Player(); p1.isGardener = true; p1.login = "******"; p2 = new Player(); p2.login = "******"; easyMode = true; GraphButtons = new List<ClickableObject>() { new Button(Game1.GetRatioDimensions(new Vector2(50, 50)), content, "graf1"), new Button(Game1.GetRatioDimensions(new Vector2(210, 50)), content, "graf2"), new Button(Game1.GetRatioDimensions(new Vector2(370, 50)), content, "graf3"), }; GameTypeButtons = new List<Button>(){ new Button(Game1.GetRatioDimensions(new Vector2(660, 100)), content, "gra-vs-gra", Color.LightBlue), new Button(Game1.GetRatioDimensions(new Vector2(660, 150)), content, "gra-vs-komp"), }; GameDifButtons = new List<Button>(){ new Button(Game1.GetRatioDimensions(new Vector2(60, 610)), content, "latwy", Color.LightBlue), new Button(Game1.GetRatioDimensions(new Vector2(60, 660)), content, "trudny"), }; GameColoringButtons = new List<Button>(){ new Button(Game1.GetRatioDimensions(new Vector2(660, 260)), content, "kwiatkow", Color.LightBlue), new Button(Game1.GetRatioDimensions(new Vector2(660, 310)), content, "plotkow"), }; GameModeButtons = new List<Button>(){ new Button(Game1.GetRatioDimensions(new Vector2(660, 610)), content, "sasiad-ogrodnik"), new Button(Game1.GetRatioDimensions(new Vector2(660, 660)), content, "ogrodnik-sasiad", Color.LightBlue), }; NewGameButtons = new List<ClickableObject>(){ new Button(Game1.GetRatioDimensions(new Vector2(350, 730)), content, "anuluj"), new Button(Game1.GetRatioDimensions(new Vector2(650, 730)), content, "start"), }; foreach (Button b in GameDifButtons) NewGameButtons.Add(b); foreach (Button b in GameTypeButtons) NewGameButtons.Add(b); foreach (Button b in GameColoringButtons) NewGameButtons.Add(b); foreach (Button b in GameModeButtons) NewGameButtons.Add(b); foreach (ClickableObject b in GraphButtons) NewGameButtons.Add(b); LoginTextBoxes = new List<TextBox>() { new TextBox(content, "Gracz1", Game1.GetRatioDimensions(new Vector2(100, 200)), Game1.GetRatioDimensions(new Vector2(550, 250)), "Gracz1",0,"CzcionkaUI") , new TextBox(content, "Gracz2", Game1.GetRatioDimensions(new Vector2(100, 500)), Game1.GetRatioDimensions(new Vector2(550, 550)), "Gracz2",0,"CzcionkaUI") }; LoginButtons = new List<Button>(){ new Button(Game1.GetRatioDimensions(new Vector2(350, 30)), content, "anuluj"), new Button(Game1.GetRatioDimensions(new Vector2(650, 30)), content, "start"), }; titleTexture = content.Load<Texture2D>("title"); titleVector = Game1.GetRatioDimensions(new Vector2(250, 100)); chosenGraph = null; }
/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element w oknie kreatora nowej gry /// </summary> /// <param name="mousePos"></param> /// <param name="game"></param> /// <param name="content"></param> public void NewGameCheck(Point mousePos, ref Game game, ContentManager content) { for (int i = 0; i < NewGameButtons.Count; i++) { if (NewGameButtons[i].ContainsPoint(mousePos)) { switch (NewGameButtons[i].name) { case "start": if (p1 != null && chosenGraph != null) state = p2 is Computer ? InterfaceState.LoginSingle : InterfaceState.LoginMulti; else Game1.MessageBox(new IntPtr(), "Wybierz graf do rozgrywki", "", 0); break; case "anuluj": state = InterfaceState.MainMenu; break; case "graf1": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[0].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graf2": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[1].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graf3": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[2].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graphcreated": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[NewGameButtons[i].index].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "gra-vs-gra": ClearButtons(GameTypeButtons); p1 = new Player("Gracz1"); p2 = new Player("Gracz2"); UpdateLogins(); UpdatePlayers(); NewGameButtons[i].color = Color.LightBlue; break; case "gra-vs-komp": ClearButtons(GameTypeButtons); p1 = new Player("Gracz1"); p2 = new Computer(easyMode); UpdateLogins(); UpdatePlayers(); NewGameButtons[i].color = Color.LightBlue; break; case "kwiatkow": ClearButtons(GameColoringButtons); gT = GameType.VerticesColoring; NewGameButtons[i].color = Color.LightBlue; break; case "plotkow": ClearButtons(GameColoringButtons); gT = GameType.EdgesColoring; NewGameButtons[i].color = Color.LightBlue; break; case "sasiad-ogrodnik": ClearButtons(GameModeButtons); gO = GameOrder.NG; UpdatePlayers(); NewGameButtons[i].color = Color.LightBlue; break; case "ogrodnik-sasiad": ClearButtons(GameModeButtons); gO = GameOrder.GN; UpdatePlayers(); NewGameButtons[i].color = Color.LightBlue; break; case "latwy": ClearButtons(GameDifButtons); easyMode = true; if(p2 is Computer) { Computer c = p2 as Computer; c.easyMode = true; } NewGameButtons[i].color = Color.LightBlue; break; case "trudny": ClearButtons(GameDifButtons); easyMode = false; if (p2 is Computer) { Computer c = p2 as Computer; c.easyMode = false; } NewGameButtons[i].color = Color.LightBlue; break; } } } }
private bool AreFlowersConnected(Flower f1, Flower f2, GardenGraph graph) { foreach (Fence fence in graph.fences) if ((fence.f1.Equals(f1) && fence.f2.Equals(f2)) || (fence.f1.Equals(f2) && fence.f2.Equals(f1))) return true; return false; }
/// Ponizej fukncje pomocnicze dla powyzszych funkcji /// <summary> /// Pomocnicza funkcja szukajaca niepokolorowanego kwiatka o najmiejszym indeksie /// </summary> /// <param name="flower"></param> /// <param name="n"></param> /// <param name="g"></param> /// <returns></returns> public int FindSmallestIndex(bool flower, int n, GardenGraph g) { if (flower) { for (int i = 0; i < n; i++) { if (g.flowers[i].color == Color.White) return i; } } else { for (int i = 0; i < n; i++) { if (g.fences[i].color == Color.White) return i; } } return -1; }
public void ValidMoveTest2() { List<Flower> flowers = new List<Flower>() { new Flower(new Vector2(0, 0), 0), new Flower(new Vector2(500, 300), 1), }; List<Fence> fences = new List<Fence>() { new Fence(flowers[0],flowers[1]), }; GardenGraph gg = new GardenGraph(flowers, fences); GraphColoring.Game game = new GraphColoring.Game(GameType.EdgesColoring, gg, 0); flowers[0].color = Color.Red; bool result = game.CheckIfValidMove(flowers[1], Color.Red); Assert.AreEqual(false, result); }
private bool AreFencesConnected(Fence f1, Fence f2, GardenGraph graph) { foreach (Fence fence in graph.fences) if (f1.f1.Equals(f2.f1) || f1.f1.Equals(f2.f2) || f1.f2.Equals(f2.f1) || f1.f2.Equals(f2.f2)) return true; return false; }
public PlayerInterface(ContentManager content) { PlayerSb = new StringBuilder[] { new StringBuilder("Player1"), new StringBuilder("Player2") }; state = InterfaceState.MainMenu; MainMenuButtons = new List<Button>() { new Button(new Vector2(470, 300), content, "nowa-gra"), new Button(new Vector2(440, 400), content, "stworz-graf"), new Button(new Vector2(485, 500), content, "wyjscie"), }; NewGameTextBoxes = new List<TextBox>() { new TextBox(content,colorsNr.ToString(),new Vector2(650,220),new Vector2(845,305),"liczba-kolorow",0,"CzcionkaUI"), new TextBox(content,"",new Vector2(650,50),new Vector2(0,0),"kolorowanie"), }; p1 = new Player(); p2 = new Player(); GraphButtons = new List<ClickableObject>() { new Button(new Vector2(50, 50), content, "graf1"), new Button(new Vector2(210, 50), content, "graf2"), new Button(new Vector2(370, 50), content, "graf3"), }; GameColoringButtons = new List<Button>(){ new Button(new Vector2(660, 90), content, "kwiatkow"), new Button(new Vector2(660, 140), content, "plotkow"), }; NewGameButtons = new List<ClickableObject>(){ new Button(new Vector2(350, 730), content, "anuluj"), new Button(new Vector2(650, 730), content, "start"), }; Mode = new List<Button>(){ new Button(new Vector2(400, 400), content, "OhvsSh"), new Button(new Vector2(400, 470), content, "OhvsSe"), new Button(new Vector2(400, 540), content, "OevsSh"), new Button(new Vector2(400, 610), content, "OevsSe") }; foreach (Button b in GameColoringButtons) NewGameButtons.Add(b); foreach (Button b in Mode) NewGameButtons.Add(b); foreach (ClickableObject b in GraphButtons) NewGameButtons.Add(b); LoginTextBoxes = new List<TextBox>() { new TextBox(content, "Player1", new Vector2(100, 200), new Vector2(550, 250), "Gracz1",0,"CzcionkaUI") , new TextBox(content, "Player2", new Vector2(100, 500), new Vector2(550, 550), "Gracz2",0,"CzcionkaUI") }; LoginButtons = new List<Button>(){ new Button(new Vector2(350, 30), content, "anuluj"), new Button(new Vector2(650, 30), content, "start"), }; titleTexture = content.Load<Texture2D>("title"); titleVector = new Vector2(250, 100); chosenGraph = null; }
/// <summary> /// Funkcja sprawdzajaca nacisk myszy na element w oknie kreatora nowej gry /// </summary> /// <param name="mousePos"></param> /// <param name="game"></param> /// <param name="content"></param> public void NewGameCheck(Point mousePos, ref Game game, ContentManager content) { for (int i = 0; i < NewGameButtons.Count; i++) { if (NewGameButtons[i].ContainsPoint(mousePos)) { switch (NewGameButtons[i].name) { case "start": if(p1!=null && chosenGraph != null) { state = InterfaceState.Game; game = new Game(gT,GameMode.ZeroPlayer, chosenGraph, colorsNr, content, p1, p2, gO); } break; case "anuluj": state = InterfaceState.MainMenu; break; case "graf1": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[0].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graf2": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[1].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graf3": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[2].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "graphcreated": ClearButtons(GraphButtons); chosenGraph = PredefinedGraphs.graphs[NewGameButtons[i].index].Copy(); NewGameButtons[i].color = Color.LightBlue; break; case "kwiatkow": ClearButtons(GameColoringButtons); gT = GameType.VerticesColoring; NewGameButtons[i].color = Color.LightBlue; break; case "plotkow": ClearButtons(GameColoringButtons); gT = GameType.EdgesColoring; NewGameButtons[i].color = Color.LightBlue; break; case "OhvsSh": ClearButtons(Mode); NewGameButtons[i].color = Color.LightBlue; p1 = new Computer(false); p1.isGardener = true; p2 = new Computer(false); p2.isGardener = false; break; case "OevsSh": ClearButtons(Mode); NewGameButtons[i].color = Color.LightBlue; p1 = new Computer(true); p1.isGardener = true; p2 = new Computer(false); p2.isGardener = false; break; case "OhvsSe": ClearButtons(Mode); NewGameButtons[i].color = Color.LightBlue; p1 = new Computer(false); p1.isGardener = true; p2 = new Computer(true); p2.isGardener = false; break; case "OevsSe": ClearButtons(Mode); NewGameButtons[i].color = Color.LightBlue; p1 = new Computer(true); p1.isGardener = true; p2 = new Computer(true); p2.isGardener = false; break; } } } }