java - How to add a score counter to my tic tac toe -


i have tic tac toe game created java swing , want add counter score how many games have been won either player. need counter counts score , don't know how add this

this code below:

package game;  import java.util.scanner;  public class main {      public static  boolean playerturn = true;     public static  boolean playerwon = false;     public static  boolean computerwon = false;     public static  boolean playing = true;     public static  scanner scan = new scanner(system.in);     public static  boolean playagain = false;       public static  tictactoe board = new tictactoe();      public static void main(string[] args){             if(board.isvisible() == false){                 board.setvisible(true);      if(playerwon == true || computerwon == true){      system.out.println("would play again!? true or false");     playagain = scan.nextboolean();     if(playagain == true ){     board.setvisible(false);     system.out.println("player1 won: " + playerwon);     system.out.println("player2 won: " + computerwon);     board.button1.settext("");     board.button2.settext("");     board.button3.settext("");     board.button4.settext("");     board.button5.settext("");     board.button6.settext("");     board.button7.settext("");     board.button8.settext("");     board.button9.settext("");                                                   playerturn = true;     playerwon = false;     computerwon = false;     board.setvisible(true);     else       system.out.println("thanks playing...! ");} 

try , tell me if works. added comment, have changed code.

public static  boolean playerturn = true;         public static  boolean playerwon = false;         public static  boolean computerwon = false;         public static  boolean playing = true;         public static  scanner scan = new scanner(system.in);         public static  boolean playagain = false;         public static  int     player1wincount = 0; //at game start nobody has won         public static  int     player2wincount = 0;           public static  tictactoe board = new tictactoe();          public static void main(string[] args){                 if(board.isvisible() == false){                     board.setvisible(true);      // here added information counter              if (playerwon == true) {             player1wincount++;             system.out.println("the player has won " + player1wincount + " time(s)");         }          if (computerwon == true) {             player2wincount++;             system.out.println("the computer has won " + player2wincount + " time(s)");         }          if(playerwon == true || computerwon == true){          system.out.println("would play again!? true or false");         playagain = scan.nextboolean();         if(playagain == true ){         board.setvisible(false);         system.out.println("player1 won: " + playerwon);         system.out.println("player2 won: " + computerwon);         board.button1.settext("");         board.button2.settext("");         board.button3.settext("");         board.button4.settext("");         board.button5.settext("");         board.button6.settext("");         board.button7.settext("");         board.button8.settext("");         board.button9.settext("");                                                       playerturn = true;         playerwon = false;         computerwon = false;         board.setvisible(true);         else           system.out.println("thanks playing...! ");} 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -