0 Replies - 661 Views - Last Post: 19 April 2017 - 11:23 PM Rate Topic: -----

#1 cfischrun  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-April 17

Need help with simon says logic in window builder

Posted 19 April 2017 - 11:23 PM

So, I'm implementing a method that randomly chooses one of the 4 buttons from an enum and adding it to an array. Each time the user clicks one of the buttons it adds it to the player array. I'm having a hard time implementing the logic that will allow the program to add the computers random choice and wait for the user to input their choice. I'm currently playing with a do while loop that I will attach below. The main problem I am having is that the method runs to the end to compare the computer choice to the user's and because it's not allowing me to input the user's choice, it compares the empty user array to the computer array and the game is over.

//	public void game(){
//		
//		do{
//			try{
//				Thread.currentThread();
//				Thread.sleep(1500);
//			}catch(InterruptedException e){
//				e.printStackTrace();
//			}
//			
//			computerPick = computersPick();
//			
//			computer.add(computerPick);
//			
//				for(int i = 0; i < computer.size(); i++){
//					if(computer.get(i) == Buttons.ACKBAR){
//						ackbarClick();
//				}
//			
//					else if(computer.get(i) == Buttons.CHEWY){
//						chewyClick();
//					}
//					
//						else if(computer.get(i) == Buttons.R2D2){
//							r2Click();
//						}
//						
//							else if(computer.get(i) == Buttons.VADER){
//								vaderClick();
//							}
//			}	
//				
//		while(player.isEmpty() || computer.size() - 1 == player.size()){
//			
//			btnVader.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent e) {
//					player.add(Buttons.VADER);
//					
//					if(!compare(player, computer)){
//						JOptionPane.showMessageDialog(null, death());
//						
//						try{
//							Thread.currentThread();
//							Thread.sleep(2000);
//						}catch(InterruptedException f){
//							f.printStackTrace();
//						}
//						clip.start();
//						reset();
//					}
//				}
//			});
//			
//			btnAckbar.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent e) {
//					player.add(Buttons.ACKBAR);
//					
//					if(!compare(player, computer)){
//						JOptionPane.showMessageDialog(null, death());
//						
//						try{
//							Thread.currentThread();
//							Thread.sleep(2000);
//						}catch(InterruptedException f){
//							f.printStackTrace();
//						}
//						clip.start();
//						reset();
//					}
//				}
//			});
//			
//			btnChewy.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent e) {
//					player.add(Buttons.CHEWY);
//					
//					if(!compare(player, computer)){
//						JOptionPane.showMessageDialog(null, death());
//						
//						try{
//							Thread.currentThread();
//							Thread.sleep(2000);
//						}catch(InterruptedException f){
//							f.printStackTrace();
//						}
//						clip.start();
//						reset();
//					}
//				}
//			});
//			
//			btnR2.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent e) {
//					player.add(Buttons.R2D2);
//					
//					if(!compare(player, computer)){
//						JOptionPane.showMessageDialog(null, death());
//						
//						try{
//							Thread.currentThread();
//							Thread.sleep(2000);
//						}catch(InterruptedException f){
//							f.printStackTrace();
//						}
//						clip.start();
//						reset();
//					}
//				}
//			});
//			
//		}
//		
//	}while(compare(player, computer));
//	
//		JOptionPane.showMessageDialog(null, death());
//		
//		try{
//			Thread.currentThread();
//			Thread.sleep(2000);
//		}catch(InterruptedException f){
//			f.printStackTrace();
//		}
//		clip.start();
//		reset();
//		
//	}


This post has been edited by stayscrisp: 22 April 2017 - 03:18 PM
Reason for edit:: Please use code tags when posting code.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1