id
stringlengths
36
36
text
stringlengths
1
1.25M
c842ce73-9dc5-4ac0-923c-d59062dc4649
public Cell(int number){ this.number = number; }
e7bb7875-15d3-416a-a6a0-12e18a3a480f
public void setPiece(Piece piece){ /** Если ячейка не занята, то можно разместить фигуру */ if(this.piece == null){ this.piece = piece; } }
818d7d41-6141-4d7c-8f67-dc20ee745de1
public Piece getPiece(){ return piece; }
d33a7434-f57b-4a1c-a658-a9bbe2a0d64e
public int number(){ return number; }
e612069c-d2a0-48f7-b499-4a1ce1c58349
private Game(int size){ /** создание объекта игрового поля */ field = new Field(size); }
fe952ccc-1873-477a-a8ed-17b695555b06
public static Game init(int size){ return new Game(size); }
22096fc1-cf8a-4db6-9e1d-ca9f40aec104
public boolean addPlayer(String name){ /** Через содержимое ячеек массива определить, были ли уже добавлены игроки */ if(players.size() == 0 || players.size() == 1){ /** объект класса Piece (Фигура игрока) */ Piece piece = null; int index; /** первый играет за крестики */ if(players.get(1) == null){ piece = Piece.X; index = 1; players.put(index, new Player(index, name, piece)); players.get(1).activate(); }else{ /** второй играет за нолики */ piece = Piece.O; index = 2; players.put(index, new Player(index, name, piece)); } /** создать объект класса Player (Игрок) и запомнить его в массиве игроков */ return true; } return false; }
17237e9d-df26-40c5-a27b-be202c520842
public void move(int id, int value){ /** получить игрока по id */ Player player = getPlayer(id); if(player == null || id > 2 || id < 1){ return; } /** "дать задание" объекту класса Поле разместить фигуру на нем */ if (!players.get(id).isActive()) System.out.println("Ваша очередь еще не настала."); if (players.get(id).isActive()) { field.place(player.getPiece(), value); players.get(id).deactivate(); // говночасть, надо подумать как реализовать лучшую масштабируемость, чтобы играли 3 и более игроков и все разными фигурам if (id == 1) players.get(2).activate(); else players.get(1).activate(); } }
491c319d-7494-4539-9904-d2e6d1207a06
public String getState() { return null; }
52bec0eb-490d-43f2-a4de-98325b6fd46b
public Player getPlayer(int id){ return players.get(id); }
ce9e5679-cbf4-468e-8ad7-a999573be137
public Player getNextPlayer(int id){ if (id == 1) return players.get(2); if (id == 2) return players.get(1); return null; }
b8775843-98dc-4bfc-b37e-d3fab0225e19
public int getActivePlayer(){ if (players.get(1).isActive()) return players.get(1).getId(); if (players.get(2).isActive()) return players.get(2).getId(); return 0; }
b62d4f8d-ff7f-4ee9-b053-67ea2b946fd4
MenuPanel() { super(); this.setLayout(new GridLayout(6, 1)); label.setForeground(Color.RED); name1.addMouseListener(new name1Clear()); name2.addMouseListener(new name2Clear()); startGameBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if(inputCheck()) return; size = fieldSize.getValue(); disposeAll(); MainFrame gameFrame = new MainFrame(size, name1.getText(), name2.getText()); } }); fieldSize.setPaintLabels(true); fieldSize.setSnapToTicks(true); fieldSize.setMajorTickSpacing(1); add(label1); add(fieldSize); add(name1); add(name2); add(startGameBtn); add(label); }
4ef1b15f-3902-4775-825e-e7dc40dcbbb8
public void actionPerformed(ActionEvent event) { if(inputCheck()) return; size = fieldSize.getValue(); disposeAll(); MainFrame gameFrame = new MainFrame(size, name1.getText(), name2.getText()); }
aafe4c3f-c2ea-4eff-9622-564ff135d97f
private void disposeAll(){ for (int i = 0; i<frames.length; i++) { frames[i].dispose(); } }
35e94678-c24f-4a17-93f7-c9745883d981
private boolean inputCheck() { if (nameCheck()) return true; if (lengthCheck()) return true; return false; }
27868f7d-b34f-4588-a009-dd692742756f
private boolean nameCheck(){ if(name1.getText().equalsIgnoreCase("") && name2.getText().equalsIgnoreCase("")) { label.setText(" Не введены имена игроков. Введите, пожалуйста, имена."); return true; } if(name1.getText().equalsIgnoreCase("Введите имя первого игрока") || name1.getText().equalsIgnoreCase("") ) { label.setText(" Не введено имя первого игрока. Введите, пожалуйста, имя."); return true; } if(name2.getText().equalsIgnoreCase("Введите имя второго игрока") || name2.getText().equalsIgnoreCase("") ) { label.setText(" Не введено имя второго игрока. Введите, пожалуйста, имя."); return true; } return false; }
74b41329-d1ba-4ee4-b5ea-aa9452f800f3
private boolean lengthCheck(){ if (name1.getText().length() > 25) { label.setText(" Слишком длинное имя первого игрока. Введите более короткое имя."); return true; } if (name2.getText().length() > 25) { label.setText(" Слишком длинное имя второго игрока. Введите более короткое имя."); return true; } return false; }
acc36a20-f265-4151-9770-de716445dec8
public void mouseClicked(MouseEvent event) { if (count1++ == 0) name1.setText(""); }
a99f522d-a536-4ab5-8068-794ff480583b
public void mouseClicked(MouseEvent event) { if (count2++ == 0) name2.setText(""); }
4c1276e3-af84-41f4-adaa-b02134a4da00
public MainFrame(){ super(); init_menu(); }
f5ec5931-9956-4604-b290-6efb038daebc
public MainFrame(int size, String name1, String name2){ super(); GamePanel = new GamePanel(size, this); init_game(); game = Game.init(size); game.addPlayer(name1); game.addPlayer(name2); }
5e281e40-c356-4b0c-8f56-e38a37c4d5a9
private void init_menu(){ width = 550; height = 300; this.setResizable(false); setTitle("Крестики-нолики"); setDefaultCloseOperation(MainFrame.HIDE_ON_CLOSE); frameDisplayCenter(width, height, this); add(MenuPanel); setVisible(true); }
5040bcec-468f-4518-9cfd-07deabbd446d
private void init_game(){ StatusPanel = new StatusPanel(this, GamePanel); add(contentPane); contentPane.setLayout(new GridBagLayout()); gbc.anchor = GridBagConstraints.FIRST_LINE_START; gbc.fill = GridBagConstraints.BOTH; gbc.gridx = 0; gbc.gridy = 0; gbc.weightx = 1.0; gbc.weighty = 0.01; setJMenuBar(menuBar); contentPane.add(StatusPanel, gbc); gbc.weighty = 0.1; gbc.gridy = 1; width = 800; height = 800; setTitle("Крестики-нолики"); setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE); frameDisplayCenter(width, height, this); contentPane.add(GamePanel, gbc); setVisible(true); }
f38fcce3-66b2-4001-bc15-cbb11d59df3d
private static void frameDisplayCenter (int sizeWidth, int sizeHeight, JFrame frame) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setSize(sizeWidth, sizeHeight); int locationX = (screenSize.width - sizeWidth) / 2; int locationY = (screenSize.height - sizeHeight) / 2; frame.setBounds(locationX, locationY, sizeWidth, sizeHeight); }
a0245fef-840e-4e7a-8785-059effc0191b
public MenuBar() { super(); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); local_game.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { MainFrame gameFrame = new MainFrame(); } }); add(gameBtn); gameBtn.add(local_game); gameBtn.add(network_game); help.add(about); help.add(rules); add(help); add(exit); }
42f4eee2-bcf4-4928-8828-e43fea8f2cb4
public void actionPerformed(ActionEvent event) { System.exit(0); }
68c9e8b6-02be-4e58-9d67-47c71519d9da
public void actionPerformed(ActionEvent event) { MainFrame gameFrame = new MainFrame(); }
12fcde69-d515-4c59-9cdd-9468bd4c2e93
GamePanel(int size, MainFrame frame){ this.setSize(size); this.frame = frame; init(); }
ea541b54-e7cd-4e98-8cc6-1fabdc057eac
private void init(){ if(size < 0){ return; } GridLayout layout = new GridLayout(size, size); layout.setHgap(1); layout.setVgap(1); setLayout(layout); cells = new JButton[size * size]; for(int i=0; i < cells.length; i++){ cells[i] = new JButton(""); final JButton button = cells[i]; final int value = i; cells[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int id = frame.game.getActivePlayer(); frame.game.move(id, value); button.setText(frame.game.getPlayer(id).getPiece().toString()); button.setEnabled(false); } }); add(cells[i]); } }
3f9257b6-e2a3-4ee4-bebd-03bd089f20dc
public void actionPerformed(ActionEvent event) { int id = frame.game.getActivePlayer(); frame.game.move(id, value); button.setText(frame.game.getPlayer(id).getPiece().toString()); button.setEnabled(false); }
174d6051-8ff1-4c3a-b508-edd74e8e9ca5
public JButton[] getCells(){ return cells; }
7b72301e-f359-4ed1-9c58-b2580e5d77a9
public void setSize(int size) { this.size = size; }
3f25b3ae-10d0-4441-a2af-4c9494c295e4
StatusPanel(MainFrame frame, GamePanel gamepanel){ super(); this.frame = frame; this.gamePanel = gamepanel; init(); }
1d00a2c5-ca2b-4f7e-8b22-ab90414c67f4
private void init(){ setLayout(new BorderLayout()); setBorder(border_title); add(status, BorderLayout.NORTH); add(piece, BorderLayout.CENTER); add(move, BorderLayout.SOUTH); cells = gamePanel.getCells(); for(int i=0; i < cells.length; i++) { final int number = i; cells[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int id = frame.game.getActivePlayer(); status.setText("Ход игрока: " + frame.game.getNextPlayer(id).getName()); piece.setText("Ваша фигура: " + frame.game.getNextPlayer(id).getPiece().toString()); move.setText("Всего ходов: " + (++count)); } }); } }
10bbd3ba-901b-43f5-9ae3-18d3d3024421
public void actionPerformed(ActionEvent event) { int id = frame.game.getActivePlayer(); status.setText("Ход игрока: " + frame.game.getNextPlayer(id).getName()); piece.setText("Ваша фигура: " + frame.game.getNextPlayer(id).getPiece().toString()); move.setText("Всего ходов: " + (++count)); }
b17ddc99-4a4f-4faf-a8a9-d740d119d18c
@Override public String toString() { return "User[id:"+getId()+" userName:"+username+"]"; }
60c34706-0b12-42aa-80c0-2b8e4bb01bda
public Collection<? extends GrantedAuthority> getAuthorities() { return Lists.newArrayList(new SimpleGrantedAuthority("ROLE_USER")); }
f58f7a14-6370-45f4-9f7b-24a5ef0d4323
public String getPassword() { return password; }
4ac1b79d-62bc-42d2-a995-42a8ba2f5c98
public String getUsername() { // TODO Auto-generated method stub return username; }
69ae4b3e-1299-49f0-bcf3-d8ec71d0f29a
public boolean isAccountNonExpired() { return true; }
b804b8de-aee8-4a27-a793-5b5b3e3dfc91
public boolean isAccountNonLocked() { return true; }
c7fc8b5c-8cb6-4a9c-b83a-dbe44a2578ee
public boolean isCredentialsNonExpired() { return true; }
2677197c-37f2-42aa-9903-b2f8c01a733b
public boolean isEnabled() { return true; }
76205cd9-acb6-4ec9-95d8-a13c6448269e
public void setPassword(String password) { this.password = password; }
e273d7df-1e57-48de-96ef-69267a26e07f
public void setUsername(String username) { this.username = username; }
140d925c-11e2-46c6-977d-29d6f2c90bde
public String getLastName() { return lastName; }
34b2885e-5ddc-4291-aa70-0cf769a1357a
public void setLastName(String lastName) { this.lastName = lastName; }
538768e1-fd0f-459f-a780-d174cec3f6d5
public String getFirstName() { return firstName; }
ef5a7bc6-3090-4eec-9b85-75bbcb31cdf9
public void setFirstName(String firstName) { this.firstName = firstName; }
c794d14a-8d7a-4560-826a-6920257f9e5e
public Person() { }
1bc6286f-75ab-483b-a098-9a4c3917c5ed
public Person(String firstName, String lastName) { super(); this.firstName = firstName; this.lastName = lastName; }
9c1ba336-dc73-4cd2-9a58-828246160488
public Long getId() { return id; }
3dfbea23-17d8-4dba-9466-f6135dba261c
public void setId(Long id) { this.id = id; }
299921b3-d536-4297-acc5-53941ffe098d
public String getFirstName() { return firstName; }
93a9a76b-6aff-4a80-98ae-f8e14aef921b
public void setFirstName(String firstName) { this.firstName = firstName; }
abea2d6e-08fd-4f19-933b-8ba56b709bf9
public String getLastName() { return lastName; }
624477ef-fd28-48bc-892b-1c80e19ee86c
public void setLastName(String lastName) { this.lastName = lastName; }
3411052c-82a6-41b2-b70f-4fcf632aa0ca
@Override public String toString() { return super.toString() + " name = " + firstName + " " + lastName + " id = " + id; }
dd752406-f3d2-4c35-af2b-93d7c1f320af
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); return result; }
7d3c4ccf-2dda-42f7-8653-94fb2888a6fc
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Person other = (Person) obj; if (firstName == null) { if (other.firstName != null) return false; } else if (!firstName.equals(other.firstName)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (lastName == null) { if (other.lastName != null) return false; } else if (!lastName.equals(other.lastName)) return false; return true; }
4963905b-5fc1-46e3-acfe-bb4ede585c28
public Long getId() { return id; }
c4bbad3f-063f-4676-9892-8b9a6287e39e
public void setId(Long id) { this.id = id; }
e91e4a03-fe63-42b4-8685-8b442f331613
public Person find(Long id) { return entityManager.find(Person.class, id); }
c181cbcd-2464-481b-9915-2a4a6b58843e
@SuppressWarnings("unchecked") public List<Person> getPeople() { return entityManager.createQuery("select p from Person p").getResultList(); }
2f212413-02c8-4480-8629-f004c1347284
@Transactional public Person save(Person person) { if (person.getId() == null) { entityManager.persist(person); return person; } else { return entityManager.merge(person); } }
e5a8420c-c605-43db-b875-57ee36a87fd7
public WordVerificationException(String orginal, String was, String shouldBe) { super(); StringBuilder sb = new StringBuilder(); sb.append("Incorrect translation of:").append(orginal).append(" was:").append(was).append(" should be:").append(shouldBe); this.orginal = orginal; this.was = was; this.shouldBe = shouldBe; }
cdfaf544-c6f9-4b03-8988-8018aa4e69ba
@Override public String getMessage() { StringBuilder sb = new StringBuilder(); sb.append("Incorrect translation of:").append(orginal).append(" was:").append(was).append(" should be:").append(shouldBe); return sb.toString(); }
a3f86156-d7e9-4955-b9a9-327459c07af2
public List<String> getWords(int num) { List<String> words = new ArrayList<String>(); if (num >3) { num = 3; } for (int i=0 ;i <num;i++) { Iterator<String> iter = dictionaryMap.keySet().iterator(); words.add(iter.next()); } return words; }
df7e4720-df85-42b2-8720-26274abe5df5
public void verfyWords(Map<String,String> wordsToVerify) { for (String word : wordsToVerify.keySet()) { if (!wordsToVerify.get(word).equals(dictionaryMap.get(word))) { throw new WordVerificationException(word, wordsToVerify.get(word), dictionaryMap.get(word)); } } }
aa8222cf-3723-4c29-99ee-3172d9758c91
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { User result = userRepository.findByUsername(username); if (result == null) { throw new UsernameNotFoundException("Cannot find User with name username"); } return result; }
c048cdef-e0eb-449a-8eea-2ace75b6b3b3
public User findByUsername(String username);
09883a5c-e1b3-4e7d-b8c7-25fa4809d292
@RequestMapping(method=RequestMethod.GET,value="edit") public ModelAndView editPerson(@RequestParam(value="id",required=false) Long id) { logger.debug("Received request to edit person id : "+id); ModelAndView mav = new ModelAndView(); mav.setViewName("person/edit"); Person person = null; if (id == null) { person = new Person(); } else { person = personDao.find(id); } mav.addObject("person", person); return mav; }
d33e7500-34b5-4113-8f03-ceb3de38721a
@RequestMapping(method=RequestMethod.POST,value="edit") public String savePerson(@ModelAttribute Person person) { logger.debug("Received postback on person "+person); personDao.save(person); return "redirect:/person/list"; }
d1688b25-cfbb-4a84-9466-927e40a111f7
@RequestMapping(method=RequestMethod.GET,value="list") public ModelAndView listPeople() { logger.debug("Received request to list persons"); ModelAndView mav = new ModelAndView(); List<Person> people = personDao.getPeople(); logger.debug("Person Listing count = "+people.size()); mav.addObject("people",people); mav.setViewName("person/list"); return mav; }
d57fbde4-30b6-4a94-86b8-43b8588db855
@RequestMapping(value = "/login", method = RequestMethod.GET) public String home(Model model) { return "login"; }
bb120c6a-1c43-433d-b03d-74247850b15e
@RequestMapping(method=RequestMethod.GET) public String get(Model model) { return get(3,model); }
41892e68-8701-4603-b4e8-899ca03f8f19
@RequestMapping(method=RequestMethod.GET, value="{size}") public String get(@PathVariable Integer size,Model model) { model.addAttribute("wordList", wordService.getWords(size)); return "words"; }
c306319c-cc86-4689-826c-395469667e4a
@RequestMapping(method=RequestMethod.POST,value="verifyAll") public String verifyAll() { return null; }
383d1b74-f0b8-4f45-9350-651a69fb1552
@RequestMapping(method=RequestMethod.POST,value="verify/{word}") public String verifyOne(@PathVariable String word, @RequestParam String translation) { return null; }
8c31f87a-d960-4e08-87ea-77ec44b13fa2
@RequestMapping(value = {"/", "/home" }, method = RequestMethod.GET) public String home(Model model) { logger.info("Welcome home!"); model.addAttribute("controllerMessage", "This is the message from the controller!"); return "home"; }
e2af9941-7902-4171-b2cd-d8446cc18347
@Before public void prepareData() { dataInitializer.initData(); }
4d84a93e-363a-4a0a-b2fb-31838d1cc3d8
@Test public void shouldSaveAPerson() { Person p = new Person(); p.setFirstName("Andy"); p.setLastName("Gibson"); personDao.save(p); Long id = p.getId(); Assert.assertNotNull(id); }
08c50b0f-28db-427b-a6bf-42ff0615b166
@Test public void shouldLoadAPerson() { Long template = dataInitializer.people.get(0); Person p = personDao.find(template); Assert.assertNotNull("Person not found!", p); Assert.assertEquals(template, p.getId()); }
56b30ba1-0a31-4e97-bb1e-da9bb5478f9c
public void shouldListPeople() { List<Person> people = personDao.getPeople(); Assert.assertEquals(DataInitializer.PERSON_COUNT, people.size()); }
34ad0b7b-6fed-40b3-bf42-80da7d3ecfbb
@Test(expected= UsernameNotFoundException.class) public void shouldReturnLogin() { userService.loadUserByUsername("bleble"); }
6e526e54-77c6-4d05-a0ff-dd40f369b869
@Before public void before() { dataInitializer.initData(); }
731241fb-e924-451c-a498-4e4b60530cad
@Test public void shouldReturnPersonListView() { ModelAndView mav = personController.listPeople(); assertEquals("list",mav.getViewName()); @SuppressWarnings("unchecked") List<Person> people = (List<Person>) mav.getModelMap().get("people"); assertNotNull(people); assertEquals(DataInitializer.PERSON_COUNT,people.size()); }
376b0295-e284-413a-ac9e-24de35964df6
public void shouldReturnNewPersonWithEditMav() { ModelAndView mav = personController.editPerson(null); assertNotNull(mav); assertEquals("edit", mav.getViewName()); Object object = mav.getModel().get("person"); assertTrue(Person.class.isAssignableFrom(object.getClass())); Person person = (Person) object; assertNull(person.getId()); assertNull(person.getFirstName()); assertNull(person.getLastName()); }
f25cd2a4-2336-43b5-bba3-0a7d7a149baa
@Test public void shouldReturnSecondPersonWithEditMav() { Long template = dataInitializer.people.get(1); ModelAndView mav = personController.editPerson(template); assertNotNull(mav); assertEquals("edit", mav.getViewName()); Object object = mav.getModel().get("person"); assertTrue(Person.class.isAssignableFrom(object.getClass())); Person person = (Person) object; assertEquals(template,person.getId()); }
3e0bbb17-1f88-41eb-9e4c-72337f7dc354
@Test public void testController() { HomeController controller = new HomeController(); Model model = new ExtendedModelMap(); Assert.assertEquals("home",controller.home(model)); Object message = model.asMap().get("controllerMessage"); Assert.assertEquals("This is the message from the controller!",message); }
f8960ff0-99e0-4765-9c15-750403db7063
public void initData() { people.clear();// clear out the previous list of people addPerson("Jim", "Smith"); addPerson("Tina", "Marsh"); addPerson("Steve", "Blair"); entityManager.flush(); entityManager.clear(); }
d164341f-928f-43c1-b826-ee81e63f1505
public void addPerson(String firstName, String lastName) { Person p = new Person(); p.setFirstName(firstName); p.setLastName(lastName); entityManager.persist(p); people.add(p.getId()); }
30a85414-57d4-4be4-84b9-70f88b0b5a26
public EntityManager getEntityManager() { return entityManager; }
abfda177-3f89-479e-8747-b6e402689432
public String getPath() { return path; }
5d0993c7-958c-4c6d-838d-bb17a234ac87
public void setPath(String path) { this.path = path; }
e8d9d19d-5de8-4bc5-8b41-f25f892b28d1
public List<String[]> getListContent() { return listContent; }
6c1b9846-e7a1-4107-acf1-589ca9b73881
public void setListContent(List<String[]> listContent) { this.listContent = listContent; }
0dfb8607-22dd-4269-9282-8485e046212d
public String getSheetName() { return sheetName; }
fe9626f1-537e-439e-9f3c-83c8864fb303
public void setSheetName(String sheetName) { this.sheetName = sheetName; }